Class SaveableCompareEditorInput
- All Implemented Interfaces:
ICompareContainer
,IPropertyChangeNotifier
,IAdaptable
,IRunnableContext
,IRunnableWithProgress
,IEditorInput
,ISaveablesSource
- Direct Known Subclasses:
SyncInfoCompareInput
Saveable
to manage the save
lifecycle of the editor input. If the element returned from
createFileElement(IFile)
is used as the left side of the compare input
and the default saveable returned from createSaveable()
is used, then
this compare input will provide the complete save lifecycle for the local file.
Clients may subclass this class.
- Since:
- 3.3
-
Field Summary
Fields inherited from class org.eclipse.compare.CompareEditorInput
DIRTY_STATE, PROP_SELECTED_EDITION, PROP_TITLE, PROP_TITLE_IMAGE
-
Constructor Summary
ConstructorDescriptionSaveableCompareEditorInput
(CompareConfiguration configuration, IWorkbenchPage page) Creates aLocalResourceCompareEditorInput
which is initialized with the given compare configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCompareInputChangeListener
(ICompareInput input, ICompareInputChangeListener listener) Register for change events for the given compare input.boolean
Returns whether this compare editor input can be run as a job.protected boolean
closeEditor
(boolean checkForUnsavedChanges) Close the editor if it is not dirty.protected void
Callback that occurs after the control for the input has been created.static ITypedElement
createFileElement
(IFile file) Returns a typed element that represents a local file.protected Saveable
Create the saveable that provides the save behavior for this compare editor input.findContentViewer
(Viewer oldViewer, ICompareInput input, Composite parent) Implements the dynamic viewer switching for content viewers.protected abstract void
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.Saveable[]
Returns the saveables currently active in the workbench part.<T> T
getAdapter
(Class<T> adapter) Returns an object which is an instance of the given class associated with this object.protected final ICompareInput
Returns the compare input of this editor input.Returns the image descriptor for this input.protected Saveable
Get the saveable that provides the save behavior for this compare editor input.Saveable[]
Returns the saveables presented by the workbench part.Returns the title image which will be used in the compare editor's title bar.protected void
Callback that occurs when the UI associated with this compare editor input is disposed.boolean
isDirty()
Returnstrue
if there are unsaved changes.protected abstract ICompareInput
prepareCompareInput
(IProgressMonitor monitor) Method called fromprepareInput(IProgressMonitor)
to obtain the input.protected Object
prepareInput
(IProgressMonitor monitor) Prepares the compare input of this editor input.void
registerContextMenu
(MenuManager menu, ISelectionProvider selectionProvider) Register the content menu with the container to give the container a chance to add additional items to the context menu such as popup menu object contributions.void
removeCompareInputChangeListener
(ICompareInput input, ICompareInputChangeListener listener) Remove the change listener from the given compare input.Methods inherited from class org.eclipse.compare.CompareEditorInput
addPropertyChangeListener, belongsTo, cancelPressed, contributeToToolBar, createContents, createContentViewerSwitchingPane, createDiffViewer, createOutlineContents, createStructureInputPane, exists, findStructureViewer, firePropertyChange, flushLeftViewers, flushRightViewers, flushViewers, getActionBars, getCancelButtonLabel, getCompareConfiguration, getCompareResult, getContainer, getContentViewerDescriptor, getMessage, getName, getNavigator, getOKButtonLabel, getPersistable, getSelectedEdition, getServiceLocator, getStructureViewerDescriptor, getTitle, getToolTipText, getWorkbenchPart, isEditionSelectionDialog, isLeftSaveNeeded, isRightSaveNeeded, isSaveNeeded, okPressed, removePropertyChangeListener, run, run, runAsynchronously, save, saveChanges, setContainer, setContentViewerDescriptor, setDirty, setFocus, setFocus2, setHelpContextId, setLeftDirty, setMessage, setRightDirty, setStatusMessage, setStructureViewerDescriptor, setTitle
-
Constructor Details
-
SaveableCompareEditorInput
Creates aLocalResourceCompareEditorInput
which is initialized with the given compare configuration. The compare configuration is passed to subsequently created viewers.- Parameters:
configuration
- the compare configurationpage
- the workbench page that will contain the editor
-
-
Method Details
-
createFileElement
Returns 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 aSaveableCompareEditorInput
, then the file will be properly saved when the compare editor input or viewers are saved.- Parameters:
file
- the file- Returns:
- a typed element that represents a local file.
-
contentsCreated
protected void contentsCreated()Description copied from class:CompareEditorInput
Callback that occurs after the control for the input has been created. If this method gets invoked thenCompareEditorInput.handleDispose()
will be invoked when the control is disposed. Subclasses may extend this method to register any listeners that need to be de-registered when the input is disposed.- Overrides:
contentsCreated
in classCompareEditorInput
-
handleDispose
protected void handleDispose()Description copied from class:CompareEditorInput
Callback that occurs when the UI associated with this compare editor input is disposed. This method will only be invoked if the UI has been created (i.e. after the call toCompareEditorInput.createContents(Composite)
. Subclasses can extend this method but ensure that the overridden method is invoked.- Overrides:
handleDispose
in classCompareEditorInput
-
prepareInput
protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException Prepares 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 theprepareCompareInput(IProgressMonitor)
method which subclasses must implement.- Specified by:
prepareInput
in classCompareEditorInput
- Parameters:
monitor
- the progress monitor to use to display progress and receive requests for cancellation- Returns:
- the result of the compare operation, or
null
if there are no differences - Throws:
InvocationTargetException
- if theprepareInput
method must propagate a checked exception, it should wrap it inside anInvocationTargetException
; runtime exceptions are automatically wrapped in anInvocationTargetException
by the calling contextInterruptedException
- if the operation detects a request to cancel, usingIProgressMonitor.isCanceled()
, it should exit by throwingInterruptedException
- See Also:
-
prepareCompareInput
protected abstract ICompareInput prepareCompareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException Method called fromprepareInput(IProgressMonitor)
to obtain the input. Its purpose is to ensure that the input is an instance ofICompareInput
.- Parameters:
monitor
- a progress monitor- Returns:
- the compare input
- Throws:
InvocationTargetException
- if an error occursInterruptedException
- if operation is interrupted
-
getCompareInput
Returns the compare input of this editor input.- Returns:
- the compare input of this editor input
-
fireInputChange
protected abstract void fireInputChange()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 fromcreateFileElement(IFile)
. -
closeEditor
protected boolean closeEditor(boolean checkForUnsavedChanges) Close the editor if it is not dirty. If it is still dirty, let the content merge viewer handle the compare input change.- Parameters:
checkForUnsavedChanges
- whether to check for unsaved changes- Returns:
true
if the editor was closed (note that the close may be asynchronous)
-
getSaveable
Get the saveable that provides the save behavior for this compare editor input. ThecreateSaveable()
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 theCompareEditorInput.run(IProgressMonitor)
method is called which will in turn will invokeprepareCompareInput(IProgressMonitor)
.- Returns:
- saveable that provides the save behavior for this compare editor input.
-
createSaveable
Create the saveable that provides the save behavior for this compare editor input. By default, a saveable that handles local files is returned.- Returns:
- the saveable that provides the save behavior for this compare editor input
-
getActiveSaveables
Description copied from interface:ISaveablesSource
Returns the saveables currently active in the workbench part.Certain workbench actions, such as Save, target only the active saveables in the active part. For example, the active saveables could be determined based on the current selection in the part.
- Specified by:
getActiveSaveables
in interfaceISaveablesSource
- Returns:
- the saveables currently active in the workbench part
-
getSaveables
Description copied from interface:ISaveablesSource
Returns the saveables presented by the workbench part. If the return value of this method changes during the lifetime of this part (i.e. after initialization and control creation but before disposal) the part must notify an implicit listener usingISaveablesLifecycleListener.handleLifecycleEvent(SaveablesLifecycleEvent)
.Additions of saveables to the list of saveables of this part are announced using an event of type
SaveablesLifecycleEvent.POST_OPEN
. Removals are announced in a two-stage process, first using an event of typeSaveablesLifecycleEvent.PRE_CLOSE
followed by an event of typeSaveablesLifecycleEvent.POST_CLOSE
. Since firing thePRE_CLOSE
event may trigger prompts to save dirty saveables, the cancellation status of the event must be checked by the part after the notification. When removing only non-dirty saveables,POST_CLOSE
notification is sufficient.The listener is obtained from the part site by calling
partSite.getService(ISaveablesLifecycleListener.class)
.The part must not notify from its initialization methods (e.g.
init
orcreatePartControl
), or from its dispose method. Parts that implementIReusableEditor
must notify when their input is changed throughIReusableEditor.setInput(IEditorInput)
.- Specified by:
getSaveables
in interfaceISaveablesSource
- Returns:
- the saveables presented by the workbench part
- See Also:
-
addCompareInputChangeListener
public void addCompareInputChangeListener(ICompareInput input, ICompareInputChangeListener listener) Description copied from interface:ICompareContainer
Register for change events for the given compare input. Although clients can register with the compare input directly, registering through the container allows for deterministic and optimized behavior in some cases. Registering multiple times for the same compare input has no effect.- Specified by:
addCompareInputChangeListener
in interfaceICompareContainer
- Overrides:
addCompareInputChangeListener
in classCompareEditorInput
- Parameters:
input
- the compare inputlistener
- the compare input change listener
-
removeCompareInputChangeListener
public void removeCompareInputChangeListener(ICompareInput input, ICompareInputChangeListener listener) Description copied from interface:ICompareContainer
Remove the change listener from the given compare input. Removing a listener that is not registered has no effect.- Specified by:
removeCompareInputChangeListener
in interfaceICompareContainer
- Overrides:
removeCompareInputChangeListener
in classCompareEditorInput
- Parameters:
input
- the compare inputlistener
- the compare input change listener
-
getAdapter
Description copied from class:PlatformObject
Returns an object which is an instance of the given class associated with this object. Returnsnull
if no such object can be found.This implementation of the method declared by
IAdaptable
passes the request along to the platform's adapter manager; roughlyPlatform.getAdapterManager().getAdapter(this, adapter)
. Subclasses may override this method (however, if they do so, they should invoke the method on their superclass to ensure that the Platform's adapter manager is consulted).- Specified by:
getAdapter
in interfaceIAdaptable
- Overrides:
getAdapter
in classCompareEditorInput
- Type Parameters:
T
- the class type- Parameters:
adapter
- the class to adapt to- Returns:
- the adapted object or
null
- See Also:
-
getTitleImage
Description copied from class:CompareEditorInput
Returns the title image which will be used in the compare editor's title bar. Returns the title image which will be used when presenting the compare result. This implementation returns a generic compare icon. Subclasses can override.- Overrides:
getTitleImage
in classCompareEditorInput
- Returns:
- the title image, or
null
if none
-
getImageDescriptor
Description copied from interface:IEditorInput
Returns the image descriptor for this input.Note: although a null return value has never been permitted from this method, there are many known buggy implementations that return null. Clients that need the image for an editor are advised to use IWorkbenchPart.getImage() instead of IEditorInput.getImageDescriptor(), or to recover from a null return value in a manner that records the ID of the problematic editor input. Implementors that have been returning null from this method should pick some other default return value (such as ImageDescriptor.getMissingImageDescriptor()).
- Specified by:
getImageDescriptor
in interfaceIEditorInput
- Overrides:
getImageDescriptor
in classCompareEditorInput
- Returns:
- the image descriptor for this input; may be
null
if there is no image.
-
findContentViewer
Description copied from class:CompareEditorInput
Implements the dynamic viewer switching for content viewers. The method must return a compare viewer based on the old (or current) viewer and a new input object. If the old viewer is suitable for showing the new input the old viewer can be returned. Otherwise a new viewer must be created under the given parent composite ornull
can be returned to indicate that no viewer could be found.This implementation forwards the request to
CompareUI.findContentViewer
.Subclasses may override to implement a different strategy.
- Overrides:
findContentViewer
in classCompareEditorInput
- Parameters:
oldViewer
- a new viewer is only created if this old viewer cannot show the given inputinput
- the input object for which to find a structure viewerparent
- the SWT parent composite under which the new viewer is created- Returns:
- a compare viewer which is suitable for the given input object or
null
-
canRunAsJob
public boolean canRunAsJob()Description copied from class:CompareEditorInput
Returns whether this compare editor input can be run as a job. By default,false
is returned since traditionally inputs were prepared in the foreground (i.e the UI was blocked when theCompareEditorInput.run(IProgressMonitor)
method (and indirectly theCompareEditorInput.prepareInput(IProgressMonitor)
method) was invoked. Subclasses may override.- Overrides:
canRunAsJob
in classCompareEditorInput
- Returns:
- whether this compare editor input can be run in the background
-
isDirty
public boolean isDirty()Description copied from class:CompareEditorInput
Returnstrue
if there are unsaved changes. The method should be called by any parts or dialogs that contain the input. By default, this method callsCompareEditorInput.isSaveNeeded()
but subclasses may extend.- Overrides:
isDirty
in classCompareEditorInput
- Returns:
true
if there are unsaved changes
-
registerContextMenu
Description copied from interface:ICompareContainer
Register the content menu with the container to give the container a chance to add additional items to the context menu such as popup menu object contributions. The provided menu should have aIWorkbenchActionConstants.MB_ADDITIONS
separator as this is where the container will add actions.- Specified by:
registerContextMenu
in interfaceICompareContainer
- Overrides:
registerContextMenu
in classCompareEditorInput
- Parameters:
menu
- the menu being registeredselectionProvider
- the selection provider
-