Class GenericEditorOpener<T extends org.eclipse.emf.ecore.EObject,P extends org.eclipse.emf.ecore.EObject,M extends IModel,E,R>
- java.lang.Object
-
- net.ssehub.easy.dslCore.ui.hyperlinking.GenericEditorOpener<T,P,M,E,R>
-
- Type Parameters:
T- the type of the top-level language elementP- the type of the "project", the top-most semantic language unitM- the type of model representing "project"E- the top-level element type of <M>R- the result type when querying for model elements inIModelQueryand 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.ObjectThis 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 givenILeafNodethat represents the element for which the declaration should be displayed. This is used to enable the "F3"-functionality.- Author:
- kroeher
-
-
Field Summary
Fields Modifier and Type Field Description private IEcoreModelQuery<P,R>ecoreModelQueryprivate IModelQuery<M,E,R>modelQuery
-
Constructor Summary
Constructors Constructor Description GenericEditorOpener(IEcoreModelQuery<P,R> ecoreModelQuery, IModelQuery<M,E,R> modelQuery)Constructs the singleton instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private EASyLoggerFactory.EASyLoggergetLogger()Returns the logger.private java.net.URIgetProjectUri(M project)Returns theURIof the givenProject.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.voidopen(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 anXtextEditorfor the language for the resource identified by the givenURI.private voidsetCursor(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 voidsetCursor(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).
-
-
-
Field Detail
-
ecoreModelQuery
private IEcoreModelQuery<P extends org.eclipse.emf.ecore.EObject,R> ecoreModelQuery
-
modelQuery
private IModelQuery<M extends IModel,E,R> modelQuery
-
-
Constructor Detail
-
GenericEditorOpener
public GenericEditorOpener(IEcoreModelQuery<P,R> ecoreModelQuery, IModelQuery<M,E,R> modelQuery)
Constructs the singleton instance.- Parameters:
ecoreModelQuery- the ECore model query objectmodelQuery- 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- theILeadNodethat represents the selection of the user for which he wants to see the declarationparseTreeProject- the project to open the editor for
-
getProjectUri
private java.net.URI getProjectUri(M project)
Returns theURIof the givenProject.- Parameters:
project- theProjectfor which theURIshould be returned- Returns:
- the
URIof the given project. May returnnullif the given project isnullor the project URI could not be resolved.
-
openEditor
private CommonXtextEditor<T,P> openEditor(java.net.URI uri)
Opens anXtextEditorfor the language for the resource identified by the givenURI. If the resource is already opened in such an editor, this editor will be activated only.- Parameters:
uri- theURIthat identifies the resource (a file) that should be opened in an editor- Returns:
- the
XtextEditorfor the language that displays the given resource. May benullif theURIdoes 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 pageprojectFile- 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 settargetObject- theEObjectthat 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 settargetOffset- the offset in the editor's file to which the cursor should be set and from which the text selection should starttargetEnd- the index at which the text selection should end (this value must be greater than targetOffset
-
getLogger
private EASyLoggerFactory.EASyLogger getLogger()
Returns the logger.- Returns:
- the logger
-
-