Class FilePropSaveable

  • All Implemented Interfaces:
    org.eclipse.core.runtime.IAdaptable, org.eclipse.ui.ISaveablesSource

    public class FilePropSaveable
    extends org.eclipse.ui.Saveable
    implements org.eclipse.ui.ISaveablesSource
    The Saveable implementation for a FilePropCnr.
    Author:
    Christopher Mindus
    • Field Summary

      Fields 
      Modifier and TypeFieldDescription
      static org.eclipse.ui.Saveable[]EMPTY
      This saveable in a single array.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and TypeMethodDescription
      voiddoSave​(org.eclipse.core.runtime.IProgressMonitor monitor)
      Saves the contents of this saveable.
      booleanequals​(java.lang.Object object)
      Clients must implement equals and hashCode as defined in Object.equals(Object) and Object.hashCode().
      org.eclipse.ui.Saveable[]getActiveSaveables()
      Returns the saveables currently active in the workbench part.
      <T> TgetAdapter​(java.lang.Class<T> adapter)
      This implementation of IAdaptable.getAdapter(Class) returns null.
      org.eclipse.jface.resource.ImageDescriptorgetImageDescriptor()
      Returns the image descriptor for this saveable.
      java.lang.StringgetName()
      Returns the name of this saveable for display purposes.
      org.eclipse.ui.Saveable[]getSaveables()
      Returns the saveables presented by the workbench part.
      java.lang.StringgetToolTipText()
      Returns the tool tip text for this saveable.
      inthashCode()
      Clients must implement equals and hashCode as defined in Object.equals(Object) and Object.hashCode().
      booleanisDirty()
      Returns whether the contents of this saveable have changed since the last save operation.
      booleanisSaving()
      Flag for saving.
      voidonDirtyChanged()
      The Editor has had its dirty state changed: verify and inform.
      booleanshow​(org.eclipse.ui.IWorkbenchPage page)
      Attempts to show this saveable in the given page and returns true on success.
      org.eclipse.ui.IEditorPartshowEditor​(org.eclipse.ui.IWorkbenchPage page)
      Attempts to show this saveable in the given page and returns the editor started or shown.
      • Methods inherited from class org.eclipse.ui.Saveable

        disableUI, doSave, enableUI
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EMPTY

        public static final org.eclipse.ui.Saveable[] EMPTY
        This saveable in a single array.
    • Method Detail

      • show

        public boolean show​(org.eclipse.ui.IWorkbenchPage page)
        Attempts to show this saveable in the given page and returns true on success.
        Overrides:
        show in class org.eclipse.ui.Saveable
        Parameters:
        page - The workbench page in which to show this saveable.
        Returns:
        true if this saveable is now visible to the user.
      • showEditor

        public org.eclipse.ui.IEditorPart showEditor​(org.eclipse.ui.IWorkbenchPage page)
        Attempts to show this saveable in the given page and returns the editor started or shown.
        Parameters:
        page - The workbench page in which to show this saveable.
        Returns:
        The editor part, or null for none.
      • getName

        public java.lang.String getName()
        Returns the name of this saveable for display purposes.
        Specified by:
        getName in class org.eclipse.ui.Saveable
        Returns:
        The model's name; never null.
      • getToolTipText

        public java.lang.String getToolTipText()
        Returns the tool tip text for this saveable. This text is used to differentiate between two inputs with the same name.
        Specified by:
        getToolTipText in class org.eclipse.ui.Saveable
        Returns:
        the tool tip text; never null.
      • getImageDescriptor

        public org.eclipse.jface.resource.ImageDescriptor getImageDescriptor()
        Returns the image descriptor for this saveable.
        Specified by:
        getImageDescriptor in class org.eclipse.ui.Saveable
        Returns:
        The image descriptor for this model.
      • isSaving

        public boolean isSaving()
        Flag for saving.
      • doSave

        public void doSave​(org.eclipse.core.runtime.IProgressMonitor monitor)
                    throws org.eclipse.core.runtime.CoreException
        Saves the contents of this saveable.

        If the save is cancelled through user action, or for any other reason, the part should invoke setCancelled on the IProgressMonitor to inform the caller.

        This method is long-running; progress and cancellation are provided by the given progress monitor.

        Specified by:
        doSave in class org.eclipse.ui.Saveable
        Parameters:
        monitor - The progress monitor.
        Throws:
        org.eclipse.core.runtime.CoreException - If the save fails; it is the caller's responsibility to report the failure to the user.
      • isDirty

        public boolean isDirty()
        Returns whether the contents of this saveable have changed since the last save operation.

        Note: this method is called frequently, for example by actions to determine their enabled status.

        Specified by:
        isDirty in class org.eclipse.ui.Saveable
        Returns:
        true if the contents have been modified and need saving, and false if they have not changed since the last save.
      • onDirtyChanged

        public void onDirtyChanged()
        The Editor has had its dirty state changed: verify and inform.
      • equals

        public boolean equals​(java.lang.Object object)
        Clients must implement equals and hashCode as defined in Object.equals(Object) and Object.hashCode(). Two saveables should be equal if their dirty state is shared, and saving one will save the other. If two saveables are equal, their names, tooltips, and images should be the same because only one of them will be shown when prompting the user to save.
        Specified by:
        equals in class org.eclipse.ui.Saveable
        Parameters:
        object - The object to verify equality with.
        Returns:
        true if this Saveable is equal to the given object.
      • hashCode

        public int hashCode()
        Clients must implement equals and hashCode as defined in Object.equals(Object) and Object.hashCode(). Two saveables should be equal if their dirty state is shared, and saving one will save the other. If two saveables are equal, their hash codes MUST be the same, and their names, tooltips, and images should be the same because only one of them will be shown when prompting the user to save.

        IMPORTANT: Implementers should ensure that the hashCode returned is sufficiently unique so as not to collide with hashCodes returned by other implementations. It is suggested that the defining plug-in's ID be used as part of the returned hashCode, as in the following example:

             int PRIME = 31;
             int hash = ...; // compute the "normal" hash code, e.g. based on some identifier unique within the defining plug-in
             return hash * PRIME + MY_PLUGIN_ID.hashCode();
         

        Specified by:
        hashCode in class org.eclipse.ui.Saveable
        Returns:
        a hash code
      • getAdapter

        public <T> T getAdapter​(java.lang.Class<T> adapter)
        This implementation of IAdaptable.getAdapter(Class) returns null. Subclasses may override. This allows two unrelated subclasses of Saveable to implement equals(Object) and hashCode() based on an underlying implementation class that is shared by both Saveable subclasses.
        Specified by:
        getAdapter in interface org.eclipse.core.runtime.IAdaptable
        Overrides:
        getAdapter in class org.eclipse.ui.Saveable
        Returns:
        This implementation always returns null.
      • getSaveables

        public org.eclipse.ui.Saveable[] getSaveables()
        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 org.eclipse.ui.ISaveablesSource
        Returns:
        The saveables presented by the workbench part.
        See Also:
        ISaveablesLifecycleListener
      • getActiveSaveables

        public org.eclipse.ui.Saveable[] getActiveSaveables()
        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 org.eclipse.ui.ISaveablesSource
        Returns:
        The saveables currently active in the workbench part.