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 118372 Details for
Bug 193324
[Sync View] Provide compare editor input for a single file that support editing on both sides
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Patch v4
saveableResourceCEI_20081120_2.txt (text/plain), 55.30 KB, created by
Tomasz Zarna
on 2008-11-20 11:11:43 EST
(
hide
)
Description:
Patch v4
Filename:
MIME Type:
Creator:
Tomasz Zarna
Created:
2008-11-20 11:11:43 EST
Size:
55.30 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.team.ui >Index: src/org/eclipse/team/ui/synchronize/SaveableCompareEditorInput.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/ui/synchronize/SaveableCompareEditorInput.java,v >retrieving revision 1.16 >diff -u -r1.16 SaveableCompareEditorInput.java >--- src/org/eclipse/team/ui/synchronize/SaveableCompareEditorInput.java 17 Jul 2008 11:50:02 -0000 1.16 >+++ src/org/eclipse/team/ui/synchronize/SaveableCompareEditorInput.java 20 Nov 2008 16:03:45 -0000 >@@ -10,34 +10,24 @@ > *******************************************************************************/ > package org.eclipse.team.ui.synchronize; > >-import java.lang.reflect.InvocationTargetException; >- > import org.eclipse.compare.*; > import org.eclipse.compare.structuremergeviewer.*; > import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IResource; >-import org.eclipse.core.runtime.*; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.jface.action.*; >-import org.eclipse.jface.resource.ImageDescriptor; >-import org.eclipse.jface.resource.ImageRegistry; >-import org.eclipse.jface.text.IDocument; >-import org.eclipse.jface.text.ITextViewer; > import org.eclipse.jface.util.IPropertyChangeListener; >-import org.eclipse.jface.viewers.*; >-import org.eclipse.osgi.util.NLS; >+import org.eclipse.jface.viewers.ISelectionProvider; >+import org.eclipse.jface.viewers.Viewer; > import org.eclipse.swt.events.DisposeEvent; > import org.eclipse.swt.events.DisposeListener; >-import org.eclipse.swt.graphics.Image; >-import org.eclipse.swt.widgets.*; >-import org.eclipse.team.internal.ui.*; >-import org.eclipse.team.internal.ui.history.CompareFileRevisionEditorInput; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.team.internal.ui.Utils; > import org.eclipse.team.internal.ui.synchronize.LocalResourceSaveableComparison; >-import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement; >-import org.eclipse.team.internal.ui.synchronize.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener; > import org.eclipse.team.ui.mapping.SaveableComparison; > import org.eclipse.ui.*; >-import org.eclipse.ui.actions.*; >-import org.eclipse.ui.keys.IBindingService; > import org.eclipse.ui.services.IDisposable; > > /** >@@ -51,101 +41,12 @@ > * </p> > * @since 3.3 > */ >-public abstract class SaveableCompareEditorInput extends CompareEditorInput implements ISaveablesSource { >+public abstract class SaveableCompareEditorInput extends AbstractSaveableCompareEditorInput { > >- private ICompareInputChangeListener compareInputChangeListener; >- private final IWorkbenchPage page; >- private final ListenerList inputChangeListeners = new ListenerList(ListenerList.IDENTITY); > private Saveable saveable; > private IPropertyListener propertyListener; > > /** >- * Return a typed element that represents a local file. If the element >- * returned from this method is used as the left contributor of the compare >- * input for a {@link SaveableCompareEditorInput}, then the file will >- * be properly saved when the compare editor input or viewers are saved. >- * @param file the file >- * @return a typed element that represents a local file. >- */ >- public static ITypedElement createFileElement(IFile file) { >- return new LocalResourceTypedElement(file); >- } >- >- private static ITypedElement getFileElement(ICompareInput input, >- CompareEditorInput editorInput) { >- if (input.getLeft() instanceof LocalResourceTypedElement) { >- return (LocalResourceTypedElement) input.getLeft(); >- } >- if (editorInput instanceof CompareFileRevisionEditorInput) { >- return ((CompareFileRevisionEditorInput) editorInput).getLocalElement(); >- } >- return null; >- } >- >- private class InternalResourceSaveableComparison extends LocalResourceSaveableComparison implements ISharedDocumentAdapterListener { >- private LocalResourceTypedElement lrte; >- private boolean connected = false; >- public InternalResourceSaveableComparison( >- ICompareInput input, CompareEditorInput editorInput) { >- super(input, editorInput, SaveableCompareEditorInput.getFileElement(input, editorInput)); >- ITypedElement element = SaveableCompareEditorInput.getFileElement(input, editorInput); >- if (element instanceof LocalResourceTypedElement) { >- lrte = (LocalResourceTypedElement) element; >- if (lrte.isConnected()) { >- registerSaveable(true); >- } else { >- lrte.setSharedDocumentListener(this); >- } >- } >- } >- protected void fireInputChange() { >- SaveableCompareEditorInput.this.fireInputChange(); >- } >- public void dispose() { >- super.dispose(); >- if (lrte != null) >- lrte.setSharedDocumentListener(null); >- } >- public void handleDocumentConnected() { >- if (connected) >- return; >- connected = true; >- registerSaveable(false); >- if (lrte != null) >- lrte.setSharedDocumentListener(null); >- } >- >- private void registerSaveable(boolean init) { >- ICompareContainer container = getContainer(); >- IWorkbenchPart part = container.getWorkbenchPart(); >- if (part != null) { >- ISaveablesLifecycleListener lifecycleListener= getSaveablesLifecycleListener(part); >- // Remove this saveable from the lifecycle listener >- if (!init) >- lifecycleListener.handleLifecycleEvent( >- new SaveablesLifecycleEvent(part, SaveablesLifecycleEvent.POST_CLOSE, new Saveable[] { this }, false)); >- // Now fix the hashing so it uses the connected document >- initializeHashing(); >- // Finally, add this saveable back to the listener >- lifecycleListener.handleLifecycleEvent( >- new SaveablesLifecycleEvent(part, SaveablesLifecycleEvent.POST_OPEN, new Saveable[] { this }, false)); >- } >- } >- public void handleDocumentDeleted() { >- // Ignore >- } >- public void handleDocumentDisconnected() { >- // Ignore >- } >- public void handleDocumentFlushed() { >- // Ignore >- } >- public void handleDocumentSaved() { >- // Ignore >- } >- } >- >- /** > * Creates a <code>LocalResourceCompareEditorInput</code> which is initialized with the given > * compare configuration. > * The compare configuration is passed to subsequently created viewers. >@@ -154,8 +55,7 @@ > * @param page the workbench page that will contain the editor > */ > public SaveableCompareEditorInput(CompareConfiguration configuration, IWorkbenchPage page) { >- super(configuration); >- this.page = page; >+ super(configuration, page); > } > > /* (non-Javadoc) >@@ -163,23 +63,6 @@ > */ > protected void contentsCreated() { > super.contentsCreated(); >- compareInputChangeListener = new ICompareInputChangeListener() { >- public void compareInputChanged(ICompareInput source) { >- if (source == getCompareResult()) { >- boolean closed = false; >- if (source.getKind() == Differencer.NO_CHANGE) { >- closed = closeEditor(true); >- } >- if (!closed) { >- // The editor was closed either because the compare input still has changes >- // or because the editor input is dirty. In either case, fire the changes >- // to the registered listeners >- propogateInputChange(); >- } >- } >- } >- }; >- getCompareInput().addCompareInputChangeListener(compareInputChangeListener); > > if (getSaveable() instanceof SaveableComparison) { > SaveableComparison scm = (SaveableComparison) saveable; >@@ -195,23 +78,11 @@ > setDirty(saveable.isDirty()); > } > >- private ISaveablesLifecycleListener getSaveablesLifecycleListener( >- IWorkbenchPart part) { >- ISaveablesLifecycleListener listener = (ISaveablesLifecycleListener)Utils.getAdapter(part, ISaveablesLifecycleListener.class); >- if (listener == null) >- listener = (ISaveablesLifecycleListener) part.getSite().getService(ISaveablesLifecycleListener.class); >- return listener; >- } >- > /* (non-Javadoc) > * @see org.eclipse.compare.CompareEditorInput#handleDispose() > */ > protected void handleDispose() { > super.handleDispose(); >- ICompareInput compareInput = getCompareInput(); >- if (compareInput != null) >- compareInput.removeCompareInputChangeListener(compareInputChangeListener); >- compareInputChangeListener = null; > if (saveable instanceof SaveableComparison) { > SaveableComparison scm = (SaveableComparison) saveable; > scm.removePropertyListener(propertyListener); >@@ -227,99 +98,6 @@ > } > > /** >- * 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 Object prepareInput(IProgressMonitor monitor) >- throws InvocationTargetException, InterruptedException { >- final ICompareInput input = prepareCompareInput(monitor); >- if (input != null) >- setTitle(NLS.bind(TeamUIMessages.SyncInfoCompareInput_title, new String[] { input.getName()})); >- return input; >- } >- >- /** >- * Method called from {@link #prepareInput(IProgressMonitor)} to obtain the input. >- * It's purpose is to ensure that the input is an instance of {@link ICompareInput}. >- * @param monitor a progress monitor >- * @return the compare input >- * @throws InvocationTargetException >- * @throws InterruptedException >- */ >- protected abstract ICompareInput prepareCompareInput(IProgressMonitor monitor) >- throws InvocationTargetException, InterruptedException; >- >- /** >- * Return the compare input of this editor input. >- * @return the compare input of this editor input >- */ >- protected final ICompareInput getCompareInput() { >- return (ICompareInput)getCompareResult(); >- } >- >- /** >- * Callback from the resource saveable that is invoked when the resource is >- * saved so that this input can fire a change event for its input. Subclasses >- * only need this method if the left side of their compare input is >- * an element returned from {@link #createFileElement(IFile)}. >- */ >- protected abstract void fireInputChange(); >- >- /** >- * Close the editor if it is not dirty. If it is still dirty, let the >- * content merge viewer handle the compare input change. >- * @param checkForUnsavedChanges whether to check for unsaved changes >- * @return <code>true</code> if the editor was closed (note that the >- * close may be asynchronous) >- */ >- protected boolean closeEditor(boolean checkForUnsavedChanges) { >- if (isSaveNeeded() && checkForUnsavedChanges) { >- return false; >- } else { >- Runnable runnable = new Runnable() { >- public void run() { >- IEditorPart part = getPage().findEditor(SaveableCompareEditorInput.this); >- getPage().closeEditor(part, false); >- } >- }; >- if (Display.getCurrent() != null) { >- runnable.run(); >- } else { >- Display display = getPage().getWorkbenchWindow().getShell().getDisplay(); >- display.asyncExec(runnable); >- } >- return true; >- } >- } >- >- private IWorkbenchPage getPage() { >- if (page == null) >- return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); >- return page; >- } >- >- /* package */ void propogateInputChange() { >- if (!inputChangeListeners.isEmpty()) { >- Object[] allListeners = inputChangeListeners.getListeners(); >- for (int i = 0; i < allListeners.length; i++) { >- final ICompareInputChangeListener listener = (ICompareInputChangeListener)allListeners[i]; >- SafeRunner.run(new ISafeRunnable() { >- public void run() throws Exception { >- listener.compareInputChanged((ICompareInput)SaveableCompareEditorInput.this.getCompareResult()); >- } >- public void handleException(Throwable exception) { >- // Logged by the safe runner >- } >- }); >- } >- } >- } >- >- /** > * Get the saveable that provides the save behavior for this compare editor input. > * 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 >@@ -342,7 +120,7 @@ > 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, getFileElement(getCompareInput().getLeft(), this)); > } > > /* (non-Javadoc) >@@ -355,37 +133,6 @@ > } > > /* (non-Javadoc) >- * @see org.eclipse.ui.ISaveablesSource#getSaveables() >- */ >- public Saveable[] getSaveables() { >- return getActiveSaveables(); >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.compare.CompareEditorInput#addCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener) >- */ >- public void addCompareInputChangeListener(ICompareInput input, >- ICompareInputChangeListener listener) { >- if (input == getCompareResult()) { >- inputChangeListeners.add(listener); >- } else { >- super.addCompareInputChangeListener(input, listener); >- } >- } >- >- /* (non-Javadoc) >- * @see org.eclipse.compare.CompareEditorInput#removeCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener) >- */ >- public void removeCompareInputChangeListener(ICompareInput input, >- ICompareInputChangeListener listener) { >- if (input == getCompareResult()) { >- inputChangeListeners.remove(listener); >- } else { >- super.removeCompareInputChangeListener(input, listener); >- } >- } >- >- /* (non-Javadoc) > * @see org.eclipse.compare.CompareEditorInput#getAdapter(java.lang.Class) > */ > public Object getAdapter(Class adapter) { >@@ -398,28 +145,6 @@ > return super.getAdapter(adapter); > } > >- /* >- * (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.ui.IEditorInput#getImageDescriptor() >- */ >- public ImageDescriptor getImageDescriptor() { >- return TeamUIPlugin.getImageDescriptor(ITeamUIImages.IMG_SYNC_VIEW); >- } >- > /* (non-Javadoc) > * @see org.eclipse.compare.CompareEditorInput#findContentViewer(org.eclipse.jface.viewers.Viewer, org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.swt.widgets.Composite) > */ >@@ -443,13 +168,6 @@ > return newViewer; > } > >- /* (non-Javadoc) >- * @see org.eclipse.compare.CompareEditorInput#canRunAsJob() >- */ >- public boolean canRunAsJob() { >- return true; >- } >- > public boolean isDirty() { > if (saveable != null) > return saveable.isDirty(); >@@ -460,60 +178,14 @@ > final ISelectionProvider selectionProvider) { > super.registerContextMenu(menu, selectionProvider); > final Saveable saveable = getSaveable(); >+ final ITypedElement element = getFileElement(getCompareInput().getLeft(), this); > if (saveable instanceof LocalResourceSaveableComparison) { > menu.addMenuListener(new IMenuListener() { > public void menuAboutToShow(IMenuManager manager) { >- handleMenuAboutToShow(manager, saveable, selectionProvider); >+ handleMenuAboutToShow(manager, saveable, element, selectionProvider); > } > }); > } > } >- >- /* package */ void handleMenuAboutToShow (IMenuManager manager, Saveable saveable, ISelectionProvider provider) { >- if (provider instanceof ITextViewer) { >- ITextViewer v = (ITextViewer) provider; >- IDocument d = v.getDocument(); >- IDocument other = (IDocument)Utils.getAdapter(saveable, IDocument.class); >- if (d == other) { >- ITypedElement element = getFileElement(getCompareInput(), this); >- if (element instanceof IResourceProvider) { >- IResourceProvider rp = (IResourceProvider) element; >- IResource resource = rp.getResource(); >- StructuredSelection selection = new StructuredSelection(resource); >- IWorkbenchPart workbenchPart = getContainer().getWorkbenchPart(); >- if (workbenchPart != null) { >- IWorkbenchSite ws = workbenchPart.getSite(); >- >- MenuManager submenu1 = >- new MenuManager(getShowInMenuLabel()); >- IContributionItem showInMenu = ContributionItemFactory.VIEWS_SHOW_IN.create(ws.getWorkbenchWindow()); >- submenu1.add(showInMenu); >- manager.insertAfter("file", submenu1); //$NON-NLS-1$ >- MenuManager submenu2 = >- new MenuManager(TeamUIMessages.OpenWithActionGroup_0); >- submenu2.add(new OpenWithMenu(ws.getPage(), resource)); >- manager.insertAfter("file", submenu2); //$NON-NLS-1$ >- >- OpenFileAction openFileAction = new OpenFileAction(ws.getPage()); >- openFileAction.selectionChanged(selection); >- manager.insertAfter("file", openFileAction); //$NON-NLS-1$ >- } >- } >- } >- } >- } >- >- private String getShowInMenuLabel() { >- String keyBinding= null; >- >- IBindingService bindingService= (IBindingService)PlatformUI.getWorkbench().getAdapter(IBindingService.class); >- if (bindingService != null) >- keyBinding= bindingService.getBestActiveBindingFormattedFor("org.eclipse.ui.navigate.showInQuickMenu"); //$NON-NLS-1$ >- >- if (keyBinding == null) >- keyBinding= ""; //$NON-NLS-1$ >- >- return NLS.bind(TeamUIMessages.SaveableCompareEditorInput_0, keyBinding); >- } > > } >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/plugin.properties,v >retrieving revision 1.75 >diff -u -r1.75 plugin.properties >--- plugin.properties 3 Jun 2008 13:35:37 -0000 1.75 >+++ plugin.properties 20 Nov 2008 16:03:44 -0000 >@@ -74,5 +74,7 @@ > CompareLocalHistory.tooltip= Compare the Selected Resource with Local History > ReplaceLocalHistory.label= &Local History... > ReplaceLocalHistory.tooltip= Replace the Selected Resource with Local History >+CompareWithEachOtherAction.label= &Each Other >+CompareWithEachOtherAction.tooltip= Compare the Selected Resources > > ignoresTransferName= Team Ignored Resources Transfer >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/plugin.xml,v >retrieving revision 1.196 >diff -u -r1.196 plugin.xml >--- plugin.xml 17 Apr 2008 15:31:56 -0000 1.196 >+++ plugin.xml 20 Nov 2008 16:03:45 -0000 >@@ -154,6 +154,15 @@ > enablesFor="1" > overrideActionId="replaceFromHistory" > tooltip="%ReplaceLocalHistory.tooltip"/> >+ <action >+ class="org.eclipse.team.internal.ui.actions.CompareAction" >+ enablesFor="2+" >+ id="org.eclipse.team.ui.compareWithEachOther" >+ label="%CompareWithEachOtherAction.label" >+ menubarPath="compareWithMenu/compareWithGroup" >+ overrideActionId="compareWithEachOther" >+ tooltip="CompareWithEachOtherAction.tooltip"> >+ </action> > </objectContribution> > <objectContribution > objectClass="org.eclipse.core.resources.IResource" >Index: src/org/eclipse/team/internal/ui/messages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties,v >retrieving revision 1.243 >diff -u -r1.243 messages.properties >--- src/org/eclipse/team/internal/ui/messages.properties 14 Nov 2008 15:35:40 -0000 1.243 >+++ src/org/eclipse/team/internal/ui/messages.properties 20 Nov 2008 16:03:45 -0000 >@@ -548,3 +548,8 @@ > TeamAction_handlerNotEnabledTitle=Warning > TeamAction_handlerNotEnabledMessage=The action doesn't apply to the current selection. > SaveableCompareEditorInput_0=Show In >+SaveablesCompareEditorInput_tooltip=Two-way compare of {0} with {1} >+ >+SelectAncestorDialog_title=Select Common Ancestor >+SelectAncestorDialog_message=Which resource would you like to use as the common ancestor in the three-way compare? >+SelectAncestorDialog_option=''{0}'' >Index: src/org/eclipse/team/internal/ui/TeamUIMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIMessages.java,v >retrieving revision 1.75 >diff -u -r1.75 TeamUIMessages.java >--- src/org/eclipse/team/internal/ui/TeamUIMessages.java 14 Nov 2008 15:35:40 -0000 1.75 >+++ src/org/eclipse/team/internal/ui/TeamUIMessages.java 20 Nov 2008 16:03:45 -0000 >@@ -225,6 +225,7 @@ > public static String RevisionAnnotationController_0; > > public static String SaveableCompareEditorInput_0; >+ public static String SaveablesCompareEditorInput_tooltip; > > public static String ShowLocalHistory_0; > >@@ -692,4 +693,9 @@ > public static String TeamAction_errorTitle; > public static String TeamAction_handlerNotEnabledTitle; > public static String TeamAction_handlerNotEnabledMessage; >+ >+ public static String SelectAncestorDialog_title; >+ public static String SelectAncestorDialog_message; >+ public static String SelectAncestorDialog_option; >+ > } >Index: src/org/eclipse/team/ui/synchronize/SaveablesCompareEditorInput.java >=================================================================== >RCS file: src/org/eclipse/team/ui/synchronize/SaveablesCompareEditorInput.java >diff -N src/org/eclipse/team/ui/synchronize/SaveablesCompareEditorInput.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/ui/synchronize/SaveablesCompareEditorInput.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,331 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 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 >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.team.ui.synchronize; >+ >+import java.lang.reflect.InvocationTargetException; >+ >+import org.eclipse.compare.*; >+import org.eclipse.compare.structuremergeviewer.*; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.jface.action.*; >+import org.eclipse.jface.util.IPropertyChangeListener; >+import org.eclipse.jface.viewers.ISelectionProvider; >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.osgi.util.NLS; >+import org.eclipse.swt.events.DisposeEvent; >+import org.eclipse.swt.events.DisposeListener; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.team.internal.ui.TeamUIMessages; >+import org.eclipse.team.internal.ui.mapping.AbstractCompareInput; >+import org.eclipse.team.internal.ui.mapping.CompareInputChangeNotifier; >+import org.eclipse.team.internal.ui.synchronize.LocalResourceSaveableComparison; >+import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement; >+import org.eclipse.team.ui.mapping.SaveableComparison; >+import org.eclipse.ui.*; >+import org.eclipse.ui.services.IDisposable; >+ >+/** >+ * A compare editor input that makes use of a {@link Saveable} to manage the >+ * save lifecycle of the left and right sides of the comparison. The ancestor >+ * part of the comparison is not editable. >+ * >+ * @noextend This class is not intended to be subclassed by clients. >+ * @since 3.5 >+ */ >+public class SaveablesCompareEditorInput extends >+ AbstractSaveableCompareEditorInput { >+ >+ private IPropertyListener fLeftPropertyListener; >+ private IPropertyListener fRightPropertyListener; >+ >+ private Saveable fLeftSaveable; >+ private Saveable fRightSaveable; >+ >+ private ITypedElement fAncestorElement; >+ private ITypedElement fLeftElement; >+ private ITypedElement fRightElement; >+ >+ public SaveablesCompareEditorInput(ITypedElement ancestor, ITypedElement left, >+ ITypedElement right, IWorkbenchPage page) { >+ super(new CompareConfiguration(), page); >+ this.fAncestorElement = ancestor; >+ this.fLeftElement = left; >+ this.fRightElement = right; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.compare.CompareEditorInput#contentsCreated() >+ */ >+ protected void contentsCreated() { >+ super.contentsCreated(); >+ >+ if (getLeftSaveable() instanceof SaveableComparison) { >+ SaveableComparison lscm = (SaveableComparison) fLeftSaveable; >+ fLeftPropertyListener = new IPropertyListener() { >+ public void propertyChanged(Object source, int propId) { >+ if (propId == SaveableComparison.PROP_DIRTY) { >+ setDirty(fLeftSaveable.isDirty()); >+ } >+ } >+ }; >+ lscm.addPropertyListener(fLeftPropertyListener); >+ } >+ >+ if (getRightSaveable() instanceof SaveableComparison) { >+ SaveableComparison rscm = (SaveableComparison) fRightSaveable; >+ fRightPropertyListener = new IPropertyListener() { >+ public void propertyChanged(Object source, int propId) { >+ if (propId == SaveableComparison.PROP_DIRTY) { >+ setDirty(fRightSaveable.isDirty()); >+ } >+ } >+ }; >+ rscm.addPropertyListener(fRightPropertyListener); >+ } >+ >+ setDirty(fLeftSaveable.isDirty() || fRightSaveable.isDirty()); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.compare.CompareEditorInput#handleDispose() >+ */ >+ protected void handleDispose() { >+ super.handleDispose(); >+ if (fLeftSaveable instanceof SaveableComparison) { >+ SaveableComparison scm = (SaveableComparison) fLeftSaveable; >+ scm.removePropertyListener(fLeftPropertyListener); >+ } >+ if (fLeftSaveable instanceof LocalResourceSaveableComparison) { >+ LocalResourceSaveableComparison rsc = (LocalResourceSaveableComparison) fLeftSaveable; >+ rsc.dispose(); >+ } >+ if (fRightSaveable instanceof SaveableComparison) { >+ SaveableComparison scm = (SaveableComparison) fRightSaveable; >+ scm.removePropertyListener(fRightPropertyListener); >+ } >+ if (fRightSaveable instanceof LocalResourceSaveableComparison) { >+ LocalResourceSaveableComparison rsc = (LocalResourceSaveableComparison) fRightSaveable; >+ rsc.dispose(); >+ } >+ >+ if (getCompareResult() instanceof IDisposable) { >+ ((IDisposable) getCompareResult()).dispose(); >+ } >+ } >+ >+ public String getToolTipText() { >+ IResource leftResource = getResource(fLeftElement); >+ IResource rightResource = getResource(fRightElement); >+ >+ if (leftResource != null && rightResource != null) { >+ String leftLabel = leftResource.getFullPath().makeRelative().toString(); >+ String rightLabel = rightResource.getFullPath().makeRelative().toString(); >+ return NLS.bind(TeamUIMessages.SaveablesCompareEditorInput_tooltip, new String[] { leftLabel, rightLabel }); >+ } >+ return NLS.bind(TeamUIMessages.SaveablesCompareEditorInput_tooltip, new String[] { fLeftElement.getName(), fRightElement.getName() }); >+ } >+ >+ protected void fireInputChange() { >+ ((MyDiffNode)getCompareResult()).fireChange(); >+ } >+ >+ protected Saveable getLeftSaveable() { >+ if (fLeftSaveable == null) { >+ fLeftSaveable = createLeftSaveable(); >+ } >+ return fLeftSaveable; >+ } >+ >+ protected Saveable getRightSaveable() { >+ if (fRightSaveable == null) { >+ fRightSaveable = createRightSaveable(); >+ } >+ return fRightSaveable; >+ } >+ >+ protected Saveable createLeftSaveable() { >+ Object compareResult = getCompareResult(); >+ Assert.isNotNull(compareResult, "This method cannot be called until after prepareInput is called"); //$NON-NLS-1$ >+ ITypedElement leftFileElement = getFileElement(getCompareInput().getLeft(), this); >+ return new InternalResourceSaveableComparison((ICompareInput)compareResult, this, leftFileElement); >+ } >+ >+ protected Saveable createRightSaveable() { >+ Object compareResult = getCompareResult(); >+ Assert.isNotNull(compareResult, "This method cannot be called until after prepareInput is called"); //$NON-NLS-1$ >+ ITypedElement rightFileElement = getFileElement(getCompareInput().getRight(), this); >+ return new InternalResourceSaveableComparison((ICompareInput)compareResult, this, rightFileElement); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.ISaveablesSource#getActiveSaveables() >+ */ >+ public Saveable[] getActiveSaveables() { >+ if (getCompareResult() == null) >+ return new Saveable[0]; >+ return new Saveable[] { getLeftSaveable(), getRightSaveable() }; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.compare.CompareEditorInput#findContentViewer(org.eclipse.jface.viewers.Viewer, org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.swt.widgets.Composite) >+ */ >+ public Viewer findContentViewer(Viewer pOldViewer, ICompareInput pInput, Composite pParent) { >+ Viewer newViewer = super.findContentViewer(pOldViewer, pInput, pParent); >+ boolean isNewViewer= newViewer != pOldViewer; >+ if (isNewViewer && newViewer instanceof IPropertyChangeNotifier >+ && fLeftSaveable instanceof IPropertyChangeListener >+ && fRightSaveable instanceof IPropertyChangeListener) { >+ // Register the model for change events if appropriate >+ final IPropertyChangeNotifier dsp= (IPropertyChangeNotifier) newViewer; >+ final IPropertyChangeListener lpcl = (IPropertyChangeListener) fLeftSaveable; >+ final IPropertyChangeListener rpcl = (IPropertyChangeListener) fRightSaveable; >+ dsp.addPropertyChangeListener(lpcl); >+ dsp.addPropertyChangeListener(rpcl); >+ Control c= newViewer.getControl(); >+ c.addDisposeListener( >+ new DisposeListener() { >+ public void widgetDisposed(DisposeEvent e) { >+ dsp.removePropertyChangeListener(lpcl); >+ dsp.removePropertyChangeListener(rpcl); >+ } >+ } >+ ); >+ } >+ return newViewer; >+ } >+ >+ >+ public boolean isDirty() { >+ if (fLeftSaveable != null && fLeftSaveable.isDirty()) >+ return true; >+ if (fRightSaveable != null && fRightSaveable.isDirty()) >+ return true; >+ return super.isDirty(); >+ } >+ >+ protected ICompareInput prepareCompareInput(IProgressMonitor monitor) >+ throws InvocationTargetException, InterruptedException { >+ ICompareInput input = createCompareInput(); >+ getCompareConfiguration().setLeftEditable(isEditable(input.getLeft())); >+ getCompareConfiguration().setRightEditable(isEditable(input.getRight())); >+ initLabels(); >+ return input; >+ } >+ >+ private boolean isEditable(Object obj) { >+ if (obj instanceof IEditableContent) { >+ return ((IEditableContent) obj).isEditable(); >+ } >+ return false; >+ } >+ >+ private void initLabels() { >+ CompareConfiguration cc = getCompareConfiguration(); >+ >+ IResource ancestorResource = getResource(fAncestorElement); >+ IResource leftResource = getResource(fLeftElement); >+ IResource rightResource = getResource(fRightElement); >+ >+ if (ancestorResource != null) { >+ String ancestorLabel = ancestorResource.getFullPath().makeRelative() >+ .toString(); >+ >+ cc.setAncestorLabel(ancestorLabel); >+ } >+ >+ if (leftResource != null && rightResource != null) { >+ String leftLabel = leftResource.getFullPath().makeRelative() >+ .toString(); >+ String rightLabel = rightResource.getFullPath().makeRelative() >+ .toString(); >+ >+ cc.setLeftLabel(leftLabel); >+ cc.setRightLabel(rightLabel); >+ } >+ } >+ >+ private ICompareInput createCompareInput() { >+ return fAncestorElement == null ? new MyDiffNode(fLeftElement, >+ fRightElement) : new MyDiffNode(fAncestorElement, fLeftElement, >+ fRightElement); >+ } >+ >+ private CompareInputChangeNotifier notifier = new CompareInputChangeNotifier() { >+ protected IResource[] getResources(ICompareInput input) { >+ IResource leftResource = getResource(fLeftElement); >+ IResource rightResource = getResource(fRightElement); >+ if (leftResource == null && rightResource == null) >+ return new IResource[0]; >+ if (leftResource == null && rightResource != null) >+ return new IResource[] { rightResource }; >+ if (leftResource != null && rightResource == null) >+ return new IResource[] { leftResource }; >+ return new IResource[] { leftResource, rightResource }; >+ } >+ }; >+ >+ private class MyDiffNode extends AbstractCompareInput { >+ public MyDiffNode(ITypedElement left, ITypedElement right) { >+ super(Differencer.CHANGE, null, left, right); >+ } >+ public MyDiffNode(ITypedElement ancestor, ITypedElement left, ITypedElement right) { >+ super(Differencer.CONFLICTING, ancestor, left, right); >+ } >+ public void fireChange() { >+ super.fireChange(); >+ } >+ protected CompareInputChangeNotifier getChangeNotifier() { >+ return notifier; >+ } >+ public boolean needsUpdate() { >+ return true; >+ } >+ public void update() { >+ fireChange(); >+ } >+ } >+ >+ private IResource getResource(ITypedElement pElement) { >+ if (pElement instanceof LocalResourceTypedElement >+ && pElement instanceof IResourceProvider) { >+ return ((IResourceProvider) pElement).getResource(); >+ } >+ return null; >+ } >+ >+ public void registerContextMenu(final MenuManager pMenuManager, >+ final ISelectionProvider pSelectionProvider) { >+ super.registerContextMenu(pMenuManager, pSelectionProvider); >+ final Saveable lLeftSaveable = getLeftSaveable(); >+ final ITypedElement lLeftElement = getFileElement(getCompareInput().getLeft(), this); >+ if (lLeftSaveable instanceof LocalResourceSaveableComparison) { >+ pMenuManager.addMenuListener(new IMenuListener() { >+ public void menuAboutToShow(IMenuManager manager) { >+ handleMenuAboutToShow(manager, lLeftSaveable, lLeftElement, pSelectionProvider); >+ } >+ }); >+ } >+ final Saveable lRightSaveable = getRightSaveable(); >+ final ITypedElement lRightElement = getFileElement(getCompareInput().getRight(), this); >+ if (lRightSaveable instanceof LocalResourceSaveableComparison) { >+ pMenuManager.addMenuListener(new IMenuListener() { >+ public void menuAboutToShow(IMenuManager manager) { >+ handleMenuAboutToShow(manager, lRightSaveable, lRightElement, pSelectionProvider); >+ } >+ }); >+ } >+ } >+ >+ //TODO: add getAdapter for IFile[] >+} >Index: src/org/eclipse/team/internal/ui/actions/CompareAction.java >=================================================================== >RCS file: src/org/eclipse/team/internal/ui/actions/CompareAction.java >diff -N src/org/eclipse/team/internal/ui/actions/CompareAction.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/internal/ui/actions/CompareAction.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,150 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 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 >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.team.internal.ui.actions; >+ >+import java.lang.reflect.InvocationTargetException; >+ >+import org.eclipse.compare.*; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.jface.action.IAction; >+import org.eclipse.jface.dialogs.IDialogConstants; >+import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.jface.window.Window; >+import org.eclipse.osgi.util.NLS; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.*; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.*; >+import org.eclipse.team.internal.ui.TeamUIMessages; >+import org.eclipse.team.ui.synchronize.AbstractSaveableCompareEditorInput; >+import org.eclipse.team.ui.synchronize.SaveablesCompareEditorInput; >+import org.eclipse.ui.*; >+ >+public class CompareAction extends TeamAction { >+ >+ protected void execute(IAction action) throws InvocationTargetException, >+ InterruptedException { >+ >+ IResource[] selectedResources = getSelectedResources(); >+ >+ ITypedElement ancestor = null; >+ ITypedElement left = null; >+ ITypedElement right = null; >+ >+ if (selectedResources.length == 2) { >+ if (selectedResources[0] != null) >+ left = getElementFor(selectedResources[0]); >+ >+ if (selectedResources[1] != null) >+ right = getElementFor(selectedResources[1]); >+ >+ } else if (selectedResources.length == 3) { >+ // prompt for ancestor >+ SelectAncestorDialog dialog = >+ new SelectAncestorDialog(getShell(), selectedResources); >+ int code = dialog.open(); >+ if (code == Window.CANCEL) >+ return; >+ >+ ancestor = getElementFor(dialog.ancestorResource); >+ left = getElementFor(dialog.leftResource); >+ right = getElementFor(dialog.rightResource); >+ } else { >+ return; >+ } >+ openInCompare(ancestor, left, right); >+ } >+ >+ //XXX: from CompareRevisionAction* >+ private void openInCompare(ITypedElement ancestor, ITypedElement left, ITypedElement right) { >+ IWorkbenchPage workBenchPage = getTargetPage(); >+ CompareEditorInput input = new SaveablesCompareEditorInput(ancestor, left, right, workBenchPage); >+ IEditorPart editor = CompareRevisionAction.findReusableCompareEditor(workBenchPage); >+ if (editor != null) { >+ IEditorInput otherInput = editor.getEditorInput(); >+ if (otherInput.equals(input)) { >+ // simply provide focus to editor >+ workBenchPage.activate(editor); >+ } else { >+ // if editor is currently not open on that input either re-use existing >+ CompareUI.reuseCompareEditor(input, (IReusableEditor) editor); >+ workBenchPage.activate(editor); >+ } >+ } else { >+ CompareUI.openCompareEditor(input); >+ } >+ } >+ >+ public boolean isEnabled() { >+ int l = getSelectedResources().length; >+ return l == 2 || l == 3; >+ } >+ >+ //XXX: from CompareRevisionAction >+ private ITypedElement getElementFor(IResource resource) { >+ return AbstractSaveableCompareEditorInput.createFileElement((IFile)resource); >+ } >+ >+ // see org.eclipse.compare.internal.ResourceCompareInput.SelectAncestorDialog >+ private class SelectAncestorDialog extends MessageDialog { >+ private IResource[] theResources; >+ IResource ancestorResource; >+ IResource leftResource; >+ IResource rightResource; >+ >+ private Button[] buttons; >+ >+ public SelectAncestorDialog(Shell parentShell, IResource[] theResources) { >+ super(parentShell, TeamUIMessages.SelectAncestorDialog_title, >+ null, TeamUIMessages.SelectAncestorDialog_message, >+ MessageDialog.QUESTION, >+ new String[] { IDialogConstants.OK_LABEL, >+ IDialogConstants.CANCEL_LABEL }, 0); >+ this.theResources = theResources; >+ } >+ >+ protected Control createCustomArea(Composite parent) { >+ Composite composite = new Composite(parent, SWT.NONE); >+ composite.setLayout(new GridLayout()); >+ buttons = new Button[3]; >+ for (int i = 0; i < 3; i++) { >+ buttons[i] = new Button(composite, SWT.RADIO); >+ buttons[i].addSelectionListener(selectionListener); >+ buttons[i].setText(NLS.bind(TeamUIMessages.SelectAncestorDialog_option, >+ theResources[i].getFullPath().toPortableString())); >+ buttons[i].setFont(parent.getFont()); >+ // set initial state >+ buttons[i].setSelection(i == 0); >+ } >+ pickAncestor(0); >+ return composite; >+ } >+ >+ private void pickAncestor(int i) { >+ ancestorResource = theResources[i]; >+ leftResource = theResources[i == 0 ? 1 : 0]; >+ rightResource = theResources[i == 2 ? 1 : 2]; >+ } >+ >+ private SelectionListener selectionListener = new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ Button selectedButton = (Button) e.widget; >+ if (!selectedButton.getSelection()) >+ return; >+ for (int i = 0; i < 3; i++) >+ if (selectedButton == buttons[i]) >+ pickAncestor(i); >+ } >+ }; >+ } >+ >+} >Index: src/org/eclipse/team/ui/synchronize/AbstractSaveableCompareEditorInput.java >=================================================================== >RCS file: src/org/eclipse/team/ui/synchronize/AbstractSaveableCompareEditorInput.java >diff -N src/org/eclipse/team/ui/synchronize/AbstractSaveableCompareEditorInput.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/ui/synchronize/AbstractSaveableCompareEditorInput.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,382 @@ >+/******************************************************************************* >+ * Copyright (c) 2007 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 >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.team.ui.synchronize; >+ >+import java.lang.reflect.InvocationTargetException; >+ >+import org.eclipse.compare.*; >+import org.eclipse.compare.structuremergeviewer.*; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.runtime.*; >+import org.eclipse.jface.action.*; >+import org.eclipse.jface.resource.ImageDescriptor; >+import org.eclipse.jface.resource.ImageRegistry; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.ITextViewer; >+import org.eclipse.jface.viewers.ISelectionProvider; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.osgi.util.NLS; >+import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.team.internal.ui.*; >+import org.eclipse.team.internal.ui.history.CompareFileRevisionEditorInput; >+import org.eclipse.team.internal.ui.synchronize.LocalResourceSaveableComparison; >+import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement; >+import org.eclipse.team.internal.ui.synchronize.EditableSharedDocumentAdapter.ISharedDocumentAdapterListener; >+import org.eclipse.ui.*; >+import org.eclipse.ui.actions.*; >+import org.eclipse.ui.keys.IBindingService; >+ >+/** >+ * @since 3.5 >+ * @noextend This class is not intended to be subclassed outside the framework. >+ */ >+public abstract class AbstractSaveableCompareEditorInput extends >+ CompareEditorInput implements ISaveablesSource { >+ >+ private final IWorkbenchPage page; >+ private final ListenerList inputChangeListeners = new ListenerList(ListenerList.IDENTITY); >+ private ICompareInputChangeListener compareInputChangeListener; >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.compare.CompareEditorInput#contentsCreated() >+ */ >+ protected void contentsCreated() { >+ super.contentsCreated(); >+ compareInputChangeListener = new ICompareInputChangeListener() { >+ public void compareInputChanged(ICompareInput source) { >+ if (source == getCompareResult()) { >+ boolean closed = false; >+ if (source.getKind() == Differencer.NO_CHANGE) { >+ closed = closeEditor(true); >+ } >+ if (!closed) { >+ // The editor was closed either because the compare input still has changes >+ // or because the editor input is dirty. In either case, fire the changes >+ // to the registered listeners >+ propogateInputChange(); >+ } >+ } >+ } >+ }; >+ getCompareInput().addCompareInputChangeListener(compareInputChangeListener); >+ } >+ >+ protected void handleDispose() { >+ super.handleDispose(); >+ ICompareInput compareInput = getCompareInput(); >+ if (compareInput != null) >+ compareInput.removeCompareInputChangeListener(compareInputChangeListener); >+ compareInputChangeListener = null; >+ } >+ >+ /* package */ static ITypedElement getFileElement(ITypedElement element, CompareEditorInput editorInput) { >+ if (element instanceof LocalResourceTypedElement) { >+ return (LocalResourceTypedElement) element; >+ } >+ if (editorInput instanceof CompareFileRevisionEditorInput) { >+ return ((CompareFileRevisionEditorInput) editorInput).getLocalElement(); >+ } >+ return null; >+ } >+ >+ /** >+ * Return a typed element that represents a local file. If the element >+ * returned from this method is used as the left contributor of the compare >+ * input for a {@link SaveableCompareEditorInput}, then the file will >+ * be properly saved when the compare editor input or viewers are saved. >+ * @param file the file >+ * @return a typed element that represents a local file. >+ */ >+ public static ITypedElement createFileElement(IFile file) { >+ return new LocalResourceTypedElement(file); >+ } >+ >+ /* package */ class InternalResourceSaveableComparison extends LocalResourceSaveableComparison implements ISharedDocumentAdapterListener { >+ private LocalResourceTypedElement lrte; >+ private boolean connected = false; >+ public InternalResourceSaveableComparison( >+ ICompareInput input, CompareEditorInput editorInput, ITypedElement element) { >+ super(input, editorInput, element); >+ if (element instanceof LocalResourceTypedElement) { >+ lrte = (LocalResourceTypedElement) element; >+ if (lrte.isConnected()) { >+ registerSaveable(true); >+ } else { >+ lrte.setSharedDocumentListener(this); >+ } >+ } >+ } >+ protected void fireInputChange() { >+ AbstractSaveableCompareEditorInput.this.fireInputChange(); >+ } >+ public void dispose() { >+ super.dispose(); >+ if (lrte != null) >+ lrte.setSharedDocumentListener(null); >+ } >+ public void handleDocumentConnected() { >+ if (connected) >+ return; >+ connected = true; >+ registerSaveable(false); >+ if (lrte != null) >+ lrte.setSharedDocumentListener(null); >+ } >+ private void registerSaveable(boolean init) { >+ ICompareContainer container = getContainer(); >+ IWorkbenchPart part = container.getWorkbenchPart(); >+ if (part != null) { >+ ISaveablesLifecycleListener lifecycleListener= getSaveablesLifecycleListener(part); >+ // Remove this saveable from the lifecycle listener >+ if (!init) >+ lifecycleListener.handleLifecycleEvent( >+ new SaveablesLifecycleEvent(part, SaveablesLifecycleEvent.POST_CLOSE, new Saveable[] { this }, false)); >+ // Now fix the hashing so it uses the connected document >+ initializeHashing(); >+ // Finally, add this saveable back to the listener >+ lifecycleListener.handleLifecycleEvent( >+ new SaveablesLifecycleEvent(part, SaveablesLifecycleEvent.POST_OPEN, new Saveable[] { this }, false)); >+ } >+ } >+ public void handleDocumentDeleted() { >+ // Ignore >+ } >+ public void handleDocumentDisconnected() { >+ // Ignore >+ } >+ public void handleDocumentFlushed() { >+ // Ignore >+ } >+ public void handleDocumentSaved() { >+ // Ignore >+ } >+ } >+ >+ public AbstractSaveableCompareEditorInput(CompareConfiguration configuration, IWorkbenchPage page) { >+ super(configuration); >+ this.page = page; >+ } >+ >+ /* package */ ISaveablesLifecycleListener getSaveablesLifecycleListener(IWorkbenchPart part) { >+ ISaveablesLifecycleListener listener = (ISaveablesLifecycleListener)Utils.getAdapter(part, ISaveablesLifecycleListener.class); >+ if (listener == null) >+ listener = (ISaveablesLifecycleListener) part.getSite().getService(ISaveablesLifecycleListener.class); >+ return listener; >+ } >+ >+ /** >+ * 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 Object prepareInput(IProgressMonitor monitor) >+ throws InvocationTargetException, InterruptedException { >+ final ICompareInput input = prepareCompareInput(monitor); >+ if (input != null) >+ setTitle(NLS.bind(TeamUIMessages.SyncInfoCompareInput_title, >+ new String[] { input.getName() })); >+ return input; >+ } >+ >+ /** >+ * Close the editor if it is not dirty. If it is still dirty, let the >+ * content merge viewer handle the compare input change. >+ * @param checkForUnsavedChanges whether to check for unsaved changes >+ * @return <code>true</code> if the editor was closed (note that the >+ * close may be asynchronous) >+ */ >+ protected boolean closeEditor(boolean checkForUnsavedChanges) { >+ if (isSaveNeeded() && checkForUnsavedChanges) { >+ return false; >+ } else { >+ Runnable runnable = new Runnable() { >+ public void run() { >+ IEditorPart part = getPage().findEditor(AbstractSaveableCompareEditorInput.this); >+ getPage().closeEditor(part, false); >+ } >+ }; >+ if (Display.getCurrent() != null) { >+ runnable.run(); >+ } else { >+ Display display = getPage().getWorkbenchWindow().getShell().getDisplay(); >+ display.asyncExec(runnable); >+ } >+ return true; >+ } >+ } >+ >+ /** >+ * Method called from {@link #prepareInput(IProgressMonitor)} to obtain the input. >+ * It's purpose is to ensure that the input is an instance of {@link ICompareInput}. >+ * @param monitor a progress monitor >+ * @return the compare input >+ * @throws InvocationTargetException >+ * @throws InterruptedException >+ */ >+ protected abstract ICompareInput prepareCompareInput(IProgressMonitor monitor) >+ throws InvocationTargetException, InterruptedException; >+ >+ /* package */ IWorkbenchPage getPage() { >+ if (page == null) >+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); >+ return page; >+ } >+ >+ /** >+ * Return the compare input of this editor input. >+ * @return the compare input of this editor input >+ */ >+ protected final ICompareInput getCompareInput() { >+ return (ICompareInput)getCompareResult(); >+ } >+ >+ /** >+ * Callback from the resource saveable that is invoked when the resource is >+ * saved so that this input can fire a change event for its input. Subclasses >+ * only need this method if the left side of their compare input is >+ * an element returned from {@link SaveableCompareEditorInput#createFileElement(IFile)}. >+ */ >+ protected abstract void fireInputChange(); >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.compare.CompareEditorInput#addCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener) >+ */ >+ public void addCompareInputChangeListener(ICompareInput input, >+ ICompareInputChangeListener listener) { >+ if (input == getCompareResult()) { >+ inputChangeListeners.add(listener); >+ } else { >+ super.addCompareInputChangeListener(input, listener); >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.compare.CompareEditorInput#removeCompareInputChangeListener(org.eclipse.compare.structuremergeviewer.ICompareInput, org.eclipse.compare.structuremergeviewer.ICompareInputChangeListener) >+ */ >+ public void removeCompareInputChangeListener(ICompareInput input, >+ ICompareInputChangeListener listener) { >+ if (input == getCompareResult()) { >+ inputChangeListeners.remove(listener); >+ } else { >+ super.removeCompareInputChangeListener(input, listener); >+ } >+ } >+ >+ /* package */ void propogateInputChange() { >+ if (!inputChangeListeners.isEmpty()) { >+ Object[] allListeners = inputChangeListeners.getListeners(); >+ final ICompareInput compareResult = (ICompareInput) getCompareResult(); >+ for (int i = 0; i < allListeners.length; i++) { >+ final ICompareInputChangeListener listener = (ICompareInputChangeListener)allListeners[i]; >+ SafeRunner.run(new ISafeRunnable() { >+ public void run() throws Exception { >+ listener.compareInputChanged(compareResult); >+ } >+ public void handleException(Throwable exception) { >+ // Logged by the safe runner >+ } >+ }); >+ } >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.ISaveablesSource#getActiveSaveables() >+ */ >+ public abstract Saveable[] getActiveSaveables(); >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.ISaveablesSource#getSaveables() >+ */ >+ public Saveable[] getSaveables() { >+ return getActiveSaveables(); >+ } >+ >+ /* >+ * (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.ui.IEditorInput#getImageDescriptor() >+ */ >+ public ImageDescriptor getImageDescriptor() { >+ return TeamUIPlugin.getImageDescriptor(ITeamUIImages.IMG_SYNC_VIEW); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.compare.CompareEditorInput#canRunAsJob() >+ */ >+ public boolean canRunAsJob() { >+ return true; >+ } >+ >+ /* package */ void handleMenuAboutToShow(IMenuManager manager, Saveable saveable, ITypedElement element, >+ ISelectionProvider provider) { >+ if (provider instanceof ITextViewer) { >+ ITextViewer v = (ITextViewer) provider; >+ IDocument d = v.getDocument(); >+ IDocument other = (IDocument)Utils.getAdapter(saveable, IDocument.class); >+ if (d == other) { >+ if (element instanceof IResourceProvider) { >+ IResourceProvider rp = (IResourceProvider) element; >+ IResource resource = rp.getResource(); >+ StructuredSelection selection = new StructuredSelection(resource); >+ IWorkbenchPart workbenchPart = getContainer().getWorkbenchPart(); >+ if (workbenchPart != null) { >+ IWorkbenchSite ws = workbenchPart.getSite(); >+ MenuManager submenu1 = >+ new MenuManager(getShowInMenuLabel()); >+ IContributionItem showInMenu = ContributionItemFactory.VIEWS_SHOW_IN.create(ws.getWorkbenchWindow()); >+ submenu1.add(showInMenu); >+ manager.insertAfter("file", submenu1); //$NON-NLS-1$ >+ MenuManager submenu2 = >+ new MenuManager(TeamUIMessages.OpenWithActionGroup_0); >+ submenu2.add(new OpenWithMenu(ws.getPage(), resource)); >+ manager.insertAfter("file", submenu2); //$NON-NLS-1$ >+ >+ OpenFileAction openFileAction = new OpenFileAction(ws.getPage()); >+ openFileAction.selectionChanged(selection); >+ manager.insertAfter("file", openFileAction); //$NON-NLS-1$ >+ } >+ } >+ } >+ } >+ } >+ >+ /* package */ String getShowInMenuLabel() { >+ String keyBinding= null; >+ >+ IBindingService bindingService= (IBindingService)PlatformUI.getWorkbench().getAdapter(IBindingService.class); >+ if (bindingService != null) >+ keyBinding= bindingService.getBestActiveBindingFormattedFor("org.eclipse.ui.navigate.showInQuickMenu"); //$NON-NLS-1$ >+ >+ if (keyBinding == null) >+ keyBinding= ""; //$NON-NLS-1$ >+ >+ return NLS.bind(TeamUIMessages.SaveableCompareEditorInput_0, keyBinding); >+ } >+}
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 193324
:
71868
|
71869
|
72494
|
73935
|
74552
|
75050
|
77123
|
118372
|
118373
|
118899
|
118928
|
118929