Lines 1-26
Link Here
|
1 |
package org.eclipse.ui.examples.jobs.views; |
1 |
package org.eclipse.ui.examples.jobs.views; |
2 |
|
2 |
|
|
|
3 |
import java.io.File; |
3 |
import java.lang.reflect.InvocationTargetException; |
4 |
import java.lang.reflect.InvocationTargetException; |
|
|
5 |
import java.net.MalformedURLException; |
6 |
import java.net.URL; |
4 |
|
7 |
|
5 |
import org.eclipse.core.resources.IWorkspaceRunnable; |
8 |
import org.eclipse.core.resources.IWorkspaceRunnable; |
6 |
import org.eclipse.core.resources.ResourcesPlugin; |
9 |
import org.eclipse.core.resources.ResourcesPlugin; |
7 |
import org.eclipse.core.runtime.*; |
10 |
import org.eclipse.core.runtime.CoreException; |
|
|
11 |
import org.eclipse.core.runtime.IProgressMonitor; |
12 |
import org.eclipse.core.runtime.IStatus; |
13 |
import org.eclipse.core.runtime.NullProgressMonitor; |
14 |
import org.eclipse.core.runtime.OperationCanceledException; |
15 |
import org.eclipse.core.runtime.Platform; |
16 |
import org.eclipse.core.runtime.Status; |
8 |
import org.eclipse.core.runtime.jobs.Job; |
17 |
import org.eclipse.core.runtime.jobs.Job; |
9 |
import org.eclipse.jface.action.Action; |
18 |
import org.eclipse.jface.action.Action; |
10 |
import org.eclipse.jface.dialogs.IDialogConstants; |
19 |
import org.eclipse.jface.dialogs.IDialogConstants; |
11 |
import org.eclipse.jface.dialogs.MessageDialog; |
20 |
import org.eclipse.jface.dialogs.MessageDialog; |
12 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
21 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
|
|
22 |
import org.eclipse.jface.resource.ImageDescriptor; |
13 |
import org.eclipse.swt.SWT; |
23 |
import org.eclipse.swt.SWT; |
14 |
import org.eclipse.swt.events.SelectionAdapter; |
24 |
import org.eclipse.swt.events.SelectionAdapter; |
15 |
import org.eclipse.swt.events.SelectionEvent; |
25 |
import org.eclipse.swt.events.SelectionEvent; |
16 |
import org.eclipse.swt.layout.GridData; |
26 |
import org.eclipse.swt.layout.GridData; |
17 |
import org.eclipse.swt.layout.GridLayout; |
27 |
import org.eclipse.swt.layout.GridLayout; |
18 |
import org.eclipse.swt.widgets.*; |
28 |
import org.eclipse.swt.widgets.Button; |
|
|
29 |
import org.eclipse.swt.widgets.Combo; |
30 |
import org.eclipse.swt.widgets.Composite; |
31 |
import org.eclipse.swt.widgets.FileDialog; |
32 |
import org.eclipse.swt.widgets.Group; |
33 |
import org.eclipse.swt.widgets.Label; |
34 |
import org.eclipse.swt.widgets.Text; |
19 |
import org.eclipse.ui.PlatformUI; |
35 |
import org.eclipse.ui.PlatformUI; |
20 |
import org.eclipse.ui.actions.WorkspaceModifyOperation; |
36 |
import org.eclipse.ui.actions.WorkspaceModifyOperation; |
|
|
37 |
import org.eclipse.ui.examples.jobs.ProgressExamplesPlugin; |
21 |
import org.eclipse.ui.examples.jobs.TestJob; |
38 |
import org.eclipse.ui.examples.jobs.TestJob; |
22 |
import org.eclipse.ui.examples.jobs.TestJobRule; |
39 |
import org.eclipse.ui.examples.jobs.TestJobRule; |
23 |
import org.eclipse.ui.examples.jobs.UITestJob; |
40 |
import org.eclipse.ui.examples.jobs.UITestJob; |
|
|
41 |
import org.eclipse.ui.internal.util.BundleUtility; |
24 |
import org.eclipse.ui.part.ViewPart; |
42 |
import org.eclipse.ui.part.ViewPart; |
25 |
import org.eclipse.ui.progress.IProgressConstants; |
43 |
import org.eclipse.ui.progress.IProgressConstants; |
26 |
import org.eclipse.ui.progress.IProgressService; |
44 |
import org.eclipse.ui.progress.IProgressService; |
Lines 37-42
Link Here
|
37 |
private Text quantityField, delayField, rescheduleDelay; |
55 |
private Text quantityField, delayField, rescheduleDelay; |
38 |
private Button schedulingRuleField; |
56 |
private Button schedulingRuleField; |
39 |
private Button noPromptField; |
57 |
private Button noPromptField; |
|
|
58 |
private Button defaultIconField; |
59 |
private ImageDescriptor normalIcon1; |
60 |
private ImageDescriptor normalIcon2; |
61 |
private ImageDescriptor normalIcon3; |
62 |
private ImageDescriptor bigIcon; |
63 |
private ImageDescriptor otherIcon; |
64 |
|
65 |
private Button normalIconField1; |
66 |
private Button normalIconField2; |
67 |
private Button normalIconField3; |
68 |
private Button bigIconField; |
69 |
private Button otherIconField; |
40 |
|
70 |
|
41 |
protected void busyCursorWhile() { |
71 |
protected void busyCursorWhile() { |
42 |
try { |
72 |
try { |
Lines 100-105
Link Here
|
100 |
result = new TestJob(duration, lock, failure, unknown, |
130 |
result = new TestJob(duration, lock, failure, unknown, |
101 |
reschedule, rescheduleWait); |
131 |
reschedule, rescheduleWait); |
102 |
|
132 |
|
|
|
133 |
setIcon(result); |
134 |
|
103 |
result.setProperty(IProgressConstants.KEEP_PROPERTY, Boolean |
135 |
result.setProperty(IProgressConstants.KEEP_PROPERTY, Boolean |
104 |
.valueOf(keep)); |
136 |
.valueOf(keep)); |
105 |
result.setProperty(IProgressConstants.KEEPONE_PROPERTY, Boolean |
137 |
result.setProperty(IProgressConstants.KEEPONE_PROPERTY, Boolean |
Lines 128-133
Link Here
|
128 |
} |
160 |
} |
129 |
} |
161 |
} |
130 |
|
162 |
|
|
|
163 |
private void setIcon(Job result) { |
164 |
if(defaultIconField.getSelection()) |
165 |
return; |
166 |
|
167 |
ImageDescriptor imageDesc; |
168 |
if(normalIconField1.getSelection()) |
169 |
imageDesc = normalIcon1; |
170 |
else if(normalIconField2.getSelection()) |
171 |
imageDesc = normalIcon2; |
172 |
else if(normalIconField3.getSelection()) |
173 |
imageDesc = normalIcon3; |
174 |
else if(bigIconField.getSelection()) |
175 |
imageDesc = bigIcon; |
176 |
else |
177 |
imageDesc = otherIcon; |
178 |
|
179 |
result.setProperty(IProgressConstants.ICON_PROPERTY, imageDesc); |
180 |
|
181 |
} |
182 |
|
131 |
/** |
183 |
/** |
132 |
* @see ViewPart#createPartControl(Composite) |
184 |
* @see ViewPart#createPartControl(Composite) |
133 |
*/ |
185 |
*/ |
Lines 242-247
Link Here
|
242 |
doSleep(); |
294 |
doSleep(); |
243 |
} |
295 |
} |
244 |
}); |
296 |
}); |
|
|
297 |
// join the running test jobs |
298 |
Button cancel = new Button(group, SWT.PUSH); |
299 |
cancel.setText("Cancel"); //$NON-NLS-1$ |
300 |
cancel.setToolTipText("Calls cancel() on all TestJobs"); //$NON-NLS-1$ |
301 |
cancel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
302 |
cancel.addSelectionListener(new SelectionAdapter() { |
303 |
public void widgetSelected(SelectionEvent e) { |
304 |
cancelTestJobs(); |
305 |
} |
306 |
}); |
307 |
|
308 |
// join the running test jobs |
309 |
Button beginRule = new Button(group, SWT.PUSH); |
310 |
beginRule.setText("beginRule: Root "); //$NON-NLS-1$ |
311 |
beginRule.setToolTipText("Calls beginRule in UI thread"); //$NON-NLS-1$ |
312 |
beginRule.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
313 |
beginRule.addSelectionListener(new SelectionAdapter() { |
314 |
public void widgetSelected(SelectionEvent e) { |
315 |
try { |
316 |
Job.getJobManager().beginRule(ResourcesPlugin.getWorkspace().getRoot(), null); |
317 |
} catch (OperationCanceledException ee) { |
318 |
MessageDialog.openInformation(e.display.getActiveShell(), "Canceled", "Operation canceled"); |
319 |
return; |
320 |
} finally { |
321 |
Job.getJobManager().endRule(ResourcesPlugin.getWorkspace().getRoot()); |
322 |
} |
323 |
MessageDialog.openInformation(e.display.getActiveShell(), "Ran", "Operation Ran"); |
324 |
} |
325 |
}); |
326 |
|
245 |
|
327 |
|
246 |
// join the running test jobs |
328 |
// join the running test jobs |
247 |
Button wake = new Button(group, SWT.PUSH); |
329 |
Button wake = new Button(group, SWT.PUSH); |
Lines 447-452
Link Here
|
447 |
noPromptField |
529 |
noPromptField |
448 |
.setToolTipText("Set the IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY to true"); |
530 |
.setToolTipText("Set the IProgressConstants.NO_IMMEDIATE_ERROR_PROMPT_PROPERTY to true"); |
449 |
noPromptField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
531 |
noPromptField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
|
|
532 |
|
533 |
Group imageGroup = new Group(group, SWT.NONE); |
534 |
imageGroup.setText("Image:"); |
535 |
imageGroup.setLayout(new GridLayout()); |
536 |
|
537 |
defaultIconField = new Button(imageGroup, SWT.RADIO); |
538 |
defaultIconField.setText("None"); |
539 |
defaultIconField.setSelection(true); |
540 |
|
541 |
normalIcon1 = ImageDescriptor.createFromURL(BundleUtility.find(ProgressExamplesPlugin.ID, "/icons/sample.gif")); |
542 |
|
543 |
normalIconField1 = new Button(imageGroup, SWT.RADIO); |
544 |
normalIconField1.setSelection(false); |
545 |
normalIconField1.setImage(normalIcon1.createImage()); |
546 |
|
547 |
normalIcon2 = ImageDescriptor.createFromURL(BundleUtility.find(ProgressExamplesPlugin.ID, "/icons/cvs_persp.gif")); |
548 |
|
549 |
normalIconField2 = new Button(imageGroup, SWT.RADIO); |
550 |
normalIconField2.setSelection(false); |
551 |
normalIconField2.setImage(normalIcon2.createImage()); |
552 |
|
553 |
normalIcon3 = ImageDescriptor.createFromURL(BundleUtility.find(ProgressExamplesPlugin.ID, "/icons/site_obj.gif")); |
554 |
|
555 |
normalIconField3 = new Button(imageGroup, SWT.RADIO); |
556 |
normalIconField3.setSelection(false); |
557 |
normalIconField3.setImage(normalIcon3.createImage()); |
558 |
|
559 |
|
560 |
bigIcon = ImageDescriptor.createFromURL(BundleUtility.find(ProgressExamplesPlugin.ID, "/icons/export_wiz.png")); |
561 |
|
562 |
bigIconField = new Button(imageGroup, SWT.RADIO); |
563 |
bigIconField.setSelection(false); |
564 |
bigIconField.setImage(bigIcon.createImage()); |
565 |
|
566 |
otherIconField = new Button(imageGroup, SWT.RADIO); |
567 |
otherIconField.setSelection(false); |
568 |
otherIconField.setText("Other..."); |
569 |
otherIconField.addSelectionListener(new SelectionAdapter() { |
570 |
@Override |
571 |
public void widgetSelected(SelectionEvent e) { |
572 |
FileDialog dialog = new FileDialog(getSite().getShell()); |
573 |
dialog.setFilterExtensions(new String[] {"*.gif;*.png"}); |
574 |
dialog.setFilterNames(new String[] {"Icon images"}); |
575 |
if(dialog.open() == null) |
576 |
return; |
577 |
try { |
578 |
otherIcon = ImageDescriptor.createFromURL(new URL("file://"+dialog.getFilterPath()+File.separatorChar+dialog.getFileName())); |
579 |
} catch (MalformedURLException e1) { |
580 |
MessageDialog.openError(getSite().getShell(), "Error", e1.getMessage()); |
581 |
defaultIconField.setSelection(true); |
582 |
} |
583 |
|
584 |
} |
585 |
}); |
586 |
|
450 |
} |
587 |
} |
451 |
|
588 |
|
452 |
protected void doRun(long duration, IProgressMonitor monitor) { |
589 |
protected void doRun(long duration, IProgressMonitor monitor) { |
Lines 544-549
Link Here
|
544 |
e.printStackTrace(); |
681 |
e.printStackTrace(); |
545 |
} |
682 |
} |
546 |
} |
683 |
} |
|
|
684 |
protected void cancelTestJobs() { |
685 |
try { |
686 |
// note that when a null progress monitor is used when in the UI |
687 |
// thread, the workbench will create a default progress monitor |
688 |
// that reports progress in a modal dialog with details area |
689 |
PlatformUI.getWorkbench().getProgressService().busyCursorWhile( |
690 |
new IRunnableWithProgress() { |
691 |
public void run(IProgressMonitor monitor) |
692 |
throws InterruptedException { |
693 |
Job.getJobManager().cancel(TestJob.FAMILY_TEST_JOB); |
694 |
} |
695 |
}); |
696 |
} catch (InterruptedException e) { |
697 |
// thrown if the user interrupts the join by canceling the progress |
698 |
// monitor |
699 |
// A UI component should swallow the exception and finish the action |
700 |
// or operation. A lower level component should just propagate the |
701 |
// exception |
702 |
e.printStackTrace(); |
703 |
} catch (InvocationTargetException e) { |
704 |
// Thrown when the operation running within busyCursorWhile throws |
705 |
// an |
706 |
// exception. This should either be propagated or displayed to the |
707 |
// user |
708 |
e.printStackTrace(); |
709 |
} |
710 |
} |
547 |
|
711 |
|
548 |
protected void progressNoFork() { |
712 |
protected void progressNoFork() { |
549 |
try { |
713 |
try { |