|
|
|
|
|
Re: Generate Code Back From Diagram [message #1743440 is a reply to message #1738732] |
Thu, 15 September 2016 09:41  |
Eclipse User |
|
|
|
I have finished the code generation and it works.
What I did was creating an eclipse plugin that creates an additional button in the eclipse GUI.
You can read how to do that here:http://www.vogella.com/tutorials/EclipseCommands/article.html
Following those steps I created a Handler class which handles button presses. I created a class XXXGenerator, which the handler creates an instance of.
The handler can then get the active diagram:
IEditorPart ieditorpart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if(ieditorpart instanceof DiagramEditor){
DiagramEditor editor = (DiagramEditor) ieditorpart;
EObject object = editor.getDiagram().getElement();
then for example:
if(object instanceof DscProject){
DscProject project = (DscProject) object;
DscCodeGen generator = new DscCodeGenJava();
DirectoryDialog dialog = new DirectoryDialog(window.getShell());
dialog.setText("Enter directory for code generation");
String url;
url = dialog.open();
if(url != null){
generator.generate(url, project);
MessageDialog.openInformation(
window.getShell(),
"Generator",
"Code for " + project.getName() + "has been created");
The generator class then has access to all model elements via project.getXXElement();
project.getXXEdge(); .
You can iterate over all your diagram elements. Don't forget to check the type and cast if needed.
I used JCodeModel to generate my code.
I hope it helps if you aren't already done with your assignment.
If you have further questions, just ask them.
|
|
|
Powered by
FUDForum. Page generated in 0.03938 seconds