Class SaveableCompareEditorInput

java.lang.Object
org.eclipse.core.runtime.PlatformObject
org.eclipse.compare.CompareEditorInput
org.eclipse.team.ui.synchronize.SaveableCompareEditorInput
All Implemented Interfaces:
ICompareContainer, IPropertyChangeNotifier, IAdaptable, IRunnableContext, IRunnableWithProgress, IEditorInput, ISaveablesSource
Direct Known Subclasses:
SyncInfoCompareInput

public abstract class SaveableCompareEditorInput extends CompareEditorInput implements ISaveablesSource
A compare editor input that makes use of a 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
  • Constructor Details

    • SaveableCompareEditorInput

      public SaveableCompareEditorInput(CompareConfiguration configuration, IWorkbenchPage page)
      Creates a LocalResourceCompareEditorInput which is initialized with the given compare configuration. The compare configuration is passed to subsequently created viewers.
      Parameters:
      configuration - the compare configuration
      page - the workbench page that will contain the editor
  • Method Details

    • createFileElement

      public static ITypedElement createFileElement(IFile file)
      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 a SaveableCompareEditorInput, 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 then 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.
      Overrides:
      contentsCreated in class CompareEditorInput
    • 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 to CompareEditorInput.createContents(Composite). Subclasses can extend this method but ensure that the overridden method is invoked.
      Overrides:
      handleDispose in class CompareEditorInput
    • 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 the prepareCompareInput(IProgressMonitor) method which subclasses must implement.
      Specified by:
      prepareInput in class CompareEditorInput
      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 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 context
      InterruptedException - if the operation detects a request to cancel, using IProgressMonitor.isCanceled(), it should exit by throwing InterruptedException
      See Also:
    • prepareCompareInput

      protected abstract ICompareInput prepareCompareInput(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
      Method called from prepareInput(IProgressMonitor) to obtain the input. Its purpose is to ensure that the input is an instance of ICompareInput.
      Parameters:
      monitor - a progress monitor
      Returns:
      the compare input
      Throws:
      InvocationTargetException - if an error occurs
      InterruptedException - if operation is interrupted
    • getCompareInput

      protected final ICompareInput 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 from createFileElement(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

      protected Saveable getSaveable()
      Get the saveable that provides the save behavior for this compare editor input. The 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).
      Returns:
      saveable that provides the save behavior for this compare editor input.
    • createSaveable

      protected Saveable 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

      public Saveable[] 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 interface ISaveablesSource
      Returns:
      the saveables currently active in the workbench part
    • getSaveables

      public Saveable[] 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 using 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).

      Specified by:
      getSaveables in interface ISaveablesSource
      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 interface ICompareContainer
      Overrides:
      addCompareInputChangeListener in class CompareEditorInput
      Parameters:
      input - the compare input
      listener - 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 interface ICompareContainer
      Overrides:
      removeCompareInputChangeListener in class CompareEditorInput
      Parameters:
      input - the compare input
      listener - the compare input change listener
    • getAdapter

      public <T> T getAdapter(Class<T> adapter)
      Description copied from class: PlatformObject
      Returns an object which is an instance of the given class associated with this object. Returns 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).

      Specified by:
      getAdapter in interface IAdaptable
      Overrides:
      getAdapter in class CompareEditorInput
      Type Parameters:
      T - the class type
      Parameters:
      adapter - the class to adapt to
      Returns:
      the adapted object or null
      See Also:
    • getTitleImage

      public Image 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 class CompareEditorInput
      Returns:
      the title image, or null if none
    • getImageDescriptor

      public ImageDescriptor 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 interface IEditorInput
      Overrides:
      getImageDescriptor in class CompareEditorInput
      Returns:
      the image descriptor for this input; may be null if there is no image.
    • findContentViewer

      public Viewer findContentViewer(Viewer oldViewer, ICompareInput input, Composite parent)
      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 or 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.

      Overrides:
      findContentViewer in class CompareEditorInput
      Parameters:
      oldViewer - a new viewer is only created if this old viewer cannot show the given input
      input - the input object for which to find a structure viewer
      parent - 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 the CompareEditorInput.run(IProgressMonitor) method (and indirectly the CompareEditorInput.prepareInput(IProgressMonitor) method) was invoked. Subclasses may override.
      Overrides:
      canRunAsJob in class CompareEditorInput
      Returns:
      whether this compare editor input can be run in the background
    • isDirty

      public boolean isDirty()
      Description copied from class: CompareEditorInput
      Returns 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.
      Overrides:
      isDirty in class CompareEditorInput
      Returns:
      true if there are unsaved changes
    • registerContextMenu

      public void registerContextMenu(MenuManager menu, ISelectionProvider selectionProvider)
      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 a IWorkbenchActionConstants.MB_ADDITIONS separator as this is where the container will add actions.
      Specified by:
      registerContextMenu in interface ICompareContainer
      Overrides:
      registerContextMenu in class CompareEditorInput
      Parameters:
      menu - the menu being registered
      selectionProvider - the selection provider