diff options
author | Michael Valenta | 2007-01-08 15:00:02 +0000 |
---|---|---|
committer | Michael Valenta | 2007-01-08 15:00:02 +0000 |
commit | 35aa39dd750a23e16ea7d8609d43068057ad6e13 (patch) | |
tree | 751a2a19676406a662abd4a43037bba965b40724 | |
parent | 116dc6fcf98bfe211e47fedc5407767c569bb53d (diff) | |
download | eclipse.platform.team-35aa39dd750a23e16ea7d8609d43068057ad6e13.tar.gz eclipse.platform.team-35aa39dd750a23e16ea7d8609d43068057ad6e13.tar.xz eclipse.platform.team-35aa39dd750a23e16ea7d8609d43068057ad6e13.zip |
Bug 167607 [EditorMgmt] Closing compare editor asks to save editor - Saveable should implement IAdaptable
5 files changed, 141 insertions, 69 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/CompareFileRevisionEditorInput.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/CompareFileRevisionEditorInput.java index 982ced857..b285ec1fb 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/CompareFileRevisionEditorInput.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/CompareFileRevisionEditorInput.java @@ -74,7 +74,7 @@ public class CompareFileRevisionEditorInput extends SaveableCompareEditorInput { /* (non-Javadoc) * @see org.eclipse.team.ui.synchronize.LocalResourceCompareEditorInput#internalPrepareInput(org.eclipse.core.runtime.IProgressMonitor) */ - protected ICompareInput internalPrepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + protected ICompareInput prepareCompareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { ICompareInput input = createCompareInput(); getCompareConfiguration().setLeftEditable(isLeftEditable(input)); getCompareConfiguration().setRightEditable(false); diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ModelCompareEditorInput.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ModelCompareEditorInput.java index 377adec1b..61e5fe65d 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ModelCompareEditorInput.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/ModelCompareEditorInput.java @@ -108,7 +108,7 @@ public class ModelCompareEditorInput extends SaveableCompareEditorInput implemen /* (non-Javadoc) * @see org.eclipse.compare.CompareEditorInput#prepareInput(org.eclipse.core.runtime.IProgressMonitor) */ - protected ICompareInput internalPrepareInput(IProgressMonitor monitor) + protected ICompareInput prepareCompareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask(TeamUIMessages.SyncInfoCompareInput_3, 100); monitor.setTaskName(TeamUIMessages.SyncInfoCompareInput_3); diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceSaveableComparison.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceSaveableComparison.java index 23434af20..aa6932431 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceSaveableComparison.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceSaveableComparison.java @@ -13,15 +13,21 @@ package org.eclipse.team.internal.ui.synchronize; import org.eclipse.compare.*; import org.eclipse.compare.internal.Utilities; import org.eclipse.compare.structuremergeviewer.ICompareInput; +import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.*; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.text.IDocument; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.graphics.Image; import org.eclipse.team.internal.ui.*; import org.eclipse.team.ui.mapping.SaveableComparison; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.Saveable; +import org.eclipse.ui.part.FileEditorInput; +import org.eclipse.ui.texteditor.IDocumentProvider; /** * A saveable that wraps a compare input in which the left side is a {@link LocalResourceTypedElement} @@ -37,6 +43,7 @@ public abstract class LocalResourceSaveableComparison extends SaveableComparison private boolean isSaving; private IContentChangeListener contentChangeListener; private ITypedElement fileElement; + private IDocument document; /** * Create the resource-based saveable comparison. @@ -44,7 +51,7 @@ public abstract class LocalResourceSaveableComparison extends SaveableComparison * @param editorInput the editor input containing the comparison */ public LocalResourceSaveableComparison(ICompareInput input, CompareEditorInput editorInput) { - this(input, editorInput, input.getLeft()); + this(input, editorInput, input.getLeft(), false); } /** @@ -52,14 +59,25 @@ public abstract class LocalResourceSaveableComparison extends SaveableComparison * @param input the compare input to be save * @param editorInput the editor input containing the comparison * @param fileElement the file element that handles the saving and change notification + * @param connected */ - public LocalResourceSaveableComparison(ICompareInput input, CompareEditorInput editorInput, ITypedElement fileElement) { + public LocalResourceSaveableComparison(ICompareInput input, CompareEditorInput editorInput, ITypedElement fileElement, boolean connected) { this.input = input; this.editorInput = editorInput; this.fileElement = fileElement; initializeContentChangeListeners(); + if (connected) { + initializeHashing(); + } } + private void initializeHashing() { + Object document= getAdapter(IDocument.class); + if (document != null) { + this.document = (IDocument)document; + } + } + private void initializeContentChangeListeners() { // We need to listen to saves to the input to catch the case // where Save was picked from the context menu @@ -252,23 +270,69 @@ public abstract class LocalResourceSaveableComparison extends SaveableComparison setDirty(changed); } } + + /* + * @see org.eclipse.ui.Saveable#hashCode() + */ + public int hashCode() { + if (document != null) { + return document.hashCode(); + } + return input.hashCode(); + } - /* (non-Javadoc) + /* * @see org.eclipse.ui.Saveable#equals(java.lang.Object) */ - public boolean equals(Object object) { - if (object instanceof LocalResourceSaveableComparison) { - LocalResourceSaveableComparison rscm = (LocalResourceSaveableComparison) object; + public boolean equals(Object obj) { + if (this == obj) + return true; + + if (!(obj instanceof Saveable)) + return false; + + if (document != null) { + Object otherDocument= ((Saveable)obj).getAdapter(IDocument.class); + + if (document == null && otherDocument == null) + return false; + + return document != null && document.equals(otherDocument); + } + + if (obj instanceof LocalResourceSaveableComparison) { + LocalResourceSaveableComparison rscm = (LocalResourceSaveableComparison) obj; return rscm.input.equals(input); } return false; } - - /* (non-Javadoc) - * @see org.eclipse.ui.Saveable#hashCode() - */ - public int hashCode() { - return input.hashCode(); + + public Object getAdapter(Class adapter) { + if (adapter == IDocument.class) { + if (document != null) + return document; + if (fileElement instanceof LocalResourceTypedElement) { + LocalResourceTypedElement lrte = (LocalResourceTypedElement) fileElement; + if (lrte.isConnected()) { + ISharedDocumentAdapter sda = (ISharedDocumentAdapter)Utils.getAdapter(lrte, ISharedDocumentAdapter.class); + if (sda != null) { + IEditorInput input = sda.getDocumentKey(lrte); + if (input != null) { + IDocumentProvider provider = SharedDocumentAdapter.getDocumentProvider(input); + if (provider != null) + return provider.getDocument(input); + } + } + } + } + } + if (adapter == IEditorInput.class) { + if (fileElement instanceof LocalResourceTypedElement) { + LocalResourceTypedElement lrte = (LocalResourceTypedElement) fileElement; + return new FileEditorInput((IFile)lrte.getResource()); + } + } + return super.getAdapter(adapter); } /** @@ -278,4 +342,12 @@ public abstract class LocalResourceSaveableComparison extends SaveableComparison public ICompareInput getInput() { return input; } + + public boolean isConnectedToSharedDocument() { + if (fileElement instanceof LocalResourceTypedElement) { + LocalResourceTypedElement lrte = (LocalResourceTypedElement) fileElement; + return lrte.isConnected(); + } + return false; + } } diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SaveableCompareEditorInput.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SaveableCompareEditorInput.java index 464d20466..5efd61750 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SaveableCompareEditorInput.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SaveableCompareEditorInput.java @@ -83,8 +83,8 @@ public abstract class SaveableCompareEditorInput extends CompareEditorInput impl private class InternalResourceSaveableComparison extends LocalResourceSaveableComparison { public InternalResourceSaveableComparison( - ICompareInput input, CompareEditorInput editorInput) { - super(input, editorInput, SaveableCompareEditorInput.getFileElement(input, editorInput)); + ICompareInput input, CompareEditorInput editorInput, boolean connected) { + super(input, editorInput, SaveableCompareEditorInput.getFileElement(input, editorInput), connected); } protected void fireInputChange() { @@ -127,6 +127,28 @@ public abstract class SaveableCompareEditorInput extends CompareEditorInput impl } }; getCompareInput().addCompareInputChangeListener(compareInputChangeListener); + + if (getSaveable() instanceof LocalResourceSaveableComparison) { + LocalResourceSaveableComparison lrsc = (LocalResourceSaveableComparison) saveable; + if (lrsc.isConnectedToSharedDocument()) { + ICompareContainer container = getContainer(); + IWorkbenchPart part = container.getWorkbenchPart(); + if (part != null) { + ISaveablesLifecycleListener lifecycleListener= (ISaveablesLifecycleListener) part.getSite().getService(ISaveablesLifecycleListener.class); + lifecycleListener.handleLifecycleEvent( + new SaveablesLifecycleEvent(part, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(), false)); + if (saveable instanceof LocalResourceSaveableComparison) { + LocalResourceSaveableComparison rsc = (LocalResourceSaveableComparison) saveable; + rsc.dispose(); + } + saveable = createConnectedSaveable(); + lifecycleListener.handleLifecycleEvent( + new SaveablesLifecycleEvent(part, SaveablesLifecycleEvent.POST_OPEN, getSaveables(), false)); + + } + } + } + if (getSaveable() instanceof SaveableComparison) { SaveableComparison scm = (SaveableComparison) saveable; propertyListener = new IPropertyListener() { @@ -162,12 +184,17 @@ public abstract class SaveableCompareEditorInput extends CompareEditorInput impl } } - /* (non-Javadoc) + /** + * Prepare the compare input of this editor input. This method is not intended to be overridden of + * extended by subclasses (but is not final for backwards compatibility reasons). + * The implementation of this method in this class + * delegates the creation of the compare input to the {@link #prepareCompareInput(IProgressMonitor)} + * method which subclasses must implement. * @see org.eclipse.compare.CompareEditorInput#prepareInput(org.eclipse.core.runtime.IProgressMonitor) */ - protected final Object prepareInput(IProgressMonitor monitor) + protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - final ICompareInput input = internalPrepareInput(monitor); + final ICompareInput input = prepareCompareInput(monitor); setTitle(NLS.bind(TeamUIMessages.SyncInfoCompareInput_title, new String[] { input.getName() })); return input; } @@ -180,7 +207,7 @@ public abstract class SaveableCompareEditorInput extends CompareEditorInput impl * @throws InvocationTargetException * @throws InterruptedException */ - protected abstract ICompareInput internalPrepareInput(IProgressMonitor monitor) + protected abstract ICompareInput prepareCompareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException; /** @@ -254,7 +281,7 @@ public abstract class SaveableCompareEditorInput extends CompareEditorInput impl * The {@link #createSaveable()} is called to create the saveable if it does not yet exist. * This method cannot be called until after the input is prepared (i.e. until after * the {@link #run(IProgressMonitor)} method is called which will in turn will invoke - * {@link #internalPrepareInput(IProgressMonitor)}. + * {@link #prepareCompareInput(IProgressMonitor)}. * @return saveable that provides the save behavior for this compare editor input. */ protected Saveable getSaveable() { @@ -272,7 +299,11 @@ public abstract class SaveableCompareEditorInput extends CompareEditorInput impl protected Saveable createSaveable() { Object compareResult = getCompareResult(); Assert.isNotNull(compareResult, "This method cannot be called until after prepareInput is called"); //$NON-NLS-1$ - return new InternalResourceSaveableComparison((ICompareInput)compareResult, this); + return new InternalResourceSaveableComparison((ICompareInput)compareResult, this, false); + } + + private Saveable createConnectedSaveable() { + return new InternalResourceSaveableComparison((ICompareInput)getCompareResult(), this, true); } /* (non-Javadoc) diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoCompareInput.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoCompareInput.java index fe66c6ac2..d6ad9325f 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoCompareInput.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SyncInfoCompareInput.java @@ -13,19 +13,18 @@ package org.eclipse.team.ui.synchronize; import java.lang.reflect.InvocationTargetException; import org.eclipse.compare.*; +import org.eclipse.compare.structuremergeviewer.ICompareInput; import org.eclipse.compare.structuremergeviewer.IDiffContainer; import org.eclipse.core.resources.*; import org.eclipse.core.runtime.*; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.graphics.Image; import org.eclipse.team.core.TeamException; import org.eclipse.team.core.synchronize.SyncInfo; import org.eclipse.team.internal.ui.*; -import org.eclipse.team.internal.ui.synchronize.*; +import org.eclipse.team.internal.ui.synchronize.SyncInfoModelElement; +import org.eclipse.team.internal.ui.synchronize.SynchronizePageConfiguration; import org.eclipse.ui.progress.UIJob; /** @@ -45,13 +44,12 @@ import org.eclipse.ui.progress.UIJob; * @see SyncInfo * @since 3.0 */ -public final class SyncInfoCompareInput extends CompareEditorInput implements IResourceChangeListener { +public final class SyncInfoCompareInput extends SaveableCompareEditorInput implements IResourceChangeListener { private MyDiffNode node; private String description; private IResource resource; private ISynchronizeParticipant participant; - private final LocalResourceSaveableComparison saveable; private ISynchronizePageConfiguration synchronizeConfiguration; /* @@ -77,17 +75,12 @@ public final class SyncInfoCompareInput extends CompareEditorInput implements IR * @param sync the <code>SyncInfo</code> used as the base for the compare input. */ public SyncInfoCompareInput(String description, SyncInfo sync) { - super(getDefaultCompareConfiguration()); + super(getDefaultCompareConfiguration(), null); Assert.isNotNull(sync); Assert.isNotNull(description); this.description = description; this.resource = sync.getLocal(); this.node = new MyDiffNode(null, sync); - this.saveable = new LocalResourceSaveableComparison(node, this) { - protected void fireInputChange() { - node.fireChange(); - } - }; } /** @@ -116,7 +109,6 @@ public final class SyncInfoCompareInput extends CompareEditorInput implements IR */ protected void handleDispose() { super.handleDispose(); - saveable.dispose(); if (synchronizeConfiguration != null) { ICompareNavigator navigator = (ICompareNavigator)synchronizeConfiguration.getProperty(SynchronizePageConfiguration.P_INPUT_NAVIGATOR); if (navigator != null && navigator == super.getNavigator()) { @@ -166,26 +158,12 @@ public final class SyncInfoCompareInput extends CompareEditorInput implements IR } } } - - /* - * (non-Javadoc) - * @see org.eclipse.compare.CompareEditorInput#getTitleImage() - */ - public Image getTitleImage() { - ImageRegistry reg = TeamUIPlugin.getPlugin().getImageRegistry(); - Image image = reg.get(ITeamUIImages.IMG_SYNC_VIEW); - if (image == null) { - image = getImageDescriptor().createImage(); - reg.put(ITeamUIImages.IMG_SYNC_VIEW, image); - } - return image; - } - /* - * (non-Javadoc) - * @see org.eclipse.compare.CompareEditorInput#prepareInput(org.eclipse.core.runtime.IProgressMonitor) + /* (non-Javadoc) + * @see org.eclipse.team.ui.synchronize.SaveableCompareEditorInput#internalPrepareInput(org.eclipse.core.runtime.IProgressMonitor) */ - protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + protected ICompareInput prepareCompareInput(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { // update the title now that the remote revision number as been fetched // from the server setTitle(getTitle()); @@ -208,22 +186,6 @@ public final class SyncInfoCompareInput extends CompareEditorInput implements IR /* * (non-Javadoc) - * @see org.eclipse.compare.CompareEditorInput#getTitle() - */ - public String getTitle() { - return NLS.bind(TeamUIMessages.SyncInfoCompareInput_title, new String[] { node.getName() }); - } - - /* - * (non-Javadoc) - * @see org.eclipse.ui.IEditorInput#getImageDescriptor() - */ - public ImageDescriptor getImageDescriptor() { - return TeamUIPlugin.getImageDescriptor(ITeamUIImages.IMG_SYNC_VIEW); - } - - /* - * (non-Javadoc) * @see org.eclipse.ui.IEditorInput#getToolTipText() */ public String getToolTipText() { @@ -285,4 +247,11 @@ public final class SyncInfoCompareInput extends CompareEditorInput implements IR } return false; } + + /* (non-Javadoc) + * @see org.eclipse.team.ui.synchronize.SaveableCompareEditorInput#fireInputChange() + */ + protected void fireInputChange() { + node.fireChange(); + } } |