Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » xpt templates
xpt templates [message #504673] Tue, 22 December 2009 03:11 Go to next message
No real name is currently offline No real nameFriend
Messages: 62
Registered: July 2009
Member
Hi,

In my diagram project, I changed A specific editpart, called FBEditPart,
which is located in diagram.edit.parts.FBEditPart.

I just added a new method and some inner classes. Now I'd like to use a
template so the code is generated automatically. So I made an new
template file NodeEditPart.xpt

Is it enough to simply add a new Define statement or do I have to change
an existing one?

And how can I specify that I want only FBEditPart to be affected and not
other EditParts?

Currently, my NodeEditPart.xpt looks like this:

------------------------------------------------------------
«IMPORT 'http://www.eclipse.org/gmf/2009/GenModel
«EXTENSION xpt::diagram::ViewmapAttributesUtils»
«EXTENSION xpt::diagram::editparts::Utils»
«EXTENSION xpt::diagram::Utils»

«DEFINE additions FOR gmfgen::GenNode-»
«IF ----- only true if this is an FBEditPart ------»
----- method code -----
----- class1 code -----
----- class1 code -----
----- class1 code -----
«ENDIF-»
«ENDDEFINE»
------------------------------------------------------------

Is this the right approach?

Thanks,
Matthias
Re: xpt templates [message #504696 is a reply to message #504673] Tue, 22 December 2009 08:50 Go to previous messageGo to next message
Esteban Dugueperoux is currently offline Esteban DugueperouxFriend
Messages: 472
Registered: July 2009
Senior Member
Hi Matthias,

You should use AROUND keyword instead of DEFINE to customize code
generation from your *.gmfgen. You should also look at UML2Tools source
code to see how they do.

Best Regards.

Matthias Schmeling wrote:
> Hi,
>
> In my diagram project, I changed A specific editpart, called FBEditPart,
> which is located in diagram.edit.parts.FBEditPart.
>
> I just added a new method and some inner classes. Now I'd like to use a
> template so the code is generated automatically. So I made an new
> template file NodeEditPart.xpt
>
> Is it enough to simply add a new Define statement or do I have to change
> an existing one?
>
> And how can I specify that I want only FBEditPart to be affected and not
> other EditParts?
>
> Currently, my NodeEditPart.xpt looks like this:
>
> ------------------------------------------------------------
> «IMPORT 'http://www.eclipse.org/gmf/2009/GenModel
> «EXTENSION xpt::diagram::ViewmapAttributesUtils»
> «EXTENSION xpt::diagram::editparts::Utils»
> «EXTENSION xpt::diagram::Utils»
>
> «DEFINE additions FOR gmfgen::GenNode-»
> «IF ----- only true if this is an FBEditPart ------»
> ----- method code -----
> ----- class1 code -----
> ----- class1 code -----
> ----- class1 code -----
> «ENDIF-»
> «ENDDEFINE»
> ------------------------------------------------------------
>
> Is this the right approach?
>
> Thanks,
> Matthias
Re: xpt templates [message #504840 is a reply to message #504696] Tue, 22 December 2009 23:41 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 62
Registered: July 2009
Member
I'll do that. Thanks :)

Esteban DUGUEPEROUX wrote:
> Hi Matthias,
>
> You should use AROUND keyword instead of DEFINE to customize code
> generation from your *.gmfgen. You should also look at UML2Tools source
> code to see how they do.
>
> Best Regards.
>
> Matthias Schmeling wrote:
>> Hi,
>>
>> In my diagram project, I changed A specific editpart, called
>> FBEditPart, which is located in diagram.edit.parts.FBEditPart.
>>
>> I just added a new method and some inner classes. Now I'd like to use
>> a template so the code is generated automatically. So I made an new
>> template file NodeEditPart.xpt
>>
>> Is it enough to simply add a new Define statement or do I have to
>> change an existing one?
>>
>> And how can I specify that I want only FBEditPart to be affected and
>> not other EditParts?
>>
>> Currently, my NodeEditPart.xpt looks like this:
>>
>> ------------------------------------------------------------
>> «IMPORT 'http://www.eclipse.org/gmf/2009/GenModel
>> «EXTENSION xpt::diagram::ViewmapAttributesUtils»
>> «EXTENSION xpt::diagram::editparts::Utils»
>> «EXTENSION xpt::diagram::Utils»
>>
>> «DEFINE additions FOR gmfgen::GenNode-»
>> «IF ----- only true if this is an FBEditPart ------»
>> ----- method code -----
>> ----- class1 code -----
>> ----- class1 code -----
>> ----- class1 code -----
>> «ENDIF-»
>> «ENDDEFINE»
>> ------------------------------------------------------------
>>
>> Is this the right approach?
>>
>> Thanks,
>> Matthias
Re: [PARTIALLY SOLVED] xpt templates [message #504841 is a reply to message #504840] Wed, 23 December 2009 01:03 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 62
Registered: July 2009
Member
Hi,

I figured out, how to do it: It is possible to add custom code to the
'additions' DEFINE statement. This is expanded after all the other code
of the NodeEditPart is generated. In addition, GenNodes have the string
attribute 'editPartClassName', so I can simply test if that one is equal
to 'FBEditPart'.

However, I keep getting a strange error message:

Problems while generating code
Exception (org.eclipse.gmf.internal.xpand.util.ParserException,
@aspects::diagram::editparts::NodeEditPart
[131:33-131:33] "ERROR_TOKEN"unexpected token(s)
ignored(aspects::diagram::editparts::NodeEditPart:131:33:131 :33: ))
while generating code
org.eclipse.gmf.internal.xpand.util.ParserException,
@aspects::diagram::editparts::NodeEditPart
[131:33-131:33] "ERROR_TOKEN"unexpected token(s)
ignored(aspects::diagram::editparts::NodeEditPart:131:33:131 :33: )
Exception (org.eclipse.gmf.internal.xpand.util.ParserException,
@aspects::diagram::editparts::NodeEditPart
[131:33-131:33] "ERROR_TOKEN"unexpected token(s)
ignored(aspects::diagram::editparts::NodeEditPart:131:33:131 :33: ))
..
..
..
(This is repeated several times)

It looks like a syntax error, but I cannot figure it out. Does anyone
know, what is wrong here?

Thanks in advance,
Matthias

Matthias Schmeling wrote:
> I'll do that. Thanks :)
>
> Esteban DUGUEPEROUX wrote:
>> Hi Matthias,
>>
>> You should use AROUND keyword instead of DEFINE to customize code
>> generation from your *.gmfgen. You should also look at UML2Tools
>> source code to see how they do.
>>
>> Best Regards.
>>
>> Matthias Schmeling wrote:
>>> Hi,
>>>
>>> In my diagram project, I changed A specific editpart, called
>>> FBEditPart, which is located in diagram.edit.parts.FBEditPart.
>>>
>>> I just added a new method and some inner classes. Now I'd like to use
>>> a template so the code is generated automatically. So I made an new
>>> template file NodeEditPart.xpt
>>>
>>> Is it enough to simply add a new Define statement or do I have to
>>> change an existing one?
>>>
>>> And how can I specify that I want only FBEditPart to be affected and
>>> not other EditParts?
>>>
>>> Currently, my NodeEditPart.xpt looks like this:
>>>
>>> ------------------------------------------------------------
>>> «IMPORT 'http://www.eclipse.org/gmf/2009/GenModel
>>> «EXTENSION xpt::diagram::ViewmapAttributesUtils»
>>> «EXTENSION xpt::diagram::editparts::Utils»
>>> «EXTENSION xpt::diagram::Utils»
>>>
>>> «DEFINE additions FOR gmfgen::GenNode-»
>>> «IF ----- only true if this is an FBEditPart ------»
>>> ----- method code -----
>>> ----- class1 code -----
>>> ----- class1 code -----
>>> ----- class1 code -----
>>> «ENDIF-»
>>> «ENDDEFINE»
>>> ------------------------------------------------------------
>>>
>>> Is this the right approach?
>>>
>>> Thanks,
>>> Matthias
Re: [PARTIALLY SOLVED] xpt templates [message #504846 is a reply to message #504841] Wed, 23 December 2009 01:10 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 62
Registered: July 2009
Member
This is my additions rule in NodeEditPart.xpt:

«DEFINE additions FOR gmfgen::GenNode-»
«IF self.editPartClassName == "FBEditPart"-»
protected void handleNotificationEvent(Notification notification) {
super.handleNotificationEvent(notification);
...
}

public class FBCommand extends Command {
...
}

public class FBDeleteEventsAndVarsCommand extends FBCommand {
...
}

public class FBAdaptEventsAndVarsCommand extends FBCommand {
...
}
«ENDIF-»
«ENDDEFINE»
Re: [PARTIALLY SOLVED] xpt templates [message #505039 is a reply to message #504846] Fri, 25 December 2009 00:07 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 62
Registered: July 2009
Member
Hi again,

I just tried to generate my diagram code with an old template, which
used to work. I get the same error here. This must mean that it's not a
syntax error. However, I have no idea what to make of this.

Regards,
Matthias

Matthias Schmeling wrote:
> This is my additions rule in NodeEditPart.xpt:
>
> «DEFINE additions FOR gmfgen::GenNode-»
> «IF self.editPartClassName == "FBEditPart"-»
> protected void handleNotificationEvent(Notification notification) {
> super.handleNotificationEvent(notification);
> ...
> }
>
> public class FBCommand extends Command {
> ...
> }
>
> public class FBDeleteEventsAndVarsCommand extends FBCommand {
> ...
> }
>
> public class FBAdaptEventsAndVarsCommand extends FBCommand {
> ...
> }
> «ENDIF-»
> «ENDDEFINE»
Re: [PARTIALLY SOLVED] xpt templates [message #527003 is a reply to message #505039] Tue, 13 April 2010 16:25 Go to previous messageGo to next message
Laura Hernández is currently offline Laura HernándezFriend
Messages: 22
Registered: September 2009
Junior Member
Hi all,

have exactly the same problem.

Anyone figured out how to solve this?

Thanks a lot!
Re: [PARTIALLY SOLVED] xpt templates [message #527049 is a reply to message #527003] Tue, 13 April 2010 19:45 Go to previous messageGo to next message
Esteban Dugueperoux is currently offline Esteban DugueperouxFriend
Messages: 472
Registered: July 2009
Senior Member
Hi laura,

Have you tried with AROUND statement instead of DEFINE statement and by
adding all dependants DEFINE statements of the statement you want to
customize?

laura hernandez wrote:
> Hi all,
> have exactly the same problem.
>
> Anyone figured out how to solve this?
>
> Thanks a lot!
Re: [PARTIALLY SOLVED] xpt templates [message #527105 is a reply to message #527049] Wed, 14 April 2010 06:09 Go to previous messageGo to next message
Laura Hernández is currently offline Laura HernándezFriend
Messages: 22
Registered: September 2009
Junior Member
Hi Esteban, and thanks for your answer.

My problem is when I try to add some IF statements, because I am interested in modify the code ONLY for some elements.

In old xpt files I used for a node:
IF this.elementType.displayName.compareTo("nameOfMyType") == 0 and it works perfectly...I can't figure out how to solve this now, I think it is a problem of dependences.

Have you tried this anyway?

Thanks Smile
Re: [PARTIALLY SOLVED] xpt templates [message #527117 is a reply to message #527105] Wed, 14 April 2010 07:21 Go to previous messageGo to next message
Esteban Dugueperoux is currently offline Esteban DugueperouxFriend
Messages: 472
Registered: July 2009
Senior Member
Hi Laura,

Do you override the impl/diagram/editparts/NodeEditPart.xpt template?
Which release of GMF do you use?
I have a example of GMF templates customization at
https://gforge.inria.fr/scm/viewvc.php/trunk/v1/plugins/fr.i nria.adam.calico.models.application.ui.editors.graphical/mod els/m2t/aspects/impl/diagram/editparts/?root=calico
if it can help.

I use Eclipse Helios M6.

Can you show your template customization?

laura hernandez wrote:
> Hi Esteban, and thanks for your answer.
>
> My problem is when I try to add some IF statements, because I am
> interested in modify the code ONLY for some elements.
> In old xpt files I used for a node:
> IF this.elementType.displayName.compareTo("nameOfMyType") == 0 and it
> works perfectly...I can't figure out how to solve this now, I think it
> is a problem of dependences.
>
> Have you tried this anyway?
>
> Thanks :)
Re: [PARTIALLY SOLVED] xpt templates [message #527432 is a reply to message #527117] Thu, 15 April 2010 09:13 Go to previous message
Laura Hernández is currently offline Laura HernándezFriend
Messages: 22
Registered: September 2009
Junior Member
Thanks a lot Esteban!

I use the IF statements as you do in your xpt template and it works!

I tried to make the condition dependant of the node type name but I get an error.
Also, I tried to use the OR in the IF statement like this:

«IF getEditPartQualifiedClassName() = 'com.ptb.rad.bpmn.emf.bpmn.diagram.edit.parts.ManualTaskEdit Part'
|| getEditPartQualifiedClassName() = 'com.ptb.rad.bpmn.emf.bpmn.diagram.edit.parts.ManualTask2Edi tPart' »
«EXPAND ..... »


without sucess, I have to use IF and ELSEIF as you :S

At least it works fine!
Thanks again!
Previous Topic:Keep Bendpoint position on Connection-End Movement
Next Topic:Move the EditPart when click the mouse and the Shift key
Goto Forum:
  


Current Time: Tue Apr 23 15:27:34 GMT 2024

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

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

Back to the top