Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Graphiti and Dependency Injection
Graphiti and Dependency Injection [message #929211] Mon, 01 October 2012 09:48 Go to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 157
Registered: July 2009
Senior Member
Dear all,

Graphiti uses Factory methods to instantiate its infrastructure. When overriding some behavior, that results in the necessity to re-implement some of the classes to override the factory methods.

Are there any thoughts on using dependency injection with Graphiti? To support standalone-tests, I have started to "branch" Graphiti and use Guice e.g. to instantiate the ExtensionManager.

But I would like to know if there are other efforts in that field, so as to avoid duplicate work.

Best Regards,

Andreas
Re: Graphiti and Dependency Injection [message #929647 is a reply to message #929211] Mon, 01 October 2012 16:28 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 601
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 01.10.12 02.48, Andreas Graf wrote:
>
> Graphiti uses Factory methods to instantiate its infrastructure. When
> overriding some behavior, that results in the necessity to re-implement
> some of the classes to override the factory methods.
>
> Are there any thoughts on using dependency injection with Graphiti? To
> support standalone-tests, I have started to "branch" Graphiti and use
> Guice e.g. to instantiate the ExtensionManager.

I've had similar thoughts, although I haven't tried implementing
anything. In general, all the services you can access through the
Graphiti class should be replaceable through injection. In this way you
could customize a lot of the standard behavior. In addition, it should
be possible to inject the logic for how to map from the diagram (shapes
and graphicalgorithms) to gef elements.

The first use case for this was supporting images referred to by URL's,
not just project files. To do this I would need to extend one service
and provide a different mapping to JFace's ImageDescriptor class.

The second use case was supporting custom gef shapes from my previous
projects. I would like to extend the diagram model and hence also the
factories and mapping to gef.

> But I would like to know if there are other efforts in that field, so as
> to avoid duplicate work.

I would like to cooperate on such an effort, hopefully with the support
of the Graphiti developers, to have any hope of merging suggested
changes back in.

Hallvard
Re: Graphiti and Dependency Injection [message #929685 is a reply to message #929211] Mon, 01 October 2012 17:08 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 756
Registered: July 2009
Senior Member
I think that is a great idea.
Though, I would use Eclipse 4's DI engine (which can be used standalone) as this will be the default in future.

Andreas Graf wrote on Mon, 01 October 2012 05:48
Dear all,

Graphiti uses Factory methods to instantiate its infrastructure. When overriding some behavior, that results in the necessity to re-implement some of the classes to override the factory methods.

Are there any thoughts on using dependency injection with Graphiti? To support standalone-tests, I have started to "branch" Graphiti and use Guice e.g. to instantiate the ExtensionManager.

But I would like to know if there are other efforts in that field, so as to avoid duplicate work.

Best Regards,

Andreas

Re: Graphiti and Dependency Injection [message #929689 is a reply to message #929685] Mon, 01 October 2012 17:12 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 157
Registered: July 2009
Senior Member
No Message Body

[Updated on: Mon, 01 October 2012 17:12]

Report message to a moderator

Re: Graphiti and Dependency Injection [message #930251 is a reply to message #929647] Tue, 02 October 2012 06:28 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1640
Registered: July 2009
Location: Walldorf, Germany
Senior Member
All,

though I also spent some thoughts on this as well, there are no concrete
plans in this respect so far. But I see there is demand for this, so I
created https://bugs.eclipse.org/bugs/show_bug.cgi?id=390887 to track this
as an enhancement request.

Hallvard, could you explain why and how you would like to influence the the
mapping from pictogram elements to GEF ?

Well, and as always: any help and contribution is highly welcome... ;-)

Michael
Re: Graphiti and Dependency Injection [message #930589 is a reply to message #930251] Tue, 02 October 2012 13:08 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 157
Registered: July 2009
Senior Member
Who will be at EclipseCon in Ludwigsburg so that we might discuss this?
Re: Graphiti and Dependency Injection [message #930861 is a reply to message #929685] Tue, 02 October 2012 18:08 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 601
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 01.10.12 10.08, Erdal Karaca wrote:
> I think that is a great idea.
> Though, I would use Eclipse 4's DI engine (which can be used standalone)
> as this will be the default in future.

For me it makes more sense to use Guice, since it's used by xtext and I
would like to integrate graphical and textual editing.

Hallvard

P.S. I'm unfortunately not in Ludwigsburg for EclipseCon Europe.
Re: Graphiti and Dependency Injection [message #930866 is a reply to message #930251] Tue, 02 October 2012 18:13 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 601
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 01.10.12 23.28, Michael Wenz wrote:
>
> though I also spent some thoughts on this as well, there are no concrete
> plans in this respect so far. But I see there is demand for this, so I
> created https://bugs.eclipse.org/bugs/show_bug.cgi?id=390887 to track
> this as an enhancement request.
>
> Hallvard, could you explain why and how you would like to influence the
> the mapping from pictogram elements to GEF?

I would like to integrate some existing GEF shapes that pre-dates my use
of Graphiti. It should be possible to extend the diagram model (add a
graphics algorithm) and provide the necessary code for mapping from new
diagram elements to GEF shapes. DI is ideal for this, as you would bind
to a new implementation of the class that defines the mapping. Of
course, the Graphiti framework needs to be designed for this kind of
extension.

Hallvard
Re: Graphiti and Dependency Injection [message #931014 is a reply to message #930866] Tue, 02 October 2012 21:18 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 157
Registered: July 2009
Senior Member
Quote:
It should be possible to extend the diagram model (add a
graphics algorithm) and provide the necessary code for mapping from new
diagram elements to GEF shapes.


Note that it is possible to extend the meta-model already, this works fine for shapes (I agree that you need some more functionality for GAs).

Basically, what you need is your own ecore that inherits from Graphiti's diagram ecore and then you register the graphiti editors for that ecore. I use that extensively for Autosar and other editors.
Re: Graphiti and Dependency Injection [message #931916 is a reply to message #931014] Wed, 03 October 2012 16:47 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 601
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 02.10.12 14.18, Andreas Graf wrote:
> Quote:
>> It should be possible to extend the diagram model (add a
>> graphics algorithm) and provide the necessary code for mapping from new
>> diagram elements to GEF shapes.
>
>
> Note that it is possible to extend the meta-model already, this works
> fine for shapes (I agree that you need some more functionality for GAs).
>
> Basically, what you need is your own ecore that inherits from Graphiti's
> diagram ecore and then you register the graphiti editors for that ecore.
> I use that extensively for Autosar and other editors.

Yes, I understand how this works. What I don't understand is how this is
useful if you cannot extend the logic for how Graphiti uses the model
e.g. the mapping to GEF.

I'm curious for what purposes you extend the model? Could you share some
experiences?

Hallvard
Re: Graphiti and Dependency Injection [message #932502 is a reply to message #931916] Thu, 04 October 2012 06:47 Go to previous messageGo to next message
Jeeeyul Lee is currently offline Jeeeyul LeeFriend
Messages: 111
Registered: July 2009
Location: Seoul
Senior Member

I used DI and Xtend on Graphiti.
It was pretty fancy for me.

See example: https://github.com/jeeeyul/graphiti-overview/blob/master/net.jeeeyul.erd/src/net/jeeeyul/erd/column/AddColumnFeature.xtend
Re: Graphiti and Dependency Injection [message #932517 is a reply to message #931916] Thu, 04 October 2012 07:09 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 157
Registered: July 2009
Senior Member
Hallvard Traetteberg wrote on Wed, 03 October 2012 12:47


Yes, I understand how this works. What I don't understand is how this is
useful if you cannot extend the logic for how Graphiti uses the model
e.g. the mapping to GEF.

I'm curious for what purposes you extend the model? Could you share some
experiences?

Hallvard


Hi Hallvard,

I use it on the shape level. As a simple example, consider e.g. the usual graphical element of a rectangle with a text label. Graphiti does not have the concept of more complex shapes, so if you want to modify the text label, you have to know that text is the n-th figure in the GA of the y-th shape.

So I extend the Graphiti MM by introducing something like a "LabeledRectangle" which has a dedicated EMF refernce to its label GA, so I just can call LabeldRectangle.getLabelGA() without navigating to the hierarchy.

Actually, I have something which is similar to the "Graphiti Pattern" : The shapes have methods that are called when being moved, layouted etc. and by the extension through EMF they can store some state. E.g., for ports that are on class' borders, I store an attribute on which border the port is located (left, right) and use that for aligning the connections.

And I use that to extend Graphiti functionality. E.g., Graphiti has no floating decorators for shapes (only for associations). But I want floating, draggable labels for port names. So I have a "SmartShape" that inherits from container shape. That stores the EMF reference to the label shape. When moving the port, SmartShape.move() is being called, which updates the position of the label shape. The label itself is an instance of SmartFloatingLabel, which in EMF stores the delta of coordinates to the port shape.....

Note that you can also store some state through Graphiti properties, but that is not as typesafe / resilient to refactoring.

There is no need for changing the Graphiti core for that approach, only my feature implementations are designed in a way that they know that I am using "SmartShapes".

Hope that clarified my approach.

Regards,

Andreas

[Updated on: Thu, 04 October 2012 07:11]

Report message to a moderator

Re: Graphiti and Dependency Injection [message #932524 is a reply to message #932502] Thu, 04 October 2012 07:19 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 157
Registered: July 2009
Senior Member
Jeeeyul Lee wrote on Thu, 04 October 2012 02:47
I used DI and Xtend on Graphiti.
It was pretty fancy for me.

See example: https://github.com/jeeeyul/graphiti-overview/blob/master/net.jeeeyul.erd/src/net/jeeeyul/erd/column/AddColumnFeature.xtend


Cool, I must admit I haven't thought about using it for the features yet. I use it to override Persistency/Update/PaletteBehavior.

Re: Graphiti and Dependency Injection [message #933110 is a reply to message #932517] Thu, 04 October 2012 18:48 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 601
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Andreas,

Thank you very much for the explanation! You are right that managing
configurations of shapes and GAs is cumbersome and error-prone and that
extending the diagram model seems better. I currently use properties for
cases such as port position, but modelling it properly seems better.

I can imagine (derived) EReferences can be used for accessing business
objects in a nicer and type-safe manner, too, don't you think? E.g. (in
pesudo Xcore syntax):

class ModelShape<T> extends ContainerShape {
derived ref T model; // getModel must fetch the appropriate bo
}

class ProcessShape extends ModelShape<Process> { ... } etc.

There should be a great potential for reuse, since many diagram
languages have the same syntactic structure, e.g. labeled boxes with
ports on the side, compartment for content etc.

Is your code available for browsing and (re)use?

Hallvard

On 04.10.12 00.09, Andreas Graf wrote:
> Hallvard Traetteberg wrote on Wed, 03 October 2012 12:47
>> Yes, I understand how this works. What I don't understand is how this
>> is useful if you cannot extend the logic for how Graphiti uses the
>> model e.g. the mapping to GEF.
>>
>> I'm curious for what purposes you extend the model? Could you share
>> some experiences?
>>
>> Hallvard
>
>
> Hi Hallvard,
>
> I use it on the shape level. As a simple example, consider e.g. the
> usual graphical element of a rectangle with a text label. Graphiti does
> not have the concept of more complex shapes, so if you want to modify
> the text label, you have to know that text is the n-th figure in the GA
> of the y-th shape.
>
> So I extend the Graphiti MM by introducing something like a
> "LabeledRectangle" which has a dedicated EMF refernce to its label GA,
> so I just can call LabeldRectangle.getLabelGA() without navigating to
> the hierarchy.
> Actually, I have something which is similar to the "Graphiti Pattern" :
> The shapes have methods that are called when being moved, layouted etc.
> and by the extension through EMF they can store some state. E.g., for
> ports that are on class' borders, I store an attribute on which border
> the port is located (left, right) and use that for aligning the
> connections.
> And I use that to extend Graphiti functionality. E.g., Graphiti has no
> floating decorators for shapes (only for associations). But I want
> floating, draggable labels for port names. So I have a "SmartShape" that
> inherits from container shape. That stores the EMF reference to the
> label shape. When moving the port, SmartShape.move() is being called,
> which updates the position of the label shape. The label itself is an
> instance of SmartFloatingLabel, which in EMF stores the delta of
> coordinates to the port shape.....
>
> Note that you can also store some state through Graphiti properties, but
> that is not as typesafe / resilient to refactoring.
>
> Hope that clarified my approach.
>
> Regards,
>
> Andreas
>
Re: Graphiti and Dependency Injection [message #933873 is a reply to message #930589] Fri, 05 October 2012 12:17 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1640
Registered: July 2009
Location: Walldorf, Germany
Senior Member
I will be there. I would like to offer a bof session on Graphiti (not sure
yet which evening). Maybe that would be a good place to discuss that?

Michael
Re: Graphiti and Dependency Injection [message #933878 is a reply to message #930866] Fri, 05 October 2012 12:20 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1640
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Ok, thanks.

Another way to achieve that would be to use PlatformGraphicsAlgforithms.
These GAs can be used to embed standard GEF figures into Graphiti diagrams.

Michael
Re: Graphiti and Dependency Injection [message #934103 is a reply to message #933878] Fri, 05 October 2012 16:58 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 601
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Michael,

I didn't know about that one, great tip! Reading
http://satreth.blogspot.com/2012/03/graphiti-platform-gas.html also helped.

I've created a generic renderer where the id is a class name or a name
key used by guice injection. This way you can more easily configure the
mapping from id to actual draw2d shape.

Perhaps this can also be used for supporting images for generic URLs
without changing Graphiti itself?

Hallvard

On 05.10.12 05.20, Michael Wenz wrote:
> Ok, thanks.
>
> Another way to achieve that would be to use PlatformGraphicsAlgforithms.
> These GAs can be used to embed standard GEF figures into Graphiti diagrams.
>
> Michael
>
Re: Graphiti and Dependency Injection [message #936978 is a reply to message #934103] Mon, 08 October 2012 14:36 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1640
Registered: July 2009
Location: Walldorf, Germany
Senior Member
> Perhaps this can also be used for supporting images for generic URLs
> without changing Graphiti itself?

That's a really interesting idea. I added a note to
https://bugs.eclipse.org/bugs/show_bug.cgi?id=366452, which deals with
making the image provider extension more flexible to check the feasibility.

Michael
Re: Graphiti and Dependency Injection [message #950160 is a reply to message #932517] Fri, 19 October 2012 17:33 Go to previous messageGo to next message
Jos Warmer is currently offline Jos WarmerFriend
Messages: 108
Registered: October 2010
Senior Member
[quote title=Andreas Graf wrote on Thu, 04 October 2012 03:09]Hallvard Traetteberg wrote on Wed, 03 October 2012 12:47
...

Note that you can also store some state through Graphiti properties, but that is not as typesafe / resilient to refactoring.

...

Andreas, I didn't realize this approach is also possible. I use (e.g. in Spray) Graphiti properties, but with a type-safe Facade. This way I can even replace the implementation with another one (like e.g. yours).

Jos
Re: Graphiti and Dependency Injection [message #968913 is a reply to message #933873] Fri, 02 November 2012 21:22 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 601
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Hi,

Did anyone meet concerning DI in Graphiti?

The last couple of weeks I've been working on a graphiti editor for an
xtext-based language, and as part of that process moved to using Guice
as much as possible. It works pretty well, but the design of some parts
make it difficult in general. E.g. the behavior objects are created by
DiagramEditor's constructor, so they can't be replaced without
subclassing. If they were initialized later, a subclass could at least
introduce DI by having its own inject fields, that could be used in
overridden createXXX methods. And the main services retrieved using
static Graphiti methods would also be nice to be able to replace/extend.

Hallvard

On 05.10.12 05.17, Michael Wenz wrote:
> I will be there. I would like to offer a bof session on Graphiti (not
> sure yet which evening). Maybe that would be a good place to discuss that?
>
> Michael
Re: Graphiti and Dependency Injection [message #981556 is a reply to message #968913] Mon, 12 November 2012 14:09 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1640
Registered: July 2009
Location: Walldorf, Germany
Senior Member
>make it difficult in general. E.g. the behavior objects are created by
>DiagramEditor's constructor, so they can't be replaced without subclassing.
>If they were initialized later, a subclass could at least introduce DI by
>having its own inject fields, that could be used in overridden createXXX
>methods. And the main services retrieved using static Graphiti methods
>would also be nice to be able to replace/extend.

Hallvard,

this sounds like a small change with little side effect. Would you open a
Bugzilla to track this?

Thanks,
Michael
Re: Graphiti and Dependency Injection [message #982462 is a reply to message #981556] Tue, 13 November 2012 06:32 Go to previous messageGo to next message
Andreas Graf is currently offline Andreas GrafFriend
Messages: 157
Registered: July 2009
Senior Member
Hi,

I could not make it to the BOF @ ECE. Is the Graphiti team interested in having a Webex on the DI topic? I could set one up for beginning of December.

Regards,

Andreas
Re: Graphiti and Dependency Injection [message #984424 is a reply to message #981556] Wed, 14 November 2012 17:38 Go to previous message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 601
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 12.11.12 06.09, Michael Wenz wrote:
>> make it difficult in general. E.g. the behavior objects are created by
>> DiagramEditor's constructor, so they can't be replaced without
>> subclassing. If they were initialized later, a subclass could at least
>> introduce DI by having its own inject fields, that could be used in
>> overridden createXXX methods. And the main services retrieved using
>> static Graphiti methods would also be nice to be able to replace/extend.
>
> Hallvard,
>
> this sounds like a small change with little side effect. Would you open
> a Bugzilla to track this?

Here it is: https://bugs.eclipse.org/bugs/show_bug.cgi?id=394315

Thanks in advance!

Hallvard
Previous Topic:Dragging between two diagrams
Next Topic:Draw Diagram after startup
Goto Forum:
  


Current Time: Thu Dec 18 21:43:49 GMT 2014

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

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