|
Re: [Xpand] Programmatic tutorial? [message #1313826 is a reply to message #1313513] |
Fri, 25 April 2014 03:17 |
Nigel Daniels Messages: 40 Registered: May 2011 |
Member |
|
|
After much googleing, trial and error I now have the following code:
private void generateJAF() {
// Open a directory dialog to get the output path
DirectoryDialog dialog = new DirectoryDialog (shell);
dialog.setText(JAFEditorPlugin.INSTANCE.getString("_UI_GenerateJAF_dialog_title"));
dialog.setMessage(JAFEditorPlugin.INSTANCE.getString("_UI_GenerateJAF_dialog_message"));
String outputPath = dialog.open();
// Now add the JAF package to a resource set
ResourceSet resourceSet = new ResourceSetImpl();
EPackage JAFPAckage = JafPackage.eINSTANCE;
resourceSet.getPackageRegistry().put(JAFPAckage.getNsURI(),
JAFPAckage);
// Get the current content of the file being worked on
FileEditorInput input =
(FileEditorInput)activeEditorPart.getEditorInput();
// Now set the Xpand output path
URI outputURI = URI.create(outputPath);
Output output = new OutputImpl();
output.addOutlet(new Outlet(outputURI.toString()));
XpandExecutionContextImpl executionContext = new
XpandExecutionContextImpl(output, null);
// Configure the EMF metamodels
EmfMetaModel EMFMetaModel = new EmfMetaModel();
EMFMetaModel.setMetaModelPackage(JafPackage.class.getName());
executionContext.registerMetaModel(EMFMetaModel);
// Now reference the template
URL templateURL =
JAFEditorPlugin.getPlugin().getBundle().getEntry("template/JADTemplate.xpt");
executionContext.registerAdvices(templateURL.getPath());
XpandFacade xpandFacade = XpandFacade.create(executionContext);
Object[] params = null;
//System.out.println(inObjects.get(0));
try {
xpandFacade.evaluate("template::JADTemplate::main",
input.getFile().getContents(), params);
MessageDialog.openInformation(shell, "JAF Generated",
String.format("Your JAF file has been generated in:%n%n", null) +
outputPath);
}
catch (Exception e) {
MessageDialog.openError(shell, "Generation Failed",
String.format("The JAF file generation failed with the message:%n%n",
null) + e.getLocalizedMessage());
}
}
The bit I'm struggling with is the reference to the Template itself? Any
idea how I add the reference to the template in my plugin (I copied it
into the root of my editor plugin into a directory called template) or
even in the Xpand plugin I originally created it in?
Where does the XpandFacade expect it to be?
Thanks for any help.
Nigel
On 24/04/2014 16:05, Nigel Daniels wrote:
> Hi,
>
> I have got an Xpand template running using a workflow and a test.xmi
> file. It is now generating the sort of output I would like, after the
> first hurdle was passed, a quick learning curve!
>
> I would now like to run it from an Eclipse UI action and let the
> customer select where the file is output to. IS there a tutorial or any
> other guidance about on how to achieve this?
>
> As well as understanding what code required I was wondering if there is
> an Xpand runtime jar I can bundle with my plugin to save people from
> having to grab multiple plugins?
>
> Thanks for any advice on this.
>
> Nigel
|
|
|
|
|
Re: [Xpand] Programmatic tutorial? [message #1315354 is a reply to message #1314874] |
Fri, 25 April 2014 23:25 |
Nigel Daniels Messages: 40 Registered: May 2011 |
Member |
|
|
Hi, any suggestion on this?
I started with the template in it's own plugin:
com.foo.xpand
|_ src
|_ template
|_ JADTemplate.xpt
I ensured that the template package was exported and that the plugin was
a dependancy for my editor plugin. I've even tried adding the template
package directly to the editor plugin and ensuring it's exported:
com.foo.editor
|_ src
|_ com.foo.presentation [My editor and action are in here]
|_ template
|_ JADTemplate.xpt
Afaik this is on the classpath (in both cases):
The JADTemplate.xpt contains the main:
«DEFINE main FOR JAFDocument»
And the code I am running calls it like this :
xpandFacade.evaluate("template::JADTemplate::main",
input.getFile().getContents(), params);
But each time I get:
EvaluationException : No Definition template::JADTemplate::main for
Object could be found!
Internal error : element was null
I've also tried adding the xpt to the evaluation context's resource
manager using a platform URL, file URL and absolute path. I each case I
get the same result.
Any advice on what I am doing wrong is very welcome.
On 25/04/2014 10:06, Nigel Daniels wrote:
> Hi Christian,
>
> When I first ran this the template was in it's own plug-in in the
> src/template directory and was included on my selected plugins for the
> debug environment, but it was not found.
>
> I have included now in the actual editor plugin and it's still not being
> found? Is there an example plugin you know of that I can look at to see
> what step I am missing as it is still not seen by the XpandFacade, and I
> am not sure why.
>
> Afaik the template was on the classpath in both cases before I attempted
> to register the advice as to it's location.
>
> Also just to check I have the name correct in the evaluate call this is
> the same name I was able to use in my workflow:
>
> <component class="org.eclipse.xpand2.Generator">
> <metaModel idRef="mm_emf"/>
> <expand value="template::JADTemplate::main FOR jad" />
> <outlet path="${src-gen}" />
> ...
>
> Thanks for helping,
>
> Nigel
>
> On 25/04/2014 00:28, Christian Dietrich wrote:
>> Hi,
>>
>> it should be fine if it is on the classpath.
>>
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03449 seconds