Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Use a provider by only a specific plugin/editor
Use a provider by only a specific plugin/editor [message #224752] Tue, 07 April 2009 15:09 Go to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
Hi all,

is it possible to easily restrict a provider (IProvider) to be used by
only a specific plugin or editor?

My very special case: There are two providers: UMLEditPartProvider and
UMLEditPartProvider3D. Both providers are registered for extension
point="org.eclipse.gmf.runtime.diagram.ui.editpartProviders ". I also
have to plugins with two editors, the first one ist the UML tools class
diagram editor plugin (and its editor UMLDiagramEditor), the second one
is my plugin with my editor (UMLDiagramEditor3D). Now I want to use the
first provider in the first editor, and the second provider in the
second editor, only.

How can I restrict the UMLEditPartProvider to be used with the
UMLDiagramEditor, and the UMLEditPartProvider3D with the
UmlDiagramEditor3D?

Note: The problem is that both editors can display the very same
models! I need information about the editor currently using the
provider in the provides method, I assume.

Cheers

Jens
Re: Use a provider by only a specific plugin/editor [message #224760 is a reply to message #224752] Tue, 07 April 2009 15:16 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Jens v.P.,

If you are generating code then you have to modify .gmfgen models used for
both editors to make unique all the properties mentioned as "unique" here:
http://wiki.eclipse.org/GMF_GenModel_Hints.
If you are writing code by hands then you have to properly implement provides()
method of each provider.

-----------------
Alex Shatalin
Re: Use a provider by only a specific plugin/editor [message #224768 is a reply to message #224760] Tue, 07 April 2009 15:28 Go to previous messageGo to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
Alex,

On 2009-04-07 17:16:04 +0200, Alex Shatalin <vano@borland.com> said:
> If you are generating code then you have to modify .gmfgen models used
> for both editors to make unique all the properties mentioned as
> "unique" here: http://wiki.eclipse.org/GMF_GenModel_Hints.
> If you are writing code by hands then you have to properly implement
> provides() method of each provider.

I'm writing code by hand. Actually I'm "3D-fying" and existing 2D
editor, that is the UML diagram editor of the UML tools. The problem is
that I don't know how to determine the editor which indirectly invokes
the provides() method. That is, in my provider, the provides() method
is called with some operation. The only thinkg I can determine is the
model, in case of IEditPartProvider this is a View. But since both, the
2D editor and my 3D version can open the very same model, the model is
useless for identifying the editor. What I need is something like
"getCurrentPlugin()" or "getCurrentEditor()" or something like this.

Cheers

Jens

(B.T.W.: Thanks for answering so quickly!)
Re: Use a provider by only a specific plugin/editor [message #224775 is a reply to message #224768] Tue, 07 April 2009 15:58 Go to previous messageGo to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
I have implemented a very very dirty hack, it's working and it
illustrates what I need:

// somewhere in my IProvider:

@Override
public synchronized boolean provides(IOperation i_operation) {
if (!isMyEditor())
return false;
return super.provides(i_operation);
}

public boolean isMyEditor() {
Exception ex = new Exception();
String thisClass = this.getClass().getName();
String name;
for (StackTraceElement element : ex.getStackTrace()) {
name = element.getClassName();
if (name.endsWith("MyEditorName") && ! name.endsWith(thisClass))
return true;
}
return false;
}

I know, it's ugly. But it does what I need: My provider is only active
in my editor. Is there a better, less dirty, way?

Cheers

Jens
Re: Use a provider by only a specific plugin/editor [message #224899 is a reply to message #224768] Wed, 08 April 2009 12:03 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Jens v.P.,

> I'm writing code by hand. Actually I'm "3D-fying" and existing 2D
> editor, that is the UML diagram editor of the UML tools. The problem
Then i sugegst you to re-generate this editor first with a bit customized
..gmfgen model to make "another instance" of UML2 editor and then just patch
a code.

> is the model, in case of IEditPartProvider this is a View. But since
> both, the 2D editor and my 3D version can open the very same model,
I suggest you to create different instances of View for 2D and 3D editors.
With generated editor code it's ratehr easy - just re-generate it once more
and you'll have a clone with different modelID..
Another option is to put a kind of flag into the View object (or root view
object - Diagram) and explicitly switch between representations by changing
this flag, but i really suggest you to clone editor first - you'll even be
able to open both editors on a same .uml2_diagram file - just choose appropriate
one...

-----------------
Alex Shatalin
Re: Use a provider by only a specific plugin/editor [message #225104 is a reply to message #224899] Thu, 09 April 2009 09:01 Go to previous messageGo to next message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
Hello Alex,

On 2009-04-08 14:03:12 +0200, Alex Shatalin <vano@borland.com> said:
>> I'm writing code by hand. Actually I'm "3D-fying" and existing 2D
>> editor, that is the UML diagram editor of the UML tools. The problem
> Then i sugegst you to re-generate this editor first with a bit
> customized .gmfgen model to make "another instance" of UML2 editor and
> then just patch a code.

Actually I don't like the idea to generate code, since I only have to
tweak very little things in the original editor. I have described that
in my blog (see:
http://jevopisdeveloperblog.blogspot.com/2009/04/you-will-be -3d-fied-resistance-is.html
).
The idea is to adapt an existing editor, and this editor maybe be
generated or manually created (or manually enriched). If we generate a
new one, manual enrichments would be lost or have to be applied again.
So I'd prefer adopting the generated 2D version.

>> is the model, in case of IEditPartProvider this is a View. But since
>> both, the 2D editor and my 3D version can open the very same model,
> I suggest you to create different instances of View for 2D and 3D
> editors. With generated editor code it's ratehr easy - just re-generate
> it once more and you'll have a clone with different modelID..

I'm not sure if I understand that correctly, but would it be possible
to open the very same diagram with the 2D and 3D version if different
views are created? The nice thing in the current version is that it's
possible to open (and edit) the very same model (semantic and notation
model) in both, the 2D and 3D editors. It is even possible to open them
simultaneously :-)

> Another option is to put a kind of flag into the View object (or root
> view object - Diagram) and explicitly switch between representations by
> changing this flag, but i really suggest you to clone editor first -
> you'll even be able to open both editors on a same .uml2_diagram file -
> just choose appropriate one...

Hmm.. I'm still not convinced why I should clone the editor. Could you
convince me? ;-) (and see my general problem below)

I don't know very much about all that provider stuff (frankly, it was
Kristian Duske from the GEF3D team who is "our" GMF guy). My problem
with these providers is that they don't have access to the current
context (i.e. the editor which uses the provider). Is there a
technique to retrieve that context within a provider? Or do I
misunderstand the concept of providers?

Besides the edit part provider, we have also implemented a provider
exchanging an edit policy. You may have a look at this policy here:
http://dev.eclipse.org/svnroot/technology/org.eclipse.gef3d/ trunk/org.eclipse.gef3d.examples.uml2/src/java/org/eclipse/g ef3d/examples/uml2/providers/UMLEditPolicyProvider3D.java
The

problem here is that we need again the context, since the provider
should only be activated in case of 3D editors. As a matter of fact,
this provider is not restricted to the UML editor, we are using the
very same policy in the 3D version of the Ecore editor and in other 3D
editors. So, it would be nice to have access to the context (in the
provides method) in order to check whether it is a 3D editor using the
provider. This would be the easiest solution, since we could check (for
example) if the root edit part is a IFigure3D. The implementors of
editors wouldn't have to bother about adding new flags to View objects
or something. If we had access to the context, we could "move" the
policy provider in our general gef3d.gmf plugin.

Cheers

Jens
Re: Use a provider by only a specific plugin/editor [message #225139 is a reply to message #225104] Thu, 09 April 2009 11:28 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Jens v.P.,

> Actually I don't like the idea to generate code, since I only have to
> tweak very little things in the original editor. I have described that
Ok.

> The idea is to adapt an existing editor, and this editor maybe be
> generated or manually created (or manually enriched). If we generate a
> new one, manual enrichments would be lost or have to be applied again.
And what about next version of UML2 2D editor? In this case you probably
have to manually re-apply all adaptations.. But, ok. It's your choice. :-)

> I'm not sure if I understand that correctly, but would it be possible
> to open the very same diagram with the 2D and 3D version if different
> views are created? The nice thing in the current version is that it's
No. you'll be able to open different diagram upon the same domain model.
If you need same diagram then you have to modify existing editor.
BTW, what is the difference between 2d and 3d editors if whole view model
structure is the same?...

> Hmm.. I'm still not convinced why I should clone the editor. Could you
> convince me? ;-) (and see my general problem below)
Ok. What about:
>> Another option is to put a kind of flag into the View object (or root
>> view object - Diagram) and explicitly switch between representations
You should be able to access this information from the providers.

> I don't know very much about all that provider stuff (frankly, it was
> Kristian Duske from the GEF3D team who is "our" GMF guy). My problem
> with these providers is that they don't have access to the current
> context (i.e. the editor which uses the provider). Is there a
> technique to retrieve that context within a provider? Or do I
> misunderstand the concept of providers?
I do not know about the way to get contextual editor instance from there.

-----------------
Alex Shatalin
Re: Use a provider by only a specific plugin/editor [message #225168 is a reply to message #225139] Thu, 09 April 2009 12:13 Go to previous message
Jens von Pilgrim is currently offline Jens von PilgrimFriend
Messages: 313
Registered: July 2009
Senior Member
Hello Alex,

On 2009-04-09 13:28:28 +0200, Alex Shatalin <vano@borland.com> said:
>> The idea is to adapt an existing editor, and this editor maybe be
>> generated or manually created (or manually enriched). If we generate a
>> new one, manual enrichments would be lost or have to be applied again.
> And what about next version of UML2 2D editor? In this case you
> probably have to manually re-apply all adaptations.. But, ok. It's your
> choice. :-)

Oh, I hope that it wouldn't be that bad. What we do when we "adapt" an
editor, it's kind of aspect oriented programming without AOP
techniques. We only "inject" some 3D features into an editor and modify
as few things as possible. If I generate my own 3D editor, well, then
it's a completely different editor, isn't it?

>> I'm not sure if I understand that correctly, but would it be possible
>> to open the very same diagram with the 2D and 3D version if different
>> views are created? The nice thing in the current version is that it's
> No. you'll be able to open different diagram upon the same domain
> model. If you need same diagram then you have to modify existing editor.

Yes, but that's exactly the idea of my 3D editor: I want to be able to
open the very same diagram (and the same model of course).

> BTW, what is the difference between 2d and 3d editors if whole view
> model structure is the same?...

The 3D editor adds a new dimension. This can be used for annotating the
diagram, e.g. for visualizing metrics as 3D bars on top of classes in a
class diagram. Or multiple diagrams could be opened in a single 3D
scene for visualizing inter-diagram/inter-model relationships, e.g. for
visualizing transformation traces (in the area of MDD), model
differences (in the context of EMF Compare), relationships of models
(e.g. show which classes implement a certain use case, visualize state
diagrams with its sub-states) etc.

Cheers

Jens
Previous Topic:How to run the example made by GMF editor as a independent program?
Next Topic:Lost EditingDomain after "save"
Goto Forum:
  


Current Time: Wed Apr 24 20:48:37 GMT 2024

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

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

Back to the top