Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Detecting editor type
Detecting editor type [message #152948] Tue, 02 October 2007 08:59 Go to next message
Eclipse UserFriend
I have several gmf editors based on the same ecore model. They are
seperated by different Model ID, Visual ID and Plugin ID. I wish to
perform some action, based on what kind of editor is being run.

How can I "smell" which editor is running?


Tomas
Re: Detecting editor type [message #152956 is a reply to message #152948] Tue, 02 October 2007 09:14 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Tomas,

Maybe IEditorPart.getSite().getId/getPluginID() will help.


Tomas Zijdemans wrote:
> I have several gmf editors based on the same ecore model. They are
> seperated by different Model ID, Visual ID and Plugin ID. I wish to
> perform some action, based on what kind of editor is being run.
>
> How can I "smell" which editor is running?
>
>
> Tomas
Re: Detecting editor type [message #152984 is a reply to message #152948] Tue, 02 October 2007 09:24 Go to previous messageGo to next message
Eclipse UserFriend
Hi Tomas,

If you have access to the diagram (e.g., if you have an edit part, then
you may use editPart.getViewer().getContents().getModel()), then
diagram.getType() is exactly the model ID.

Best regards,
Boris


Tomas Zijdemans wrote:
> I have several gmf editors based on the same ecore model. They are
> seperated by different Model ID, Visual ID and Plugin ID. I wish to
> perform some action, based on what kind of editor is being run.
>
> How can I "smell" which editor is running?
>
>
> Tomas
Re: Detecting editor type [message #152992 is a reply to message #152956] Tue, 02 October 2007 09:39 Go to previous messageGo to next message
Eclipse UserFriend
Thanks, this sounds good - but in order to do some action in the main
package. It seems impossible to make calls to the .edit plugin.. (I
would like to do this action in the DiagramElement class) hmmm.. well
well, thanks for helping. I'll post a solution if I find one.



Ed Merks skrev:
> Tomas,
>
> Maybe IEditorPart.getSite().getId/getPluginID() will help.
>
>
> Tomas Zijdemans wrote:
>> I have several gmf editors based on the same ecore model. They are
>> seperated by different Model ID, Visual ID and Plugin ID. I wish to
>> perform some action, based on what kind of editor is being run.
>>
>> How can I "smell" which editor is running?
>>
>>
>> Tomas
Re: Detecting editor type [message #152999 is a reply to message #152984] Tue, 02 October 2007 09:56 Go to previous messageGo to next message
Eclipse UserFriend
This could work :)
How should I access the diagram, there are so many classes it makes me dizzy

Thanks,

Tomas

Boris Blajer skrev:
> Hi Tomas,
>
> If you have access to the diagram (e.g., if you have an edit part, then
> you may use editPart.getViewer().getContents().getModel()), then
> diagram.getType() is exactly the model ID.
>
> Best regards,
> Boris
>
>
Re: Detecting editor type [message #153022 is a reply to message #152999] Tue, 02 October 2007 10:49 Go to previous messageGo to next message
Eclipse UserFriend
Hi Tomas,

I'm sorry I cannot answer your question without knowing at least how you
plan to invoke (or register) your action. Depending on that, there may
be many ways to skin a cat ;)

Best regards,
Boris


Tomas Zijdemans wrote:
> This could work :)
> How should I access the diagram, there are so many classes it makes me
> dizzy
>
> Thanks,
>
> Tomas
>
> Boris Blajer skrev:
>> Hi Tomas,
>>
>> If you have access to the diagram (e.g., if you have an edit part,
>> then you may use editPart.getViewer().getContents().getModel()), then
>> diagram.getType() is exactly the model ID.
>>
>> Best regards,
>> Boris
>>
>>
Re: Detecting editor type [message #153211 is a reply to message #153022] Wed, 03 October 2007 05:52 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for helping :)

Ok, say we're in the Node class (or in the DiagramElement class that
contains that Node class), and have made a method:

public SniffDiagram () {
// Load diagram type into a variabel
// ex: aDiagram = diagram.getType()

if (aDiagram instanceOf ClassDiagram) {

system.out.println("It is a Class diagram :)");
}
}


Regards

Tomas


Boris Blajer skrev:
> Hi Tomas,
>
> I'm sorry I cannot answer your question without knowing at least how you
> plan to invoke (or register) your action. Depending on that, there may
> be many ways to skin a cat ;)
>
> Best regards,
> Boris
>
>
> Tomas Zijdemans wrote:
>> This could work :)
>> How should I access the diagram, there are so many classes it makes me
>> dizzy
>>
>> Thanks,
>>
>> Tomas
>>
>> Boris Blajer skrev:
>>> Hi Tomas,
>>>
>>> If you have access to the diagram (e.g., if you have an edit part,
>>> then you may use editPart.getViewer().getContents().getModel()), then
>>> diagram.getType() is exactly the model ID.
>>>
>>> Best regards,
>>> Boris
>>>
>>>
Re: Detecting editor type [message #153247 is a reply to message #153211] Wed, 03 October 2007 08:07 Go to previous messageGo to next message
Eclipse UserFriend
Hi Tomas,

Well, to be honest, I still do not really understand the context... I
expected something like "This is going to be an
IObjectActionContribution", or
org.eclipse.gef.ui.actions.SelectionAction etc. "DiagramElement" does
not really help, it could mean org.eclipse.gmf.runtime.notation.View or
a generated EditPart or probably something else...

I will try to answer, anyway, although this could be a solution to a
problem you do not have...

If you mean an org.eclipse.gmf.runtime.notation.Node, the diagram is
accessible as View#getDiagram(). If DiagramElement you mean is an
org.eclipse.gef.EditPart, use EditPart.getModel() to access the
underlying model, which should be a View (then, use the above suggestion
to navigate to the diagram).

Once you have the diagram instance, diagram.getType() will be the model
ID string.

Hope this helps and
Best regards,
Boris


Tomas Zijdemans wrote:
> Thanks for helping :)
>
> Ok, say we're in the Node class (or in the DiagramElement class that
> contains that Node class), and have made a method:
>
> public SniffDiagram () {
> // Load diagram type into a variabel
> // ex: aDiagram = diagram.getType()
>
> if (aDiagram instanceOf ClassDiagram) {
>
> system.out.println("It is a Class diagram :)");
> }
> }
>
>
> Regards
>
> Tomas
>
>
> Boris Blajer skrev:
>> Hi Tomas,
>>
>> I'm sorry I cannot answer your question without knowing at least how
>> you plan to invoke (or register) your action. Depending on that, there
>> may be many ways to skin a cat ;)
>>
>> Best regards,
>> Boris
>>
>>
>> Tomas Zijdemans wrote:
>>> This could work :)
>>> How should I access the diagram, there are so many classes it makes
>>> me dizzy
>>>
>>> Thanks,
>>>
>>> Tomas
>>>
>>> Boris Blajer skrev:
>>>> Hi Tomas,
>>>>
>>>> If you have access to the diagram (e.g., if you have an edit part,
>>>> then you may use editPart.getViewer().getContents().getModel()),
>>>> then diagram.getType() is exactly the model ID.
>>>>
>>>> Best regards,
>>>> Boris
>>>>
>>>>
Re: Detecting editor type [message #153296 is a reply to message #153247] Wed, 03 October 2007 11:13 Go to previous messageGo to next message
Eclipse UserFriend
Ok, thanks :) I'll look into this.

What I simply meant was that I have a Node class (like "book" in library
or "ship" in taipan) - By DiagramElement, I mean the container for the
objects in the model (like the library class in the library example). By
action, I just meant to run some handwritten code, sorry..

So the method I mentioned, would be inside ex. a book class. (In the
main project, not in the .edit plugin)

Thanks again :)

Tomas

Boris Blajer skrev:
> Hi Tomas,
>
> Well, to be honest, I still do not really understand the context... I
> expected something like "This is going to be an
> IObjectActionContribution", or
> org.eclipse.gef.ui.actions.SelectionAction etc. "DiagramElement" does
> not really help, it could mean org.eclipse.gmf.runtime.notation.View or
> a generated EditPart or probably something else...
>
> I will try to answer, anyway, although this could be a solution to a
> problem you do not have...
>
> If you mean an org.eclipse.gmf.runtime.notation.Node, the diagram is
> accessible as View#getDiagram(). If DiagramElement you mean is an
> org.eclipse.gef.EditPart, use EditPart.getModel() to access the
> underlying model, which should be a View (then, use the above suggestion
> to navigate to the diagram).
>
> Once you have the diagram instance, diagram.getType() will be the model
> ID string.
>
> Hope this helps and
> Best regards,
> Boris
>
>
> Tomas Zijdemans wrote:
>> Thanks for helping :)
>>
>> Ok, say we're in the Node class (or in the DiagramElement class that
>> contains that Node class), and have made a method:
>>
>> public SniffDiagram () {
>> // Load diagram type into a variabel
>> // ex: aDiagram = diagram.getType()
>>
>> if (aDiagram instanceOf ClassDiagram) {
>>
>> system.out.println("It is a Class diagram :)");
>> }
>> }
>>
>>
>> Regards
>>
>> Tomas
>>
>>
>> Boris Blajer skrev:
>>> Hi Tomas,
>>>
>>> I'm sorry I cannot answer your question without knowing at least how
>>> you plan to invoke (or register) your action. Depending on that,
>>> there may be many ways to skin a cat ;)
>>>
>>> Best regards,
>>> Boris
>>>
>>>
>>> Tomas Zijdemans wrote:
>>>> This could work :)
>>>> How should I access the diagram, there are so many classes it makes
>>>> me dizzy
>>>>
>>>> Thanks,
>>>>
>>>> Tomas
>>>>
>>>> Boris Blajer skrev:
>>>>> Hi Tomas,
>>>>>
>>>>> If you have access to the diagram (e.g., if you have an edit part,
>>>>> then you may use editPart.getViewer().getContents().getModel()),
>>>>> then diagram.getType() is exactly the model ID.
>>>>>
>>>>> Best regards,
>>>>> Boris
>>>>>
>>>>>
Re: Detecting editor type [message #153320 is a reply to message #153296] Wed, 03 October 2007 11:59 Go to previous message
Eclipse UserFriend
Hi Tomas,

I would say that it does not seem a good idea to me at all to assume
that an underlying model element has any visual representation on any
diagram whatsoever. The element may be used in a non-diagram context at
all (e.g., with a standard EMF tree editor).

However, if you have an instance of an underlying model element and
*really have to* find how it is represented on a diagram, here is what
you can do. I should stress it that this procedure is potentially VERY
long-running and may give you multiple results, especially if you use
shared editing domains, so proceed with caution.

First, using
org.eclipse.emf.transaction.util.TransactionUtil.getEditingD omain(),
find the editing domain this element is associated with. If it is null
(which means that either this element is effectively deleted or the
editing domain associated with it is not transactional), you only can
give up: there can be no diagram referencing it.

Then, enumerate all resources in the resource set (which is available as
EditingDomain.getResourceSet()).

For each resource, iterate over its #getContents() (you may safely skip
top-level elements that are not
org.eclipse.gmf.runtime.notation.Diagram's). For each diagram, take a
look at its edges (diagram.getEdges()) and see if it contains the
element you are looking for (what is meant by this "contains" will be
explained later). Additionally, you would need to recurse over all Views
(starting with the diagram and, potentially, recursing over Edge's as
well) to see if the element or its View.getChildren() contains the
element you are looking for.

In the above, a view "contains" an underlying model element if and only
if view.isSetElement() && view.getElement() == elementYouAreLookingFor.
Note isSetElement() here, otherwise you will get false positives for labels.

In the end, you will have zero or more (possibly, more than one) View's
whose underlying element is the one you started with. Whether you can do
something with them likely depends on how many hits you will get...

Hope this helps and
Best regards,
Boris

Tomas Zijdemans wrote:
> Ok, thanks :) I'll look into this.
>
> What I simply meant was that I have a Node class (like "book" in library
> or "ship" in taipan) - By DiagramElement, I mean the container for the
> objects in the model (like the library class in the library example). By
> action, I just meant to run some handwritten code, sorry..
>
> So the method I mentioned, would be inside ex. a book class. (In the
> main project, not in the .edit plugin)
>
> Thanks again :)
>
> Tomas
>
> Boris Blajer skrev:
>> Hi Tomas,
>>
>> Well, to be honest, I still do not really understand the context... I
>> expected something like "This is going to be an
>> IObjectActionContribution", or
>> org.eclipse.gef.ui.actions.SelectionAction etc. "DiagramElement" does
>> not really help, it could mean org.eclipse.gmf.runtime.notation.View
>> or a generated EditPart or probably something else...
>>
>> I will try to answer, anyway, although this could be a solution to a
>> problem you do not have...
>>
>> If you mean an org.eclipse.gmf.runtime.notation.Node, the diagram is
>> accessible as View#getDiagram(). If DiagramElement you mean is an
>> org.eclipse.gef.EditPart, use EditPart.getModel() to access the
>> underlying model, which should be a View (then, use the above
>> suggestion to navigate to the diagram).
>>
>> Once you have the diagram instance, diagram.getType() will be the
>> model ID string.
>>
>> Hope this helps and
>> Best regards,
>> Boris
>>
>>
>> Tomas Zijdemans wrote:
>>> Thanks for helping :)
>>>
>>> Ok, say we're in the Node class (or in the DiagramElement class that
>>> contains that Node class), and have made a method:
>>>
>>> public SniffDiagram () {
>>> // Load diagram type into a variabel
>>> // ex: aDiagram = diagram.getType()
>>>
>>> if (aDiagram instanceOf ClassDiagram) {
>>>
>>> system.out.println("It is a Class diagram :)");
>>> }
>>> }
>>>
>>>
>>> Regards
>>>
>>> Tomas
>>>
>>>
>>> Boris Blajer skrev:
>>>> Hi Tomas,
>>>>
>>>> I'm sorry I cannot answer your question without knowing at least how
>>>> you plan to invoke (or register) your action. Depending on that,
>>>> there may be many ways to skin a cat ;)
>>>>
>>>> Best regards,
>>>> Boris
>>>>
>>>>
>>>> Tomas Zijdemans wrote:
>>>>> This could work :)
>>>>> How should I access the diagram, there are so many classes it makes
>>>>> me dizzy
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Tomas
>>>>>
>>>>> Boris Blajer skrev:
>>>>>> Hi Tomas,
>>>>>>
>>>>>> If you have access to the diagram (e.g., if you have an edit part,
>>>>>> then you may use editPart.getViewer().getContents().getModel()),
>>>>>> then diagram.getType() is exactly the model ID.
>>>>>>
>>>>>> Best regards,
>>>>>> Boris
>>>>>>
>>>>>>
Previous Topic:Composite figures from mindmap example in gmf 2
Next Topic:How to work with formdialog in eclipse forms
Goto Forum:
  


Current Time: Sun May 11 11:58:12 EDT 2025

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

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

Back to the top