add .xpt template [message #233305] |
Wed, 10 June 2009 14:37 |
Eclipse User |
|
|
|
Originally posted by: aurelien.pupier.esial.net
Hi,
I want to add some template to generate custom files.
I can modify existing, I mean : I modify an existing .xpt, so the
generated class is correctly modified
But when I create a new .xpt file in order to generate a class... it
seems that the .xpt is not used...
The new .xpt files are in the same folder of existing templates.
The most strange is that at the first "generate diagram code", there was
a trace in the log which indicates errors but now there is no more trace
in the log at the "generate diagram code" invocation.
Is there something to do to consider the new .xpt files?
Thanks for any help
One of my new .xpt file(PropertySourceExtended.xpt) :
«IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
«DEFINE Class FOR gmfgen::GenCustomPropertyTab»
«EXPAND xpt::Common::copyright FOR sheet.editorGen-»
package «sheet.packageName»;
«EXPAND xpt::Common::generatedClassComment»
public class PropertySourceExtended extends
org.eclipse.emf.edit.ui.provider.PropertySource implements
org.eclipse.ui.views.properties.IPropertySource{
«EXPAND createPropertyDescriptorMethod»
}
«ENDDEFINE»
«DEFINE createPropertyDescriptorMethod FOR gmfgen::GenCustomPropertyTab-»
«EXPAND xpt::Common::generatedMemberComment»
protected IPropertyDescriptor
createPropertyDescriptor(org.eclipse.emf.edit.provider.IItem PropertyDescriptor
itemPropertyDescriptor) {
return new PropertyDescriptorExtended(object,
itemPropertyDescriptor);
}
«ENDDEFINE»
|
|
|
|
Re: add .xpt template [message #233400 is a reply to message #233322] |
Thu, 11 June 2009 07:31 |
Eclipse User |
|
|
|
Originally posted by: aurelien.pupier.esial.net
Alex Shatalin a écrit :
> Hello Aurelien,
>
>> But when I create a new .xpt file in order to generate a class... it
>> seems that the .xpt is not used...
> You can override/aspect exisitng GMF templates, but if you created a new
> one you have to either call it from any other existing (customized) GMf
> templates - to inject corresponding code into GMf-generated files or
> call separate generate code process (e.g. using ANT task) executing this
> template.
>
> -----------------
> Alex Shatalin
>
>
OK, thanks.
So... some more question.
I think that I will call it from existing GMF templates... but need help
for that too
I looked there
http://www.openarchitectureware.org/pub/documentation/4.1/r2 0_xPandReference.pdf
and find that we can call an other definition in an other template file
if we specified the name of the template...
«EXPAND my::templates::TemplateFile::definitionName
FOR myModelElement»
So I try various things and I have some questions :
Where do I start the path? (my??)
What is the myModelElement? (gmfgen::GenCustomPropertyTab??)
info :
templates
-xpt
-propsheet
- existingTemplate.xpt where I put the EXPAND instruction [1]
- newTemplate.xpt with [2]
I thought it is something like that but it's seems not...
[1]
[...]
«EXPAND xpt::propsheet::newTemplate::Class
FOR gmfgen::GenCustomPropertyTab»
[...]
[2]
[...]
«DEFINE Class FOR gmfgen::GenCustomPropertyTab»
//what i want to generate
«ENDDEFINE»
[...]
|
|
|
|
Re: add .xpt template [message #233468 is a reply to message #233415] |
Thu, 11 June 2009 13:03 |
Eclipse User |
|
|
|
Originally posted by: aurelien.pupier.esial.net
Alex Shatalin a écrit :
> Hello Aurelien,
>
>> Where do I start the path? (my??)
> In .gmfgen model there are two properties:
> - GenEditorGenerator.Dynamic Templates (boolean)
> - GenEditorGenerator.Template Directory (string) - see
> http://wiki.eclipse.org/GMF_GenModel_Hints#GenEditorGenerato r
>
> So, you can:
> - create new template in a file:
> /project1/customTemplates/folder1/TemplateFile.xpt
I create here :
\org.ow2.jasmine.design.gmf.codegen\templates\xpt\propsheet\ PropertySourceExtended.xpt
> - set Template Directory to "/project1/customTemplates"
set to : /org.ow2.jasmine.design.gmf.codegen/templates
> - use «EXPAND folder1::TemplateFile::definitionName FOR myModelElement»
> to execute definition "definitionName" from this file.
in
\org.ow2.jasmine.design.gmf.codegen\templates\xpt\propsheet\ PropertySourceExtended.xpt
:
«IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
«DEFINE Class FOR gmfgen::GenCustomPropertyTab»
«EXPAND xpt::Common::copyright FOR sheet.editorGen-»
package «sheet.packageName»;
«EXPAND xpt::Common::generatedClassComment»
public class PropertySourceExtended extends
org.eclipse.emf.edit.ui.provider.PropertySource implements
org.eclipse.ui.views.properties.IPropertySource{
}
«ENDDEFINE»
and in
org.ow2.jasmine.design.gmf.codegen\templates\xpt\propsheet\P ropertySection.xpt
(which already exists) :
«IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
«IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
«DEFINE Class FOR gmfgen::GenCustomPropertyTab»
«EXPAND xpt::propsheet::PropertySourceExtended::Class FOR
self.customPropertyTab» [1]
«EXPAND xpt::Common::copyright FOR sheet.editorGen-»
package «sheet.packageName»;
«EXPAND xpt::Common::generatedClassComment»
public class «className» extends «EXPAND extendsList» «EXPAND
implementsClause»{
«EXPAND getPropertySourceMethod»
«IF sheet.readOnly»
«EXPAND createReadonlyControlsMethod»
«ENDIF»
«EXPAND getPropertySourceProviderMethod»
«EXPAND transfromSelectionMethod»
«EXPAND setInputMethod»
«EXPAND getAdapterFactoryMethod»
«EXPAND additions»
}
«ENDDEFINE»
[...]the definition of EXPANDs
>
>> What is the myModelElement? (gmfgen::GenCustomPropertyTab??)
> myModelElement is a name of variable or reference/attribute. It's type
> can be gmfgen::GenCustomPropertyTab. Here is an example from GMF templates:
>
> «DEFINE Class FOR gmfgen::GenCustomPropertyTab»
> ............
> public class «className» extends «EXPAND extendsList» «EXPAND
> implementsClause»{
> ............
> «ENDDEFINE»
>
> «EXPAND extendsList» is a way to call another definition with name
> "extendsList" (defined in this file). This call is equivalent to:
> «EXPAND extendsList FOR self» where "self" is a contextual parameter
> name (instanceof gmfgen::GenCustomPropertyTab). If you need to call a
> definition using any feature of contextual parameter you can use
> constructions like:
>
> «EXPAND myDefinition FOR self.className»
>
> the the following definition will be called:
> «DEFINE myDefinition FOR String»
> ............
> «ENDDEFINE»
>
> where "String" is a type of gmfgen::GenCustomPropertyTab::className
> attribute in the model. Instead of shortname of a definition located in
> same file you can use full name like: myFolder::MyTemplate::myDefinition
>
>> [1]
>> [...]
>> «EXPAND xpt::propsheet::newTemplate::Class
>> FOR gmfgen::GenCustomPropertyTab»
> It should be something like:
> «EXPAND xpt::propsheet::newTemplate::Class FOR self.customPropertyTab»
>
I've got this error :
Unknown GenCustomPropertyTab property, variable, type or enumeration
literal 'self' on line [1]
> -----------------
> Alex Shatalin
>
>
>
|
|
|
|
Re: add .xpt template [message #233500 is a reply to message #233477] |
Thu, 11 June 2009 14:25 |
Eclipse User |
|
|
|
Originally posted by: aurelien.pupier.esial.net
Alex Shatalin a écrit :
> Hello Aurelien,
>
>> and in
>> org.ow2.jasmine.design.gmf.codegen\templates\xpt\propsheet\P ropertySec
>> tion.xpt
>> (which already exists) :
>> «IMPORT "http://www.eclipse.org/gmf/2008/GenModel"»
>> «IMPORT "http://www.eclipse.org/emf/2002/Ecore"»
>> «DEFINE Class FOR gmfgen::GenCustomPropertyTab»
>>
>> «EXPAND xpt::propsheet::PropertySourceExtended::Class FOR
>> self.customPropertyTab»
> Try «EXPAND xpt::propsheet::PropertySourceExtended::Class» instead
OMG
>
> -----------------
> Alex Shatalin
>
>
thanks a lot!!
Now the code is well-generated but... in the same file that it is
called. or I want to generate a new file
I tried to create a new file with :
«FILE 'templates/xpt/propsheet/PropertySourceExtended.java'»
«EXPAND xpt::propsheet::PropertySourceExtended::Class»
«ENDFILE»
//also tried with TO_SRC
But I catch this error while generating :
java.lang.UnsupportedOperationException: OPEN FILE
('templates/xpt/propsheet/PropertySourceExtended.java', null)
at
org.eclipse.gmf.internal.xpand.BufferOutput.openFile(BufferO utput.java:44)
at
org.eclipse.gmf.internal.xpand.ast.FileStatement.evaluateInt ernal(FileStatement.java:81)
at org.eclipse.gmf.internal.xpand.ast.Statement.evaluate(Statem ent.java:30)
at
org.eclipse.gmf.internal.xpand.ast.AbstractDefinition.evalua te(AbstractDefinition.java:94)
at
org.eclipse.gmf.internal.xpand.ast.ExpandStatement.invokeDef inition(ExpandStatement.java:190)
at
org.eclipse.gmf.internal.xpand.ast.ExpandStatement.evaluateI nternal(ExpandStatement.java:161)
at org.eclipse.gmf.internal.xpand.ast.Statement.evaluate(Statem ent.java:30)
at
org.eclipse.gmf.internal.xpand.ast.AbstractDefinition.evalua te(AbstractDefinition.java:94)
at org.eclipse.gmf.internal.xpand.XpandFacade.evaluate(XpandFac ade.java:60)
at
org.eclipse.gmf.internal.common.codegen.XpandTextEmitter.gen erate(XpandTextEmitter.java:64)
at
org.eclipse.gmf.internal.common.codegen.GeneratorBase.doGene rateJavaClass(GeneratorBase.java:335)
at
org.eclipse.gmf.codegen.util.Generator.internalGenerateJavaC lass(Generator.java:1006)
at
org.eclipse.gmf.codegen.util.Generator.internalGenerateJavaC lass(Generator.java:1010)
at
org.eclipse.gmf.codegen.util.Generator.generatePropertySheet Sections(Generator.java:857)
at org.eclipse.gmf.codegen.util.Generator.customRun(Generator.j ava:259)
at
org.eclipse.gmf.internal.common.codegen.GeneratorBase$1.run( GeneratorBase.java:474)
at org.eclipse.core.internal.resources.Workspace.run(Workspace. java:1800)
at org.eclipse.core.internal.resources.Workspace.run(Workspace. java:1782)
at
org.eclipse.gmf.internal.common.codegen.GeneratorBase.doRun( GeneratorBase.java:471)
at
org.eclipse.gmf.internal.common.codegen.GeneratorBase.run(Ge neratorBase.java:90)
at
org.eclipse.gmf.internal.codegen.popup.actions.ExecuteTempla tesOperation.run(ExecuteTemplatesOperation.java:182)
at
org.eclipse.jface.operation.ModalContext$ModalContextThread. run(ModalContext.java:121)
|
|
|
|
Re: add .xpt template [message #233517 is a reply to message #233509] |
Thu, 11 June 2009 15:33 |
Eclipse User |
|
|
|
Originally posted by: aurelien.pupier.esial.net
Alex Shatalin a écrit :
> Hello Aurelien,
>
> Rigth. FILE directive is not supported in GMF xpand.
Will it be supported with the new version of GMF which use QvTo?
> This is why I said you in the very first letted that you probably have
> to use ANT task for it.
if you have an example ant task to generate it...
Say me if I'm right.
I can generate all diagram code using an ant task? or is there
limitations? which?
> Another option is to extend org.eclipse.gmf.codegen.util.Generator,
> create custom popup menu action using this class for code generation,
> deploy everything to currently running platform and use this action for
> diagram code generation.
calling a doGenerateJavaClass I suppose at first sight?
>
> -----------------
> Alex Shatalin
>
>
|
|
|
|
Re: add .xpt template [message #233619 is a reply to message #233525] |
Mon, 15 June 2009 08:08 |
Eclipse User |
|
|
|
Originally posted by: aurelien.pupier.esial.net
Alex Shatalin a écrit :
> Hello Aurelien,
>
>> Will it be supported with the new version of GMF which use QvTo?
> No, it's not planned.
>
>> if you have an example ant task to generate it...
> Here it is (build.xml from org.eclipse.gmf.graphdef.editor plugin):
>
> <project name="graphdef.editor" default="main"
> xmlns:xpt="eclipse.org/gmf/2008/xpand">
>
> <property name="graphdef.plugin"
> value="platform:/resource/org.eclipse.gmf.graphdef.editor"/ >
> <property name="formtk.plugin"
> value="platform:/resource/org.eclipse.gmf.formtk"/>
>
> <target name="main">
> <antcall target="generateSection">
> <param name="section" value="Size"/>
> </antcall>
> <antcall target="generateSection">
> <param name="section" value="Layout"/>
> </antcall>
> <antcall target="generateSection">
> <param name="section" value="LayoutData"/>
> </antcall>
> <antcall target="generateSection">
> <param name="section" value="Figure"/>
> </antcall>
> </target>
>
> <target name="generateSection">
> <xpt:template name="PropSheet::Main"
> inputURI="${graphdef.plugin}/models/${section}Section.xmi#/ "
>
> templateroot=" ${graphdef.plugin}/templates-context,${graphdef.plugin}/temp lates-propsheet,${formtk.plugin}/templates-propsheet,${formt k.plugin}/templates-formpage,${formtk.plugin}/templates-cont ext,${formtk.plugin}/templates-widget "
>
>
> outfile=" ${basedir}/src-extra/org/eclipse/gmf/graphdef/editor/sheet/$ {section}Section.java "/>
>
> </target>
>
> </project>
>
>> I can generate all diagram code using an ant task? or is there
>> limitations? which?
> No, it's not supported now. You can generate diagram code using UI
> action only and you can generate additional classes using modified UI
> action or using ant file.
>
>> calling a doGenerateJavaClass I suppose at first sight?
> Right you can call doGenerateJavaClass() from GeNeratorExt class.
>
I tried this.
I created a custom popup menu which launch :
a CustomExecuteTemplatesAction extends ExecuteTemplatesAction, overriden
the createOperation Method by return CustomExecuteTemplatesOperation
CustomExecuteTemplatesOperation extends ExecuteTemplatesOperation,
overriden the createGenerator which return a CustomGenerator
CustomGenerator extends Generator, here I'm calling the dogenerateClass
I tried with argument :
doGenerateJavaClass(
myEmittersCustom.getPropertySourceEmitter()/*newXpandEmitter ( "xpt::propsheet::PropertySource::Class")*/,
"org.ow2.jasmine.design.model.jonas.diagram.sheet",
"PropertySourceExtended",
myDiagram);
}
This exception is thrown by Eclipse while generating :
Problems while generating code
Exception (No Definition xpt::propsheet::PropertySource::Class for
GenDiagram could be found!) while generating code
No Definition xpt::propsheet::PropertySource::Class for GenDiagram
could be found!
The stack trace in the log is:
!SUBENTRY 1 org.eclipse.gmf.common 4 0 2009-06-15 09:59:40.503
!MESSAGE Exception (No Definition xpt::propsheet::PropertySource::Class
for GenDiagram could be found!) while generating code
!STACK 0
org.eclipse.gmf.internal.xpand.expression.EvaluationExceptio n: No
Definition xpt::propsheet::PropertySource::Class for GenDiagram could be
found!
at org.eclipse.gmf.internal.xpand.XpandFacade.evaluate(XpandFac ade.java:50)
at
org.eclipse.gmf.internal.common.codegen.XpandTextEmitter.gen erate(XpandTextEmitter.java:64)
at
org.eclipse.gmf.internal.common.codegen.GeneratorBase.doGene rateJavaClass(GeneratorBase.java:335)
at
org.ow2.jasmine.design.gmf.codegen.generator.popup.actions.C ustomGenerator.generateCustomDialogCellEditorPropertySheet(C ustomGenerator.java:83)
at
org.ow2.jasmine.design.gmf.codegen.generator.popup.actions.C ustomGenerator.generatePropertySheetSections(CustomGenerator .java:57)
at org.eclipse.gmf.codegen.util.Generator.customRun(Generator.j ava:259)
at
org.eclipse.gmf.internal.common.codegen.GeneratorBase$1.run( GeneratorBase.java:474)
at org.eclipse.core.internal.resources.Workspace.run(Workspace. java:1800)
at org.eclipse.core.internal.resources.Workspace.run(Workspace. java:1782)
at
org.eclipse.gmf.internal.common.codegen.GeneratorBase.doRun( GeneratorBase.java:471)
at
org.eclipse.gmf.internal.common.codegen.GeneratorBase.run(Ge neratorBase.java:90)
at
org.eclipse.gmf.internal.codegen.popup.actions.ExecuteTempla tesOperation.run(ExecuteTemplatesOperation.java:182)
at
org.eclipse.jface.operation.ModalContext$ModalContextThread. run(ModalContext.java:121)
It may be other thing to do but what? Do I declare the path to the
template? isn't already declare in the XPandEmitter constructor?
> -----------------
> Alex Shatalin
>
>
|
|
|
|
Re: add .xpt template [message #233682 is a reply to message #233650] |
Mon, 15 June 2009 11:39 |
Eclipse User |
|
|
|
Originally posted by: aurelien.pupier.esial.net
Alex Shatalin a écrit :
> Hello Aurelien,
>
> Looks like specified template was not found by code generation process.
> You've used xpt::propsheet::PropertySource::Class template for
> GenDiagram input.
> This means there should be xpt/propsheet/PropertySource.xpt file with
> appropriate definition in one of the template roots.
> By default GMF generator load all the templates from GMF plugins (you
> probably can not add your template there) + customized templates from
> the "template directory" (specified by corresponding property of
> GenEditorGenerator) if GenEditorGenerator.Dynamic template property was
> set to true.
>
> So, can you please check that:
> - GenEditorGenerator.template directory =
> "/<projectName>/<templateDirectoryName>"
> - GenEditorGenerator.dynamic template = "true"
done for this 2 things (and i'm sure it works because an existing and
changed templates is used)
> - xpt/propsheet/PropertySource.xpt is available in
> /<projectName>/<templateDirectoryName> folder.
right too
> - there is corresponding definition inside this template file.
the definiton :
«DEFINE Class FOR gmfgen::GenCustomPropertyTab»
«EXPAND xpt::Common::copyright FOR sheet.editorGen-»
package «sheet.packageName»;
«EXPAND xpt::Common::generatedClassComment»
public class PropertySourceExtended extends
org.eclipse.emf.edit.ui.provider.PropertySource implements
org.eclipse.ui.views.properties.IPropertySource{
«EXPAND PropertySourceExtendedConstructor»
«EXPAND createPropertyDescriptorMethod»
}
«ENDDEFINE»
[...]
I use GMF SDK 2.1.3, not supported in this version?
>
> -----------------
> Alex Shatalin
>
>
|
|
|
|
Re: add .xpt template [message #233693 is a reply to message #233688] |
Mon, 15 June 2009 12:29 |
Eclipse User |
|
|
|
Originally posted by: aurelien.pupier.esial.net
Alex Shatalin a écrit :
> Hello Aurelien,
>
>> the definiton :
>> «DEFINE Class FOR gmfgen::GenCustomPropertyTab»
> This definition is not one you are calling (there should be «DEFINE
> Class FOR gmfgen::GenDiagram» to satisfy used parameters).
>
> You have to either create «DEFINE Class FOR gmfgen::GenDiagram»
I've tried to use a different input object :
«DEFINE Class FOR gmfgen::GenDiagram»
«EXPAND xpt::Common::copyright FOR sheet.editorGen-»
package «sheet.packageName»;
«EXPAND xpt::Common::generatedClassComment»
public class PropertySourceExtended extends
org.eclipse.emf.edit.ui.provider.PropertySource implements
org.eclipse.ui.views.properties.IPropertySource{
«EXPAND PropertySourceExtendedConstructor»
«EXPAND createPropertyDescriptorMethod»
}
«ENDDEFINE»
with error :
Exception (No Definition xpt::propsheet::PropertySource::Class for
GenDiagram could be found!) while generating code
or call
> doGenerateJavaClass for gmfgen::GenCustomPropertyTab (use different
> input object as a last parameter in doGenerateJavaClass method call).
>
> Instead of:
> doGenerateJavaClass(myEmittersCustom.getPropertySourceEmitte r(),
> "org.ow2.jasmine.design.model.jonas.diagram.sheet",
> "PropertySourceExtended", myDiagram);
>
> You have to use:
> doGenerateJavaClass(myEmittersCustom.getPropertySourceEmitte r(),
> "org.ow2.jasmine.design.model.jonas.diagram.sheet",
> "PropertySourceExtended",
> selectCustomPropertyTabs(myDiagram.getEditorGen().getPropert ySheet().getTabs()));
>
I also tried something like that :
private Object selectCustomPropertyTabs(EList<GenPropertyTab> tabs) {
for (GenPropertyTab tab :tabs) {
if(tab instanceof GenCustomPropertyTab) {
return tab;
}
}
return null;
}
with :
«DEFINE Class FOR gmfgen::GenCustomPropertyTab»
«EXPAND xpt::Common::copyright FOR sheet.editorGen-»
package «sheet.packageName»;
«EXPAND xpt::Common::generatedClassComment»
public class PropertySourceExtended extends
org.eclipse.emf.edit.ui.provider.PropertySource implements
org.eclipse.ui.views.properties.IPropertySource{
«EXPAND PropertySourceExtendedConstructor»
«EXPAND createPropertyDescriptorMethod»
}
«ENDDEFINE»
with error :
Exception (No Definition xpt::propsheet::PropertySource::Class for
GenCustomPropertyTab could be found!) while generating code
>
> -----------------
> Alex Shatalin
>
>
|
|
|
|
[SOLVED]Re: add .xpt template [message #233707 is a reply to message #233701] |
Mon, 15 June 2009 13:09 |
Eclipse User |
|
|
|
Originally posted by: aurelien.pupier.esial.net
Alex Shatalin a écrit :
> Hello Aurelien,
>
> Do you have org.eclipse.gmf.codegen plugin (with gmfgen.ecore model
> inside) in your workspace? If yes - try closing this plugin + restarting
> eclipse + executing generate code action again.
>
>
> -----------------
> Alex Shatalin
>
>
Ok It was that.
Alex, Thanks a LOT for all your help!!!
|
|
|
|
Powered by
FUDForum. Page generated in 0.04267 seconds