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
ConstructorsConstructorDescriptionSaveableCompareEditorInput(CompareConfiguration configuration, IWorkbenchPage page) Creates aLocalResourceCompareEditorInputwhich is initialized with the given compare configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCompareInputChangeListener(ICompareInput input, ICompareInputChangeListener listener) Register for change events for the given compare input.booleanReturns whether this compare editor input can be run as a job.protected booleancloseEditor(boolean checkForUnsavedChanges) Close the editor if it is not dirty.protected voidCallback that occurs after the control for the input has been created.static ITypedElementcreateFileElement(IFile file) Returns a typed element that represents a local file.protected SaveableCreate 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 voidCallback 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> TgetAdapter(Class<T> adapter) Returns an object which is an instance of the given class associated with this object.protected final ICompareInputReturns the compare input of this editor input.Returns the image descriptor for this input.protected SaveableGet 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 voidCallback that occurs when the UI associated with this compare editor input is disposed.booleanisDirty()Returnstrueif there are unsaved changes.protected abstract ICompareInputprepareCompareInput(IProgressMonitor monitor) Method called fromprepareInput(IProgressMonitor)to obtain the input.protected ObjectprepareInput(IProgressMonitor monitor) Prepares the compare input of this editor input.voidregisterContextMenu(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.voidremoveCompareInputChangeListener(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 aLocalResourceCompareEditorInputwhich 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:CompareEditorInputCallback 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:
contentsCreatedin classCompareEditorInput
-
handleDispose
protected void handleDispose()Description copied from class:CompareEditorInputCallback 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:
handleDisposein 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:
prepareInputin classCompareEditorInput- Parameters:
monitor- the progress monitor to use to display progress and receive requests for cancellation- Returns:
- the result of the compare operation, or
nullif there are no differences - Throws:
InvocationTargetException- if theprepareInputmethod must propagate a checked exception, it should wrap it inside anInvocationTargetException; runtime exceptions are automatically wrapped in anInvocationTargetExceptionby 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:
trueif 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:ISaveablesSourceReturns 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:
getActiveSaveablesin interfaceISaveablesSource- Returns:
- the saveables currently active in the workbench part
-
getSaveables
Description copied from interface:ISaveablesSourceReturns 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_CLOSEfollowed by an event of typeSaveablesLifecycleEvent.POST_CLOSE. Since firing thePRE_CLOSEevent 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_CLOSEnotification 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.
initorcreatePartControl), or from its dispose method. Parts that implementIReusableEditormust notify when their input is changed throughIReusableEditor.setInput(IEditorInput).- Specified by:
getSaveablesin interfaceISaveablesSource- Returns:
- the saveables presented by the workbench part
- See Also:
-
addCompareInputChangeListener
public void addCompareInputChangeListener(ICompareInput input, ICompareInputChangeListener listener) Description copied from interface:ICompareContainerRegister 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:
addCompareInputChangeListenerin interfaceICompareContainer- Overrides:
addCompareInputChangeListenerin classCompareEditorInput- Parameters:
input- the compare inputlistener- the compare input change listener
-
removeCompareInputChangeListener
public void removeCompareInputChangeListener(ICompareInput input, ICompareInputChangeListener listener) Description copied from interface:ICompareContainerRemove the change listener from the given compare input. Removing a listener that is not registered has no effect.- Specified by:
removeCompareInputChangeListenerin interfaceICompareContainer- Overrides:
removeCompareInputChangeListenerin classCompareEditorInput- Parameters:
input- the compare inputlistener- the compare input change listener
-
getAdapter
Description copied from class:PlatformObjectReturns an object which is an instance of the given class associated with this object. Returnsnullif no such object can be found.This implementation of the method declared by
IAdaptablepasses 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:
getAdapterin interfaceIAdaptable- Overrides:
getAdapterin 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:CompareEditorInputReturns 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:
getTitleImagein classCompareEditorInput- Returns:
- the title image, or
nullif none
-
getImageDescriptor
Description copied from interface:IEditorInputReturns 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:
getImageDescriptorin interfaceIEditorInput- Overrides:
getImageDescriptorin classCompareEditorInput- Returns:
- the image descriptor for this input; may be
nullif there is no image.
-
findContentViewer
Description copied from class:CompareEditorInputImplements 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 ornullcan 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:
findContentViewerin 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:CompareEditorInputReturns whether this compare editor input can be run as a job. By default,falseis 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:
canRunAsJobin classCompareEditorInput- Returns:
- whether this compare editor input can be run in the background
-
isDirty
public boolean isDirty()Description copied from class:CompareEditorInputReturnstrueif 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:
isDirtyin classCompareEditorInput- Returns:
trueif there are unsaved changes
-
registerContextMenu
Description copied from interface:ICompareContainerRegister 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_ADDITIONSseparator as this is where the container will add actions.- Specified by:
registerContextMenuin interfaceICompareContainer- Overrides:
registerContextMenuin classCompareEditorInput- Parameters:
menu- the menu being registeredselectionProvider- the selection provider
-