Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2007-01-05 16:42:50 +0000
committerMichael Valenta2007-01-05 16:42:50 +0000
commit2b91823b83cc9e5e210760884e46a2a865d0cd13 (patch)
tree10318d99f3df5d09b37a02621f0637f540fcc606
parentec203b7b055fae52853d7e2265ce9ee69c4d3c28 (diff)
downloadeclipse.platform.team-2b91823b83cc9e5e210760884e46a2a865d0cd13.tar.gz
eclipse.platform.team-2b91823b83cc9e5e210760884e46a2a865d0cd13.tar.xz
eclipse.platform.team-2b91823b83cc9e5e210760884e46a2a865d0cd13.zip
Bug 167607 [EditorMgmt] Closing compare editor asks to save editor - Saveable should implement IAdaptable
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java7
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/ICompareContainer.java11
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContainer.java7
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java91
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java7
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/ICompareContainer.java11
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContainer.java7
-rw-r--r--bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java91
8 files changed, 150 insertions, 82 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
index 672f8fa6e..537f65609 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
@@ -951,6 +951,13 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
}
/* (non-Javadoc)
+ * @see org.eclipse.compare.ICompareContainer#getWorkbenchPart()
+ */
+ public IWorkbenchPart getWorkbenchPart() {
+ return fContainer.getWorkbenchPart();
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.jface.operation.IRunnableContext#run(boolean, boolean, org.eclipse.jface.operation.IRunnableWithProgress)
*/
public void run(boolean fork, boolean cancelable,
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/ICompareContainer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/ICompareContainer.java
index 462a66d3b..1253adc42 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/ICompareContainer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/ICompareContainer.java
@@ -16,8 +16,7 @@ import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.*;
import org.eclipse.ui.services.IServiceLocator;
/**
@@ -105,5 +104,13 @@ public interface ICompareContainer extends IRunnableContext{
* @param runnable the task to be performed
*/
public void runAsynchronously(IRunnableWithProgress runnable);
+
+ /**
+ * Return the workbench part associated with this container or
+ * <code>null</code> if there is no part or it is not available.
+ * @return the workbench part associated with this container or
+ * <code>null</code>
+ */
+ public IWorkbenchPart getWorkbenchPart();
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContainer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContainer.java
index 6c3263887..eec21ec8c 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContainer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContainer.java
@@ -19,8 +19,7 @@ import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.*;
import org.eclipse.ui.services.IServiceLocator;
public class CompareContainer implements ICompareContainer {
@@ -106,4 +105,8 @@ public class CompareContainer implements ICompareContainer {
return CompareMessages.CompareContainer_0;
}
+ public IWorkbenchPart getWorkbenchPart() {
+ return null;
+ }
+
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java
index 9312d3128..761fb422c 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java
@@ -118,6 +118,13 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
protected String getWorkerJobName() {
return NLS.bind(CompareMessages.CompareEditor_11, getTitle());
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.internal.CompareContainer#getWorkbenchPart()
+ */
+ public IWorkbenchPart getWorkbenchPart() {
+ return CompareEditor.this;
+ }
}
/**
@@ -175,46 +182,45 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
* @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput)
*/
public void setInput(IEditorInput input) {
- try {
- doSetInput(input);
- // Need to refresh the contributor (see #67888)
- IEditorSite editorSite= getEditorSite();
- if (editorSite != null) {
- IEditorActionBarContributor actionBarContributor= editorSite.getActionBarContributor();
- if (actionBarContributor != null) {
- actionBarContributor.setActiveEditor(null);
- actionBarContributor.setActiveEditor(this);
- }
- }
- } catch (CoreException x) {
- String title= Utilities.getString("CompareEditor.error.setinput.title"); //$NON-NLS-1$
- String msg= Utilities.getString("CompareEditor.error.setinput.message"); //$NON-NLS-1$
- ErrorDialog.openError(getSite().getShell(), title, msg, x.getStatus());
- }
- }
-
- private void doSetInput(IEditorInput input) throws CoreException {
if (!(input instanceof CompareEditorInput)) {
IStatus s= new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, Utilities.getString("CompareEditor.invalidInput"), null); //$NON-NLS-1$
- throw new CoreException(s);
+ String title= Utilities.getString("CompareEditor.error.setinput.title"); //$NON-NLS-1$
+ String msg= Utilities.getString("CompareEditor.error.setinput.message"); //$NON-NLS-1$
+ ErrorDialog.openError(getSite().getShell(), title, msg, s);
+ return;
}
+ doSetInput(input);
+ // Need to refresh the contributor (see #67888)
+ refreshActionBarsContributor();
+ }
+ private void refreshActionBarsContributor() {
+ IEditorSite editorSite= getEditorSite();
+ if (editorSite != null) {
+ IEditorActionBarContributor actionBarContributor= editorSite.getActionBarContributor();
+ if (actionBarContributor != null) {
+ actionBarContributor.setActiveEditor(null);
+ actionBarContributor.setActiveEditor(this);
+ }
+ }
+ }
+
+ private void doSetInput(IEditorInput input) {
IEditorInput oldInput= getEditorInput();
- if (oldInput instanceof IPropertyChangeNotifier)
- ((IPropertyChangeNotifier)input).removePropertyChangeListener(this);
-
- ISaveablesLifecycleListener lifecycleListener= null;
+ disconnectFromInput(oldInput);
+ Point oldSize = null;
if (oldInput != null) {
- lifecycleListener= (ISaveablesLifecycleListener) getSite().getService(ISaveablesLifecycleListener.class);
- lifecycleListener.handleLifecycleEvent(
- new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(), false));
+ if (fControl != null && !fControl.isDisposed()) {
+ oldSize= fControl.getSize();
+ fControl.dispose();
+ fControl = null;
+ }
}
super.setInput(input);
final CompareEditorInput cei= (CompareEditorInput) input;
cei.setContainer(fContainer);
-
setTitleImage(cei.getTitleImage());
setPartName(cei.getTitle());
setTitleToolTip(cei.getToolTipText());
@@ -223,14 +229,6 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
((IPropertyChangeNotifier)input).addPropertyChangeListener(this);
setState(cei.getCompareResult() == null ? INITIALIZING : INITIALIZED);
- Point oldSize = null;
- if (oldInput != null) {
- if (fControl != null && !fControl.isDisposed()) {
- oldSize= fControl.getSize();
- fControl.dispose();
- fControl = null;
- }
- }
if (fPageBook != null)
createCompareControl();
if (fControl != null && oldSize != null)
@@ -243,11 +241,26 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
firePropertyChange(IWorkbenchPartConstants.PROP_INPUT);
- if (lifecycleListener != null) {
+ // We only need to notify of new Saveables if we are changing inputs
+ if (oldInput != null) {
+ ISaveablesLifecycleListener lifecycleListener= (ISaveablesLifecycleListener) getSite().getService(ISaveablesLifecycleListener.class);
lifecycleListener.handleLifecycleEvent(
new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_OPEN, getSaveables(), false));
}
}
+
+ private void disconnectFromInput(IEditorInput oldInput) {
+ if (oldInput != null) {
+
+ if (oldInput instanceof IPropertyChangeNotifier)
+ ((IPropertyChangeNotifier)oldInput).removePropertyChangeListener(this);
+
+ // Let the workbench know that the old input's saveables are no longer needed
+ ISaveablesLifecycleListener lifecycleListener= (ISaveablesLifecycleListener) getSite().getService(ISaveablesLifecycleListener.class);
+ lifecycleListener.handleLifecycleEvent(
+ new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(oldInput), false));
+ }
+ }
protected void initializeInBackground(final CompareEditorInput cei) {
// Need to cancel any running jobs associated with the oldInput
@@ -478,6 +491,10 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
*/
public Saveable[] getSaveables() {
IEditorInput input= getEditorInput();
+ return getSaveables(input);
+ }
+
+ private Saveable[] getSaveables(IEditorInput input) {
if (input instanceof ISaveablesSource) {
ISaveablesSource source= (ISaveablesSource) input;
return source.getSaveables();
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
index 672f8fa6e..537f65609 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/CompareEditorInput.java
@@ -951,6 +951,13 @@ public abstract class CompareEditorInput implements IEditorInput, IPropertyChang
}
/* (non-Javadoc)
+ * @see org.eclipse.compare.ICompareContainer#getWorkbenchPart()
+ */
+ public IWorkbenchPart getWorkbenchPart() {
+ return fContainer.getWorkbenchPart();
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.jface.operation.IRunnableContext#run(boolean, boolean, org.eclipse.jface.operation.IRunnableWithProgress)
*/
public void run(boolean fork, boolean cancelable,
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/ICompareContainer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/ICompareContainer.java
index 462a66d3b..1253adc42 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/ICompareContainer.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/ICompareContainer.java
@@ -16,8 +16,7 @@ import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.*;
import org.eclipse.ui.services.IServiceLocator;
/**
@@ -105,5 +104,13 @@ public interface ICompareContainer extends IRunnableContext{
* @param runnable the task to be performed
*/
public void runAsynchronously(IRunnableWithProgress runnable);
+
+ /**
+ * Return the workbench part associated with this container or
+ * <code>null</code> if there is no part or it is not available.
+ * @return the workbench part associated with this container or
+ * <code>null</code>
+ */
+ public IWorkbenchPart getWorkbenchPart();
}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContainer.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContainer.java
index 6c3263887..eec21ec8c 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContainer.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareContainer.java
@@ -19,8 +19,7 @@ import org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.*;
import org.eclipse.ui.services.IServiceLocator;
public class CompareContainer implements ICompareContainer {
@@ -106,4 +105,8 @@ public class CompareContainer implements ICompareContainer {
return CompareMessages.CompareContainer_0;
}
+ public IWorkbenchPart getWorkbenchPart() {
+ return null;
+ }
+
}
diff --git a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java
index 9312d3128..761fb422c 100644
--- a/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java
+++ b/bundles/org.eclipse.compare/plugins/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareEditor.java
@@ -118,6 +118,13 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
protected String getWorkerJobName() {
return NLS.bind(CompareMessages.CompareEditor_11, getTitle());
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.internal.CompareContainer#getWorkbenchPart()
+ */
+ public IWorkbenchPart getWorkbenchPart() {
+ return CompareEditor.this;
+ }
}
/**
@@ -175,46 +182,45 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
* @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput)
*/
public void setInput(IEditorInput input) {
- try {
- doSetInput(input);
- // Need to refresh the contributor (see #67888)
- IEditorSite editorSite= getEditorSite();
- if (editorSite != null) {
- IEditorActionBarContributor actionBarContributor= editorSite.getActionBarContributor();
- if (actionBarContributor != null) {
- actionBarContributor.setActiveEditor(null);
- actionBarContributor.setActiveEditor(this);
- }
- }
- } catch (CoreException x) {
- String title= Utilities.getString("CompareEditor.error.setinput.title"); //$NON-NLS-1$
- String msg= Utilities.getString("CompareEditor.error.setinput.message"); //$NON-NLS-1$
- ErrorDialog.openError(getSite().getShell(), title, msg, x.getStatus());
- }
- }
-
- private void doSetInput(IEditorInput input) throws CoreException {
if (!(input instanceof CompareEditorInput)) {
IStatus s= new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, Utilities.getString("CompareEditor.invalidInput"), null); //$NON-NLS-1$
- throw new CoreException(s);
+ String title= Utilities.getString("CompareEditor.error.setinput.title"); //$NON-NLS-1$
+ String msg= Utilities.getString("CompareEditor.error.setinput.message"); //$NON-NLS-1$
+ ErrorDialog.openError(getSite().getShell(), title, msg, s);
+ return;
}
+ doSetInput(input);
+ // Need to refresh the contributor (see #67888)
+ refreshActionBarsContributor();
+ }
+ private void refreshActionBarsContributor() {
+ IEditorSite editorSite= getEditorSite();
+ if (editorSite != null) {
+ IEditorActionBarContributor actionBarContributor= editorSite.getActionBarContributor();
+ if (actionBarContributor != null) {
+ actionBarContributor.setActiveEditor(null);
+ actionBarContributor.setActiveEditor(this);
+ }
+ }
+ }
+
+ private void doSetInput(IEditorInput input) {
IEditorInput oldInput= getEditorInput();
- if (oldInput instanceof IPropertyChangeNotifier)
- ((IPropertyChangeNotifier)input).removePropertyChangeListener(this);
-
- ISaveablesLifecycleListener lifecycleListener= null;
+ disconnectFromInput(oldInput);
+ Point oldSize = null;
if (oldInput != null) {
- lifecycleListener= (ISaveablesLifecycleListener) getSite().getService(ISaveablesLifecycleListener.class);
- lifecycleListener.handleLifecycleEvent(
- new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(), false));
+ if (fControl != null && !fControl.isDisposed()) {
+ oldSize= fControl.getSize();
+ fControl.dispose();
+ fControl = null;
+ }
}
super.setInput(input);
final CompareEditorInput cei= (CompareEditorInput) input;
cei.setContainer(fContainer);
-
setTitleImage(cei.getTitleImage());
setPartName(cei.getTitle());
setTitleToolTip(cei.getToolTipText());
@@ -223,14 +229,6 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
((IPropertyChangeNotifier)input).addPropertyChangeListener(this);
setState(cei.getCompareResult() == null ? INITIALIZING : INITIALIZED);
- Point oldSize = null;
- if (oldInput != null) {
- if (fControl != null && !fControl.isDisposed()) {
- oldSize= fControl.getSize();
- fControl.dispose();
- fControl = null;
- }
- }
if (fPageBook != null)
createCompareControl();
if (fControl != null && oldSize != null)
@@ -243,11 +241,26 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
firePropertyChange(IWorkbenchPartConstants.PROP_INPUT);
- if (lifecycleListener != null) {
+ // We only need to notify of new Saveables if we are changing inputs
+ if (oldInput != null) {
+ ISaveablesLifecycleListener lifecycleListener= (ISaveablesLifecycleListener) getSite().getService(ISaveablesLifecycleListener.class);
lifecycleListener.handleLifecycleEvent(
new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_OPEN, getSaveables(), false));
}
}
+
+ private void disconnectFromInput(IEditorInput oldInput) {
+ if (oldInput != null) {
+
+ if (oldInput instanceof IPropertyChangeNotifier)
+ ((IPropertyChangeNotifier)oldInput).removePropertyChangeListener(this);
+
+ // Let the workbench know that the old input's saveables are no longer needed
+ ISaveablesLifecycleListener lifecycleListener= (ISaveablesLifecycleListener) getSite().getService(ISaveablesLifecycleListener.class);
+ lifecycleListener.handleLifecycleEvent(
+ new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(oldInput), false));
+ }
+ }
protected void initializeInBackground(final CompareEditorInput cei) {
// Need to cancel any running jobs associated with the oldInput
@@ -478,6 +491,10 @@ public class CompareEditor extends EditorPart implements IReusableEditor, ISavea
*/
public Saveable[] getSaveables() {
IEditorInput input= getEditorInput();
+ return getSaveables(input);
+ }
+
+ private Saveable[] getSaveables(IEditorInput input) {
if (input instanceof ISaveablesSource) {
ISaveablesSource source= (ISaveablesSource) input;
return source.getSaveables();

Back to the top