Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Checking if model is opened in an editor (and opening if not)
Checking if model is opened in an editor (and opening if not) [message #665923] Mon, 18 April 2011 08:03 Go to next message
teddyclaw is currently offline teddyclawFriend
Messages: 9
Registered: July 2009
Junior Member
hello!

so my problem is the following:
i wrote a plugin finding EObjects in a given EMF based model and grouping them after certain criteria. the result of this searching and grouping is a tree whos leaves are the grouped EObjects.

i take this tree and display it in an own view using a treeviewer. Now i want to be able to click in my result tree and take the selected element to highlight the model element(s) in the original model. therefore i need to somehow check if the original model is already open. if so i need to locate it and set the selection of the editor. if it is not opened i want to do so and set the selection afterwards.

i started by adding a selectionchangelistener to my viewer which takes the selected object and extracts one EObject. From that i locate the IFile containing the model. I than try to find a correct editor by using the IEditorRegistry using the filename to locate the right editor for the model. I don't know why but i always end up not finding any proper editor. plus if i had that, i still did not know how to check if it is already open. And then how would i locate and manupilate it?

thanks in advance and don't hesitate to ask for more specific information.
matt b.

Re: Checking if model is opened in an editor (and opening if not) [message #666006 is a reply to message #665923] Mon, 18 April 2011 15:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jonas.helming.googlemail.com

Hi,
I asume you use the generated Editor? I am not definitly sure, but I
think if you open the editor with the same input as an editor which is
already open, the open editor will get active instead. Relevant for this
is the equals method in the EditorInput. So I think you can open the
editor without checking if it is already open and you will get you
desired result.
Cheers
Jonas

Am 18.04.2011 10:04, schrieb Matt Burhenne:
> hello!
>
> so my problem is the following:
> i wrote a plugin finding EObjects in a given EMF based model and
> grouping them after certain criteria. the result of this searching and
> grouping is a tree whos leaves are the grouped EObjects.
>
> i take this tree and display it in an own view using a treeviewer. Now i
> want to be able to click in my result tree and take the selected element
> to highlight the model element(s) in the original model. therefore i
> need to somehow check if the original model is already open. if so i
> need to locate it and set the selection of the editor. if it is not
> opened i want to do so and set the selection afterwards.
>
> i started by adding a selectionchangelistener to my viewer which takes
> the selected object and extracts one EObject. From that i locate the
> IFile containing the model. I than try to find a correct editor by using
> the IEditorRegistry using the filename to locate the right editor for
> the model. I don't know why but i always end up not finding any proper
> editor. plus if i had that, i still did not know how to check if it is
> already open. And then how would i locate and manupilate it?
>
> thanks in advance and don't hesitate to ask for more specific information.
> matt b.
>
>
Re: Checking if model is opened in an editor (and opening if not) [message #666022 is a reply to message #665923] Mon, 18 April 2011 16:46 Go to previous messageGo to next message
teddyclaw is currently offline teddyclawFriend
Messages: 9
Registered: July 2009
Junior Member
ok, i think i need to clarify what i want to do.

i have one model (A) which can be an instance of any kind of EMF based metamodel. i wrote a software that searches model elements in model A and as a result builds a second model (B) which contains certain model elements of model A. the search is executed on model A's file in the package explorer and therfore model A is not necessarily opened. Model B is automatically passed to an extra view which uses a tree viewer to display it.

I now got the request to add in the possibility to click in the displayed model B in its extra view and have the model elements that are displayed in the result model B highlighted in the original model A. Since as is mentioned model A is not necessarily open i want to check, whether it is. Anyhow i need a way to first find an appropriate editor for the type of model of A. this editor i need to either open if the model A is not opened or locate and manipulate if it is.

thanks again
matt B.
Re: Checking if model is opened in an editor (and opening if not) [message #666031 is a reply to message #666022] Mon, 18 April 2011 17:09 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Matt,

Have a look at how the generated wizard opens an editor.


Matt Burhenne wrote:
> ok, i think i need to clarify what i want to do.
>
> i have one model (A) which can be an instance of any kind of EMF based
> metamodel. i wrote a software that searches model elements in model A
> and as a result builds a second model (B) which contains certain model
> elements of model A. the search is executed on model A's file in the
> package explorer and therfore model A is not necessarily opened. Model
> B is automatically passed to an extra view which uses a tree viewer to
> display it.
>
> I now got the request to add in the possibility to click in the
> displayed model B in its extra view and have the model elements that
> are displayed in the result model B highlighted in the original model
> A. Since as is mentioned model A is not necessarily open i want to
> check, whether it is. Anyhow i need a way to first find an appropriate
> editor for the type of model of A. this editor i need to either open
> if the model A is not opened or locate and manipulate if it is.
>
> thanks again
> matt B.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Checking if model is opened in an editor (and opening if not) [message #666139 is a reply to message #665923] Tue, 19 April 2011 09:56 Go to previous messageGo to next message
teddyclaw is currently offline teddyclawFriend
Messages: 9
Registered: July 2009
Junior Member
thanks for the reply. i tried that already. problem is that i triy to get my IEditorDescriptor by calling;

IEditorDescriptor descriptor = workbench.getEditorRegistry().getDefaultEditor(pathName) ;

and i always end up with the descriptor beeing null. i tried it now for ecore and uml files and in both cases it is null. could the mistake be that i access the wrong workbench? and if so, how do i locate the right one? so far i am using

IWorkbench workbench = PlatformUI.getWorkbench();

thanks again
matt

[Updated on: Tue, 19 April 2011 10:12]

Report message to a moderator

Re: Checking if model is opened in an editor (and opening if not) [message #666215 is a reply to message #666139] Tue, 19 April 2011 13:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Matt,

What's the value of pathName? What editors are available in your
workbench? Have you tried seeing why it works in the wizard but not for
you.


Matt Burhenne wrote:
> thanks for the reply. i tried that already. problem is that i triy to
> get my IEditorDescriptor by calling;
>
> IEditorDescriptor descriptor =
> workbench.getEditorRegistry().getDefaultEditor(pathName) ;
>
> and i always end up with the descriptor beeing null. i tried it now
> for ecore and uml files and in both cases it is null. could the
> mistake be that i access the wrong workbench? and if so, how do i
> locate the right one?
>
> thanks again
> matt


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Checking if model is opened in an editor (and opening if not) [message #668767 is a reply to message #665923] Sat, 07 May 2011 08:02 Go to previous message
teddyclaw is currently offline teddyclawFriend
Messages: 9
Registered: July 2009
Junior Member
the pathName variable contains the path of the model file i wish to open relative to the workspace (i extracted that from the model's IFile). I checked the editor registry and it turns out there are no entries for either ecore or uml. maybe i am looking totaly in the wrong place.

my intention is to simply open the appropriate tree editor for a given model file (emf based model of course). is there some other way i have to do that?

say i have the IFile of the model i want to open. how do i locate the tree editor for that file and open it since the tree editors do not seem to be registered in the editor registry i used earlier?

thanks again
matt
Previous Topic:Static initializer exceeding 65535 bytes
Next Topic:Empty namespace URI in ecore?
Goto Forum:
  


Current Time: Fri Apr 26 22:47:03 GMT 2024

Powered by FUDForum. Page generated in 0.03086 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top