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 52912 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
patch-154122.txt (text/plain), 11.29 KB, created by
Boris Bokowski
on 2006-10-28 23:14:19 EDT
(
hide
)
Description:
work in progress
Filename:
MIME Type:
Creator:
Boris Bokowski
Created:
2006-10-28 23:14:19 EDT
Size:
11.29 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.13 >diff -u -r1.13 SaveableHelper.java >--- Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java 8 May 2006 20:55:36 -0000 1.13 >+++ Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java 29 Oct 2006 03:07:34 -0000 >@@ -19,6 +19,8 @@ > import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.Status; > import org.eclipse.core.runtime.SubProgressMonitor; >+import org.eclipse.core.runtime.jobs.ILock; >+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; >@@ -169,12 +171,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), window); > if (monitor.isCanceled()) { > break; > } >@@ -289,5 +286,67 @@ > } > return false; > } >+ >+ /** >+ * @param model >+ * @param progressMonitor >+ * @param window >+ */ >+ public static void doSaveModel(final Saveable model, >+ IProgressMonitor progressMonitor, final IWorkbenchWindow window) { >+ if (!model.prepareBackgroundSave()) { >+ try { >+ model.doSave(progressMonitor); >+ } >+ catch (CoreException e) { >+ ErrorDialog.openError(window.getShell(), WorkbenchMessages.Error, e.getMessage(), e.getStatus()); >+ } >+ } else { >+ final ILock lock = Job.getJobManager().newLock(); >+ final boolean[] isUIdisabled = { false }; >+ final boolean[] isSaveFinished = { false }; >+ Job saveJob = new Job(NLS.bind( >+ WorkbenchMessages.EditorManager_backgroundSaveJobName, >+ model.getName())) { >+ protected IStatus run(IProgressMonitor monitor) { >+ IStatus result = model.doBackgroundSave(monitor); >+ boolean enableUINeeded = false; >+ lock.acquire(); >+ try { >+ if (isUIdisabled[0]) { >+ enableUINeeded = true; >+ isSaveFinished[0] = true; >+ } >+ } finally { >+ lock.release(); >+ } >+ // do the syncExec after releasing the lock >+ if (enableUINeeded) { >+ window.getShell().getDisplay().syncExec(new Runnable() { >+ public void run() { >+ model.enableUI(); >+ } >+ }); >+ } >+ return result; >+ } >+ }; >+ saveJob.schedule(); >+ try { >+ Thread.sleep(50); >+ } catch (InterruptedException e) { >+ Thread.currentThread().interrupt(); >+ } >+ lock.acquire(); >+ try { >+ if (!isSaveFinished[0]) { >+ model.disableUI(); >+ isUIdisabled[0] = true; >+ } >+ } finally { >+ lock.release(); >+ } >+ } >+ } > > } >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.72 >diff -u -r1.72 WorkbenchMessages.java >--- Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java 25 Oct 2006 20:27:00 -0000 1.72 >+++ Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java 29 Oct 2006 03:07:36 -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.329 >diff -u -r1.329 messages.properties >--- Eclipse UI/org/eclipse/ui/internal/messages.properties 25 Oct 2006 20:27:00 -0000 1.329 >+++ Eclipse UI/org/eclipse/ui/internal/messages.properties 29 Oct 2006 03:07:36 -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/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 29 Oct 2006 03:07:34 -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), window); > if (monitorWrap.isCanceled()) > break; > } >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.112 >diff -u -r1.112 EditorManager.java >--- Eclipse UI/org/eclipse/ui/internal/EditorManager.java 12 Sep 2006 18:34:17 -0000 1.112 >+++ Eclipse UI/org/eclipse/ui/internal/EditorManager.java 29 Oct 2006 03:07:33 -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; >@@ -1247,11 +1246,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), window); > 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 29 Oct 2006 03:07:32 -0000 >@@ -13,6 +13,8 @@ > > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; > import org.eclipse.jface.resource.ImageDescriptor; > > /** >@@ -43,6 +45,9 @@ > * @since 3.3 > */ > public boolean show(IWorkbenchPage page) { >+ if (page == null) { >+ // avoids warning about unused parameter >+ } > return false; > } > >@@ -142,4 +147,74 @@ > */ > public abstract int hashCode(); > >-} >+ /** >+ * Prepares this saveable for a background save operation. Returns false if >+ * this saveable cannot be saved in the background at this time. Returns >+ * true if the saveable has been prepared for a background save operation >+ * successfully. This method is called in the UI thread and should do only >+ * minimal work. In particular, it should not change the visual appearance >+ * of the Saveable in the UI, or disable any controls. However, since >+ * {@link #doBackgroundSave(IProgressMonitor)} will not be called on the UI >+ * thread, this method should copy any state that can only be accessed from >+ * the UI thread so that {@link #doBackgroundSave(IProgressMonitor)} will be >+ * able to access it. >+ * >+ * <p> >+ * The default implementation of this method returns <code>false</code>. >+ * </p> >+ * >+ * @return <code>false</code> if this saveable cannot be saved in the >+ * background at this time, or <code>true</code> if the saveable >+ * has been prepared for a background save operation successfully >+ * >+ * @since 3.3 >+ */ >+ public boolean prepareBackgroundSave() { >+ return false; >+ } >+ >+ /** >+ * Saves the contents of this saveable. This method is not called on the UI >+ * thread. It will only be called after a preceding call to >+ * {@link #prepareBackgroundSave()} returned <code>true</code>. >+ * <p> >+ * If 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. >+ * </p> >+ * <p> >+ * This method is long-running; progress and cancellation are provided by >+ * the given progress monitor. >+ * </p> >+ * >+ * @param monitor >+ * @return a status object >+ * >+ * @since 3.3 >+ */ >+ public IStatus doBackgroundSave(IProgressMonitor monitor) { >+ if (monitor == null) { >+ // avoids warning about unused parameters >+ } >+ return Status.CANCEL_STATUS; >+ } >+ >+ /** >+ * Disable the user interface that can change the state of this saveable. >+ * This method will be called on the UI thread during a background save >+ * operation before processing UI events, so that saveables can disable >+ * their UI. If this method is called during a background save operation, a >+ * call to {@link #enableUI()} will follow. >+ */ >+ public void disableUI() { >+ } >+ >+ /** >+ * Enable the user interface after a corresponding call to disableUI. This >+ * method will be called on the UI thread after a background save operation >+ * if the saveable's UI was disabled during the background save operation. >+ */ >+ public void enableUI() { >+ } >+ >+} >\ No newline at end of file
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