Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 51996
Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/dialogs/EventLoopProgressMonitor.java (-45 / +21 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
2
 * Copyright (c) 2000, 2004 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials 
3
 * All rights reserved. This program and the accompanying materials 
4
 * are made available under the terms of the Common Public License v1.0
4
 * are made available under the terms of the Common Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 9-26 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.dialogs;
11
package org.eclipse.ui.internal.dialogs;
12
import org.eclipse.core.runtime.IProgressMonitor;
12
import org.eclipse.core.runtime.*;
13
import org.eclipse.core.runtime.IProgressMonitorWithBlocking;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.ProgressMonitorWrapper;
16
import org.eclipse.core.runtime.Status;
17
import org.eclipse.swt.widgets.Display;
13
import org.eclipse.swt.widgets.Display;
18
import org.eclipse.ui.PlatformUI;
19
import org.eclipse.ui.internal.ExceptionHandler;
14
import org.eclipse.ui.internal.ExceptionHandler;
20
import org.eclipse.ui.internal.WorkbenchMessages;
21
import org.eclipse.ui.internal.progress.BlockedJobsDialog;
15
import org.eclipse.ui.internal.progress.BlockedJobsDialog;
22
import org.eclipse.ui.internal.progress.ProgressManagerUtil;
23
import org.eclipse.ui.progress.WorkbenchJob;
24
/**
16
/**
25
 * Used to run an event loop whenever progress monitor methods
17
 * Used to run an event loop whenever progress monitor methods
26
 * are invoked.  <p>
18
 * are invoked.  <p>
Lines 40-49 Link Here
40
	 * Maximum amount of time to spend processing events, in ms.
32
	 * Maximum amount of time to spend processing events, in ms.
41
	 */
33
	 */
42
	private static int T_MAX = 50;
34
	private static int T_MAX = 50;
35
	
43
	/**
36
	/**
44
	 * The dialog that is shown when the operation is blocked
37
	 * The dialog that is shown when the operation is blocked, or null when no
38
	 * operation in the UI thread is blocked. 
45
	 */
39
	 */
46
	private BlockedJobsDialog dialog;
40
	protected BlockedJobsDialog dialog;
41
	
47
	/**
42
	/**
48
	 * Last time the event loop was spun.
43
	 * Last time the event loop was spun.
49
	 */
44
	 */
Lines 65-76 Link Here
65
	 * @see org.eclipse.core.runtime.IProgressMonitorWithBlocking#clearBlocked()
60
	 * @see org.eclipse.core.runtime.IProgressMonitorWithBlocking#clearBlocked()
66
	 */
61
	 */
67
	public void clearBlocked() {
62
	public void clearBlocked() {
68
		//the UI operation is no longer blocked so get rid of the progress dialog
63
		//dismiss the dialog that was reporting the blockage
69
		if (dialog == null || dialog.getShell() == null || dialog.getShell().isDisposed()){
64
		if (dialog != null)
70
			dialog = null;
65
			dialog.close(this);
71
			return;
72
		}
73
		dialog.close();
74
		dialog = null;
66
		dialog = null;
75
	}
67
	}
76
	/**
68
	/**
Lines 91-96 Link Here
91
	 * @see IProgressMonitor#isCanceled
83
	 * @see IProgressMonitor#isCanceled
92
	 */
84
	 */
93
	public boolean isCanceled() {
85
	public boolean isCanceled() {
86
		if (dialog != null) {
87
			IProgressMonitor blockedMonitor = dialog.getProgressMonitor();
88
			// If the blocked dialog already exists, and is associated with a different
89
			// progress monitor, then this is a recursive blockage. Respond to the cancelation
90
			// in the progress monitor that is associated with the dialog rather than this one.
91
			// This will allow cancelation in the dialog to cancel all event loop monitors in
92
			// the stack.
93
			if (blockedMonitor != null && blockedMonitor != this)
94
				return blockedMonitor.isCanceled();
95
		}
94
		runEventLoop();
96
		runEventLoop();
95
		return super.isCanceled();
97
		return super.isCanceled();
96
	}
98
	}
Lines 135-167 Link Here
135
	 * @see org.eclipse.core.runtime.IProgressMonitorWithBlocking#setBlocked(org.eclipse.core.runtime.IStatus)
137
	 * @see org.eclipse.core.runtime.IProgressMonitorWithBlocking#setBlocked(org.eclipse.core.runtime.IStatus)
136
	 */
138
	 */
137
	public void setBlocked(IStatus reason) {
139
	public void setBlocked(IStatus reason) {
138
		
140
		dialog = BlockedJobsDialog.createBlockedDialog(null, this, reason);
139
		//The UI operation has been blocked.  Open a progress dialog
140
		//to report the situation and give the user an opportunity to cancel.
141
		
142
		dialog = new BlockedJobsDialog(null, EventLoopProgressMonitor.this,reason);
143
		dialog.setBlockOnOpen(false);
144
		
145
		WorkbenchJob dialogJob = new WorkbenchJob(WorkbenchMessages.getString("EventLoopProgressMonitor.OpenDialogJobName")){ //$NON-NLS-1$
146
			/* (non-Javadoc)
147
			 * @see org.eclipse.ui.progress.UIJob#runInUIThread(org.eclipse.core.runtime.IProgressMonitor)
148
			 */
149
			public IStatus runInUIThread(IProgressMonitor monitor) {
150
				
151
				if(dialog == null)
152
					return Status.CANCEL_STATUS;
153
				if(ProgressManagerUtil.rescheduleIfModalShellOpen(this))
154
					return Status.CANCEL_STATUS;
155
				dialog.open();
156
				return Status.OK_STATUS;
157
			}
158
		};
159
		
160
		//Wait for long operation time to prevent a proliferation
161
		//of dialogs
162
		dialogJob.setSystem(true);
163
		dialogJob.schedule(PlatformUI.getWorkbench().getProgressService().getLongOperationTime());
164
		
165
	}
141
	}
166
	/**
142
	/**
167
	 * @see IProgressMonitor#setCanceled
143
	 * @see IProgressMonitor#setCanceled
(-)Eclipse UI/org/eclipse/ui/internal/dialogs/WorkbenchWizardBlockedHandler.java (-3 / +11 lines)
Lines 19-25 Link Here
19
 * implements the blocked handler for the workbench.
19
 * implements the blocked handler for the workbench.
20
 */
20
 */
21
public class WorkbenchWizardBlockedHandler implements IWizardBlockedHandler {
21
public class WorkbenchWizardBlockedHandler implements IWizardBlockedHandler {
22
	/**
23
	 * The dialog that reports blockage to the user.
24
	 */
22
	BlockedJobsDialog blockedDialog;
25
	BlockedJobsDialog blockedDialog;
26
	/**
27
	 * The progress monitor that is blocked.
28
	 */
29
	IProgressMonitor blockingMonitor;
23
	
30
	
24
	/**
31
	/**
25
	 * Create a new instance of the receiver.
32
	 * Create a new instance of the receiver.
Lines 33-40 Link Here
33
	public void clearBlocked() {
40
	public void clearBlocked() {
34
		if (blockedDialog == null)
41
		if (blockedDialog == null)
35
			return;
42
			return;
36
		blockedDialog.close();
43
		blockedDialog.close(blockingMonitor);
37
		blockedDialog = null;
44
		blockedDialog = null;
45
		blockingMonitor = null;
38
	}
46
	}
39
	/* (non-Javadoc)
47
	/* (non-Javadoc)
40
	 * @see org.eclipse.jface.wizard.IWizardBlockedHandler#showBlocked(org.eclipse.swt.widgets.Shell, org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IStatus, java.lang.String)
48
	 * @see org.eclipse.jface.wizard.IWizardBlockedHandler#showBlocked(org.eclipse.swt.widgets.Shell, org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IStatus, java.lang.String)
Lines 42-51 Link Here
42
	public void showBlocked(Shell parentShell, IProgressMonitor blockingMonitor,
50
	public void showBlocked(Shell parentShell, IProgressMonitor blockingMonitor,
43
			IStatus blockingStatus, String blockedName) {
51
			IStatus blockingStatus, String blockedName) {
44
		//Try to get a name as best as possible
52
		//Try to get a name as best as possible
53
		this.blockingMonitor = blockingMonitor;
45
		if (blockedName == null)
54
		if (blockedName == null)
46
			blockedName = parentShell.getText();
55
			blockedName = parentShell.getText();
47
		blockedDialog = new BlockedJobsDialog(parentShell, blockingMonitor, blockingStatus);
56
		blockedDialog = BlockedJobsDialog.createBlockedDialog(parentShell, blockingMonitor, blockingStatus);
48
		blockedDialog.setBlockedTaskName(blockedName);
57
		blockedDialog.setBlockedTaskName(blockedName);
49
		blockedDialog.open();
50
	}
58
	}
51
}
59
}
(-)Eclipse UI/org/eclipse/ui/internal/progress/BlockedJobsDialog.java (-24 / +81 lines)
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
}

Return to bug 51996