Home » Modeling » GMF (Graphical Modeling Framework) » XPT template + gfmgen
XPT template + gfmgen [message #200134] |
Mon, 04 August 2008 10:07  |
Eclipse User |
|
|
|
Hi,
I'm trying to customize some GMFGen generated classes using XPT
templates. It doesn't work but I'm not sure about the way to do that.
I set "dynamic templates" to true et "template directory" to
"myproject/templates"
"myproject/templates" contains folder aspects/xpt/diagram/editparts/
I'm not sure about the naming of the file and it's contents.
I want to find a method and customize its content if some test is at true.
For example:
IF getDomainMetaClass().ecoreClass.eAllSuperTypes.select(c | c.name ==
'MyType').size()>0
Have you an answer or a tutorial?
Thanks,
Olivier Patry
|
|
| |
Re: XPT template + gfmgen [message #200327 is a reply to message #200177] |
Tue, 05 August 2008 05:28   |
Eclipse User |
|
|
|
Alex Shatalin a écrit :
> Hello Olivier,
>
> I think you have to use "/myproject/templates" as a value - see
> http://wiki.eclipse.org/GMF_GenModel_Hints#GenEditorGenerato r.
>
>> I'm not sure about the naming of the file and it's contents. I want to
> File name should be exactly the same as original template file name and
> you have to put "<<AROUND>>" declaration there with the same signature
> as in the original template.
> As a simple test you can just put empty AROUND into the custom memplate
> - some part of the generated code will be "suppressed" as a result. This
> is moslty useless action, but you'll be able to check if the rest of the
> environment was correctly set up.
>
> -----------------
> Alex Shatalin
>
>
Hi,
thanks for answer.
The link point to GenModel templates (JET), I use them already, it works
well.
But here, I need to modify diagram generated files (editparts ones), I
think I have to use GmfGen templates (XPT?) No?
I'm a little lost about that!
You talk about "original template file", where can I find it?
Thank you,
Olivier Patry
|
|
| | | | |
Re: XPT template + gfmgen [message #200547 is a reply to message #200514] |
Tue, 05 August 2008 10:35   |
Eclipse User |
|
|
|
Alex Shatalin a écrit :
> Hello Olivier,
>
>> «EXPAND impl::diagram::editparts::NodeEditPart::createNodePlate-»
> This is another template definition resided in another template file
> (impl\diagram\editparts\NodeEditPart.xpt) So looks like you have to add
> an aspect to this definition inside
> aspects\impl\diagram\editparts\NodeEditPart.xpt
>
> -----------------
> Alex Shatalin
>
>
Ok, I'm being crazy :D
So, it's more clear now I think.
Stop me if I'm wrong:
There are default templates in org.eclipse.gmf.codegen/templates
xpt/diagram, impl/diagram and diagram folders
Which of theses folders must I "override" (is it the mechanism?) in my
project?
I place a folder templates at the root of my project and point the path
attribute of my .gmfgen on it (+ dynamic template attribute to true).
Am I good?
So, I try some way (xpt/diagram/editparts/EditNodePart.xpt,
impl/diagram/editparts/EditNodePart.xpt,
diagram/editpart/EditNodePart.xpt) but with all these ways, nothing
called, I put some syntax errors to verify, no error, so I think the xpt
is not called.
It's a first problem/question, how to make my xpt called by gmfgen code
generation?
Another problem/question, about AROUND, I have to copy an existing
EditNodePart.xpt file and modify some things (with AROUND key word?) or
can I simply put the modification I want? (how?)
Thanks again Alex for helping!
++
|
|
|
Re: XPT template + gfmgen [message #200578 is a reply to message #200547] |
Tue, 05 August 2008 12:11   |
Eclipse User |
|
|
|
Hello Olivier,
> There are default templates in org.eclipse.gmf.codegen/templates
> xpt/diagram, impl/diagram and diagram folders
Right. These folders are like a "top-level" packages in java so, if you have
a template file located inside "myPackage" folder in a /templates root folder
then you can address definition from this file using
mypackage::<TemplateName>::<DefinitionName> string.
> Which of theses folders must I "override" (is it the mechanism?) in my
> project?
I think you should find particular <<DEFINE>> generating the code you are
interested in and override (or "AROUND") only this particular define. Sorry
for not mentioning it before - in Xpand you can override particular <<DEFINE>>
keeping the rest of template file untouched. For this you have to create
template file with the same name in a same location as the original one and
put only one selected DEFINE there - the rest of DEFINE statements will be
loaded from the original template file.
> I place a folder templates at the root of my project and point the
> path attribute of my .gmfgen on it (+ dynamic template attribute to
> true).
> Am I good?
I think so. With only one important note: workspace root-relative custom
template path should starts with "/" symbol. In other words, "/myproject/templates"
should be used rather then "myproject/templates".
> It's a first problem/question, how to make my xpt called by gmfgen
> code generation?
Well, it's easy - create custom template folder, set proper path to it, switch
on "use dynamic templates" property in .gmfgen model and copy any template
representing e.g. whole class from the original template folder + remove
several methods/attributes from there to see compilation errors if your custom
template was called.
> Another problem/question, about AROUND, I have to copy an existing
> EditNodePart.xpt file and modify some things (with AROUND key word?)
> or can I simply put the modification I want? (how?)
Let's use impl/diagram/editparts/NodeEditPart.xpt as an example.
you can create new file " /myproject/templates/impl/diagram/editparts/NodeEditPart.xpt "
and write there only:
«IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
«DEFINE constructor FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
public «editPartClassName»(org.eclipse.gmf.runtime.notation.View view) {
// generating incorrect constructor as an example
// super(view);
}
«ENDDEFINE»
As a result particular template file definition («DEFINE constructor FOR
gmfgen::GenNode-») will be overridden by your custom one, the rest should
be used from the original template file.
Or you can create new " /myproject/templates/aspects/impl/diagram/editparts/NodeEdit Part.xpt "
with:
«IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
«AROUND constructor FOR gmfgen::GenNode-»
«EXPAND xpt::Common::generatedMemberComment»
public «editPartClassName»(org.eclipse.gmf.runtime.notation.View view) {
// generating incorrect constructor as an example
// super(view);
}
«AROUND»
and you should get the same result. The difference between "overriding" and
"aspecting" definitions can be illustrated by following example. In case
of " /myproject/templates/aspects/impl/diagram/editparts/NodeEdit Part.xpt "
you can write there:
«IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
«AROUND constructor FOR gmfgen::GenNode-»
«targetDef.proceed()»
«EXPAND xpt::Common::generatedMemberComment»
private int myAdditionalAttribute;
«AROUND»
as a result original code generating original content of the constructor
will be called plus "myAdditionalAttribute" will be generated just below
original template output. In other words, you can call original template
or/and generate your custom code from the aspects. For future details I suggest
you to read xpand documentation: http://www.eclipse.org/gmt/oaw/doc/4.1/r20_xPandReference.pd f
-----------------
Alex Shatalin
|
|
|
Re: XPT template + gfmgen [message #200596 is a reply to message #200578] |
Tue, 05 August 2008 12:31   |
Eclipse User |
|
|
|
Alex Shatalin a écrit :
> Hello Olivier,
>
>> There are default templates in org.eclipse.gmf.codegen/templates
>> xpt/diagram, impl/diagram and diagram folders
> Right. These folders are like a "top-level" packages in java so, if you
> have a template file located inside "myPackage" folder in a /templates
> root folder then you can address definition from this file using
> mypackage::<TemplateName>::<DefinitionName> string.
>
>> Which of theses folders must I "override" (is it the mechanism?) in my
>> project?
> I think you should find particular <<DEFINE>> generating the code you
> are interested in and override (or "AROUND") only this particular
> define. Sorry for not mentioning it before - in Xpand you can override
> particular <<DEFINE>> keeping the rest of template file untouched. For
> this you have to create template file with the same name in a same
> location as the original one and put only one selected DEFINE there -
> the rest of DEFINE statements will be loaded from the original template
> file.
>
>> I place a folder templates at the root of my project and point the
>> path attribute of my .gmfgen on it (+ dynamic template attribute to
>> true).
>> Am I good?
> I think so. With only one important note: workspace root-relative custom
> template path should starts with "/" symbol. In other words,
> "/myproject/templates" should be used rather then "myproject/templates".
>
>> It's a first problem/question, how to make my xpt called by gmfgen
>> code generation?
> Well, it's easy - create custom template folder, set proper path to it,
> switch on "use dynamic templates" property in .gmfgen model and copy any
> template representing e.g. whole class from the original template folder
> + remove several methods/attributes from there to see compilation errors
> if your custom template was called.
>
>
>> Another problem/question, about AROUND, I have to copy an existing
>> EditNodePart.xpt file and modify some things (with AROUND key word?)
>> or can I simply put the modification I want? (how?)
> Let's use impl/diagram/editparts/NodeEditPart.xpt as an example.
>
> you can create new file
> " /myproject/templates/impl/diagram/editparts/NodeEditPart.xpt " and write
> there only:
>
> «IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
> «DEFINE constructor FOR gmfgen::GenNode-»
> «EXPAND xpt::Common::generatedMemberComment»
> public «editPartClassName»(org.eclipse.gmf.runtime.notation.View
> view) {
> // generating incorrect constructor as an example
> // super(view);
> }
> «ENDDEFINE»
>
> As a result particular template file definition («DEFINE constructor FOR
> gmfgen::GenNode-») will be overridden by your custom one, the rest
> should be used from the original template file.
>
> Or you can create new
> " /myproject/templates/aspects/impl/diagram/editparts/NodeEdit Part.xpt "
> with:
>
> «IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
> «AROUND constructor FOR gmfgen::GenNode-»
> «EXPAND xpt::Common::generatedMemberComment»
> public «editPartClassName»(org.eclipse.gmf.runtime.notation.View
> view) {
> // generating incorrect constructor as an example
> // super(view);
> }
> «AROUND»
>
>
> and you should get the same result. The difference between "overriding"
> and "aspecting" definitions can be illustrated by following example. In
> case of
> " /myproject/templates/aspects/impl/diagram/editparts/NodeEdit Part.xpt "
> you can write there:
>
> «IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
> «AROUND constructor FOR gmfgen::GenNode-»
> «targetDef.proceed()»
>
> «EXPAND xpt::Common::generatedMemberComment»
> private int myAdditionalAttribute;
> «AROUND»
>
> as a result original code generating original content of the constructor
> will be called plus "myAdditionalAttribute" will be generated just below
> original template output. In other words, you can call original template
> or/and generate your custom code from the aspects. For future details I
> suggest you to read xpand documentation:
> http://www.eclipse.org/gmt/oaw/doc/4.1/r20_xPandReference.pd f
>
> -----------------
> Alex Shatalin
>
>
Thanks again for help.
I had test some things more and understand better the use of AROUND,
DEFINE etc. confirmed by your last message.
But, my templates aren't called, I paste your example for constructor
generation and nothing change, the constructors are the default ones.
My projectpackage.diagram.edit.parts.*.java are the same as before.
I test with "AROUND" way a placing folder in /myproject/template/impl/
instead of /myproject/template/aspect/impl/ and get something different.
Errors (logical I think) but an interesting behavior, all the Nodes
(gmfgen::GenNode) wasn't created, only Label. So I think it's a proof of
good template path in my .gmfgen, but it's a little bit useless!
Very surprising that your code didn't work at all :( I certainly miss
something, but what and where?
(I'll read the xpand PDF, it should be very useful, I had search "xpt"
on google for doc, not xpand!)
|
|
| |
Re: XPT template + gfmgen [message #200748 is a reply to message #200602] |
Wed, 06 August 2008 06:32   |
Eclipse User |
|
|
|
Alex Shatalin a écrit :
> Hello Olivier,
>
> I've just checked the following using org.eclipse.gmf.ecore.editor
> plugin from GMF examples (checked out from CVS repository):
>
> 1. Created templates\aspects\impl\diagram\editparts\NodeEditPart.xpt
> with following content:
>
> «IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
>
> «AROUND constructor FOR gmfgen::GenNode-»
> «ENDAROUND»
>
> 2. Set "Template Directory" property of Gen Editor Generator to:
> /org.eclipse.gmf.ecore.editor/templates
> 3. Set "Dynamic Templates" property of Gen Editor Generator to "true".
>
> Regenerate code and as a result all the constructors inside *EditParts
> for diagram nodes was not generated (specified "AROUND" is empty, so
> nothing should be generated)
>
> So, looks like in general ti works. I can only suggest you play a little
> bit more with this functionality and probably try using the steps listed
> above.
>
> -----------------
> Alex Shatalin
>
>
Hi,
ok, I finaly try from scratch with a little sample project.
I get the thing I want with no "aspects/AROUND" (ok with DEFINE). I'll
try later with AROUND.
On my little sample project, it works like a charm but in my original
project, I get a problem:
Problems while generating code
Can't organize imports due to syntax errors in the compilation unit
MYCLASSEditPart.java
The generated constructor is:
 /**
* @generated
*/
public ÂMYCLASSEditPart(org.eclipse.gmf.runtime.notation.View view) {
// TEST
//super(view);
}
Â
What are these "Â"? If I suppress them it works but I didn't understand
why they are here!
Secondly, with is the "view" type org.eclipse.gmf.runtime.notation.View
and not just View with the correct "import" instruction? (in my little
sample example, it works, View view + import
org.eclipse.gmf.runtime.notation.View
Thanks Alex for your help and your time, I finaly get something working!
Olivier Patry
|
|
| |
Re: XPT template + gfmgen [message #200917 is a reply to message #200794] |
Wed, 06 August 2008 11:16  |
Eclipse User |
|
|
|
Alex Shatalin a écrit :
> Hello Olivier,
>
>> The generated constructor is:
>> Â /**
>> * @generated
>> */
>> public ÂMYCLASSEditPart(org.eclipse.gmf.runtime.notation.View view) {
>> // TEST
>> //super(view);
>> }
>> Â
>> What are these "Â"? If I suppress them it works but I didn't
> So, looks like you have to double-check custom template file used in the
> original project. "Â" symbol, I assume, can be produced by French
> quotation marks used in the template code.. Are you sure you are using
> proper encoding for custom template files? "ISO-8859-1" encoding should
> be used there.
>
>> Secondly, with is the "view" type
>> org.eclipse.gmf.runtime.notation.View
>> and not just View with the correct "import" instruction? (in my little
> The reason for it is compilation errors in the generated code. If you
> resolve these errors (correct code will be generated by custom template)
> then generation process will execute "organize imports" operation at the
> end of code generation. As a result all fully-qualified class names will
> be substituted by short one + imports.
>
> -----------------
> Alex Shatalin
>
>
Thanks again Alex,
So, it's an encoding issue certainly, I'll test some modifications to
correct this.
I finaly make the AROUND way working too!
Olivier Patry
|
|
|
Goto Forum:
Current Time: Sun May 11 22:39:57 EDT 2025
Powered by FUDForum. Page generated in 0.08450 seconds
|