|
|
|
|
|
|
Re: How to serialize DSL-Files to UML-Model [message #1150089 is a reply to message #1148580] |
Tue, 22 October 2013 14:26 |
Alexander R Messages: 211 Registered: July 2013 |
Senior Member |
|
|
Hi,
thanks again for the reply.
I followed the instractions from followig sites to implement a command that fulfils a serialization of the xtext-model.
Here the sides:
http://christiandietrich.wordpress.com/2011/10/15/xtext-calling-the-generator-from-a-context-menu/
http://koehnlein.blogspot.de/2012/11/xtext-tip-how-do-i-get-guice-injector.html
I've done the following steps:
- Created a Command with a Handler
<extension
point="org.eclipse.ui.handlers">
<handler
class="...SerializationHandler"
commandId="...ui.SerializationCommand">
</handler>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
id="...ui.SerializationCommand"
name="Serialize UML">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
<command
commandId="...ui.SerializationCommand"
style="push">
<visibleWhen
checkEnabled="false">
<iterate>
<adapt type="org.eclipse.core.resources.IResource">
<test property="org.eclipse.core.resources.name"
value="*.cdalf"/>
</adapt>
</iterate>
</visibleWhen>
</command>
</menuContribution>
</extension>
-Created the necessary HandlerClass (SerializationHandler) which makes use of the @Inject
public class SerializationHandler extends AbstractHandler implements IHandler {
//
@Inject
private Injector injector;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
System.out.println("@ SERIALIZATION HANDLER 1");
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object firstElement = structuredSelection.getFirstElement();
if (firstElement instanceof IFile) {
IFile model = (IFile) firstElement;
// create a model URI for the selected xtext-file
URI modelURI = URI.createPlatformResourceURI(model.getFullPath().toString(), true);
IProject project = model.getProject();
System.out.println("@ SERIALIZATION HANDLER 2");
// create an output folder for the serialized uml-model
IFolder srcGenFolder = project.getFolder("model");
if (!srcGenFolder.exists()) {
try {
srcGenFolder.create(true, true, new NullProgressMonitor());
} catch (CoreException e) {
return null;
}
}
try {
// run the serializiation
serializeXtext(modelURI, project);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//
// IWorkbenchWindow window =
// HandlerUtil.getActiveWorkbenchWindowChecked(event);
// MessageDialog.openInformation(
// window.getShell(),
// "ZZZ",
// "Hello, Eclipse world");
return null;
}
/**
* Serialization of the parsed DSL-Model which is represented in an .cdalf
* file
*
* @param modelURI
* @param target
* @throws IOException
*/
protected void serializeXtext(URI modelURI, IContainer target) throws IOException {
String xtextExtention = modelURI.fileExtension();
File modelName = new File(modelURI.path());
String fullUMLModelName = modelName.getName().substring(0,
modelName.getName().length() - xtextExtention.length() - 1)
+ ".uml";
//
/*
* TODO: Check if file is saved without problems
*/
// injector = new
// CdalfStandaloneSetup().createInjectorAndDoEMFRegistration();
// load the xtext model to an xtextresourceset
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
Resource xtextResource = resourceSet.getResource(modelURI, true);
EcoreUtil.resolveAll(xtextResource);
// store in a xmi-resoure
Resource xmiResource = resourceSet.createResource(URI.createURI(target.getFullPath() + "/" + fullUMLModelName));
xmiResource.getContents().add(xtextResource.getContents().get(0));
try {
xmiResource.save(null);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public boolean isEnabled() {
return true;
}
}
But the problem is now, that my command isn't visible in the runtime-eclipse. Did I somethning wrong? I checked the configuration of the plugin.xml several times but I stillt can't find
the mistake.
Thanks for your answres,
Alex
[Updated on: Mon, 17 November 2014 15:07] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03132 seconds