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 (-7 / +43 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.Job;
22
import org.eclipse.jface.dialogs.ErrorDialog;
23
import org.eclipse.jface.dialogs.ErrorDialog;
23
import org.eclipse.jface.dialogs.IDialogConstants;
24
import org.eclipse.jface.dialogs.IDialogConstants;
24
import org.eclipse.jface.dialogs.MessageDialog;
25
import org.eclipse.jface.dialogs.MessageDialog;
Lines 168-179 Link Here
168
						monitor.worked(1);
169
						monitor.worked(1);
169
						continue;
170
						continue;
170
					}
171
					}
171
					try {
172
					doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), (WorkbenchWindow)window, false);
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()) {
173
					if (monitor.isCanceled()) {
178
						break;
174
						break;
179
					}
175
					}
Lines 294-298 Link Here
294
		}
290
		}
295
		return false;
291
		return false;
296
	}
292
	}
297
	
293
294
	/**
295
	 * @param model
296
	 * @param progressMonitor
297
	 * @param shellProvider
298
	 * @param closing
299
	 *            TODO
300
	 */
301
	public static void doSaveModel(final Saveable model,
302
			IProgressMonitor progressMonitor,
303
			final IShellProvider shellProvider, boolean closing) {
304
		try {
305
			Job backgroundSaveJob = model.doSave(progressMonitor,
306
					shellProvider, closing);
307
			if (backgroundSaveJob != null) {
308
				// backgroundSaveJob.addJobChangeListener(new JobChangeAdapter()
309
				// {
310
				// public void done(IJobChangeEvent event) {
311
				// }
312
				// });
313
				backgroundSaveJob.schedule();
314
				try {
315
					backgroundSaveJob.join();
316
					IStatus result = backgroundSaveJob.getResult();
317
					if (result.getSeverity() == IStatus.CANCEL) {
318
						progressMonitor.setCanceled(true);
319
					} else if (!result.isOK()) {
320
						ErrorDialog.openError(shellProvider.getShell(),
321
								WorkbenchMessages.Error, result.getMessage(),
322
								result);
323
					}
324
				} catch (InterruptedException e) {
325
					Thread.currentThread().interrupt();
326
				}
327
			}
328
		} catch (CoreException e) {
329
			ErrorDialog.openError(shellProvider.getShell(),
330
					WorkbenchMessages.Error, e.getMessage(), e.getStatus());
331
		}
332
	}
333
298
}
334
}
(-)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 (-7 / +2 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 1105-1111 Link Here
1105
	 * @return <code>true</code> on success, <code>false</code> if the user
1104
	 * @return <code>true</code> on success, <code>false</code> if the user
1106
	 *         canceled the save
1105
	 *         canceled the save
1107
	 */
1106
	 */
1108
	public static boolean saveAll(List dirtyParts, boolean confirm, boolean closing,
1107
	public static boolean saveAll(List dirtyParts, boolean confirm, final boolean closing,
1109
				boolean addNonPartSources, final IRunnableContext runnableContext, final IShellProvider shellProvider) {
1108
				boolean addNonPartSources, final IRunnableContext runnableContext, final IShellProvider shellProvider) {
1110
		// clone the input list
1109
		// clone the input list
1111
		dirtyParts = new ArrayList(dirtyParts);
1110
		dirtyParts = new ArrayList(dirtyParts);
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, closing);
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, true);
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 (+70 lines)
Lines 13-19 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.jobs.Job;
16
import org.eclipse.jface.resource.ImageDescriptor;
18
import org.eclipse.jface.resource.ImageDescriptor;
19
import org.eclipse.jface.window.IShellProvider;
17
20
18
/**
21
/**
19
 * A <code>Saveable</code> represents a unit of saveability, e.g. an editable
22
 * A <code>Saveable</code> represents a unit of saveability, e.g. an editable
Lines 43-48 Link Here
43
	 * @since 3.3
46
	 * @since 3.3
44
	 */
47
	 */
45
	public boolean show(IWorkbenchPage page) {
48
	public boolean show(IWorkbenchPage page) {
49
		if (page == null) {
50
			// I wish it was easier to avoid warnings about unused parameters
51
		}
46
		return false;
52
		return false;
47
	}
53
	}
48
54
Lines 142-145 Link Here
142
	 */
148
	 */
143
	public abstract int hashCode();
149
	public abstract int hashCode();
144
150
151
	/**
152
	 * Saves this saveable, or prepares this saveable for a background save
153
	 * operation. Returns null if this saveable has been successfully saved, or
154
	 * a job that needs to be run to complete the save in the background. This
155
	 * method is called in the UI thread. If this saveable supports saving in
156
	 * the background, it should do only minimal work. However, since the job
157
	 * returned by this method (if any) will not run on the UI thread, this
158
	 * method should copy any state that can only be accessed from the UI thread
159
	 * so that the background job will be able to access it.
160
	 * <p>
161
	 * The supplied shell provider can be used from within this method and from
162
	 * within the job for the purpose of parenting dialogs. Care should be taken
163
	 * not to open dialogs gratuitously and only if user input is required for
164
	 * cases where the save cannot otherwise proceed - note that in any given
165
	 * save operation, many saveable objects may be saved at the same time. In
166
	 * particular, errors should be signaled by throwing an exception, or if an
167
	 * error occurs while running the background job, an error status should be
168
	 * returned.
169
	 * </p>
170
	 * <p>
171
	 * Saveables that can be saved in the background should ensure that the user
172
	 * cannot make changes to their data from the UI, for example by disabling
173
	 * controls, unless they are prepared to handle this case. The
174
	 * <code>closing</code> flag indicates that this saveable is saved in
175
	 * response to closing a workbench part, in which case further changes to
176
	 * this saveable through the UI must be prevented if a background save job
177
	 * is returned.
178
	 * </p>
179
	 * <p>
180
	 * If the foreground part of the save is cancelled through user action, or
181
	 * for any other reason, the part should invoke <code>setCancelled</code>
182
	 * on the <code>IProgressMonitor</code> to inform the caller. If the
183
	 * background part of the save is cancelled, the job should return a
184
	 * {@link IStatus#CANCEL} status.
185
	 * </p>
186
	 * <p>
187
	 * This method is long-running; progress and cancellation are provided by
188
	 * the given progress monitor.
189
	 * </p>
190
	 * <p>
191
	 * The default implementation of this method calls
192
	 * {@link #doSave(IProgressMonitor)} and returns <code>null</code>.
193
	 * </p>
194
	 * 
195
	 * @param monitor
196
	 *            a progress monitor used for reporting progress and
197
	 *            cancellation
198
	 * @param shellProvider
199
	 *            an object that can provide a shell for parenting dialogs
200
	 * @param closing
201
	 *            a boolean flag indicating whether the save was triggered by a
202
	 *            request to close a workbench part
203
	 * @return <code>null</code> if this saveable has been saved successfully,
204
	 *         or a job that needs to be run to complete the save in the
205
	 *         background.
206
	 * 
207
	 * @since 3.3
208
	 */
209
	public Job doSave(IProgressMonitor monitor, IShellProvider shellProvider,
210
			boolean closing) throws CoreException {
211
		doSave(monitor);
212
		return null;
213
	}
214
145
}
215
}

Return to bug 154122