Home » Modeling » Epsilon » [EuGENia | EGL][newbie] Standalone applications
| | | |
Re: [EuGENia | EGL][newbie] Standalone applications [message #539198 is a reply to message #539159] |
Wed, 09 June 2010 22:33 |
Endre Balogh Messages: 38 Registered: May 2010 |
Member |
|
|
Hi Louis,
Changing EglTemplateFactory to EglFileGeneratingTemplateFactory did solve the problem. I will now try to implement my wizard-based approach.
Cheers,
Endre
L.E. Sorry for asking again, but I have no idea whatsoever how to do this... I invoke the standalone EGL example from the wizard, that's done... how could I pass the currently edited diagram file (in the spawned Eclipse instance), the metamodel file and the EGL code file (in the original eclipse instance) as parameters to the tool? java.io.File objects point to the Eclipse installation folder from the tool's java code as well (not just from EOL, which I mentioned earlier )
Could the model and metamodel objects be passed directly (from memory or something), without using their files? If yes, what about the EGL code?
If this could be made to work, it would make a nice addition to your Examples
The tool code is this so far:
public class CodeGenerator {
public void generateCodeFromModel() throws Exception {
new EglStandaloneExample().execute();
}
}
I fiddled a bit with the EglStandaloneExample code trying to figure out the file handling issue, but no luck for now.
[Updated on: Wed, 09 June 2010 23:12] Report message to a moderator
|
|
| | |
Re: [EuGENia | EGL][newbie] Standalone applications [message #539556 is a reply to message #539482] |
Fri, 11 June 2010 09:49 |
Louis Rose Messages: 440 Registered: July 2009 Location: York, United Kingdom |
Senior Member |
|
|
Hi Endre,
Endre Balogh wrote on Thu, 10 June 2010 18:06 | I've posted the question regarding retrieval of the EMF resource from the diagram in the GMF forums, and I am currently awaiting an answer. Until they give me an optimal way, could you please be more specific regarding your approach? I don't know how to retrieve a specific EditPart to invoke resolveSemanticElement() on it.
|
Great - please do relay any useful information to us. I'd definitely be interested in the solution.
In the past, I've executed a transformation on the resource held in a GMF editor when an element of the model is changed. GMF calls the XX method of the EditPart generated for that model element's type. In the XX method, I've called resolveSemanticElement() to grab the model element being changed.
Specifically, here's an edit part I've edited in this way:
http://epsilonlabs.svn.sourceforge.net/viewvc/epsilonlabs/fp tc/trunk/plugins/org.eclipse.epsilon.fptc.system.diagram/src /org/eclipse/epsilon/fptc/system/diagram/edit/parts/BlockEdi tPart.java?revision=293&view=markup
The hand-written method is at the very bottom of the file.
Quote: | Also, you might have overlooked something in the rest of the code you provided. Contexts are created from TemplateFactories, not vice versa, i.e.
IEglContext context = new EglContext();
is undefined, while
IEglContext context = new EglContext(templateFactory);
exists.
|
You're right! Sorry about this - we're recently made some refactorings to EGL, and I forgot about this change. In which case, I would use the following code:
final EglFileGeneratingTemplateFactory factory = new EglFileGeneratingTemplateFactory();
factory.getContext().getModelRepository().addModel(model);
(That's pretty ugly - we should probably add an addModel method to the template factory in a future version of Epsilon).
Quote: | This line
File templateFile = new File("...");
final EglFileGeneratingTemplate template = templateFactory.load(templateFile);
also gives the following compilation error: type mismatch: cannot convert from EglTemplate to EglFileGeneratingTemplate
|
Whoops, sorry about that. Because you're using an EglFileGeneratingTemplateFactory, it's safe to cast the result of factory.load to an EglFileGeneratingTemplate.
Cheers,
Louis.
|
|
|
Re: [EuGENia | EGL][newbie] Standalone applications [message #539641 is a reply to message #539556] |
Fri, 11 June 2010 15:25 |
Endre Balogh Messages: 38 Registered: May 2010 |
Member |
|
|
Hi Louis,
On the GMF forums I received the following solution:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IDiagramWorkbenchPart diagramPart = (IDiagramWorkbenchPart)page.getActiveEditor();
MyEditPart editPart = (MyEditPart) diagramPart.getDiagramEditPart();
Here I applied your solution (I repeat it for the sake of completeness):
final Resource resource = editPart.resolveSemanticElement().eResource();
final InMemoryEmfModel model = new InMemoryEmfModel("Model", resource, MyPackage.eINSTANCE);
EglFileGeneratingTemplateFactory templateFactory = new EglFileGeneratingTemplateFactory();
templateFactory.getContext().getModelRepository().addModel(model);
File templateFile = new File(".../Generator.egl");
final EglFileGeneratingTemplate template = (EglFileGeneratingTemplate) templateFactory.load(templateFile);
I have hardcoded the location of the EGL template, which will suffice for now.
The only remaining task is to devise the correct path for the code generation. It looks as the only way to localize the resource is by using resource.getURI(), but this returns a path of the form
platform:/resource/projectName/diagramName.my_diagram
Of course, if I cut of the 'platform' prefix and pass this to the EGL template, it will just interpret it as a relative path and create the folders in its own directory.
I will further investigate on how to find the absolute path of the current workspace, since that would allow me to derive the path to the current project's 'src' folder, but if you know a quick solution, it would be more than welcome.
Cheers,
Endre
L.E. The path to the current workspace is returned by ResourcesPlugin.getWorkspace().getRoot().getLocation();
[Updated on: Fri, 11 June 2010 15:29] Report message to a moderator
|
|
| |
Re: [EuGENia | EGL][newbie] Standalone applications [message #539653 is a reply to message #539651] |
Fri, 11 June 2010 16:38 |
Endre Balogh Messages: 38 Registered: May 2010 |
Member |
|
|
Hi Louis,
ResourcesPlugin.getWorkspace().getRoot().getLocation();
worked just fine. However, I encountered another issue, although I can't say whether it's GMF related or Epsilon specific. (I managed to solve it though.)
So the problem encountered: after successfully passing the path parameter to the template, I spawned a new Eclipse instance, created a diagram and generated the code. Everything went smoothly up to here, the code appeared nicely in the project's 'src' folder after a refresh. Then I wanted to open a Java file. The editor displayed a cannot find editor ID type message (the same that you see when you modify the metamodel, regenerate the editor and try to open an old diagram), and then the entire eclipse died with an out of memory error: perm gen. I read a bit about it, and it seems that some part of the application holds on for too many resources for too long.
The solution was to start both the original eclipse and the spawned instance with the -XX:MaxPermSize=256m JVM parameter, which gives more than enough perm gen space (don't know if both were actually necessary, but I did it just in case).
All this appeared quite strange to me, since nothing like this happened when the generation was an isolated project, with me simply copying the diagram file into it and running it on its own.
If you're interested in investigating the issue, I can send you my projects (which have grown quite a bit, but I think they are still manageable); I for one am content with the increased memory solution.
Cheers,
Endre
|
|
| | | | | | | |
Re: [EuGENia | EGL][newbie] Standalone applications [message #590013 is a reply to message #590006] |
Fri, 11 June 2010 09:49 |
Louis Rose Messages: 440 Registered: July 2009 Location: York, United Kingdom |
Senior Member |
|
|
Hi Endre,
Endre Balogh wrote on Thu, 10 June 2010 18:06
> I've posted the question regarding retrieval of the EMF resource from the diagram in the GMF forums, and I am currently awaiting an answer. Until they give me an optimal way, could you please be more specific regarding your approach? I don't know how to retrieve a specific EditPart to invoke resolveSemanticElement() on it.
Great - please do relay any useful information to us. I'd definitely be interested in the solution.
In the past, I've executed a transformation on the resource held in a GMF editor when an element of the model is changed. GMF calls the XX method of the EditPart generated for that model element's type. In the XX method, I've called resolveSemanticElement() to grab the model element being changed.
Specifically, here's an edit part I've edited in this way:
http://epsilonlabs.svn.sourceforge.net/viewvc/epsilonlabs/fp tc/trunk/plugins/org.eclipse.epsilon.fptc.system.diagram/src /org/eclipse/epsilon/fptc/system/diagram/edit/parts/BlockEdi tPart.java?revision=293&view=markup
The hand-written method is at the very bottom of the file.
Quote:
> Also, you might have overlooked something in the rest of the code you provided. Contexts are created from TemplateFactories, not vice versa, i.e.
> IEglContext context = new EglContext();
> is undefined, while
> IEglContext context = new EglContext(templateFactory);
> exists.
You're right! Sorry about this - we're recently made some refactorings to EGL, and I forgot about this change. In which case, I would use the following code:
final EglFileGeneratingTemplateFactory factory = new EglFileGeneratingTemplateFactory();
factory.getContext().getModelRepository().addModel(model);
(That's pretty ugly - we should probably add an addModel method to the template factory in a future version of Epsilon).
Quote:
> This line
> File templateFile = new File("...");
> final EglFileGeneratingTemplate template = templateFactory.load(templateFile);
> also gives the following compilation error: type mismatch: cannot convert from EglTemplate to EglFileGeneratingTemplate
Whoops, sorry about that. Because you're using an EglFileGeneratingTemplateFactory, it's safe to cast the result of factory.load to an EglFileGeneratingTemplate.
Cheers,
Louis.
|
|
|
Re: [EuGENia | EGL][newbie] Standalone applications [message #590027 is a reply to message #539556] |
Fri, 11 June 2010 15:25 |
Endre Balogh Messages: 38 Registered: May 2010 |
Member |
|
|
Hi Louis,
On the GMF forums I received the following solution:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage();
IDiagramWorkbenchPart diagramPart = (IDiagramWorkbenchPart)page.getActiveEditor();
MyEditPart editPart = (MyEditPart) diagramPart.getDiagramEditPart();
Here I applied your solution (I repeat it for the sake of completeness):
final Resource resource = editPart.resolveSemanticElement().eResource();
final InMemoryEmfModel model = new InMemoryEmfModel("Model", resource, MyPackage.eINSTANCE);
EglFileGeneratingTemplateFactory templateFactory = new EglFileGeneratingTemplateFactory();
templateFactory.getContext().getModelRepository().addModel(m odel);
File templateFile = new File(".../Generator.egl");
final EglFileGeneratingTemplate template = (EglFileGeneratingTemplate) templateFactory.load(templateFile);
I have hardcoded the location of the EGL template, which will suffice for now.
The only remaining task is to devise the correct path for the code generation. It looks as the only way to localize the resource is by using resource.getURI(), but this returns a path of the form
platform:/resource/projectName/diagramName.my_diagram
Of course, if I cut of the 'platform' prefix and pass this to the EGL template, it will just interpret it as a relative path and create the folders in its own directory.
I will further investigate on how to find the absolute path of the current workspace, since that would allow me to derive the path to the current project's 'src' folder, but if you know a quick solution, it would be more than welcome. :)
Cheers,
Endre
|
|
| |
Goto Forum:
Current Time: Thu Apr 25 16:50:50 GMT 2024
Powered by FUDForum. Page generated in 0.04672 seconds
|