/** @generated */ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { Variable newElement = StatechartFactory.eINSTANCE.createVariable(); Model owner = (Model) getElementToEdit(); owner.getVariables().add(newElement); doConfigure(newElement, monitor, info); ((CreateElementRequest) getRequest()).setNewElement(newElement); return CommandResult.newOKCommandResult(newElement); }
public String IACToStateChart(String filename, String Path) { String file = new String(); IAC.Model old = (IAC.Model) IACFactory.eINSTANCE.createModel(); ResourceSet resourceSet1 = new ResourceSetImpl(); resourceSet1 .getResourceFactoryRegistry() .getExtensionToFactoryMap() .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); resourceSet1.getPackageRegistry().put(IACPackage.eNS_URI, IACPackage.eINSTANCE); Resource resource = resourceSet1.createResource(URI.createURI(IACPackage.eNS_URI)); try { File source = new File(filename); resource.load(new FileInputStream(source), new HashMap<Object, Object>()); resource.load(null); old = (IAC.Model) resource.getContents().get(0); root = StatechartFactory.eINSTANCE.createNode(); statechart.Node node = StatechartFactory.eINSTANCE.createNode(); model = StatechartFactory.eINSTANCE.createModel(); for (Iterator<IAC.Node> it = old.getNodes().iterator(); it.hasNext(); ) { IAC.Node cur = it.next(); node = IACNodeToStateChartNode(cur); if (cur.getFather_of().size() == 0) { root = node; model.getNodes().add(root); } else { addNodeStatechart(node, cur.getFather_of().get(0).getLabel()); } } statechart.Transition item = StatechartFactory.eINSTANCE.createTransition(); for (Iterator<IAC.Transition> it = old.getTransitions().iterator(); it.hasNext(); ) { IAC.Transition cur = it.next(); item = StatechartFactory.eINSTANCE.createTransition(); item.setName(cur.getName()); if (cur.getTE() != null) item.setTE(cur.getTE()); item.setSource(getNodeStateChart(cur.getSource().getLabel())); item.setTarget(getNodeStateChart(cur.getTarget().getLabel())); model.getTransitions().add(item); } statechart.Variable var; IAC.Variable vIAC = IACFactory.eINSTANCE.createVariable(); for (Iterator<IAC.Variable> it = old.getVariables().iterator(); it.hasNext(); ) { vIAC = it.next(); var = StatechartFactory.eINSTANCE.createVariable(); var.setName(vIAC.getName()); var.setType(vIAC.getType()); model.getVariables().add(var); } model.setName(old.getName()); ResourceSet resourceSet = new ResourceSetImpl(); // Register the appropriate resource factory to handle all file // extensions. // resourceSet .getResourceFactoryRegistry() .getExtensionToFactoryMap() .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); // Register the package to ensure it is available during loading. // resourceSet.getPackageRegistry().put(StatechartPackage.eNS_URI, StatechartPackage.eINSTANCE); Resource resource1 = resourceSet.createResource(URI.createURI(StatechartPackage.eNS_URI)); resource1.getContents().add(model); try { file = Path + File.separator + model.getName() + "_new.stct"; FileOutputStream out = new FileOutputStream(new File(file)); resource1.save(out, null); System.out.println("The new Model is in the file : " + file); } catch (Exception e) { // TODO: handle exception System.out.println(e.getMessage()); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block // createDialog(e.getMessage()); System.out.println(e.getMessage()); } catch (IOException e) { // TODO Auto-generated catch block // createDialog(e.getMessage()); System.out.println(e.getMessage()); } return file; }
public String StateChartToIAC(String filename, String Path) { String file = new String(); statechart.Model old = (statechart.Model) StatechartFactory.eINSTANCE.createModel(); ResourceSet resourceSet1 = new ResourceSetImpl(); resourceSet1 .getResourceFactoryRegistry() .getExtensionToFactoryMap() .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); resourceSet1.getPackageRegistry().put(StatechartPackage.eNS_URI, StatechartPackage.eINSTANCE); Resource resource = resourceSet1.createResource(URI.createURI(StatechartPackage.eNS_URI)); try { File source = new File(filename); resource.load(new FileInputStream(source), new HashMap<Object, Object>()); resource.load(null); old = (statechart.Model) resource.getContents().get(0); root = old.getNodes().get(0); IACroot = StatechartNodeToIACNode(root); IACModel.getNodes().add(IACroot); for (int i = 0; i < root.getChildren().size(); i++) { IACModel.getNodes().add(StatechartNodeToIACNode(root.getChildren().get(i))); DFAccess(root.getChildren().get(i)); } IAC.Transition item = IACFactory.eINSTANCE.createTransition(); for (Iterator<statechart.Transition> it = old.getTransitions().iterator(); it.hasNext(); ) { statechart.Transition cur = it.next(); item = IACFactory.eINSTANCE.createTransition(); item.setName(cur.getName()); if (cur.getTE() != null) item.setTE(cur.getTE()); item.setSource(getNodeIAC(cur.getSource().getLabel())); item.setTarget(getNodeIAC(cur.getTarget().getLabel())); IACModel.getTransitions().add(item); } IAC.Variable var; for (int i = 0; i < old.getVariables().size(); i++) { var = IACFactory.eINSTANCE.createVariable(); var.setName(old.getVariables().get(i).getName()); var.setType(old.getVariables().get(i).getType()); IACModel.getVariables().add(var); } DFAddVariables(root); IACModel.setName(old.getName()); ResourceSet resourceSet = new ResourceSetImpl(); // Register the appropriate resource factory to handle all file // extensions. // resourceSet .getResourceFactoryRegistry() .getExtensionToFactoryMap() .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); // Register the package to ensure it is available during loading. // resourceSet.getPackageRegistry().put(StatechartPackage.eNS_URI, IACPackage.eINSTANCE); Resource resource1 = resourceSet.createResource(URI.createURI(IACPackage.eNS_URI)); resource1.getContents().add(IACModel); try { file = Path + File.separator + IACModel.getName() + "_new.iac"; FileOutputStream out = new FileOutputStream(new File(file)); resource1.save(out, null); // createDialog("The new Model is in the file : " +file); } catch (Exception e) { // TODO: handle exception // createDialog(e.getMessage()); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block // createDialog(e.getMessage()); } catch (IOException e) { // TODO Auto-generated catch block // createDialog(e.getMessage()); } return file; }