Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2015-02-12 23:14:52 +0000
committerAndrey Loskutov2015-03-25 21:15:04 +0000
commit7464658bb4965909cb1936f93a0db6d25ed43e64 (patch)
treec2a5ee7165c92bca6d3b89a43531dc1938f74912
parent4ae427dbbbece2d65577891b0fcccf2b24f7bbdc (diff)
downloadeclipse.platform.ui-7464658bb4965909cb1936f93a0db6d25ed43e64.tar.gz
eclipse.platform.ui-7464658bb4965909cb1936f93a0db6d25ed43e64.tar.xz
eclipse.platform.ui-7464658bb4965909cb1936f93a0db6d25ed43e64.zip
Bug 372799 - [Workbench] [GlobalActions] ViewPart cannot adapt
ISaveablePart any longer but must implement it. - Introduced new helper methods in SaveableHelper which are checking both instanceof and getAdapter() on given parts. - Redirected all instanceof uses of ISaveablePart to SaveableHelper - Exception: PropertySheet and PropertySheetPage which javadoc explicitly expects instanceof ISaveablePart Change-Id: I5c48ae46f02f055d4835cf5f8e1d42f2db6255e1 Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/DefaultSaveable.java12
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java71
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveablesList.java15
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java8
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java118
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java8
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java9
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityPart.java13
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/AbstractSaveHandler.java35
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/DirtyStateTracker.java89
10 files changed, 176 insertions, 202 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/DefaultSaveable.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/DefaultSaveable.java
index fc0452819ee..7fea7985181 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/DefaultSaveable.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/DefaultSaveable.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 IBM Corporation and others.
+ * Copyright (c) 2006, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Andrey Loskutov <loskutov@gmx.de> - Bug 372799
******************************************************************************/
package org.eclipse.ui.internal;
@@ -45,8 +46,8 @@ public class DefaultSaveable extends Saveable {
@Override
public void doSave(IProgressMonitor monitor) {
- if (part instanceof ISaveablePart) {
- ISaveablePart saveable = (ISaveablePart) part;
+ ISaveablePart saveable = SaveableHelper.getSaveable(part);
+ if (saveable != null) {
saveable.doSave(monitor);
}
}
@@ -75,8 +76,9 @@ public class DefaultSaveable extends Saveable {
@Override
public boolean isDirty() {
- if (part instanceof ISaveablePart) {
- return ((ISaveablePart) part).isDirty();
+ ISaveablePart saveable = SaveableHelper.getSaveable(part);
+ if (saveable != null) {
+ return saveable.isDirty();
}
return false;
}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java
index 6be1936c8fb..6dbb1a6494f 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveableHelper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2013 IBM Corporation and others.
+ * Copyright (c) 2004, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Andrey Loskutov <loskutov@gmx.de> - Bug 372799
*******************************************************************************/
package org.eclipse.ui.internal;
@@ -45,6 +46,7 @@ import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.Saveable;
import org.eclipse.ui.internal.dialogs.EventLoopProgressMonitor;
import org.eclipse.ui.internal.misc.StatusUtil;
+import org.eclipse.ui.internal.util.Util;
import org.eclipse.ui.progress.IJobRunnable;
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
import org.eclipse.ui.statushandlers.StatusManager;
@@ -170,7 +172,7 @@ public class SaveableHelper {
*/
private static boolean saveModels(ISaveablesSource modelSource, final IWorkbenchWindow window, final boolean confirm) {
Saveable[] selectedModels = modelSource.getActiveSaveables();
- final ArrayList dirtyModels = new ArrayList();
+ final ArrayList<Saveable> dirtyModels = new ArrayList<Saveable>();
for (int i = 0; i < selectedModels.length; i++) {
Saveable model = selectedModels[i];
if (model.isDirty()) {
@@ -188,8 +190,8 @@ public class SaveableHelper {
IProgressMonitor monitorWrap = new EventLoopProgressMonitor(monitor);
monitorWrap.beginTask(WorkbenchMessages.Save, dirtyModels.size());
try {
- for (Iterator i = dirtyModels.iterator(); i.hasNext();) {
- Saveable model = (Saveable) i.next();
+ for (Iterator<Saveable> i = dirtyModels.iterator(); i.hasNext();) {
+ Saveable model = i.next();
// handle case where this model got saved as a result of
// saving another
if (!model.isDirty()) {
@@ -352,8 +354,7 @@ public class SaveableHelper {
final IJobRunnable[] backgroundSaveRunnable = new IJobRunnable[1];
try {
SubMonitor subMonitor = SubMonitor.convert(progressMonitor, 3);
- backgroundSaveRunnable[0] = model.doSave(
- subMonitor.newChild(2), shellProvider);
+ backgroundSaveRunnable[0] = model.doSave(subMonitor.newChild(2), shellProvider);
if (backgroundSaveRunnable[0] == null) {
// no further work needs to be done
return;
@@ -361,11 +362,9 @@ public class SaveableHelper {
if (blockUntilSaved) {
// for now, block on close by running the runnable in the UI
// thread
- IStatus result = backgroundSaveRunnable[0].run(subMonitor
- .newChild(1));
+ IStatus result = backgroundSaveRunnable[0].run(subMonitor.newChild(1));
if (!result.isOK()) {
- StatusUtil.handleStatus(result, StatusManager.SHOW,
- shellProvider.getShell());
+ StatusUtil.handleStatus(result, StatusManager.SHOW, shellProvider.getShell());
progressMonitor.setCanceled(true);
}
return;
@@ -373,9 +372,8 @@ public class SaveableHelper {
// for the job family, we use the model object because based on
// the family we can display the busy state with an animated tab
// (see the calls to showBusyForFamily() below).
- Job saveJob = new Job(NLS.bind(
- WorkbenchMessages.EditorManager_backgroundSaveJobName,
- model.getName())) {
+ Job saveJob = new Job(
+ NLS.bind(WorkbenchMessages.EditorManager_backgroundSaveJobName, model.getName())) {
@Override
public boolean belongsTo(Object family) {
if (family instanceof DynamicFamily) {
@@ -391,11 +389,9 @@ public class SaveableHelper {
};
// we will need the associated parts (for disabling their UI)
((InternalSaveable) model).setBackgroundSaveJob(saveJob);
- SaveablesList saveablesList = (SaveablesList) PlatformUI
- .getWorkbench().getService(
- ISaveablesLifecycleListener.class);
- final IWorkbenchPart[] parts = saveablesList
- .getPartsForSaveable(model);
+ SaveablesList saveablesList = (SaveablesList) PlatformUI.getWorkbench()
+ .getService(ISaveablesLifecycleListener.class);
+ final IWorkbenchPart[] parts = saveablesList.getPartsForSaveable(model);
// this will cause the parts tabs to show the ongoing background operation
for (int i = 0; i < parts.length; i++) {
@@ -429,8 +425,7 @@ public class SaveableHelper {
// we can get from the parts...
notifySaveAction(parts);
} catch (CoreException e) {
- StatusUtil.handleStatus(e.getStatus(), StatusManager.SHOW,
- shellProvider.getShell());
+ StatusUtil.handleStatus(e.getStatus(), StatusManager.SHOW, shellProvider.getShell());
progressMonitor.setCanceled(true);
}
} finally {
@@ -439,11 +434,11 @@ public class SaveableHelper {
}
private static void notifySaveAction(final IWorkbenchPart[] parts) {
- Set wwindows = new HashSet();
+ Set<IWorkbenchWindow> wwindows = new HashSet<IWorkbenchWindow>();
for (int i = 0; i < parts.length; i++) {
wwindows.add(parts[i].getSite().getWorkbenchWindow());
}
- for (Iterator it = wwindows.iterator(); it.hasNext();) {
+ for (Iterator<IWorkbenchWindow> it = wwindows.iterator(); it.hasNext();) {
WorkbenchWindow wwin = (WorkbenchWindow) it.next();
wwin.fireBackgroundSaveStarted();
}
@@ -457,7 +452,7 @@ public class SaveableHelper {
* @return true if the user canceled.
*/
private static boolean waitForBackgroundSaveJob(final Saveable model) {
- List models = new ArrayList();
+ List<Saveable> models = new ArrayList<Saveable>();
models.add(model);
return waitForBackgroundSaveJobs(models);
}
@@ -484,7 +479,7 @@ public class SaveableHelper {
return true;
}
// remove saveables that are no longer dirty from the list
- for (Iterator it = modelsToSave.iterator(); it.hasNext();) {
+ for (Iterator<?> it = modelsToSave.iterator(); it.hasNext();) {
Saveable model = (Saveable) it.next();
if (!model.isDirty()) {
it.remove();
@@ -493,11 +488,35 @@ public class SaveableHelper {
return false;
}
- private static class DynamicFamily extends HashSet {
+ private static class DynamicFamily extends HashSet<Object> {
private static final long serialVersionUID = 1L;
- public DynamicFamily(Collection collection) {
+
+ public DynamicFamily(Collection<?> collection) {
super(collection);
}
}
+ public static ISaveablePart getSaveable(Object o) {
+ if (o instanceof ISaveablePart) {
+ return (ISaveablePart) o;
+ }
+ return Util.getAdapter(o, ISaveablePart.class);
+ }
+
+ public static boolean isSaveable(Object o) {
+ return getSaveable(o) != null;
+ }
+
+ public static ISaveablePart2 getSaveable2(Object o) {
+ ISaveablePart saveable = getSaveable(o);
+ if (saveable instanceof ISaveablePart2) {
+ return (ISaveablePart2) saveable;
+ }
+ return Util.getAdapter(o, ISaveablePart2.class);
+ }
+
+ public static boolean isSaveable2(Object o) {
+ return getSaveable2(o) != null;
+ }
+
}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveablesList.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveablesList.java
index 9d2926600c4..e8b7be6ea19 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveablesList.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/SaveablesList.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2014 IBM Corporation and others.
+ * Copyright (c) 2006, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Andrey Loskutov <loskutov@gmx.de> - Bug 372799
*******************************************************************************/
package org.eclipse.ui.internal;
@@ -360,15 +361,15 @@ public class SaveablesList implements ISaveablesLifecycleListener {
for (Iterator it = partsToClose.iterator(); it.hasNext();) {
IWorkbenchPart part = (IWorkbenchPart) it.next();
postCloseInfo.partsClosing.add(part);
- if (part instanceof ISaveablePart) {
- ISaveablePart saveablePart = (ISaveablePart) part;
- if (save && !saveablePart.isSaveOnCloseNeeded()) {
+ ISaveablePart saveable = SaveableHelper.getSaveable(part);
+ if (saveable != null) {
+ if (save && !saveable.isSaveOnCloseNeeded()) {
// pretend for now that this part is not closing
continue;
}
}
- if (save && part instanceof ISaveablePart2) {
- ISaveablePart2 saveablePart2 = (ISaveablePart2) part;
+ if (save && saveable instanceof ISaveablePart2) {
+ ISaveablePart2 saveablePart2 = (ISaveablePart2) saveable;
// TODO show saveablePart2 before prompting, see
// EditorManager.saveAll
int response = SaveableHelper.savePart(saveablePart2, window,
@@ -722,7 +723,7 @@ public class SaveablesList implements ISaveablesLifecycleListener {
if (part instanceof ISaveablesSource) {
ISaveablesSource source = (ISaveablesSource) part;
return source.getSaveables();
- } else if (part instanceof ISaveablePart) {
+ } else if (SaveableHelper.isSaveable(part)) {
return new Saveable[] { new DefaultSaveable(part) };
} else {
return new Saveable[0];
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
index 47d240b8b3c..f699f127958 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/Workbench.java
@@ -16,6 +16,7 @@
* Terry Parker <tparker@google.com> - Bug 416673
* Sergey Prigogin <eclipse.sprigogin@gmail.com> - Bug 438324
* Snjezana Peco <snjeza.peco@gmail.com> - Bug 405542
+ * Andrey Loskutov <loskutov@gmx.de> - Bug 372799
*******************************************************************************/
package org.eclipse.ui.internal;
@@ -160,7 +161,6 @@ import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveRegistry;
import org.eclipse.ui.ISaveableFilter;
-import org.eclipse.ui.ISaveablePart;
import org.eclipse.ui.ISaveablesLifecycleListener;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.ISourceProvider;
@@ -1363,11 +1363,11 @@ public final class Workbench extends EventManager implements IWorkbench,
return true;
}
- Set<ISaveablePart> dirtyParts = new HashSet<ISaveablePart>();
+ Set<IWorkbenchPart> dirtyParts = new HashSet<IWorkbenchPart>();
for (IWorkbenchWindow window : windows) {
WorkbenchPage page = (WorkbenchPage) window.getActivePage();
if (page != null) {
- Collections.addAll(dirtyParts, page.getDirtyParts());
+ Collections.addAll(dirtyParts, page.getDirtyWorkbenchParts());
}
}
@@ -1375,7 +1375,7 @@ public final class Workbench extends EventManager implements IWorkbench,
if (activeWindow == null) {
activeWindow = windows[0];
}
- return WorkbenchPage.saveAll(new ArrayList<ISaveablePart>(dirtyParts),
+ return WorkbenchPage.saveAll(new ArrayList<IWorkbenchPart>(dirtyParts),
confirm, closing, true, activeWindow, activeWindow);
}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java
index dfbc5898b4a..f4a52194306 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java
@@ -12,7 +12,7 @@
* Lars Vogel <Lars.Vogel@gmail.com> - Bug 431340, 431348, 426535, 433234
* Lars Vogel <Lars.Vogel@gmail.com> - Bug 431868
* Cornel Izbasa <cizbasa@info.uvt.ro> - Bug 442214
- * Andrey Loskutov <loskutov@gmx.de> - Bug 411639
+ * Andrey Loskutov <loskutov@gmx.de> - Bug 411639, 372799
*******************************************************************************/
package org.eclipse.ui.internal;
@@ -1557,8 +1557,8 @@ public class WorkbenchPage implements IWorkbenchPage {
CompatibilityPart compatibilityPart = (CompatibilityPart) clientObject;
IWorkbenchPart workbenchPart = compatibilityPart.getPart();
if (save) {
- if (workbenchPart instanceof ISaveablePart) {
- ISaveablePart saveablePart = (ISaveablePart) workbenchPart;
+ ISaveablePart saveablePart = SaveableHelper.getSaveable(workbenchPart);
+ if (saveablePart != null) {
if (saveablePart.isSaveOnCloseNeeded()) {
if (!saveSaveable(saveablePart, workbenchPart, confirm, true)) {
return false;
@@ -1665,8 +1665,9 @@ public class WorkbenchPage implements IWorkbenchPage {
if (object instanceof CompatibilityPart) {
IWorkbenchPart workbenchPart = ((CompatibilityPart) object)
.getPart();
- if (workbenchPart instanceof ISaveablePart) {
- if (!((ISaveablePart) workbenchPart).isSaveOnCloseNeeded()) {
+ ISaveablePart saveablePart = SaveableHelper.getSaveable(workbenchPart);
+ if (saveablePart != null) {
+ if (!saveablePart.isSaveOnCloseNeeded()) {
part.setDirty(false);
it.remove();
} else {
@@ -2715,7 +2716,7 @@ public class WorkbenchPage implements IWorkbenchPage {
workingSetMem = XMLMemento.createReadRoot(new StringReader(workingSetMemString));
IMemento[] workingSetChildren = workingSetMem
.getChildren(IWorkbenchConstants.TAG_WORKING_SET);
- List workingSetList = new ArrayList(workingSetChildren.length);
+ List<IWorkingSet> workingSetList = new ArrayList<IWorkingSet>(workingSetChildren.length);
for (int i = 0; i < workingSetChildren.length; i++) {
IWorkingSet set = getWorkbenchWindow().getWorkbench().getWorkingSetManager()
.getWorkingSet(workingSetChildren[i].getID());
@@ -2724,8 +2725,7 @@ public class WorkbenchPage implements IWorkbenchPage {
}
}
- workingSets = (IWorkingSet[]) workingSetList.toArray(new IWorkingSet[workingSetList
- .size()]);
+ workingSets = workingSetList.toArray(new IWorkingSet[workingSetList.size()]);
} catch (WorkbenchException e) {
StatusManager.getManager().handle(
new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.ERROR,
@@ -2795,7 +2795,7 @@ public class WorkbenchPage implements IWorkbenchPage {
}
}
- ArrayList getPerspectiveExtensionActionSets(String id) {
+ ArrayList<String> getPerspectiveExtensionActionSets(String id) {
IPerspectiveDescriptor desc = getWorkbenchWindow().getWorkbench().getPerspectiveRegistry()
.findPerspectiveWithId(id);
if (desc != null) {
@@ -2806,8 +2806,7 @@ public class WorkbenchPage implements IWorkbenchPage {
PerspectiveExtensionReader reader = new PerspectiveExtensionReader();
reader.setIncludeOnlyTags(new String[] { IWorkbenchRegistryConstants.TAG_ACTION_SET });
reader.extendLayout(null, id, modelLayout);
- return new ArrayList(ModeledPageLayout.getIds(temporary,
- ModeledPageLayout.ACTION_SET_TAG));
+ return new ArrayList<String>(ModeledPageLayout.getIds(temporary, ModeledPageLayout.ACTION_SET_TAG));
}
return null;
}
@@ -3353,8 +3352,8 @@ public class WorkbenchPage implements IWorkbenchPage {
continue;
} else if (object instanceof CompatibilityPart) {
IWorkbenchPart workbenchPart = ((CompatibilityPart) object).getPart();
- if (!(workbenchPart instanceof ISaveablePart)
- || !((ISaveablePart) workbenchPart).isSaveOnCloseNeeded()) {
+ ISaveablePart saveable = SaveableHelper.getSaveable(workbenchPart);
+ if (saveable == null || !saveable.isSaveOnCloseNeeded()) {
continue;
}
partsToSave.add(workbenchPart);
@@ -3516,31 +3515,55 @@ public class WorkbenchPage implements IWorkbenchPage {
return saveAllEditors(confirm, false, false);
}
+ /**
+ * @return {@link ISaveablePart} objects derived from {@link IWorkbenchPart}
+ * 's on this page
+ */
public ISaveablePart[] getDirtyParts() {
- List result = new ArrayList(3);
+ List<ISaveablePart> result = new ArrayList<ISaveablePart>(3);
IWorkbenchPartReference[] allParts = getSortedParts(true, true, true);
for (int i = 0; i < allParts.length; i++) {
IWorkbenchPartReference reference = allParts[i];
IWorkbenchPart part = reference.getPart(false);
- if (part != null && part instanceof ISaveablePart) {
- ISaveablePart saveable = (ISaveablePart) part;
+ ISaveablePart saveable = SaveableHelper.getSaveable(part);
+ if (saveable != null) {
if (saveable.isDirty()) {
result.add(saveable);
}
}
}
+ return result.toArray(new ISaveablePart[result.size()]);
+ }
- return (ISaveablePart[]) result.toArray(new ISaveablePart[result.size()]);
+ /**
+ * @return workbench parts which are dirty (implement or adapt to
+ * {@link ISaveablePart})
+ */
+ public IWorkbenchPart[] getDirtyWorkbenchParts() {
+ List<IWorkbenchPart> result = new ArrayList<IWorkbenchPart>(3);
+ IWorkbenchPartReference[] allParts = getSortedParts(true, true, true);
+ for (int i = 0; i < allParts.length; i++) {
+ IWorkbenchPartReference reference = allParts[i];
+
+ IWorkbenchPart part = reference.getPart(false);
+ ISaveablePart saveable = SaveableHelper.getSaveable(part);
+ if (saveable != null) {
+ if (saveable.isDirty()) {
+ result.add(part);
+ }
+ }
+ }
+ return result.toArray(new IWorkbenchPart[result.size()]);
}
public boolean saveAllEditors(boolean confirm, boolean closing, boolean addNonPartSources) {
- ISaveablePart[] parts = getDirtyParts();
+ IWorkbenchPart[] parts = getDirtyWorkbenchParts();
if (parts.length == 0) {
return true;
}
// saveAll below expects a mutable list
- List dirtyParts = new ArrayList(parts.length);
+ List<IWorkbenchPart> dirtyParts = new ArrayList<IWorkbenchPart>(parts.length);
for (int i = 0; i < parts.length; i++) {
dirtyParts.add(parts[i]);
}
@@ -3549,11 +3572,11 @@ public class WorkbenchPage implements IWorkbenchPage {
return saveAll(dirtyParts, confirm, closing, addNonPartSources, legacyWindow, legacyWindow);
}
- public static boolean saveAll(List dirtyParts, final boolean confirm, final boolean closing,
+ public static boolean saveAll(List<IWorkbenchPart> dirtyParts, final boolean confirm, final boolean closing,
boolean addNonPartSources, final IRunnableContext runnableContext,
final IWorkbenchWindow workbenchWindow) {
// clone the input list
- dirtyParts = new ArrayList(dirtyParts);
+ dirtyParts = new ArrayList<IWorkbenchPart>(dirtyParts);
if (closing) {
// if the parts are going to be closed, then we only save those that
@@ -3567,7 +3590,7 @@ public class WorkbenchPage implements IWorkbenchPage {
return processSaveable2(dirtyParts) ? false : saveablesList.preCloseParts(dirtyParts, true, true,
workbenchWindow, workbenchWindow) != null;
}
- List modelsToSave = convertToSaveables(dirtyParts, closing, addNonPartSources);
+ List<Saveable> modelsToSave = convertToSaveables(dirtyParts, closing, addNonPartSources);
return modelsToSave.isEmpty() ? true : !saveablesList.saveModels(modelsToSave, workbenchWindow,
runnableContext, closing);
@@ -3580,10 +3603,11 @@ public class WorkbenchPage implements IWorkbenchPage {
* @param parts
* the list of the parts (ISaveablePart)
*/
- private static void removeSaveOnCloseNotNeededParts(List parts) {
- for (Iterator it = parts.iterator(); it.hasNext();) {
- ISaveablePart saveablePart = (ISaveablePart) it.next();
- if (!saveablePart.isSaveOnCloseNeeded()) {
+ private static void removeSaveOnCloseNotNeededParts(List<IWorkbenchPart> parts) {
+ for (Iterator<IWorkbenchPart> it = parts.iterator(); it.hasNext();) {
+ IWorkbenchPart part = it.next();
+ ISaveablePart saveable = SaveableHelper.getSaveable(part);
+ if (saveable == null || !saveable.isSaveOnCloseNeeded()) {
it.remove();
}
}
@@ -3597,7 +3621,7 @@ public class WorkbenchPage implements IWorkbenchPage {
* the list of the parts
* @return true if cancelled
*/
- private static boolean processSaveable2(List dirtyParts) {
+ private static boolean processSaveable2(List<IWorkbenchPart> dirtyParts) {
boolean saveable2Processed = false;
// Process all parts that implement ISaveablePart2.
// These parts are removed from the list after saving
@@ -3606,13 +3630,14 @@ public class WorkbenchPage implements IWorkbenchPage {
// active perspective.
// Note that the given parts may come from multiple
// windows, pages and perspectives.
- ListIterator listIterator = dirtyParts.listIterator();
+ ListIterator<IWorkbenchPart> listIterator = dirtyParts.listIterator();
WorkbenchPage currentPage = null;
Perspective currentPageOriginalPerspective = null;
while (listIterator.hasNext()) {
- IWorkbenchPart part = (IWorkbenchPart) listIterator.next();
- if (part instanceof ISaveablePart2) {
+ IWorkbenchPart part = listIterator.next();
+ ISaveablePart2 saveable2 = SaveableHelper.getSaveable2(part);
+ if (saveable2 != null) {
WorkbenchPage page = (WorkbenchPage) part.getSite().getPage();
if (!Util.equals(currentPage, page)) {
if (currentPage != null && currentPageOriginalPerspective != null) {
@@ -3627,7 +3652,7 @@ public class WorkbenchPage implements IWorkbenchPage {
}
page.bringToTop(part);
// try to save the part
- int choice = SaveableHelper.savePart((ISaveablePart2) part, page.getWorkbenchWindow(), true);
+ int choice = SaveableHelper.savePart(saveable2, page.getWorkbenchWindow(), true);
if (choice == ISaveablePart2.CANCEL) {
// If the user cancels, don't restore the previous
// workbench state, as that will
@@ -3656,12 +3681,12 @@ public class WorkbenchPage implements IWorkbenchPage {
return false;
}
- private static void removeNonDirtyParts(List parts) {
- ListIterator listIterator;
+ private static void removeNonDirtyParts(List<IWorkbenchPart> parts) {
+ ListIterator<IWorkbenchPart> listIterator;
listIterator = parts.listIterator();
while (listIterator.hasNext()) {
- ISaveablePart part = (ISaveablePart) listIterator.next();
- if (!part.isDirty()) {
+ ISaveablePart part = SaveableHelper.getSaveable(listIterator.next());
+ if (part == null || !part.isDirty()) {
listIterator.remove();
}
}
@@ -3682,11 +3707,11 @@ public class WorkbenchPage implements IWorkbenchPage {
* All action, see bug 139004)
* @return the dirty models
*/
- private static List convertToSaveables(List parts, boolean closing, boolean addNonPartSources) {
- ArrayList result = new ArrayList();
- HashSet seen = new HashSet();
- for (Iterator i = parts.iterator(); i.hasNext();) {
- IWorkbenchPart part = (IWorkbenchPart) i.next();
+ private static List<Saveable> convertToSaveables(List<IWorkbenchPart> parts, boolean closing,
+ boolean addNonPartSources) {
+ ArrayList<Saveable> result = new ArrayList<Saveable>();
+ HashSet<Saveable> seen = new HashSet<Saveable>();
+ for (IWorkbenchPart part : parts) {
Saveable[] saveables = getSaveables(part);
for (int j = 0; j < saveables.length; j++) {
Saveable saveable = saveables[j];
@@ -3748,18 +3773,17 @@ public class WorkbenchPage implements IWorkbenchPage {
* @return <code>true</code> if no more parts in the page will reference the
* given model, <code>false</code> otherwise
*/
- private static boolean closingLastPartShowingModel(Saveable model, List closingParts,
+ private static boolean closingLastPartShowingModel(Saveable model, List<IWorkbenchPart> closingParts,
IWorkbenchPage page) {
- HashSet closingPartsWithSameModel = new HashSet();
- for (Iterator i = closingParts.iterator(); i.hasNext();) {
- IWorkbenchPart part = (IWorkbenchPart) i.next();
+ HashSet<IWorkbenchPart> closingPartsWithSameModel = new HashSet<IWorkbenchPart>();
+ for (IWorkbenchPart part : closingParts) {
Saveable[] models = getSaveables(part);
if (Arrays.asList(models).contains(model)) {
closingPartsWithSameModel.add(part);
}
}
IWorkbenchPartReference[] pagePartRefs = ((WorkbenchPage) page).getSortedParts();
- HashSet pagePartsWithSameModels = new HashSet();
+ HashSet<IWorkbenchPart> pagePartsWithSameModels = new HashSet<IWorkbenchPart>();
for (int i = 0; i < pagePartRefs.length; i++) {
IWorkbenchPartReference partRef = pagePartRefs[i];
IWorkbenchPart part = partRef.getPart(false);
@@ -3770,8 +3794,7 @@ public class WorkbenchPage implements IWorkbenchPage {
}
}
}
- for (Iterator i = closingPartsWithSameModel.iterator(); i.hasNext();) {
- IWorkbenchPart part = (IWorkbenchPart) i.next();
+ for (IWorkbenchPart part : closingPartsWithSameModel) {
pagePartsWithSameModels.remove(part);
}
return pagePartsWithSameModels.isEmpty();
@@ -3783,6 +3806,7 @@ public class WorkbenchPage implements IWorkbenchPage {
*
* @param saveable
* the saveable part to save
+ * @param part
* @param confirm
* whether the user should be prompted for confirmation of the
* save request
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java
index eb8e9aeefd2..50b3e82a0f4 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchPartReference.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* Stefan Xenos, IBM; Chris Torrence, ITT Visual Information Solutions - bug 51580
* Nikolay Botev - bug 240651
+ * Andrey Loskutov <loskutov@gmx.de> - Bug 372799
*******************************************************************************/
package org.eclipse.ui.internal;
@@ -563,8 +564,9 @@ public abstract class WorkbenchPartReference implements IWorkbenchPartReference,
@Override
public boolean isDirty() {
IWorkbenchPart part = getPart(false);
- if (part instanceof ISaveablePart) {
- return ((ISaveablePart) part).isDirty();
+ ISaveablePart saveable = SaveableHelper.getSaveable(part);
+ if (saveable != null) {
+ return saveable.isDirty();
}
return false;
}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
index ae7d8ad5c25..50baa651758 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
@@ -14,6 +14,7 @@
* through a fragment or other means
* Lars Vogel <Lars.Vogel@vogella.com> - Bug 431446, 433979, 440810, 441184
* Denis Zygann <d.zygann@web.de> - Bug 457390
+ * Andrey Loskutov <loskutov@gmx.de> - Bug 372799
*******************************************************************************/
package org.eclipse.ui.internal;
@@ -527,9 +528,11 @@ public class WorkbenchWindow implements IWorkbenchWindow {
Object object = dirtyPart.getObject();
if (object instanceof CompatibilityPart) {
IWorkbenchPart part = ((CompatibilityPart) object).getPart();
- if (part instanceof ISaveablePart) {
- if (!((ISaveablePart) part).isSaveOnCloseNeeded())
+ ISaveablePart saveable = SaveableHelper.getSaveable(part);
+ if (saveable != null) {
+ if (!saveable.isSaveOnCloseNeeded()) {
return Save.NO;
+ }
return SaveableHelper.savePart((ISaveablePart) part, part,
WorkbenchWindow.this, true) ? Save.NO : Save.CANCEL;
}
@@ -2860,7 +2863,7 @@ public class WorkbenchWindow implements IWorkbenchWindow {
setPerspectiveBarVisible(!perspectivebarVisible);
}
ICommandService commandService = (ICommandService) getService(ICommandService.class);
- Map filter = new HashMap();
+ Map<String, WorkbenchWindow> filter = new HashMap<String, WorkbenchWindow>();
filter.put(IServiceScopes.WINDOW_SCOPE, this);
commandService.refreshElements(COMMAND_ID_TOGGLE_COOLBAR, filter);
}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityPart.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityPart.java
index 7c0c14adb09..307ab9ddcc5 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityPart.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/e4/compatibility/CompatibilityPart.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2014 IBM Corporation and others.
+ * Copyright (c) 2010, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Steven Spungin <steven@spungin.tv> - Bug 436908
+ * Andrey Loskutov <loskutov@gmx.de> - Bug 372799
******************************************************************************/
package org.eclipse.ui.internal.e4.compatibility;
@@ -368,8 +369,9 @@ public abstract class CompatibilityPart implements ISelectionChangedListener {
}
break;
case IWorkbenchPartConstants.PROP_DIRTY:
- if (wrapped instanceof ISaveablePart) {
- ((MDirtyable) part).setDirty(((ISaveablePart) wrapped).isDirty());
+ ISaveablePart saveable = SaveableHelper.getSaveable(wrapped);
+ if (saveable != null) {
+ ((MDirtyable) part).setDirty(saveable.isDirty());
}
break;
case IWorkbenchPartConstants.PROP_INPUT:
@@ -411,8 +413,9 @@ public abstract class CompatibilityPart implements ISelectionChangedListener {
@Persist
void doSave() {
- if (wrapped instanceof ISaveablePart) {
- SaveableHelper.savePart((ISaveablePart) wrapped, wrapped, getReference().getSite()
+ ISaveablePart saveable = SaveableHelper.getSaveable(wrapped);
+ if (saveable != null) {
+ SaveableHelper.savePart(saveable, wrapped, getReference().getSite()
.getWorkbenchWindow(), false);
}
// ContextInjectionFactory.invoke(wrapped, Persist.class, part.getContext(), null);
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/AbstractSaveHandler.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/AbstractSaveHandler.java
index 2688d1f7406..3f97972f6fb 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/AbstractSaveHandler.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/AbstractSaveHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2013 IBM Corporation and others.
+ * Copyright (c) 2010, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,8 +7,8 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Andrey Loskutov <loskutov@gmx.de> - Bug 372799
******************************************************************************/
-
package org.eclipse.ui.internal.handlers;
import org.eclipse.core.commands.ExecutionEvent;
@@ -22,7 +22,7 @@ import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.internal.AbstractEvaluationHandler;
import org.eclipse.ui.internal.InternalHandlerUtil;
-import org.eclipse.ui.internal.util.Util;
+import org.eclipse.ui.internal.SaveableHelper;
/**
* @since 3.7
@@ -34,8 +34,9 @@ public abstract class AbstractSaveHandler extends AbstractEvaluationHandler {
private Expression enabledWhen;
public AbstractSaveHandler() {
- if (dirtyStateTracker == null)
+ if (dirtyStateTracker == null) {
dirtyStateTracker = new DirtyStateTracker();
+ }
}
@Override
@@ -47,11 +48,6 @@ public abstract class AbstractSaveHandler extends AbstractEvaluationHandler {
return AbstractSaveHandler.this.evaluate(context);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.core.expressions.Expression#collectExpressionInfo(org.eclipse.core.expressions.ExpressionInfo)
- */
@Override
public void collectExpressionInfo(ExpressionInfo info) {
info.addVariableNameAccess(ISources.ACTIVE_PART_NAME);
@@ -65,28 +61,19 @@ public abstract class AbstractSaveHandler extends AbstractEvaluationHandler {
protected ISaveablePart getSaveablePart(IEvaluationContext context) {
IWorkbenchPart activePart = InternalHandlerUtil.getActivePart(context);
-
- if (activePart instanceof ISaveablePart)
- return (ISaveablePart) activePart;
-
- ISaveablePart part = Util.getAdapter(activePart, ISaveablePart.class);
- if (part != null)
+ ISaveablePart part = SaveableHelper.getSaveable(activePart);
+ if (part != null) {
return part;
-
+ }
return InternalHandlerUtil.getActiveEditor(context);
}
protected ISaveablePart getSaveablePart(ExecutionEvent event) {
-
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
- if (activePart instanceof ISaveablePart) {
- return (ISaveablePart) activePart;
- }
-
- ISaveablePart part = Util.getAdapter(activePart, ISaveablePart.class);
- if (part != null)
+ ISaveablePart part = SaveableHelper.getSaveable(activePart);
+ if (part != null) {
return part;
-
+ }
return HandlerUtil.getActiveEditor(event);
}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/DirtyStateTracker.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/DirtyStateTracker.java
index 0a89e5875d5..cc7834373b2 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/DirtyStateTracker.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/DirtyStateTracker.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2014 IBM Corporation and others.
+ * Copyright (c) 2010, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Lars Vogel <Lars.Vogel@gmail.com> - Bug 440810
+ * Andrey Loskutov <loskutov@gmx.de> - Bug 372799
******************************************************************************/
package org.eclipse.ui.internal.handlers;
@@ -20,6 +21,7 @@ import org.eclipse.ui.IWindowListener;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.internal.SaveableHelper;
import org.eclipse.ui.internal.Workbench;
import org.eclipse.ui.services.IEvaluationService;
@@ -27,13 +29,11 @@ import org.eclipse.ui.services.IEvaluationService;
* @since 3.7
*
*/
-public class DirtyStateTracker implements IPartListener, IWindowListener,
- IPropertyListener {
+public class DirtyStateTracker implements IPartListener, IWindowListener, IPropertyListener {
private final IWorkbench workbench;
public DirtyStateTracker() {
-
workbench = Workbench.getInstance();
workbench.addWindowListener(this);
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
@@ -41,136 +41,69 @@ public class DirtyStateTracker implements IPartListener, IWindowListener,
}
public void update() {
- IEvaluationService service = workbench
- .getService(IEvaluationService.class);
+ IEvaluationService service = workbench.getService(IEvaluationService.class);
service.requestEvaluation(ISources.ACTIVE_PART_NAME);
}
- /**
- * @param window
- */
private void register(IWorkbenchWindow window) {
- if (window == null)
+ if (window == null) {
return;
+ }
window.getPartService().addPartListener(this);
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart)
- */
@Override
public void partActivated(IWorkbenchPart part) {
- if (part instanceof ISaveablePart) {
+ if (SaveableHelper.isSaveable(part)) {
part.addPropertyListener(this);
}
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart
- * )
- */
@Override
public void partBroughtToTop(IWorkbenchPart part) {
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
- */
@Override
public void partClosed(IWorkbenchPart part) {
- if (part instanceof ISaveablePart) {
+ if (SaveableHelper.isSaveable(part)) {
part.removePropertyListener(this);
update();
}
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart
- * )
- */
@Override
public void partDeactivated(IWorkbenchPart part) {
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart)
- */
@Override
public void partOpened(IWorkbenchPart part) {
- if (part instanceof ISaveablePart) {
+ if (SaveableHelper.isSaveable(part)) {
part.addPropertyListener(this);
}
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.
- * IWorkbenchWindow)
- */
@Override
public void windowActivated(IWorkbenchWindow window) {
register(window);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IWindowListener#windowDeactivated(org.eclipse.ui.
- * IWorkbenchWindow)
- */
@Override
public void windowDeactivated(IWorkbenchWindow window) {
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.IWindowListener#windowClosed(org.eclipse.ui.IWorkbenchWindow
- * )
- */
@Override
public void windowClosed(IWorkbenchWindow window) {
window.getPartService().removePartListener(this);
}
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.ui.IWindowListener#windowOpened(org.eclipse.ui.IWorkbenchWindow
- * )
- */
@Override
public void windowOpened(IWorkbenchWindow window) {
register(window);
}
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IPropertyListener#propertyChanged(java.lang.Object,
- * int)
- */
@Override
public void propertyChanged(Object source, int propID) {
- if (source instanceof ISaveablePart && propID == ISaveablePart.PROP_DIRTY) {
+ if (SaveableHelper.isSaveable(source) && propID == ISaveablePart.PROP_DIRTY) {
update();
}
}

Back to the top