Go to the documentation of this file.00001 package org.best_of_robotics.transform.sysml_sm.to.smach.handler;
00002
00003 import java.io.FileOutputStream;
00004 import java.io.IOException;
00005 import java.util.Collections;
00006 import java.util.HashMap;
00007
00008 import org.best_of_robotics.transform.sysml_sm.to.smach.Activator;
00009 import org.best_of_robotics.transform.service.ITransformService;
00010 import org.best_of_robotics.transform.service.access.TransformAccessActivator;
00011 import org.best_of_robotics.transform.service.parameter.IEtlTransformParameter;
00012 import org.best_of_robotics.transform.service.parameter.TransformParameterFactory;
00013 import org.eclipse.core.commands.AbstractHandler;
00014 import org.eclipse.core.commands.ExecutionEvent;
00015 import org.eclipse.core.commands.ExecutionException;
00016 import org.eclipse.core.resources.IFile;
00017 import org.eclipse.emf.common.util.URI;
00018 import org.eclipse.emf.ecore.resource.Resource;
00019 import org.eclipse.emf.ecore.resource.ResourceSet;
00020 import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
00021 import org.eclipse.emf.ecore.xmi.XMIResource;
00022 import org.eclipse.jface.dialogs.MessageDialog;
00023 import org.eclipse.jface.viewers.ISelection;
00024 import org.eclipse.jface.viewers.ITreeSelection;
00025 import org.eclipse.swt.SWT;
00026 import org.eclipse.swt.widgets.FileDialog;
00027 import org.eclipse.ui.IEditorInput;
00028 import org.eclipse.ui.IEditorPart;
00029 import org.eclipse.ui.IWorkbenchWindow;
00030 import org.eclipse.ui.PlatformUI;
00031 import org.eclipse.ui.handlers.HandlerUtil;
00032 import org.eclipse.papyrus.infra.onefile.model.IPapyrusFile;
00033 import org.eclipse.xtext.resource.XtextResource;
00034
00035 import org.eclipse.ui.IFileEditorInput;
00036
00037 import com.google.inject.Injector;
00038
00039
00040 public class SysMLToSMACHHandler extends AbstractHandler {
00041
00042 public SysMLToSMACHHandler() {
00043 }
00044
00045 @Override
00046 public Object execute(ExecutionEvent event) throws ExecutionException {
00047
00048 IFile sourceModelFilePath = null;
00049 IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
00050 if (editor != null) {
00051 IEditorInput input = editor.getEditorInput();
00052 if (input instanceof IFileEditorInput) {
00053 sourceModelFilePath = ((IFileEditorInput)input).getFile();
00054 System.out.println("File from editor: " + sourceModelFilePath.getLocation().toOSString());
00055 System.out.println("getFileExtension: " + sourceModelFilePath.getFileExtension().toString().compareTo("di"));
00056 if(sourceModelFilePath.getFileExtension().toString().compareTo("di")!=0)
00057 {
00058 sourceModelFilePath = null;
00059 MessageDialog
00060 .openError(
00061 PlatformUI.getWorkbench()
00062 .getActiveWorkbenchWindow().getShell(),
00063 "Error on Editor Selection",
00064 "Please select the editor from which you want to generate code and execute command again.");
00065 }
00066
00067 }
00068 }
00069 if(sourceModelFilePath == null)
00070 return null;
00071
00072
00073 IEtlTransformParameter etlTransformParameter = TransformParameterFactory.createEtlTransformParameter();
00074 etlTransformParameter.setTransformName("SYSML to SMACH");
00075 etlTransformParameter.setEtlTransformPath("epsilon/sysml_sm_to_smach.etl");
00076 etlTransformParameter.setPluginID(Activator.PLUGIN_ID);
00077 etlTransformParameter.setSourceMetaModelURI("http://www.eclipse.org/papyrus/0.7.0/SysML/StateMachines");
00078 etlTransformParameter.setSourceModelFilePath(sourceModelFilePath.getLocation().removeFileExtension().toOSString() + ".uml");
00079 etlTransformParameter.setSourceName("Source");
00080 etlTransformParameter.setSourceReadOnLoad(true);
00081 etlTransformParameter.setSourceStoreOnDisposal(false);
00082 etlTransformParameter.setTargetMetaModelURI("http://ros/1.0");
00083
00084 String targetModelFilePath = sourceModelFilePath.getLocation().removeFileExtension().toOSString() + "gen.ros_coordinator";
00085
00086 etlTransformParameter.setTargetModelFilePath(targetModelFilePath);
00087 etlTransformParameter.setTargetName("Target");
00088 etlTransformParameter.setTargetReadOnLoad(false);
00089 etlTransformParameter.setTargetStoreOnDisposal(true);
00090
00091
00092
00093 ITransformService transformService = TransformAccessActivator.getDefault().getTransformService();
00094
00095
00096 transformService.doTransform(etlTransformParameter);
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 return null;
00124 }
00125
00126 }