public abstract class SaveableCompareEditorInput extends CompareEditorInput implements ISaveablesSource
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.
DIRTY_STATE, PROP_SELECTED_EDITION, PROP_TITLE, PROP_TITLE_IMAGE
Constructor and Description |
---|
SaveableCompareEditorInput(CompareConfiguration configuration,
IWorkbenchPage page)
Creates a
LocalResourceCompareEditorInput which is initialized with the given
compare configuration. |
Modifier and Type | Method and Description |
---|---|
void |
addCompareInputChangeListener(ICompareInput input,
ICompareInputChangeListener listener)
Register for change events for the given compare input.
|
boolean |
canRunAsJob()
Return 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 |
contentsCreated()
Callback that occurs after the control for the input has
been created.
|
static ITypedElement |
createFileElement(IFile file)
Return a typed element that represents a local file.
|
protected Saveable |
createSaveable()
Create the saveable that provides the save behavior for this compare editor input.
|
Viewer |
findContentViewer(Viewer oldViewer,
ICompareInput input,
Composite parent)
Implements the dynamic viewer switching for content viewers.
|
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.
|
Saveable[] |
getActiveSaveables()
Returns the saveables currently active in the workbench part.
|
Object |
getAdapter(Class adapter)
Returns an object which is an instance of the given class
associated with this object.
|
protected ICompareInput |
getCompareInput()
Return the compare input of this editor input.
|
ImageDescriptor |
getImageDescriptor()
Returns the image descriptor for this input.
|
protected Saveable |
getSaveable()
Get the saveable that provides the save behavior for this compare editor input.
|
Saveable[] |
getSaveables()
Returns the saveables presented by the workbench part.
|
Image |
getTitleImage()
Returns the title image which will be used in the compare editor's title bar.
|
protected void |
handleDispose()
Callback that occurs when the UI associated with this compare editor
input is disposed.
|
boolean |
isDirty()
Returns
true if there are unsaved changes. |
protected abstract ICompareInput |
prepareCompareInput(IProgressMonitor monitor)
Method called from
prepareInput(IProgressMonitor) to obtain the input. |
protected Object |
prepareInput(IProgressMonitor monitor)
Prepare 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.
|
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
public SaveableCompareEditorInput(CompareConfiguration configuration, IWorkbenchPage page)
LocalResourceCompareEditorInput
which is initialized with the given
compare configuration.
The compare configuration is passed to subsequently created viewers.configuration
- the compare configurationpage
- the workbench page that will contain the editorpublic static ITypedElement createFileElement(IFile file)
SaveableCompareEditorInput
, then the file will
be properly saved when the compare editor input or viewers are saved.file
- the fileprotected void contentsCreated()
CompareEditorInput
CompareEditorInput.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.contentsCreated
in class CompareEditorInput
protected void handleDispose()
CompareEditorInput
CompareEditorInput.createContents(Composite)
.
Subclasses can extend this method but ensure that the overridden method
is invoked.handleDispose
in class CompareEditorInput
protected Object prepareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
prepareCompareInput(IProgressMonitor)
method which subclasses must implement.prepareInput
in class CompareEditorInput
monitor
- the progress monitor to use to display progress and receive
requests for cancelationnull
if there are no differencesInvocationTargetException
- if the prepareInput
method must propagate a checked exception,
it should wrap it inside an InvocationTargetException
; runtime exceptions are automatically
wrapped in an InvocationTargetException
by the calling contextInterruptedException
- if the operation detects a request to cancel,
using IProgressMonitor.isCanceled()
, it should exit by throwing
InterruptedException
CompareEditorInput.prepareInput(org.eclipse.core.runtime.IProgressMonitor)
protected abstract ICompareInput prepareCompareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
prepareInput(IProgressMonitor)
to obtain the input. Its purpose
is to ensure that the input is an instance of ICompareInput
.monitor
- a progress monitorInvocationTargetException
InterruptedException
protected final ICompareInput getCompareInput()
protected abstract void fireInputChange()
createFileElement(IFile)
.protected boolean closeEditor(boolean checkForUnsavedChanges)
checkForUnsavedChanges
- whether to check for unsaved changestrue
if the editor was closed (note that the
close may be asynchronous)protected Saveable getSaveable()
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 CompareEditorInput.run(IProgressMonitor)
method is called which will in turn will invoke
prepareCompareInput(IProgressMonitor)
.protected Saveable createSaveable()
public Saveable[] getActiveSaveables()
ISaveablesSource
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.
getActiveSaveables
in interface ISaveablesSource
public Saveable[] getSaveables()
ISaveablesSource
ISaveablesLifecycleListener.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 type
SaveablesLifecycleEvent.PRE_CLOSE
followed by an event of type
SaveablesLifecycleEvent.POST_CLOSE
. Since firing the
PRE_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
or createPartControl
), or from its dispose method. Parts that
implement IReusableEditor
must notify when their input is changed
through IReusableEditor.setInput(IEditorInput)
.
getSaveables
in interface ISaveablesSource
ISaveablesLifecycleListener
public void addCompareInputChangeListener(ICompareInput input, ICompareInputChangeListener listener)
ICompareContainer
addCompareInputChangeListener
in interface ICompareContainer
addCompareInputChangeListener
in class CompareEditorInput
input
- the compare inputlistener
- the compare input change listenerpublic void removeCompareInputChangeListener(ICompareInput input, ICompareInputChangeListener listener)
ICompareContainer
removeCompareInputChangeListener
in interface ICompareContainer
removeCompareInputChangeListener
in class CompareEditorInput
input
- the compare inputlistener
- the compare input change listenerpublic Object getAdapter(Class adapter)
PlatformObject
null
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; roughly
Platform.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).
getAdapter
in interface IAdaptable
getAdapter
in class CompareEditorInput
adapter
- the class to adapt tonull
IAdaptable.getAdapter(Class)
public Image getTitleImage()
CompareEditorInput
getTitleImage
in class CompareEditorInput
null
if nonepublic ImageDescriptor getImageDescriptor()
IEditorInput
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()).
getImageDescriptor
in interface IEditorInput
getImageDescriptor
in class CompareEditorInput
null
if
there is no image.public Viewer findContentViewer(Viewer oldViewer, ICompareInput input, Composite parent)
CompareEditorInput
null
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.
findContentViewer
in class CompareEditorInput
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 creatednull
public boolean canRunAsJob()
CompareEditorInput
false
is returned since traditionally inputs
were prepared in the foreground (i.e the UI was blocked when the
CompareEditorInput.run(IProgressMonitor)
method (and indirectly the
CompareEditorInput.prepareInput(IProgressMonitor)
method) was invoked. Subclasses
may override.canRunAsJob
in class CompareEditorInput
public boolean isDirty()
CompareEditorInput
true
if there are unsaved changes.
The method should be called by any parts or dialogs
that contain the input.
By default, this method calls CompareEditorInput.isSaveNeeded()
but subclasses may extend.isDirty
in class CompareEditorInput
true
if there are unsaved changespublic void registerContextMenu(MenuManager menu, ISelectionProvider selectionProvider)
ICompareContainer
IWorkbenchActionConstants.MB_ADDITIONS
separator as this is where the container will add actions.registerContextMenu
in interface ICompareContainer
registerContextMenu
in class CompareEditorInput
menu
- the menu being registeredselectionProvider
- the selection provider
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.