SmachToCodeHandler.java
Go to the documentation of this file.
00001 package org.best_of_robotics.transform.smach.to.python.handler;
00002 
00003 import org.best_of_robotics.transform.service.ITransformService;
00004 import org.best_of_robotics.transform.service.access.TransformAccessActivator;
00005 import org.best_of_robotics.transform.service.parameter.IEglTransformParameter;
00006 import org.best_of_robotics.transform.service.parameter.TransformParameterFactory;
00007 import org.best_of_robotics.transform.smach.to.python.Activator;
00008 import org.eclipse.core.commands.AbstractHandler;
00009 import org.eclipse.core.commands.ExecutionEvent;
00010 import org.eclipse.core.commands.ExecutionException;
00011 import org.eclipse.core.resources.IFile;
00012 import org.eclipse.jface.dialogs.MessageDialog;
00013 import org.eclipse.jface.viewers.ISelection;
00014 import org.eclipse.jface.viewers.ITreeSelection;
00015 import org.eclipse.swt.SWT;
00016 import org.eclipse.swt.widgets.FileDialog;
00017 import org.eclipse.ui.IEditorInput;
00018 import org.eclipse.ui.IEditorPart;
00019 import org.eclipse.ui.IFileEditorInput;
00020 import org.eclipse.ui.IWorkbenchWindow;
00021 import org.eclipse.ui.PlatformUI;
00022 import org.eclipse.ui.handlers.HandlerUtil;
00023 
00024 public class SmachToCodeHandler extends AbstractHandler {
00025 
00026         public SmachToCodeHandler() {
00027         }
00028 
00029         @Override
00030         public Object execute(ExecutionEvent event) throws ExecutionException {
00031                 //get the selected source file
00032                                 
00033                 IFile sourcefile = null;
00034                 IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
00035                 if (editor != null) {
00036             IEditorInput input = editor.getEditorInput();
00037             if (input instanceof IFileEditorInput) {
00038                 sourcefile = ((IFileEditorInput)input).getFile();
00039                 System.out.println("File from editor: " + sourcefile.getLocation().toOSString());
00040                 if(sourcefile.getFileExtension() != "smach_model")
00041                 {
00042                         sourcefile = null;
00043                         MessageDialog
00044                                         .openError(
00045                                                         PlatformUI.getWorkbench()
00046                                                                         .getActiveWorkbenchWindow().getShell(),
00047                                                         "Error on Editor Selection",
00048                                                         "Please select the editor from which you want to generate code and execute command again.");
00049                 }
00050                 
00051             }
00052         }
00053                 if(sourcefile == null)
00054                         return null;
00055                 
00056                 //configure new transform parameter
00057                 IEglTransformParameter eglTransformParameter = TransformParameterFactory.createEglTransformParameter();
00058                 eglTransformParameter.setTransformName("SMACH to python implementation");
00059                 eglTransformParameter.setEglTransform("epsilon/smach_to_code.egl");//??
00060                 eglTransformParameter.setPluginID(Activator.PLUGIN_ID);
00061                 eglTransformParameter.setSourceMetaModelURI("http://www.best.org/of/robotics/SmachDSL");
00062                 eglTransformParameter.setSourceModelFilePath(sourcefile.getLocation().toOSString());
00063                 eglTransformParameter.setSourceName("Source");
00064                 eglTransformParameter.setSourceReadOnLoad(true);
00065                 eglTransformParameter.setSourceStoreOnDisposal(false);
00066                 
00067                 eglTransformParameter.setOutputRoot(sourcefile.getParent().getLocation().toOSString());
00068                 
00069                 //get transform service
00070                 
00071                 ITransformService transformService = TransformAccessActivator.getDefault().getTransformService();
00072                 
00073                 //do transform
00074                 transformService.doTransform(eglTransformParameter);
00075                 
00076                 
00077                 return null;
00078         }
00079 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


bride_plugin_source
Author(s): Alexander Bubeck
autogenerated on Wed Aug 14 2013 10:06:09