Class GenericEditorOpener<T extends org.eclipse.emf.ecore.EObject,​P extends org.eclipse.emf.ecore.EObject,​M extends IModel,​E,​R>

  • Type Parameters:
    T - the type of the top-level language element
    P - the type of the "project", the top-most semantic language unit
    M - the type of model representing "project"
    E - the top-level element type of <M>
    R - the result type when querying for model elements in IModelQuery and searching them on Ecore (IEcoreModelQuery)

    public class GenericEditorOpener<T extends org.eclipse.emf.ecore.EObject,​P extends org.eclipse.emf.ecore.EObject,​M extends IModel,​E,​R>
    extends java.lang.Object
    This class provides a single method for opening an language-specific editor and selecting a specific element of the opened file in that editor based on a given ILeafNode that represents the element for which the declaration should be displayed. This is used to enable the "F3"-functionality.
    Author:
    kroeher
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private EASyLoggerFactory.EASyLogger getLogger()
      Returns the logger.
      private java.net.URI getProjectUri​(M project)
      Returns the URI of the given Project.
      private CommonXtextEditor<T,​P> open​(org.eclipse.ui.IEditorDescriptor editorDescr, org.eclipse.ui.IWorkbenchPage activeWorkbenchWindowPage, org.eclipse.core.resources.IFile projectFile)
      Finally opens the editor.
      void open​(org.eclipse.xtext.nodemodel.ILeafNode parseTreeElement, P parseTreeProject)
      Opens an editor for displaying the declaration of an element to the user.
      private CommonXtextEditor<T,​P> openEditor​(java.net.URI uri)
      Opens an XtextEditor for the language for the resource identified by the given URI.
      private void setCursor​(CommonXtextEditor<T,​P> editor, int targetOffset, int targetEnd)
      Sets the cursor in the given editor to the given target offset and selects the full text from that offset to the given target end.
      private void setCursor​(CommonXtextEditor<T,​P> editor, org.eclipse.emf.ecore.EObject targetObject)
      Sets the cursor in the given editor to the location of the given object and highlights this object (the textual representation in the file).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GenericEditorOpener

        public GenericEditorOpener​(IEcoreModelQuery<P,​R> ecoreModelQuery,
                                   IModelQuery<M,​E,​R> modelQuery)
        Constructs the singleton instance.
        Parameters:
        ecoreModelQuery - the ECore model query object
        modelQuery - the model query object
    • Method Detail

      • open

        public void open​(org.eclipse.xtext.nodemodel.ILeafNode parseTreeElement,
                         P parseTreeProject)
        Opens an editor for displaying the declaration of an element to the user. If the declaration is in the same file than the selected element, no new editor will be opened but the selection will change to the declaration.
        Parameters:
        parseTreeElement - the ILeadNode that represents the selection of the user for which he wants to see the declaration
        parseTreeProject - the project to open the editor for
      • getProjectUri

        private java.net.URI getProjectUri​(M project)
        Returns the URI of the given Project.
        Parameters:
        project - the Project for which the URI should be returned
        Returns:
        the URI of the given project. May return null if the given project is null or the project URI could not be resolved.
      • openEditor

        private CommonXtextEditor<T,​P> openEditor​(java.net.URI uri)
        Opens an XtextEditor for the language for the resource identified by the given URI. If the resource is already opened in such an editor, this editor will be activated only.
        Parameters:
        uri - the URI that identifies the resource (a file) that should be opened in an editor
        Returns:
        the XtextEditor for the language that displays the given resource. May be null if the URI does not identify an existing file in the workspace or the editor cannot be opened
      • open

        private CommonXtextEditor<T,​P> open​(org.eclipse.ui.IEditorDescriptor editorDescr,
                                                  org.eclipse.ui.IWorkbenchPage activeWorkbenchWindowPage,
                                                  org.eclipse.core.resources.IFile projectFile)
        Finally opens the editor.
        Parameters:
        editorDescr - the editor descriptor (may be null)
        activeWorkbenchWindowPage - the active workbench window page
        projectFile - the project file
        Returns:
        the editor (may be null)
      • setCursor

        private void setCursor​(CommonXtextEditor<T,​P> editor,
                               org.eclipse.emf.ecore.EObject targetObject)
        Sets the cursor in the given editor to the location of the given object and highlights this object (the textual representation in the file).
        Parameters:
        editor - the editor in which the the cursor should be set
        targetObject - the EObject that represent the element in the file of the editor to which the cursor should be set
      • setCursor

        private void setCursor​(CommonXtextEditor<T,​P> editor,
                               int targetOffset,
                               int targetEnd)
        Sets the cursor in the given editor to the given target offset and selects the full text from that offset to the given target end.
        Parameters:
        editor - the editor in which the the cursor should be set
        targetOffset - the offset in the editor's file to which the cursor should be set and from which the text selection should start
        targetEnd - the index at which the text selection should end (this value must be greater than targetOffset