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 154122 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java (-6 / +65 lines)
Lines 19-24 Link Here
19
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.Status;
20
import org.eclipse.core.runtime.Status;
21
import org.eclipse.core.runtime.SubProgressMonitor;
21
import org.eclipse.core.runtime.SubProgressMonitor;
22
import org.eclipse.core.runtime.jobs.ILock;
23
import org.eclipse.core.runtime.jobs.Job;
22
import org.eclipse.jface.dialogs.ErrorDialog;
24
import org.eclipse.jface.dialogs.ErrorDialog;
23
import org.eclipse.jface.dialogs.IDialogConstants;
25
import org.eclipse.jface.dialogs.IDialogConstants;
24
import org.eclipse.jface.dialogs.MessageDialog;
26
import org.eclipse.jface.dialogs.MessageDialog;
Lines 168-179 Link Here
168
						monitor.worked(1);
170
						monitor.worked(1);
169
						continue;
171
						continue;
170
					}
172
					}
171
					try {
173
					doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), (WorkbenchWindow)window);
172
						model.doSave(new SubProgressMonitor(monitorWrap, 1));
173
					}
174
					catch (CoreException e) {
175
						ErrorDialog.openError(window.getShell(), WorkbenchMessages.Error, e.getMessage(), e.getStatus());
176
					}
177
					if (monitor.isCanceled()) {
174
					if (monitor.isCanceled()) {
178
						break;
175
						break;
179
					}
176
					}
Lines 294-298 Link Here
294
		}
291
		}
295
		return false;
292
		return false;
296
	}
293
	}
294
295
	/**
296
	 * @param model
297
	 * @param progressMonitor
298
	 * @param shellProvider
299
	 */
300
	public static void doSaveModel(final Saveable model,
301
			IProgressMonitor progressMonitor, final IShellProvider shellProvider) {
302
		if (!model.prepareBackgroundSave()) {
303
			try {
304
				model.doSave(progressMonitor);
305
			}
306
			catch (CoreException e) {
307
				ErrorDialog.openError(shellProvider.getShell(), WorkbenchMessages.Error, e.getMessage(), e.getStatus());
308
			}
309
		} else {
310
			final ILock lock = Job.getJobManager().newLock();
311
			final boolean[] isUIdisabled = { false };
312
			final boolean[] isSaveFinished = { false };
313
			Job saveJob = new Job(NLS.bind(
314
					WorkbenchMessages.EditorManager_backgroundSaveJobName,
315
					model.getName())) {
316
				protected IStatus run(IProgressMonitor monitor) {
317
					IStatus result = model.doBackgroundSave(monitor);
318
					boolean enableUINeeded = false;
319
					lock.acquire();
320
					try {
321
						if (isUIdisabled[0]) {
322
							enableUINeeded = true;
323
							isSaveFinished[0] = true;
324
						}
325
					} finally {
326
						lock.release();
327
					}
328
					// do the syncExec after releasing the lock
329
					if (enableUINeeded) {
330
						shellProvider.getShell().getDisplay().syncExec(new Runnable() {
331
							public void run() {
332
								model.enableUI();
333
							}
334
						});
335
					}
336
					return result;
337
				}
338
			};
339
			saveJob.schedule();
340
			try {
341
				Thread.sleep(50);
342
			} catch (InterruptedException e) {
343
				Thread.currentThread().interrupt();
344
			}
345
			lock.acquire();
346
			try {
347
				if (!isSaveFinished[0]) {
348
					model.disableUI();
349
					isUIdisabled[0] = true;
350
				}
351
			} finally {
352
				lock.release();
353
			}
354
		}
355
	}
297
	
356
	
298
}
357
}
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java (-1 / +1 lines)
Lines 20-26 Link Here
20
public class WorkbenchMessages extends NLS {
20
public class WorkbenchMessages extends NLS {
21
	private static final String BUNDLE_NAME = "org.eclipse.ui.internal.messages";//$NON-NLS-1$
21
	private static final String BUNDLE_NAME = "org.eclipse.ui.internal.messages";//$NON-NLS-1$
22
22
23
24
	public static String PlatformUI_NoWorkbench;
23
	public static String PlatformUI_NoWorkbench;
25
24
26
	public static String Workbench_CreatingWorkbenchTwice;
25
	public static String Workbench_CreatingWorkbenchTwice;
Lines 521-526 Link Here
521
    public static String EditorManager_bad_element_factory;
520
    public static String EditorManager_bad_element_factory;
522
    public static String EditorManager_create_element_returned_null;
521
    public static String EditorManager_create_element_returned_null;
523
    public static String EditorManager_wrong_createElement_result;
522
    public static String EditorManager_wrong_createElement_result;
523
    public static String EditorManager_backgroundSaveJobName;
524
    
524
    
525
	public static String EditorPane_pinEditor;
525
	public static String EditorPane_pinEditor;
526
526
(-)Eclipse UI/org/eclipse/ui/internal/messages.properties (+1 lines)
Lines 517-522 Link Here
517
EditorManager_invalid_editor_descriptor=Invalid editor descriptor for id {0}
517
EditorManager_invalid_editor_descriptor=Invalid editor descriptor for id {0}
518
EditorManager_problemsSavingEditors=Problems occurred saving editors.
518
EditorManager_problemsSavingEditors=Problems occurred saving editors.
519
EditorManager_unableToSaveEditor=Unable to save editor: {0}.
519
EditorManager_unableToSaveEditor=Unable to save editor: {0}.
520
EditorManager_backgroundSaveJobName=Saving {0}
520
521
521
EditorPane_pinEditor=&Pin Editor
522
EditorPane_pinEditor=&Pin Editor
522
523
(-)Eclipse UI/org/eclipse/ui/internal/EditorManager.java (-6 / +1 lines)
Lines 35-41 Link Here
35
import org.eclipse.core.runtime.SubProgressMonitor;
35
import org.eclipse.core.runtime.SubProgressMonitor;
36
import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
36
import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler;
37
import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
37
import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
38
import org.eclipse.jface.dialogs.ErrorDialog;
39
import org.eclipse.jface.dialogs.IDialogConstants;
38
import org.eclipse.jface.dialogs.IDialogConstants;
40
import org.eclipse.jface.dialogs.MessageDialog;
39
import org.eclipse.jface.dialogs.MessageDialog;
41
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
40
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
Lines 1276-1286 Link Here
1276
						monitor.worked(1);
1275
						monitor.worked(1);
1277
						continue;
1276
						continue;
1278
					}
1277
					}
1279
					try {
1278
					SaveableHelper.doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), shellProvider);
1280
						model.doSave(new SubProgressMonitor(monitorWrap, 1));
1281
					} catch (CoreException e) {
1282
						ErrorDialog.openError(shellProvider.getShell(), WorkbenchMessages.Error, e.getMessage(), e.getStatus());
1283
					}
1284
					if (monitorWrap.isCanceled()) {
1279
					if (monitorWrap.isCanceled()) {
1285
						break;
1280
						break;
1286
					}
1281
					}
(-)Eclipse UI/org/eclipse/ui/internal/SaveablesList.java (-9 / +1 lines)
Lines 21-31 Link Here
21
import java.util.Set;
21
import java.util.Set;
22
22
23
import org.eclipse.core.runtime.Assert;
23
import org.eclipse.core.runtime.Assert;
24
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.IProgressMonitor;
24
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.ListenerList;
25
import org.eclipse.core.runtime.ListenerList;
27
import org.eclipse.core.runtime.SubProgressMonitor;
26
import org.eclipse.core.runtime.SubProgressMonitor;
28
import org.eclipse.jface.dialogs.ErrorDialog;
29
import org.eclipse.jface.dialogs.IDialogConstants;
27
import org.eclipse.jface.dialogs.IDialogConstants;
30
import org.eclipse.jface.dialogs.MessageDialog;
28
import org.eclipse.jface.dialogs.MessageDialog;
31
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
29
import org.eclipse.jface.dialogs.MessageDialogWithToggle;
Lines 555-567 Link Here
555
						monitor.worked(1);
553
						monitor.worked(1);
556
						continue;
554
						continue;
557
					}
555
					}
558
					try {
556
					SaveableHelper.doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), (WorkbenchWindow)window);
559
						model.doSave(new SubProgressMonitor(monitorWrap, 1));
560
					} catch (CoreException e) {
561
						ErrorDialog.openError(window.getShell(),
562
								WorkbenchMessages.Error, e.getMessage(), e
563
										.getStatus());
564
					}
565
					if (monitorWrap.isCanceled())
557
					if (monitorWrap.isCanceled())
566
						break;
558
						break;
567
				}
559
				}
(-)Eclipse UI/org/eclipse/ui/Saveable.java (+75 lines)
Lines 13-18 Link Here
13
13
14
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.Status;
16
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.resource.ImageDescriptor;
17
19
18
/**
20
/**
Lines 43-48 Link Here
43
	 * @since 3.3
45
	 * @since 3.3
44
	 */
46
	 */
45
	public boolean show(IWorkbenchPage page) {
47
	public boolean show(IWorkbenchPage page) {
48
		if (page == null) {
49
			// I wish it was easier to avoid warnings about unused parameters
50
		}
46
		return false;
51
		return false;
47
	}
52
	}
48
53
Lines 142-145 Link Here
142
	 */
147
	 */
143
	public abstract int hashCode();
148
	public abstract int hashCode();
144
149
150
	/**
151
	 * Prepares this saveable for a background save operation. Returns false if
152
	 * this saveable cannot be saved in the background at this time. Returns
153
	 * true if the saveable has been prepared for a background save operation
154
	 * successfully. This method is called in the UI thread and should do only
155
	 * minimal work. In particular, it should not change the visual appearance
156
	 * of the Saveable in the UI, or disable any controls. However, since
157
	 * {@link #doBackgroundSave(IProgressMonitor)} will not be called on the UI
158
	 * thread, this method should copy any state that can only be accessed from
159
	 * the UI thread so that {@link #doBackgroundSave(IProgressMonitor)} will be
160
	 * able to access it.
161
	 * 
162
	 * <p>
163
	 * The default implementation of this method returns <code>false</code>.
164
	 * </p>
165
	 * 
166
	 * @return <code>false</code> if this saveable cannot be saved in the
167
	 *         background at this time, or <code>true</code> if the saveable
168
	 *         has been prepared for a background save operation successfully
169
	 * 
170
	 * @since 3.3
171
	 */
172
	public boolean prepareBackgroundSave() {
173
		return false;
174
	}
175
176
	/**
177
	 * Saves the contents of this saveable. This method is not called on the UI
178
	 * thread. It will only be called after a preceding call to
179
	 * {@link #prepareBackgroundSave()} returned <code>true</code>.
180
	 * <p>
181
	 * If the save is cancelled through user action, or for any other reason,
182
	 * the part should invoke <code>setCancelled</code> on the
183
	 * <code>IProgressMonitor</code> to inform the caller.
184
	 * </p>
185
	 * <p>
186
	 * This method is long-running; progress and cancellation are provided by
187
	 * the given progress monitor.
188
	 * </p>
189
	 * 
190
	 * @param monitor
191
	 * @return a status object
192
	 * 
193
	 * @since 3.3
194
	 */
195
	public IStatus doBackgroundSave(IProgressMonitor monitor) {
196
		if (monitor == null) {
197
			// avoids warning about unused parameters
198
		}
199
		return Status.CANCEL_STATUS;
200
	}
201
202
	/**
203
	 * Disable the user interface that can change the state of this saveable.
204
	 * This method will be called on the UI thread during a background save
205
	 * operation before processing UI events, so that saveables can disable
206
	 * their UI. If this method is called during a background save operation, a
207
	 * call to {@link #enableUI()} will follow.
208
	 */
209
	public void disableUI() {
210
	}
211
	
212
	/**
213
	 * Enable the user interface after a corresponding call to disableUI. This
214
	 * method will be called on the UI thread after a background save operation
215
	 * if the saveable's UI was disabled during the background save operation.
216
	 */
217
	public void enableUI() {
218
	}
219
145
}
220
}

Return to bug 154122