Class GenericEditor

  • All Implemented Interfaces:
    org.eclipse.core.runtime.IAdaptable, org.eclipse.core.runtime.IExecutableExtension, org.eclipse.emf.edit.domain.IEditingDomainProvider, org.eclipse.ui.ide.IGotoMarker, org.eclipse.ui.IEditorPart, org.eclipse.ui.ISaveablePart, org.eclipse.ui.IWorkbenchPart, org.eclipse.ui.IWorkbenchPart2, org.eclipse.ui.IWorkbenchPart3, org.eclipse.ui.part.IWorkbenchPartOrientation
    Direct Known Subclasses:
    DataTemplateEditor, EcoreEditor, GenModelEditor, RuleRepositoryEditor, TemplateModelEditorPart, ViewModelEditor

    public class GenericEditor
    extends org.eclipse.ui.part.EditorPart
    implements org.eclipse.emf.edit.domain.IEditingDomainProvider, org.eclipse.ui.ide.IGotoMarker
    The Class GenericEditor it is the generic part for editing any EObject.
    • Field Summary

      • Fields inherited from interface org.eclipse.ui.IEditorPart

        PROP_DIRTY, PROP_INPUT
      • Fields inherited from interface org.eclipse.ui.IWorkbenchPart

        PROP_TITLE
    • Constructor Summary

      Constructors 
      Constructor Description
      GenericEditor()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean adjustErrorMarker​(org.eclipse.core.resources.IMarker marker, org.eclipse.emf.common.util.Diagnostic diagnostic)
      Override this method to set additional attributes on the given IMarker, e.g.
      protected DiagnosticCache createDiangosticCache​(org.eclipse.emf.common.notify.Notifier input)
      Creates the diagnostic cache.
      void createPartControl​(org.eclipse.swt.widgets.Composite parent)  
      protected TreeMasterDetailComposite createRootView​(org.eclipse.swt.widgets.Composite parent, java.lang.String editorTitle, java.lang.Object editorInput, java.util.List<org.eclipse.jface.action.Action> toolbarActions, CreateElementCallback createElementCallback)
      Creates the top area of the editor.
      protected TreeMasterDetailComposite createTreeMasterDetail​(org.eclipse.swt.widgets.Composite composite, java.lang.Object editorInput, CreateElementCallback createElementCallback)
      This method creates a tree master detail.
      protected TreeViewerBuilder createTreeViewerBuilder()
      Create the TreeViewerBuilder customization which creates the tree for the editor's tree master detail.
      protected TreeMasterDetailSWTBuilder customizeTree​(TreeMasterDetailSWTBuilder builder)
      Customize the tree builder.
      protected void deleteMarkers()
      Deletes the problem markers created by this Editor.
      void dispose()  
      void doSave​(org.eclipse.core.runtime.IProgressMonitor monitor)  
      void doSaveAs()  
      protected boolean enableValidation()  
      protected org.eclipse.emf.common.command.BasicCommandStack getCommandStack()  
      protected java.lang.String getContextId()
      Returns the context id set for this editor.
      protected CreateElementCallback getCreateElementCallback()
      Returns the createElementCallback for this editor.
      protected DiagnosticCache getDiagnosticCache()  
      org.eclipse.emf.edit.domain.EditingDomain getEditingDomain()
      protected java.lang.String getEditorTitle()
      Returns the title for the currently displayed editor.
      protected org.eclipse.emf.common.notify.Notifier getNotifierFromEditorInput​(java.lang.Object editorInput)
      Get the Notifier from the tree input.
      protected java.util.Map<java.lang.Object,​java.lang.Object> getResourceLoadOptions()
      The options to be used when loading the editor's resource.
      protected java.util.Map<java.lang.Object,​java.lang.Object> getResourceSaveOptions()
      The options to be used when saving the editor's resource.
      org.eclipse.emf.ecore.resource.ResourceSet getResourceSet()
      Returns the ResouceSet of this Editor.
      protected TreeMasterDetailComposite getRootView()
      Returns the root composite containing the tree and the detail view.
      protected java.util.List<org.eclipse.jface.action.Action> getToolbarActions()
      Returns the toolbar actions for this editor.
      void gotoMarker​(org.eclipse.core.resources.IMarker marker)
      protected void handleDetailActivated​(ViewModelContext detailContext)
      React to the rendering or re-activation of a detail context.
      protected void handleResourceChange​(java.util.Collection<org.eclipse.emf.ecore.resource.Resource> changedResources, java.util.Collection<org.eclipse.emf.ecore.resource.Resource> removedResources)
      Handles filesystem changes.
      protected boolean hasShortcuts()
      Returns true, if the editor should have shortcuts.
      void init​(org.eclipse.ui.IEditorSite site, org.eclipse.ui.IEditorInput input)  
      protected boolean isClosing()
      Returns whether this editor is currently in the process of shutting down.
      boolean isDirty()  
      protected boolean isEditable​(org.eclipse.ui.IEditorInput editorInput)
      Returns whether the editor input allows editing of its contents.
      boolean isSaveAsAllowed()  
      protected org.eclipse.emf.ecore.resource.ResourceSet loadResource​(org.eclipse.ui.IEditorInput editorInput)
      Creates a resource set and loads all required resources for the editor input.
      protected java.lang.Object modifyEditorInput​(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
      Allows to modify the input object for the editor.
      protected void postSave()
      Executes the code which needs to be executed after a save, e.g.
      protected void preSave()
      Executes the code which needs to be executed before a save, e.g.
      protected java.util.List<org.eclipse.jface.action.Action> readToolbarActions()
      Read toolbar actions from all extensions.
      protected void refreshTreeAfterResourceChange()
      Called after a resource change to refresh the tree master detail of the editor.
      protected void reloadResources​(java.util.Collection<org.eclipse.emf.ecore.resource.Resource> resources)
      Reloads the given resources and refreshes the tree accordingly.
      protected void removeResources​(java.util.Collection<org.eclipse.emf.ecore.resource.Resource> resources)
      Removes the given Resources from this editor's ResourceSet.
      void reveal​(org.eclipse.emf.ecore.EObject objectToReveal)
      The given element will be revealed in the tree of the editor.
      void reveal​(UniqueSetting setting)
      Reveal the control that edits a setting of some object.
      protected void setClosing​(boolean closing)
      Set whether this editor is currently in the process of shutting down.
      void setFocus()  
      protected void verifyEditorResource​(org.eclipse.emf.common.util.URI resourceURI, org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
      Check that the resource was loaded correctly and show any warnings to the user.
      • Methods inherited from class org.eclipse.ui.part.EditorPart

        checkSite, getEditorInput, getEditorSite, getTitleToolTip, isSaveOnCloseNeeded, setContentDescription, setInitializationData, setInput, setInputWithNotify, setPartName
      • Methods inherited from class org.eclipse.ui.part.WorkbenchPart

        addPartPropertyListener, addPropertyListener, firePartPropertyChanged, firePropertyChange, getAdapter, getConfigurationElement, getContentDescription, getDefaultImage, getOrientation, getPartName, getPartProperties, getPartProperty, getSite, getTitle, getTitleImage, removePartPropertyListener, removePropertyListener, setPartProperty, setSite, setTitle, setTitleImage, setTitleToolTip, showBusy
      • Methods inherited from class org.eclipse.core.commands.common.EventManager

        addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.eclipse.core.runtime.IAdaptable

        getAdapter
      • Methods inherited from interface org.eclipse.ui.IWorkbenchPart

        addPropertyListener, getSite, getTitle, getTitleImage, removePropertyListener
    • Constructor Detail

      • GenericEditor

        public GenericEditor()
    • Method Detail

      • doSave

        public void doSave​(org.eclipse.core.runtime.IProgressMonitor monitor)
        Specified by:
        doSave in interface org.eclipse.ui.ISaveablePart
        Specified by:
        doSave in class org.eclipse.ui.part.EditorPart
      • preSave

        protected void preSave()
        Executes the code which needs to be executed before a save, e.g. removing listeners.
        Since:
        1.10
      • postSave

        protected void postSave()
        Executes the code which needs to be executed after a save, e.g. readding listeners.
        Since:
        1.10
      • handleResourceChange

        protected void handleResourceChange​(java.util.Collection<org.eclipse.emf.ecore.resource.Resource> changedResources,
                                            java.util.Collection<org.eclipse.emf.ecore.resource.Resource> removedResources)
        Handles filesystem changes.
        Parameters:
        changedResources - A List of changed Resources
        removedResources - A List of removed Resources
      • reloadResources

        protected void reloadResources​(java.util.Collection<org.eclipse.emf.ecore.resource.Resource> resources)
        Reloads the given resources and refreshes the tree accordingly.
        Parameters:
        resources - The Resources to reload
        Since:
        1.22
      • refreshTreeAfterResourceChange

        protected void refreshTreeAfterResourceChange()
        Called after a resource change to refresh the tree master detail of the editor. By default only the tree is refreshed. If the tree's input is not this editor's resource but only derived from it, this method should be overridden to reset the tree's input.
        Since:
        1.22
      • doSaveAs

        public void doSaveAs()
        Specified by:
        doSaveAs in interface org.eclipse.ui.ISaveablePart
        Specified by:
        doSaveAs in class org.eclipse.ui.part.EditorPart
      • init

        public void init​(org.eclipse.ui.IEditorSite site,
                         org.eclipse.ui.IEditorInput input)
                  throws org.eclipse.ui.PartInitException
        Specified by:
        init in interface org.eclipse.ui.IEditorPart
        Specified by:
        init in class org.eclipse.ui.part.EditorPart
        Throws:
        org.eclipse.ui.PartInitException
      • getContextId

        protected java.lang.String getContextId()
        Returns the context id set for this editor.
        Returns:
        the context id
      • isDirty

        public boolean isDirty()
        Specified by:
        isDirty in interface org.eclipse.ui.ISaveablePart
        Specified by:
        isDirty in class org.eclipse.ui.part.EditorPart
      • isSaveAsAllowed

        public boolean isSaveAsAllowed()
        Specified by:
        isSaveAsAllowed in interface org.eclipse.ui.ISaveablePart
        Specified by:
        isSaveAsAllowed in class org.eclipse.ui.part.EditorPart
      • createPartControl

        public void createPartControl​(org.eclipse.swt.widgets.Composite parent)
        Specified by:
        createPartControl in interface org.eclipse.ui.IWorkbenchPart
        Specified by:
        createPartControl in class org.eclipse.ui.part.WorkbenchPart
      • deleteMarkers

        protected void deleteMarkers()
                              throws org.eclipse.core.runtime.CoreException
        Deletes the problem markers created by this Editor. Please take care that this method should be called from a Job to avoid problems with a locked index.
        Throws:
        org.eclipse.core.runtime.CoreException - if the method fails
        Since:
        1.10
      • getNotifierFromEditorInput

        protected org.eclipse.emf.common.notify.Notifier getNotifierFromEditorInput​(java.lang.Object editorInput)
        Get the Notifier from the tree input.
        Parameters:
        editorInput - The editor input to transform
        Returns:
        Notifier
        Throws:
        java.lang.IllegalStateException - if the editor input is not a Notifier
      • createDiangosticCache

        protected DiagnosticCache createDiangosticCache​(org.eclipse.emf.common.notify.Notifier input)
        Creates the diagnostic cache.
        Parameters:
        input - the input
        Returns:
        the cache
        Since:
        1.10
      • enableValidation

        protected boolean enableValidation()
        Returns:
        whether a diagnostic cache should be managed.
        Since:
        1.10
      • createRootView

        protected TreeMasterDetailComposite createRootView​(org.eclipse.swt.widgets.Composite parent,
                                                           java.lang.String editorTitle,
                                                           java.lang.Object editorInput,
                                                           java.util.List<org.eclipse.jface.action.Action> toolbarActions,
                                                           CreateElementCallback createElementCallback)
        Creates the top area of the editor.
        Parameters:
        parent - The parent Composite
        editorTitle - The title of the editor
        editorInput - the editor input
        toolbarActions - The actions shown on the top area
        createElementCallback - a call back if elements are created
        Returns:
        a TreeMasterDetailComposite
        Since:
        1.14
      • getRootView

        protected TreeMasterDetailComposite getRootView()
        Returns the root composite containing the tree and the detail view. This is null before the editor control is created.
        Returns:
        The root TreeMasterDetailComposite of this editor
        Since:
        1.20
      • createTreeMasterDetail

        protected TreeMasterDetailComposite createTreeMasterDetail​(org.eclipse.swt.widgets.Composite composite,
                                                                   java.lang.Object editorInput,
                                                                   CreateElementCallback createElementCallback)
        This method creates a tree master detail. Override this method if you want to customize the tree.
        Parameters:
        composite - the parent composite
        editorInput - the editor input
        createElementCallback - the create element callback to add
        Returns:
        the TreeMasterDetailComposite
      • createTreeViewerBuilder

        protected TreeViewerBuilder createTreeViewerBuilder()
        Create the TreeViewerBuilder customization which creates the tree for the editor's tree master detail.

        Clients can override this to customize the tree viewer.

        Returns:
        the TreeViewerBuilder which creates the tree viewer for the editor's tree master detail
        Since:
        1.20
      • modifyEditorInput

        protected java.lang.Object modifyEditorInput​(org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
        Allows to modify the input object for the editor.
        Parameters:
        resourceSet - the resourceSet which is the default editor input
        Returns:
        the object to set as the input
      • loadResource

        protected org.eclipse.emf.ecore.resource.ResourceSet loadResource​(org.eclipse.ui.IEditorInput editorInput)
                                                                   throws org.eclipse.ui.PartInitException
        Creates a resource set and loads all required resources for the editor input.
        Parameters:
        editorInput - the editor input
        Returns:
        the resource set
        Throws:
        org.eclipse.ui.PartInitException - if the resource could not be loaded
      • isEditable

        protected boolean isEditable​(org.eclipse.ui.IEditorInput editorInput)
        Returns whether the editor input allows editing of its contents.
        Parameters:
        editorInput - the editor's IEditorInput
        Returns:
        true if the input source allows editing, false otherwise
        Since:
        1.22
      • verifyEditorResource

        protected void verifyEditorResource​(org.eclipse.emf.common.util.URI resourceURI,
                                            org.eclipse.emf.ecore.resource.ResourceSet resourceSet)
        Check that the resource was loaded correctly and show any warnings to the user.
        Parameters:
        resourceSet - the resource set
        resourceURI - the URI of the resource
        Since:
        1.19
      • getResourceLoadOptions

        protected java.util.Map<java.lang.Object,​java.lang.Object> getResourceLoadOptions()
        The options to be used when loading the editor's resource.
        Returns:
        the load options
        Since:
        1.19
      • getResourceSaveOptions

        protected java.util.Map<java.lang.Object,​java.lang.Object> getResourceSaveOptions()
        The options to be used when saving the editor's resource.
        Returns:
        the save options
        Since:
        1.19
      • setFocus

        public void setFocus()
        Specified by:
        setFocus in interface org.eclipse.ui.IWorkbenchPart
        Specified by:
        setFocus in class org.eclipse.ui.part.WorkbenchPart
      • hasShortcuts

        protected boolean hasShortcuts()
        Returns true, if the editor should have shortcuts.
        Returns:
        true, if the editor has shortcuts
      • getEditorTitle

        protected java.lang.String getEditorTitle()
        Returns the title for the currently displayed editor. Subclasses should override this function to change the Editor's title
        Returns:
        the title
      • getCreateElementCallback

        protected CreateElementCallback getCreateElementCallback()
        Returns the createElementCallback for this editor. By default, there is none.
        Returns:
        the callback
      • getEditingDomain

        public org.eclipse.emf.edit.domain.EditingDomain getEditingDomain()
        Specified by:
        getEditingDomain in interface org.eclipse.emf.edit.domain.IEditingDomainProvider
      • getToolbarActions

        protected java.util.List<org.eclipse.jface.action.Action> getToolbarActions()
        Returns the toolbar actions for this editor.
        Returns:
        A list of actions to show in the Editor's Toolbar
        Since:
        1.10
      • readToolbarActions

        protected java.util.List<org.eclipse.jface.action.Action> readToolbarActions()
        Read toolbar actions from all extensions.
        Returns:
        the Actions registered via extension point
        Since:
        1.10
      • getResourceSet

        public org.eclipse.emf.ecore.resource.ResourceSet getResourceSet()
        Returns the ResouceSet of this Editor.
        Returns:
        The resource set
      • dispose

        public void dispose()
        Specified by:
        dispose in interface org.eclipse.ui.IWorkbenchPart
        Overrides:
        dispose in class org.eclipse.ui.part.WorkbenchPart
      • gotoMarker

        public void gotoMarker​(org.eclipse.core.resources.IMarker marker)
        Specified by:
        gotoMarker in interface org.eclipse.ui.ide.IGotoMarker
        Since:
        1.10
        See Also:
        IGotoMarker.gotoMarker(org.eclipse.core.resources.IMarker)
      • reveal

        public void reveal​(org.eclipse.emf.ecore.EObject objectToReveal)
        The given element will be revealed in the tree of the editor.
        Parameters:
        objectToReveal - the object to reveal
        Since:
        1.10
      • reveal

        public void reveal​(UniqueSetting setting)
        Reveal the control that edits a setting of some object.
        Parameters:
        setting - the feature setting to reveal of object
        Since:
        1.22
      • getCommandStack

        protected org.eclipse.emf.common.command.BasicCommandStack getCommandStack()
        Returns:
        the commandStack the {@link import org.eclipse.emf.common.command.CommandStack;}
        Since:
        1.10
      • adjustErrorMarker

        protected boolean adjustErrorMarker​(org.eclipse.core.resources.IMarker marker,
                                            org.eclipse.emf.common.util.Diagnostic diagnostic)
                                     throws org.eclipse.core.runtime.CoreException
        Override this method to set additional attributes on the given IMarker, e.g. location information.
        Parameters:
        marker - the IMarker to adjust
        diagnostic - the Diagnostic
        Returns:
        true if the marker was changed, false otherwise
        Throws:
        org.eclipse.core.runtime.CoreException - in case of an error
        Since:
        1.10
      • isClosing

        protected boolean isClosing()
        Returns whether this editor is currently in the process of shutting down.
        Returns:
        true if the editor is currently closing, false otherwise
        Since:
        1.18
      • setClosing

        protected void setClosing​(boolean closing)
        Set whether this editor is currently in the process of shutting down. Set this flag in case you will close the editor.
        Parameters:
        closing - Whether the editor is currently closing (shutting down)
        Since:
        1.18
      • removeResources

        protected void removeResources​(java.util.Collection<org.eclipse.emf.ecore.resource.Resource> resources)
        Removes the given Resources from this editor's ResourceSet. Thereby the resources are matched by URI.
        Parameters:
        resources - The Resources to remove from this editor's ResourceSet.
        Since:
        1.18
      • customizeTree

        protected TreeMasterDetailSWTBuilder customizeTree​(TreeMasterDetailSWTBuilder builder)
        Customize the tree builder. Subclasses are free to add customizations or override default customizations installed by this class, but the latter requires care not to break expected editor behaviour.
        Parameters:
        builder - the tree builder
        Returns:
        the builder for convenience of call chaining, or if absolutely necessary an entirely new builder
        Since:
        1.24
      • handleDetailActivated

        protected void handleDetailActivated​(ViewModelContext detailContext)
        React to the rendering or re-activation of a detail context. The default implementation does nothing; subclasses may just override it.
        Parameters:
        detailContext - the active detail context
        Since:
        1.24