|
Lines 9-42
Link Here
|
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.ui.internal.progress; |
11 |
package org.eclipse.ui.internal.progress; |
| 12 |
import org.eclipse.core.runtime.IProgressMonitor; |
12 |
import org.eclipse.core.runtime.*; |
| 13 |
import org.eclipse.core.runtime.IStatus; |
|
|
| 14 |
import org.eclipse.jface.dialogs.Dialog; |
13 |
import org.eclipse.jface.dialogs.Dialog; |
| 15 |
import org.eclipse.jface.dialogs.IconAndMessageDialog; |
14 |
import org.eclipse.jface.dialogs.IconAndMessageDialog; |
| 16 |
import org.eclipse.jface.resource.JFaceResources; |
15 |
import org.eclipse.jface.resource.JFaceResources; |
| 17 |
import org.eclipse.jface.viewers.IContentProvider; |
16 |
import org.eclipse.jface.viewers.*; |
| 18 |
import org.eclipse.jface.viewers.Viewer; |
|
|
| 19 |
import org.eclipse.jface.viewers.ViewerSorter; |
| 20 |
import org.eclipse.swt.SWT; |
17 |
import org.eclipse.swt.SWT; |
| 21 |
import org.eclipse.swt.graphics.Cursor; |
18 |
import org.eclipse.swt.graphics.Cursor; |
| 22 |
import org.eclipse.swt.graphics.Image; |
19 |
import org.eclipse.swt.graphics.Image; |
| 23 |
import org.eclipse.swt.layout.GridData; |
20 |
import org.eclipse.swt.layout.GridData; |
| 24 |
import org.eclipse.swt.widgets.Button; |
21 |
import org.eclipse.swt.widgets.*; |
| 25 |
import org.eclipse.swt.widgets.Composite; |
22 |
import org.eclipse.ui.PlatformUI; |
| 26 |
import org.eclipse.swt.widgets.Control; |
23 |
import org.eclipse.ui.internal.WorkbenchMessages; |
| 27 |
import org.eclipse.swt.widgets.Shell; |
24 |
import org.eclipse.ui.progress.WorkbenchJob; |
| 28 |
import org.eclipse.swt.widgets.TreeItem; |
|
|
| 29 |
/** |
25 |
/** |
| 30 |
* The BlockedJobsDialog class displays a dialog that provides information on |
26 |
* The BlockedJobsDialog class displays a dialog that provides information on |
| 31 |
* the running jobs. |
27 |
* the running jobs. |
| 32 |
*/ |
28 |
*/ |
| 33 |
public class BlockedJobsDialog extends IconAndMessageDialog { |
29 |
public class BlockedJobsDialog extends IconAndMessageDialog { |
| 34 |
/** |
30 |
/** |
|
|
31 |
* The singleton dialog instance. A singleton avoids the possibility |
| 32 |
* of recursive dialogs being created. The singleton is created |
| 33 |
* when a dialog is requested, and cleared when the dialog is disposed. |
| 34 |
*/ |
| 35 |
protected static BlockedJobsDialog singleton; |
| 36 |
|
| 37 |
/** |
| 35 |
* The running jobs progress tree. |
38 |
* The running jobs progress tree. |
| 36 |
* |
39 |
* |
| 37 |
* @see /org.eclipse.ui.workbench/Eclipse |
40 |
* @see org.eclipse.ui.internal.progress.ProgressTreeViewer |
| 38 |
* UI/org/eclipse/ui/internal/progress/ProgressTreeViewer.java |
|
|
| 39 |
* (org.eclipse.ui.internal.progress) |
| 40 |
*/ |
41 |
*/ |
| 41 |
private ProgressTreeViewer viewer; |
42 |
private ProgressTreeViewer viewer; |
| 42 |
/** |
43 |
/** |
|
Lines 141-146
Link Here
|
| 141 |
} |
142 |
} |
| 142 |
/** |
143 |
/** |
| 143 |
* Creates a progress monitor dialog under the given shell. It also sets the |
144 |
* Creates a progress monitor dialog under the given shell. It also sets the |
|
|
145 |
* dialog's message. The dialog is opened automatically after a reasonable delay. |
| 146 |
* When no longer needed, the dialog must be closed by calling |
| 147 |
* <code>close(IProgressMonitor)</code>, where the supplied monitor is the |
| 148 |
* same monitor passed to this factory method. |
| 149 |
* |
| 150 |
* @param parentShell |
| 151 |
* The parent shell, or <code>null</code> to create a top-level shell. |
| 152 |
* @param monitor |
| 153 |
* The monitor that is currently blocked |
| 154 |
* @param reason |
| 155 |
* A status describing why the monitor is blocked |
| 156 |
*/ |
| 157 |
public static BlockedJobsDialog createBlockedDialog(Shell parentShell, IProgressMonitor monitor, IStatus reason) { |
| 158 |
//use an existing dialog if available |
| 159 |
if (singleton != null) |
| 160 |
return singleton; |
| 161 |
singleton = new BlockedJobsDialog(parentShell, monitor, reason); |
| 162 |
|
| 163 |
//create the job that will open the dialog after a delay. |
| 164 |
WorkbenchJob dialogJob = new WorkbenchJob(WorkbenchMessages.getString("EventLoopProgressMonitor.OpenDialogJobName")){ //$NON-NLS-1$ |
| 165 |
/* (non-Javadoc) |
| 166 |
* @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor) |
| 167 |
*/ |
| 168 |
public IStatus runInUIThread(IProgressMonitor monitor) { |
| 169 |
if(singleton == null) |
| 170 |
return Status.CANCEL_STATUS; |
| 171 |
if(ProgressManagerUtil.rescheduleIfModalShellOpen(this)) |
| 172 |
return Status.CANCEL_STATUS; |
| 173 |
singleton.open(); |
| 174 |
return Status.OK_STATUS; |
| 175 |
} |
| 176 |
}; |
| 177 |
|
| 178 |
//Wait for long operation time to prevent a proliferation |
| 179 |
//of dialogs |
| 180 |
dialogJob.setSystem(true); |
| 181 |
dialogJob.schedule(PlatformUI.getWorkbench().getProgressService().getLongOperationTime()); |
| 182 |
return singleton; |
| 183 |
} |
| 184 |
/** |
| 185 |
* Creates a progress monitor dialog under the given shell. It also sets the |
| 144 |
* dialog's\ message. <code>open</code> is non-blocking. |
186 |
* dialog's\ message. <code>open</code> is non-blocking. |
| 145 |
* |
187 |
* |
| 146 |
* @param parentShell |
188 |
* @param parentShell |
|
Lines 148-155
Link Here
|
| 148 |
* shell. |
190 |
* shell. |
| 149 |
* @param blocking |
191 |
* @param blocking |
| 150 |
* The monitor that is blocking the job |
192 |
* The monitor that is blocking the job |
|
|
193 |
* @param blockingStatus |
| 194 |
* A status describing why the monitor is blocked |
| 151 |
*/ |
195 |
*/ |
| 152 |
public BlockedJobsDialog(Shell parentShell, IProgressMonitor blocking, |
196 |
private BlockedJobsDialog(Shell parentShell, IProgressMonitor blocking, |
| 153 |
IStatus blockingStatus) { |
197 |
IStatus blockingStatus) { |
| 154 |
super(parentShell == null |
198 |
super(parentShell == null |
| 155 |
? ProgressManagerUtil.getDefaultParent() |
199 |
? ProgressManagerUtil.getDefaultParent() |
|
Lines 242-248
Link Here
|
| 242 |
} |
286 |
} |
| 243 |
}; |
287 |
}; |
| 244 |
} |
288 |
} |
| 245 |
|
|
|
| 246 |
/** |
289 |
/** |
| 247 |
* Clear the cursors in the dialog. |
290 |
* Clear the cursors in the dialog. |
| 248 |
*/ |
291 |
*/ |
|
Lines 300-313
Link Here
|
| 300 |
protected Image getImage() { |
343 |
protected Image getImage() { |
| 301 |
return JFaceResources.getImageRegistry().get(Dialog.DLG_IMG_INFO); |
344 |
return JFaceResources.getImageRegistry().get(Dialog.DLG_IMG_INFO); |
| 302 |
} |
345 |
} |
| 303 |
/* |
346 |
/** |
| 304 |
* (non-Javadoc) |
347 |
* Returns the progress monitor being used for this dialog. This allows recursive |
| 305 |
* |
348 |
* blockages to also respond to cancelation. |
| 306 |
* @see org.eclipse.jface.dialogs.Dialog#close() |
349 |
* @return |
| 307 |
*/ |
350 |
*/ |
| 308 |
public boolean close() { |
351 |
public IProgressMonitor getProgressMonitor() { |
| 309 |
clearCursors(); |
352 |
return blockingMonitor; |
| 310 |
return super.close(); |
353 |
} |
|
|
354 |
/** |
| 355 |
* Requests that the blocked jobs dialog be closed. The supplied monitor |
| 356 |
* must be the same one that was passed to the createBlockedDialog method. |
| 357 |
*/ |
| 358 |
public boolean close(IProgressMonitor monitor) { |
| 359 |
//ignore requests to close the dialog from all but the first monitor |
| 360 |
if (blockingMonitor != monitor) |
| 361 |
return false; |
| 362 |
try { |
| 363 |
clearCursors(); |
| 364 |
return super.close(); |
| 365 |
} finally { |
| 366 |
//make sure the singleton is discarded, even in case of failure |
| 367 |
singleton = null; |
| 368 |
} |
| 311 |
} |
369 |
} |
| 312 |
/** |
370 |
/** |
| 313 |
* Set the name of the task being blocked. If this value is not set then the |
371 |
* Set the name of the task being blocked. If this value is not set then the |
|
Lines 325-329
Link Here
|
| 325 |
protected Control createButtonBar(Composite parent) { |
383 |
protected Control createButtonBar(Composite parent) { |
| 326 |
// Do nothing here as we want no buttons |
384 |
// Do nothing here as we want no buttons |
| 327 |
return parent; |
385 |
return parent; |
| 328 |
} |
386 |
}} |
| 329 |
} |
|
|