Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 55172 Details for
Bug 154122
[EditorMgmt] Enable background saving of editors
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
work in progress, simpler API
patch-154122.txt (text/plain), 11.85 KB, created by
Boris Bokowski
on 2006-12-06 18:22:18 EST
(
hide
)
Description:
work in progress, simpler API
Filename:
MIME Type:
Creator:
Boris Bokowski
Created:
2006-12-06 18:22:18 EST
Size:
11.85 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.workbench >Index: Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java,v >retrieving revision 1.14 >diff -u -r1.14 SaveableHelper.java >--- Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java 8 Nov 2006 15:13:29 -0000 1.14 >+++ Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java 6 Dec 2006 23:20:07 -0000 >@@ -19,6 +19,7 @@ > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Status; > import org.eclipse.core.runtime.SubProgressMonitor; >+import org.eclipse.core.runtime.jobs.Job; > import org.eclipse.jface.dialogs.ErrorDialog; > import org.eclipse.jface.dialogs.IDialogConstants; > import org.eclipse.jface.dialogs.MessageDialog; >@@ -168,12 +169,7 @@ > monitor.worked(1); > continue; > } >- try { >- model.doSave(new SubProgressMonitor(monitorWrap, 1)); >- } >- catch (CoreException e) { >- ErrorDialog.openError(window.getShell(), WorkbenchMessages.Error, e.getMessage(), e.getStatus()); >- } >+ doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), (WorkbenchWindow)window, false); > if (monitor.isCanceled()) { > break; > } >@@ -294,5 +290,45 @@ > } > return false; > } >- >+ >+ /** >+ * @param model >+ * @param progressMonitor >+ * @param shellProvider >+ * @param closing >+ * TODO >+ */ >+ public static void doSaveModel(final Saveable model, >+ IProgressMonitor progressMonitor, >+ final IShellProvider shellProvider, boolean closing) { >+ try { >+ Job backgroundSaveJob = model.doSave(progressMonitor, >+ shellProvider, closing); >+ if (backgroundSaveJob != null) { >+ // backgroundSaveJob.addJobChangeListener(new JobChangeAdapter() >+ // { >+ // public void done(IJobChangeEvent event) { >+ // } >+ // }); >+ backgroundSaveJob.schedule(); >+ try { >+ backgroundSaveJob.join(); >+ IStatus result = backgroundSaveJob.getResult(); >+ if (result.getSeverity() == IStatus.CANCEL) { >+ progressMonitor.setCanceled(true); >+ } else if (!result.isOK()) { >+ ErrorDialog.openError(shellProvider.getShell(), >+ WorkbenchMessages.Error, result.getMessage(), >+ result); >+ } >+ } catch (InterruptedException e) { >+ Thread.currentThread().interrupt(); >+ } >+ } >+ } catch (CoreException e) { >+ ErrorDialog.openError(shellProvider.getShell(), >+ WorkbenchMessages.Error, e.getMessage(), e.getStatus()); >+ } >+ } >+ > } >Index: Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java,v >retrieving revision 1.75 >diff -u -r1.75 WorkbenchMessages.java >--- Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java 24 Nov 2006 16:41:35 -0000 1.75 >+++ Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java 6 Dec 2006 23:20:07 -0000 >@@ -20,7 +20,6 @@ > public class WorkbenchMessages extends NLS { > private static final String BUNDLE_NAME = "org.eclipse.ui.internal.messages";//$NON-NLS-1$ > >- > public static String PlatformUI_NoWorkbench; > > public static String Workbench_CreatingWorkbenchTwice; >@@ -521,6 +520,7 @@ > public static String EditorManager_bad_element_factory; > public static String EditorManager_create_element_returned_null; > public static String EditorManager_wrong_createElement_result; >+ public static String EditorManager_backgroundSaveJobName; > > public static String EditorPane_pinEditor; > >Index: Eclipse UI/org/eclipse/ui/internal/messages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties,v >retrieving revision 1.333 >diff -u -r1.333 messages.properties >--- Eclipse UI/org/eclipse/ui/internal/messages.properties 24 Nov 2006 16:41:35 -0000 1.333 >+++ Eclipse UI/org/eclipse/ui/internal/messages.properties 6 Dec 2006 23:20:07 -0000 >@@ -517,6 +517,7 @@ > EditorManager_invalid_editor_descriptor=Invalid editor descriptor for id {0} > EditorManager_problemsSavingEditors=Problems occurred saving editors. > EditorManager_unableToSaveEditor=Unable to save editor: {0}. >+EditorManager_backgroundSaveJobName=Saving {0} > > EditorPane_pinEditor=&Pin Editor > >Index: Eclipse UI/org/eclipse/ui/internal/EditorManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/EditorManager.java,v >retrieving revision 1.114 >diff -u -r1.114 EditorManager.java >--- Eclipse UI/org/eclipse/ui/internal/EditorManager.java 10 Nov 2006 12:51:45 -0000 1.114 >+++ Eclipse UI/org/eclipse/ui/internal/EditorManager.java 6 Dec 2006 23:20:07 -0000 >@@ -35,7 +35,6 @@ > import org.eclipse.core.runtime.SubProgressMonitor; > import org.eclipse.core.runtime.dynamichelpers.IExtensionChangeHandler; > import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker; >-import org.eclipse.jface.dialogs.ErrorDialog; > import org.eclipse.jface.dialogs.IDialogConstants; > import org.eclipse.jface.dialogs.MessageDialog; > import org.eclipse.jface.dialogs.ProgressMonitorDialog; >@@ -1105,7 +1104,7 @@ > * @return <code>true</code> on success, <code>false</code> if the user > * canceled the save > */ >- public static boolean saveAll(List dirtyParts, boolean confirm, boolean closing, >+ public static boolean saveAll(List dirtyParts, boolean confirm, final boolean closing, > boolean addNonPartSources, final IRunnableContext runnableContext, final IShellProvider shellProvider) { > // clone the input list > dirtyParts = new ArrayList(dirtyParts); >@@ -1276,11 +1275,7 @@ > monitor.worked(1); > continue; > } >- try { >- model.doSave(new SubProgressMonitor(monitorWrap, 1)); >- } catch (CoreException e) { >- ErrorDialog.openError(shellProvider.getShell(), WorkbenchMessages.Error, e.getMessage(), e.getStatus()); >- } >+ SaveableHelper.doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), shellProvider, closing); > if (monitorWrap.isCanceled()) { > break; > } >Index: Eclipse UI/org/eclipse/ui/internal/SaveablesList.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveablesList.java,v >retrieving revision 1.10 >diff -u -r1.10 SaveablesList.java >--- Eclipse UI/org/eclipse/ui/internal/SaveablesList.java 16 Aug 2006 03:24:12 -0000 1.10 >+++ Eclipse UI/org/eclipse/ui/internal/SaveablesList.java 6 Dec 2006 23:20:07 -0000 >@@ -21,11 +21,9 @@ > import java.util.Set; > > import org.eclipse.core.runtime.Assert; >-import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.ListenerList; > import org.eclipse.core.runtime.SubProgressMonitor; >-import org.eclipse.jface.dialogs.ErrorDialog; > import org.eclipse.jface.dialogs.IDialogConstants; > import org.eclipse.jface.dialogs.MessageDialog; > import org.eclipse.jface.dialogs.MessageDialogWithToggle; >@@ -555,13 +553,7 @@ > monitor.worked(1); > continue; > } >- try { >- model.doSave(new SubProgressMonitor(monitorWrap, 1)); >- } catch (CoreException e) { >- ErrorDialog.openError(window.getShell(), >- WorkbenchMessages.Error, e.getMessage(), e >- .getStatus()); >- } >+ SaveableHelper.doSaveModel(model, new SubProgressMonitor(monitorWrap, 1), (WorkbenchWindow)window, true); > if (monitorWrap.isCanceled()) > break; > } >Index: Eclipse UI/org/eclipse/ui/Saveable.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/Saveable.java,v >retrieving revision 1.2 >diff -u -r1.2 Saveable.java >--- Eclipse UI/org/eclipse/ui/Saveable.java 11 Jul 2006 17:53:06 -0000 1.2 >+++ Eclipse UI/org/eclipse/ui/Saveable.java 6 Dec 2006 23:20:07 -0000 >@@ -13,7 +13,10 @@ > > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.jobs.Job; > import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.jface.window.IShellProvider; > > /** > * A <code>Saveable</code> represents a unit of saveability, e.g. an editable >@@ -43,6 +46,9 @@ > * @since 3.3 > */ > public boolean show(IWorkbenchPage page) { >+ if (page == null) { >+ // I wish it was easier to avoid warnings about unused parameters >+ } > return false; > } > >@@ -142,4 +148,68 @@ > */ > public abstract int hashCode(); > >+ /** >+ * Saves this saveable, or prepares this saveable for a background save >+ * operation. Returns null if this saveable has been successfully saved, or >+ * a job that needs to be run to complete the save in the background. This >+ * method is called in the UI thread. If this saveable supports saving in >+ * the background, it should do only minimal work. However, since the job >+ * returned by this method (if any) will not run on the UI thread, this >+ * method should copy any state that can only be accessed from the UI thread >+ * so that the background job will be able to access it. >+ * <p> >+ * The supplied shell provider can be used from within this method and from >+ * within the job for the purpose of parenting dialogs. Care should be taken >+ * not to open dialogs gratuitously and only if user input is required for >+ * cases where the save cannot otherwise proceed - note that in any given >+ * save operation, many saveable objects may be saved at the same time. In >+ * particular, errors should be signaled by throwing an exception, or if an >+ * error occurs while running the background job, an error status should be >+ * returned. >+ * </p> >+ * <p> >+ * Saveables that can be saved in the background should ensure that the user >+ * cannot make changes to their data from the UI, for example by disabling >+ * controls, unless they are prepared to handle this case. The >+ * <code>closing</code> flag indicates that this saveable is saved in >+ * response to closing a workbench part, in which case further changes to >+ * this saveable through the UI must be prevented if a background save job >+ * is returned. >+ * </p> >+ * <p> >+ * If the foreground part of the save is cancelled through user action, or >+ * for any other reason, the part should invoke <code>setCancelled</code> >+ * on the <code>IProgressMonitor</code> to inform the caller. If the >+ * background part of the save is cancelled, the job should return a >+ * {@link IStatus#CANCEL} status. >+ * </p> >+ * <p> >+ * This method is long-running; progress and cancellation are provided by >+ * the given progress monitor. >+ * </p> >+ * <p> >+ * The default implementation of this method calls >+ * {@link #doSave(IProgressMonitor)} and returns <code>null</code>. >+ * </p> >+ * >+ * @param monitor >+ * a progress monitor used for reporting progress and >+ * cancellation >+ * @param shellProvider >+ * an object that can provide a shell for parenting dialogs >+ * @param closing >+ * a boolean flag indicating whether the save was triggered by a >+ * request to close a workbench part >+ * @return <code>null</code> if this saveable has been saved successfully, >+ * or a job that needs to be run to complete the save in the >+ * background. >+ * >+ * @since 3.3 >+ */ >+ public Job doSave(IProgressMonitor monitor, IShellProvider shellProvider, >+ boolean closing) throws CoreException { >+ doSave(monitor); >+ return null; >+ } >+ > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 154122
:
52912
|
53784
|
55172
|
55378