Skip to main content



      Home
Home » Modeling » Graphiti » Performing custom operation after loading the diagram
Performing custom operation after loading the diagram [message #638665] Thu, 11 November 2010 22:24 Go to next message
Eclipse UserFriend
Hi all,

I would like to know what is the best way to perform custom operations after loading the
diagram.

For example, after loading the diagram I would like to change ContainerShape or
GraphicAlgorithm properties.

Thanks.

Regards,
Re: Performing custom operation after loading the diagram [message #638684 is a reply to message #638665] Fri, 12 November 2010 03:03 Go to previous messageGo to next message
Eclipse UserFriend
First a word of warning: this will lead to some strange behavior for the
user of the editor. It will turn dirty diectly after opening a diagram.

If this is part of an update necessary for some of the shapes on a diagram,
you might use an UpdateFeature for that purpose and set the
autoUpdateAtStartup flag to true in the DiagramTypeProvider.

Of course it is also possible (although not really recommended, see above)
to trigger the execution of a feature after the diagram editor has
successfully initialized (e.g. at the end of init method).

Michael


"Vincent L." <lapointe_vincent_1975@hotmail.com> wrote in message
news:ibibp5$5gi$1@news.eclipse.org...
> Hi all,
>
> I would like to know what is the best way to perform custom operations
> after loading the diagram.
>
> For example, after loading the diagram I would like to change
> ContainerShape or GraphicAlgorithm properties.
>
> Thanks.
>
> Regards,
Re: Performing custom operation after loading the diagram [message #638749 is a reply to message #638684] Fri, 12 November 2010 07:59 Go to previous messageGo to next message
Eclipse UserFriend
Hi Michael,

How could I trigger the execution of a feature after the diagram editor has initialized?

Thanks

Vincent


On 12/11/2010 3:03 AM, Michael Wenz wrote:
> First a word of warning: this will lead to some strange behavior for the
> user of the editor. It will turn dirty diectly after opening a diagram.
>
> If this is part of an update necessary for some of the shapes on a diagram,
> you might use an UpdateFeature for that purpose and set the
> autoUpdateAtStartup flag to true in the DiagramTypeProvider.
>
> Of course it is also possible (although not really recommended, see above)
> to trigger the execution of a feature after the diagram editor has
> successfully initialized (e.g. at the end of init method).
>
> Michael
>
>
> "Vincent L."<lapointe_vincent_1975@hotmail.com> wrote in message
> news:ibibp5$5gi$1@news.eclipse.org...
>> Hi all,
>>
>> I would like to know what is the best way to perform custom operations
>> after loading the diagram.
>>
>> For example, after loading the diagram I would like to change
>> ContainerShape or GraphicAlgorithm properties.
>>
>> Thanks.
>>
>> Regards,
>
>
Re: Performing custom operation after loading the diagram [message #638750 is a reply to message #638749] Fri, 12 November 2010 08:10 Go to previous messageGo to next message
Eclipse UserFriend
You could simply call the execute method on that feature. Assure that the
call happens in the right write transaction (so called from within
TransactionalEditingDomain.runExclusive()).

Of course you should also check if the feature can be executed before.

Michael


"Vincent L." <lapointe_vincent_1975@hotmail.com> wrote in message
news:ibjdfg$2qu$1@news.eclipse.org...
> Hi Michael,
>
> How could I trigger the execution of a feature after the diagram editor
> has initialized?
>
> Thanks
>
> Vincent
>
>
> On 12/11/2010 3:03 AM, Michael Wenz wrote:
>> First a word of warning: this will lead to some strange behavior for the
>> user of the editor. It will turn dirty diectly after opening a diagram.
>>
>> If this is part of an update necessary for some of the shapes on a
>> diagram,
>> you might use an UpdateFeature for that purpose and set the
>> autoUpdateAtStartup flag to true in the DiagramTypeProvider.
>>
>> Of course it is also possible (although not really recommended, see
>> above)
>> to trigger the execution of a feature after the diagram editor has
>> successfully initialized (e.g. at the end of init method).
>>
>> Michael
>>
>>
>> "Vincent L."<lapointe_vincent_1975@hotmail.com> wrote in message
>> news:ibibp5$5gi$1@news.eclipse.org...
>>> Hi all,
>>>
>>> I would like to know what is the best way to perform custom operations
>>> after loading the diagram.
>>>
>>> For example, after loading the diagram I would like to change
>>> ContainerShape or GraphicAlgorithm properties.
>>>
>>> Thanks.
>>>
>>> Regards,
>>
>>
>
Re: Performing custom operation after loading the diagram [message #638766 is a reply to message #638684] Fri, 12 November 2010 09:06 Go to previous messageGo to next message
Eclipse UserFriend
Hi Michael,

I tryed your two suggestions but it seems that that my code is called to early in the
initialisation process. Here is my explanation:

1- Using isAutoUpdateAtStartup = true

In this case my update feature is called correctly but when I get the canvas reference it
seems that it doesn't exist yet.

public class MyUpdateFeature extends AbstractUpdateFeature {
...
public boolean update(IUpdateContext context) {
...
DiagramEditor de = (DiagramEditor) getDiagramEditor();
FigureCanvas canvas = de.getFigureCanvas();

// !!! canvas is null in the update at startup !!!

2- Using a custom feature in the initialization of the DiagramTypeProvider

In this case I have a similar problem. When my feature is executed, the canvas doesn't
exist yet.

public class DiagramTypeProvider extends AbstractDiagramTypeProvider {
...
public void init(Diagram diagram, IDiagramEditor diagramEditor) {

super.init(diagram, diagramEditor);
callMyCustomFeature(); //call my custom feature
}
...

public class UpdateSWTCompositeFeature extends AbstractCustomFeature {
...
public void execute(ICustomContext context) {
...
DiagramEditor de = (DiagramEditor) getDiagramEditor();
FigureCanvas canvas = de.getFigureCanvas();

// !!! canvas is null in the update at startup !!!


What could I do? Is there any way to force canvas initialisation? Is there another 'hook'
I could use to modify the canvas after the diagram was loaded ?

Thanks

Regards,

Vincent
Re: Performing custom operation after loading the diagram [message #639891 is a reply to message #638766] Thu, 18 November 2010 05:00 Go to previous messageGo to next message
Eclipse UserFriend
Hi Vincent,

Graphiti initializes the FigureCanvas only when it really starts drawing the
diagram, so you cannot rely on the Canvas being initialized in any feature
or any hook from the editor. Modifying pictogram model data is possible of
course (including properties at these model objects), which I understood as
your usecase.

If you want to access the canvas you might have a look at the so-called
PlatformGraphicsAlgorithms that can be used to provide custom shapes that
are drawn using standard GEF means.

Michael


"Vincent L." <lapointe_vincent_1975@hotmail.com> wrote in message
news:ibjhe9$ai6$1@news.eclipse.org...
>
> Hi Michael,
>
> I tryed your two suggestions but it seems that that my code is called to
> early in the initialisation process. Here is my explanation:
>
> 1- Using isAutoUpdateAtStartup = true
>
> In this case my update feature is called correctly but when I get the
> canvas reference it seems that it doesn't exist yet.
>
> public class MyUpdateFeature extends AbstractUpdateFeature {
> ...
> public boolean update(IUpdateContext context) {
> ...
> DiagramEditor de = (DiagramEditor) getDiagramEditor();
> FigureCanvas canvas = de.getFigureCanvas();
>
> // !!! canvas is null in the update at startup !!!
>
> 2- Using a custom feature in the initialization of the DiagramTypeProvider
>
> In this case I have a similar problem. When my feature is executed, the
> canvas doesn't exist yet.
>
> public class DiagramTypeProvider extends AbstractDiagramTypeProvider {
> ...
> public void init(Diagram diagram, IDiagramEditor diagramEditor) {
>
> super.init(diagram, diagramEditor);
> callMyCustomFeature(); //call my custom feature
> }
> ...
>
> public class UpdateSWTCompositeFeature extends AbstractCustomFeature {
> ...
> public void execute(ICustomContext context) {
> ...
> DiagramEditor de = (DiagramEditor) getDiagramEditor();
> FigureCanvas canvas = de.getFigureCanvas();
>
> // !!! canvas is null in the update at startup !!!
>
>
> What could I do? Is there any way to force canvas initialisation? Is there
> another 'hook' I could use to modify the canvas after the diagram was
> loaded ?
>
> Thanks
>
> Regards,
>
> Vincent
Re: Performing custom operation after loading the diagram [message #639960 is a reply to message #639891] Thu, 18 November 2010 09:31 Go to previous message
Eclipse UserFriend
Hi Michael,

The PlatformGraphicsAlgorithms seems to be the way to go. It works for me.

Thank you.

Vincent


On 18/11/2010 5:00 AM, Michael Wenz wrote:
> Hi Vincent,
>
> Graphiti initializes the FigureCanvas only when it really starts drawing the
> diagram, so you cannot rely on the Canvas being initialized in any feature
> or any hook from the editor. Modifying pictogram model data is possible of
> course (including properties at these model objects), which I understood as
> your usecase.
>
> If you want to access the canvas you might have a look at the so-called
> PlatformGraphicsAlgorithms that can be used to provide custom shapes that
> are drawn using standard GEF means.
>
> Michael
>
Previous Topic:Custom tooltips
Next Topic:Subclassing GraphicAlgorithm and provide custom implementation.
Goto Forum:
  


Current Time: Tue Jul 01 19:12:07 EDT 2025

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

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

Back to the top