diff --git a/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/services/ModelBuilderService.java b/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/services/ModelBuilderService.java index 01f88106..bf8185e4 100644 --- a/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/services/ModelBuilderService.java +++ b/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/services/ModelBuilderService.java @@ -12,6 +12,7 @@ import java.util.Map; + public interface ModelBuilderService { public Class getSupportedModelClass(); @@ -20,7 +21,7 @@ public interface ModelBuilderService { public boolean insertActor(CompositeActor parent,String actorName,String actorclass,Map parameters); - public boolean insertDirector(CompositeActor actor,String directorClass, String entityClass, Map params); + public boolean insertDirector(CompositeActor actor,String directorName, String entityClass, Map params); public boolean insertPort(Actor actor, String portClass, String entityClass, Map params); @@ -28,8 +29,10 @@ public interface ModelBuilderService { public CompositeActor getParent(Actor actor); - public Actor getChild(String name); + public Actor getChild(CompositeActor parent, String name); public boolean connect(CompositeActor currentActor, String from, String to); + + } diff --git a/org.eclipse.triquetrum.commands.xtext.ide/META-INF/MANIFEST.MF b/org.eclipse.triquetrum.commands.xtext.ide/META-INF/MANIFEST.MF index ac5d63ae..2691d852 100644 --- a/org.eclipse.triquetrum.commands.xtext.ide/META-INF/MANIFEST.MF +++ b/org.eclipse.triquetrum.commands.xtext.ide/META-INF/MANIFEST.MF @@ -14,5 +14,9 @@ Require-Bundle: org.eclipse.xtext.ide;bundle-version="2.10.0", org.eclipse.debug.ui;bundle-version="3.11.200", org.eclipse.ui;bundle-version="3.108.0", org.eclipse.core.runtime;bundle-version="3.12.0", - org.eclipse.ui.console;bundle-version="3.6.200" + org.eclipse.ui.console;bundle-version="3.6.200", + org.eclipse.triquetrum.workflow.model;bundle-version="0.1.0", + ptolemy.core;bundle-version="11.0.0", + org.eclipse.triquetrum.workflow.api;bundle-version="0.1.0", + org.eclipse.triquetrum.workflow.editor;bundle-version="0.1.0" diff --git a/org.eclipse.triquetrum.commands.xtext.ide/plugin.xml b/org.eclipse.triquetrum.commands.xtext.ide/plugin.xml index 1c286c57..ca97dd58 100644 --- a/org.eclipse.triquetrum.commands.xtext.ide/plugin.xml +++ b/org.eclipse.triquetrum.commands.xtext.ide/plugin.xml @@ -36,6 +36,30 @@ + + + + + + + + + + + + + + diff --git a/org.eclipse.triquetrum.commands.xtext.ide/src/main/java/org/eclipse/triquetrum/commands/xtext/ide/TqCLLaunchShortcut.java b/org.eclipse.triquetrum.commands.xtext.ide/src/main/java/org/eclipse/triquetrum/commands/xtext/ide/TqCLLaunchShortcut.java index 2d761d32..fd7a7b8d 100644 --- a/org.eclipse.triquetrum.commands.xtext.ide/src/main/java/org/eclipse/triquetrum/commands/xtext/ide/TqCLLaunchShortcut.java +++ b/org.eclipse.triquetrum.commands.xtext.ide/src/main/java/org/eclipse/triquetrum/commands/xtext/ide/TqCLLaunchShortcut.java @@ -34,7 +34,7 @@ public void launch(ISelection selection, String mode) { // newMessageStream TqclInterpreter interpreter = new TqclInterpreter(); - interpreter.interpret(file.getName(),file.getContents(), file.getParent().getLocationURI()); + interpreter.interpret(file.getName(),file.getContents(), file.getParent().getLocationURI(),org.eclipse.triquetrum.workflow.model.CompositeActor.class); } catch (CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/org.eclipse.triquetrum.commands.xtext.ide/src/main/java/org/eclipse/triquetrum/commands/xtext/ide/TqCLPtolemyLaunchShortcut.java b/org.eclipse.triquetrum.commands.xtext.ide/src/main/java/org/eclipse/triquetrum/commands/xtext/ide/TqCLPtolemyLaunchShortcut.java new file mode 100644 index 00000000..e9655863 --- /dev/null +++ b/org.eclipse.triquetrum.commands.xtext.ide/src/main/java/org/eclipse/triquetrum/commands/xtext/ide/TqCLPtolemyLaunchShortcut.java @@ -0,0 +1,67 @@ +package org.eclipse.triquetrum.commands.xtext.ide; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.debug.ui.ILaunchShortcut; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.triquetrum.commands.interpreter.TqclInterpreter; +import org.eclipse.triquetrum.workflow.WorkflowExecutionService; +import org.eclipse.triquetrum.workflow.WorkflowExecutionService.StartMode; +import org.eclipse.triquetrum.workflow.editor.TriqEditorPlugin; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.MessageConsole; +import org.eclipse.ui.console.MessageConsoleStream; + +import ptolemy.actor.CompositeActor; + +public class TqCLPtolemyLaunchShortcut implements ILaunchShortcut { + + @Override + public void launch(ISelection selection, String mode) { + Object firstElement = ((IStructuredSelection) selection).getFirstElement(); + if (firstElement instanceof IFile) { + try { + IFile file = (IFile) firstElement; + java.net.URI rawLocationURI = file.getRawLocationURI(); + + IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager(); + MessageConsole messageConsole = new MessageConsole(file.getName(), "TqCL", null, false); + consoleManager.addConsoles(new IConsole[] { messageConsole }); + MessageConsoleStream newMessageStream = messageConsole.newMessageStream(); + // newMessageStream + + TqclInterpreter interpreter = new TqclInterpreter(); + CompositeActor model = (CompositeActor) interpreter.interpret(file.getName(), file.getContents(), + file.getParent().getLocationURI(), CompositeActor.class); + + String moml = model.exportMoML(); + + System.out.println(moml); + + //workflow service could be exposed by a different plugin; not workflow editor + WorkflowExecutionService executionService = TriqEditorPlugin.getDefault().getWorkflowExecutionService(); + executionService.start(StartMode.RUN, model, null, null, null); + + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + @Override + public void launch(IEditorPart editor, String mode) { + // TODO Auto-generated method stub + IEditorInput firstElement = editor.getEditorInput(); + if (firstElement instanceof IFile) { + IFile file = (IFile) firstElement; + + } + } + +} diff --git a/org.eclipse.triquetrum.commands.xtext.tests/src/test/xtend-gen/org/eclipse/triquetrum/commands/tests/.TqclParsingTest.xtendbin b/org.eclipse.triquetrum.commands.xtext.tests/src/test/xtend-gen/org/eclipse/triquetrum/commands/tests/.TqclParsingTest.xtendbin index 1be9c20f..585666f9 100644 Binary files a/org.eclipse.triquetrum.commands.xtext.tests/src/test/xtend-gen/org/eclipse/triquetrum/commands/tests/.TqclParsingTest.xtendbin and b/org.eclipse.triquetrum.commands.xtext.tests/src/test/xtend-gen/org/eclipse/triquetrum/commands/tests/.TqclParsingTest.xtendbin differ diff --git a/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/labeling/.TqclDescriptionLabelProvider.xtendbin b/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/labeling/.TqclDescriptionLabelProvider.xtendbin index 8389bfbc..383b2bf1 100644 Binary files a/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/labeling/.TqclDescriptionLabelProvider.xtendbin and b/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/labeling/.TqclDescriptionLabelProvider.xtendbin differ diff --git a/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/labeling/.TqclLabelProvider.xtendbin b/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/labeling/.TqclLabelProvider.xtendbin index 32a39f65..33c8102c 100644 Binary files a/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/labeling/.TqclLabelProvider.xtendbin and b/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/labeling/.TqclLabelProvider.xtendbin differ diff --git a/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/outline/.TqclOutlineTreeProvider.xtendbin b/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/outline/.TqclOutlineTreeProvider.xtendbin index 8a930fb0..bce4cbf5 100644 Binary files a/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/outline/.TqclOutlineTreeProvider.xtendbin and b/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/outline/.TqclOutlineTreeProvider.xtendbin differ diff --git a/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/quickfix/.TqclQuickfixProvider.xtendbin b/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/quickfix/.TqclQuickfixProvider.xtendbin index ddf2ab58..4cf297ca 100644 Binary files a/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/quickfix/.TqclQuickfixProvider.xtendbin and b/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/quickfix/.TqclQuickfixProvider.xtendbin differ diff --git a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/interpreter/GoInterpreterComponent.java b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/interpreter/GoInterpreterComponent.java index a2feded6..25306512 100644 --- a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/interpreter/GoInterpreterComponent.java +++ b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/interpreter/GoInterpreterComponent.java @@ -22,7 +22,7 @@ public void interpret(EObject element, InterpretContext context) { case "into": Insert actor = go.getActor(); String name = actor.getName(); - context.setCurrentActor(context.getModelBuilderService().getChild(name)); + context.setCurrentActor(context.getModelBuilderService().getChild(context.getCurrentActor(),name)); break; case "out": context.setCurrentActor(context.getModelBuilderService().getParent(context.getCurrentActor())); diff --git a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/interpreter/InterpretContext.java b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/interpreter/InterpretContext.java index edafe974..e89f1893 100644 --- a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/interpreter/InterpretContext.java +++ b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/interpreter/InterpretContext.java @@ -16,6 +16,7 @@ public InterpretContext(TqclInterpreter interpreter,Compos super(); this.interpreter = interpreter; this.model = model; + this.currentActor = (Actor) model; this.modelBuilderService = modelBuilderService; } diff --git a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/interpreter/TqclInterpreter.java b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/interpreter/TqclInterpreter.java index b6dee9a6..a231517c 100644 --- a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/interpreter/TqclInterpreter.java +++ b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/interpreter/TqclInterpreter.java @@ -51,7 +51,7 @@ private static void addComponent(TqclInterpreterComponent component){ } } - public void interpret(String modelName,InputStream script, java.net.URI uri) { + public CompositeActor interpret(String modelName,InputStream script, java.net.URI uri,Class modelClass) { try { Injector injector = new TqclStandaloneSetup().createInjectorAndDoEMFRegistration(); IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class); @@ -84,14 +84,19 @@ public void accept(IConcreteSyntaxDiagnostic arg0) { } }, Collections.EMPTY_MAP); - ModelBuilderService modelBuilderService = TqCLServices.getInstance().getModelBuilderService(org.eclipse.triquetrum.workflow.model.CompositeActor.class); + ModelBuilderService modelBuilderService = TqCLServices.getInstance().getModelBuilderService(modelClass); CompositeActor model = modelBuilderService.createNewModel(StringUtils.removeEnd(modelName, ".tqcl"), uri.toString()); + interpret(root, new InterpretContext(this,model,modelBuilderService)); + return model; + } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } + + return null; } void interpret(EObject element, InterpretContext context) diff --git a/org.eclipse.triquetrum.workflow.editor/META-INF/MANIFEST.MF b/org.eclipse.triquetrum.workflow.editor/META-INF/MANIFEST.MF index 61f2bd40..19d40463 100644 --- a/org.eclipse.triquetrum.workflow.editor/META-INF/MANIFEST.MF +++ b/org.eclipse.triquetrum.workflow.editor/META-INF/MANIFEST.MF @@ -108,7 +108,7 @@ Import-Package: org.apache.batik.bridge;version="1.6.0", ptolemy.vergil.kernel.attributes;version="11.0.0" Bundle-Activator: org.eclipse.triquetrum.workflow.editor.TriqEditorPlugin Service-Component: OSGI-INF/colorRendererService.xml,OSGI-INF/attributesRendererService.xml,OSGI-INF/librariesProvider.xml, - OSGI-INF/ModelBuilderService.xml + OSGI-INF/ModelBuilderService.xml,OSGI-INF/PtolemyModelBuilderService.xml Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.triquetrum.workflow.editor, org.eclipse.triquetrum.workflow.editor.features, diff --git a/org.eclipse.triquetrum.workflow.editor/OSGI-INF/PtolemyModelBuilderService.xml b/org.eclipse.triquetrum.workflow.editor/OSGI-INF/PtolemyModelBuilderService.xml new file mode 100644 index 00000000..caafff1e --- /dev/null +++ b/org.eclipse.triquetrum.workflow.editor/OSGI-INF/PtolemyModelBuilderService.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/PtolemyModelBuilderService.java b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/PtolemyModelBuilderService.java new file mode 100644 index 00000000..3d900e9c --- /dev/null +++ b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/PtolemyModelBuilderService.java @@ -0,0 +1,178 @@ +package org.eclipse.triquetrum.workflow.editor; + +import java.util.Map; + +import org.eclipse.triquetrum.commands.api.services.ModelBuilderService; +import org.eclipse.triquetrum.workflow.model.util.PtolemyUtil; +import org.osgi.framework.Version; +import org.ptolemy.commons.ThreeDigitVersionSpecification; +import org.ptolemy.commons.VersionSpecification; + +import ptolemy.actor.CompositeActor; +import ptolemy.actor.Director; +import ptolemy.actor.IOPort; +import ptolemy.actor.IORelation; +import ptolemy.actor.TypedCompositeActor; +import ptolemy.actor.TypedIORelation; +import ptolemy.data.expr.Parameter; +import ptolemy.kernel.ComponentEntity; +import ptolemy.kernel.ComponentRelation; +import ptolemy.kernel.CompositeEntity; +import ptolemy.kernel.Entity; +import ptolemy.kernel.Port; +import ptolemy.kernel.Relation; +import ptolemy.kernel.util.Attribute; +import ptolemy.kernel.util.IllegalActionException; +import ptolemy.kernel.util.NameDuplicationException; + +public class PtolemyModelBuilderService implements ModelBuilderService> { + + @Override + public Class getSupportedModelClass() { + return CompositeActor.class; + } + + @Override + public CompositeEntity createNewModel(String modelName, String folderPath) { + return new TypedCompositeActor(); + } + + private VersionSpecification getVersion() { + Version bundleVersion = TriqEditorPlugin.getDefault().getBundle().getVersion(); + VersionSpecification providerVersion = new ThreeDigitVersionSpecification(bundleVersion.getMajor(), + bundleVersion.getMinor(), bundleVersion.getMicro(), bundleVersion.getQualifier()); + return providerVersion; + } + + @Override + public boolean insertActor(CompositeEntity parent, String actorName, String actorclass, + Map parameters) { + try { + Entity actor = PtolemyUtil._createEntity(parent, actorclass, /*getVersion()*/null, actorName); + for (String paramKey : parameters.keySet()) { + Attribute attribute = actor.getAttribute(paramKey); + if (attribute instanceof Parameter) { + Parameter param = (Parameter) attribute; + param.setExpression(parameters.get(paramKey)); + param.propagateValue(); + } + } +// parent.entityList().add(actor); + return true; + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return false; + } + + @Override + public boolean insertDirector(CompositeEntity actor, String directorName, String entityClass, + Map params) { + try { + Attribute attribute = PtolemyUtil._createAttribute(actor, entityClass, directorName); + if (attribute instanceof Director) { + for (String paramKey : params.keySet()) { + Attribute directorAttribute = attribute.getAttribute(paramKey); + if (directorAttribute instanceof Parameter) { + Parameter param = (Parameter) directorAttribute; + param.setExpression(params.get(paramKey)); + param.propagateValue(); + } + } + return true; + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return false; + } + + @Override + public boolean insertPort(ComponentEntity actor, String portName, String entityClass, + Map params) { + try { + Port port = PtolemyUtil._createPort(actor, entityClass, portName); + + if (port instanceof IOPort) { + IOPort ioPort = (IOPort) port; + if(params.containsKey("input") && Boolean.parseBoolean(params.get("input"))) + { + ioPort.setInput(true); + } + if(params.containsKey("output") && Boolean.parseBoolean(params.get("output"))) + { + ioPort.setOutput(true); + } + if(params.containsKey("multi") && Boolean.parseBoolean(params.get("multi"))) + { + ioPort.setMultiport(true); + } + + } + + return true; + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return false; + } + + @Override + public boolean insertParameter(ComponentEntity actor, String parameterName, String entityClass, + Map params) { + try { + Attribute attribute = PtolemyUtil._createAttribute(actor, entityClass, parameterName); + if (attribute instanceof Parameter) { + Parameter param = (Parameter) attribute; + param.setExpression(params.get("expression")); + return true; + } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return false; + } + + @Override + public CompositeEntity getParent(ComponentEntity actor) { + return (CompositeEntity) actor.getContainer(); + } + + @Override + public ComponentEntity getChild(CompositeEntity parent, String name) { + return parent.getEntity(name); + } + + @Override + public boolean connect(CompositeEntity currentActor, String from, String to) { + int size = currentActor.relationList().size(); + try { + + ComponentRelation relation = currentActor.newRelation("_R" + (size + 1)); + + String[] splitFrom = from.split("\\."); + String actorFrom = splitFrom[0]; + String portFrom = splitFrom[1]; + + String[] splitTo = to.split("\\."); + String actorTo = splitTo[0]; + String portTo = splitTo[1]; + + Port outputport = currentActor.getEntity(actorFrom).getPort(portFrom); + Port inputPort = currentActor.getEntity(actorTo).getPort(portTo); + + inputPort.link(relation); + outputport.link(relation); + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return false; + } + +} diff --git a/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/TriquetrumModelBuilderService.java b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/TriquetrumModelBuilderService.java index e294b9e9..ce309975 100644 --- a/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/TriquetrumModelBuilderService.java +++ b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/TriquetrumModelBuilderService.java @@ -1,6 +1,5 @@ package org.eclipse.triquetrum.workflow.editor; -import java.io.ObjectInputStream.GetField; import java.net.URI; import java.text.MessageFormat; import java.util.HashMap; @@ -14,19 +13,27 @@ import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.emf.common.command.AbstractCommand; +import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.edit.command.SetCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.graphiti.features.ICreateFeature; +import org.eclipse.graphiti.features.context.impl.AddContext; +import org.eclipse.graphiti.features.context.impl.CreateConnectionContext; import org.eclipse.graphiti.features.context.impl.CreateContext; import org.eclipse.graphiti.mm.pictograms.Diagram; import org.eclipse.graphiti.services.Graphiti; import org.eclipse.triquetrum.commands.api.services.ModelBuilderService; +import org.eclipse.triquetrum.workflow.editor.features.ConnectionCreateFeature; import org.eclipse.triquetrum.workflow.editor.features.ModelElementCreateFeature; import org.eclipse.triquetrum.workflow.editor.wizard.WizardUtils; import org.eclipse.triquetrum.workflow.model.Actor; import org.eclipse.triquetrum.workflow.model.CompositeActor; +import org.eclipse.triquetrum.workflow.model.CompositeEntity; +import org.eclipse.triquetrum.workflow.model.Entity; +import org.eclipse.triquetrum.workflow.model.TriqFactory; import org.eclipse.ui.PartInitException; import org.osgi.framework.Version; import org.ptolemy.commons.ThreeDigitVersionSpecification; @@ -34,7 +41,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class TriquetrumModelBuilderService implements ModelBuilderService { +public class TriquetrumModelBuilderService implements ModelBuilderService { private static final Logger LOGGER = LoggerFactory.getLogger(TriquetrumModelBuilderService.class); private Diagram diagram; @@ -63,8 +70,34 @@ public CompositeActor createNewModel(String modelName, String folderPath) { } diagram = WizardUtils.createDiagramAndFile("Triquetrum workflow", modelName, project, (IFolder) modelContainer); + + CompositeActor model = TriqFactory.eINSTANCE.createCompositeActor(); + model.setName(diagram.getName()); + model.buildWrappedObject(); + diagram.eResource().getContents().add(model); try { editor = WizardUtils.openDiagramInEditor(diagram); + TransactionalEditingDomain editingDomain = editor.getDiagramBehavior().getEditingDomain(); + editingDomain.getCommandStack().execute(new AbstractCommand("Create model","Model Builder creting new model") { + + { + isExecutable=true; + isPrepared = true; + } + + @Override + public void redo() { + // TODO Auto-generated method stub + + } + + @Override + public void execute() { + getFeatureProvider().link(diagram, model); + } + }); + + } catch (PartInitException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -73,8 +106,8 @@ public CompositeActor createNewModel(String modelName, String folderPath) { // TODO exception to manage throw new RuntimeException("file not in workspace"); } - - return null; + return (CompositeActor) Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement(diagram); } private VersionSpecification getVersion() { @@ -84,78 +117,117 @@ private VersionSpecification getVersion() { return providerVersion; } + private EObject createElement(String entityClass) { + TriqFeatureProvider triqFeatureProvider = getFeatureProvider(); + + ICreateFeature[] createFeatures = triqFeatureProvider.getCreateFeatures(); + for (ICreateFeature iCreateFeature : createFeatures) { + if (iCreateFeature instanceof ModelElementCreateFeature) { + ModelElementCreateFeature modelElementCreateFeature = (ModelElementCreateFeature) iCreateFeature; + + if (modelElementCreateFeature.getWrappedClass().equals(entityClass)) { + CreateContext createContext = new CreateContext(); + createContext.setTargetContainer(triqFeatureProvider.getDiagramTypeProvider().getDiagram()); + + editor.getDiagramBehavior().executeFeature(modelElementCreateFeature,createContext); + + EObject businessObjectForLinkedPictogramElement = Graphiti.getLinkService() + .getBusinessObjectForLinkedPictogramElement(diagram); + return businessObjectForLinkedPictogramElement; + + } + } + } + + return null; + } + + public TriqFeatureProvider getFeatureProvider() { + TriqFeatureProvider triqFeatureProvider = (TriqFeatureProvider) editor.getDiagramTypeProvider() + .getFeatureProvider(); + return triqFeatureProvider; + } + @Override - public boolean insertActor(CompositeActor parent, String actorName, String actorclass, + public boolean insertActor(CompositeEntity parent, String actorName, String actorclass, Map parameters) { LOGGER.debug(MessageFormat.format("Creating actor {0} of type {1} with parameters {2}", actorName, actorclass, parameters.toString())); try { - TriqFeatureProvider triqFeatureProvider = (TriqFeatureProvider) editor.getDiagramTypeProvider() - .getFeatureProvider(); - ICreateFeature[] createFeatures = triqFeatureProvider.getCreateFeatures(); - - for (ICreateFeature iCreateFeature : createFeatures) { - if (iCreateFeature instanceof ModelElementCreateFeature) { - ModelElementCreateFeature modelElementCreateFeature = (ModelElementCreateFeature) iCreateFeature; - - - if (modelElementCreateFeature.getWrappedClass().equals(actorclass)) { - CreateContext createContext = new CreateContext(); - createContext.setTargetContainer(triqFeatureProvider.getDiagramTypeProvider().getDiagram()); - Object executeFeature = editor.getDiagramBehavior().executeFeature(modelElementCreateFeature, createContext); - - - EObject businessObjectForLinkedPictogramElement = Graphiti.getLinkService() - .getBusinessObjectForLinkedPictogramElement(diagram); - if (businessObjectForLinkedPictogramElement instanceof CompositeActor) { - CompositeActor mainActor = (CompositeActor) businessObjectForLinkedPictogramElement; - org.eclipse.triquetrum.workflow.model.NamedObj child = mainActor - .getChild(modelElementCreateFeature.getCreateName()); - TransactionalEditingDomain editingDomain = editor.getDiagramBehavior().getEditingDomain(); - if (child instanceof Actor) { - Actor actor = (Actor) child; - Map modelParameters = new HashMap<>(); - for (org.eclipse.triquetrum.workflow.model.Parameter parameter : actor - .getParameters()) { - modelParameters.put(parameter.getName(), parameter); - } - // EStructuralFeature eStructuralFeatureName = - // actor.eClass().getEStructuralFeature("name"); - // editingDomain.getCommandStack().execute(new - // SetCommand(editingDomain, actor, - // eStructuralFeatureName, actorInstanceName)); - - for (Entry parameter : parameters.entrySet()) { - String paramName = parameter.getKey(); - org.eclipse.triquetrum.workflow.model.Parameter parameterToSet = modelParameters - .get(paramName); - EStructuralFeature eStructuralFeatureExpression = parameterToSet.eClass() - .getEStructuralFeature("expression"); - editingDomain.getCommandStack().execute(new SetCommand(editingDomain, - parameterToSet, eStructuralFeatureExpression, parameter.getValue())); - } - - } - } + TransactionalEditingDomain editingDomain = editor.getDiagramBehavior().getEditingDomain(); + Actor actor = TriqFactory.eINSTANCE.createActor(); + Map modelParameters = new HashMap<>(); + for (org.eclipse.triquetrum.workflow.model.Parameter parameter : actor.getParameters()) { + modelParameters.put(parameter.getName(), parameter); + } + EStructuralFeature eStructuralFeatureName = actor.eClass().getEStructuralFeature("name"); + editingDomain.getCommandStack() + .execute(new SetCommand(editingDomain, actor, eStructuralFeatureName, actorName)); - } - } + for (Entry parameter : parameters.entrySet()) { + String paramName = parameter.getKey(); + org.eclipse.triquetrum.workflow.model.Parameter parameterToSet = modelParameters.get(paramName); + EStructuralFeature eStructuralFeatureExpression = parameterToSet.eClass() + .getEStructuralFeature("expression"); + editingDomain.getCommandStack().execute(new SetCommand(editingDomain, parameterToSet, + eStructuralFeatureExpression, parameter.getValue())); } - LOGGER.debug("Done"); - return true; + + + AddContext context = new AddContext(); + context.setNewObject(actor); + getFeatureProvider().getAddFeature(context); + + + + +// EObject businessObjectForLinkedPictogramElement = parent; + + +// AddContext context = new AddContext(); +// context.setNewObject(TriqFactory); +// getFeatureProvider().getAddFeature(context) + +// EObject businessObjectForLinkedPictogramElement = createElement(actorclass); +// +// if (businessObjectForLinkedPictogramElement instanceof CompositeActor) { +// CompositeActor mainActor = (CompositeActor) businessObjectForLinkedPictogramElement; +// org.eclipse.triquetrum.workflow.model.NamedObj child = mainActor +// .getChild(((CompositeActor) businessObjectForLinkedPictogramElement).getName()); +// TransactionalEditingDomain editingDomain = editor.getDiagramBehavior().getEditingDomain(); +// if (child instanceof Actor) { +// Actor actor = (Actor) child; +// Map modelParameters = new HashMap<>(); +// for (org.eclipse.triquetrum.workflow.model.Parameter parameter : actor.getParameters()) { +// modelParameters.put(parameter.getName(), parameter); +// } +// EStructuralFeature eStructuralFeatureName = actor.eClass().getEStructuralFeature("name"); +// editingDomain.getCommandStack() +// .execute(new SetCommand(editingDomain, actor, eStructuralFeatureName, actorName)); +// +// for (Entry parameter : parameters.entrySet()) { +// String paramName = parameter.getKey(); +// org.eclipse.triquetrum.workflow.model.Parameter parameterToSet = modelParameters.get(paramName); +// EStructuralFeature eStructuralFeatureExpression = parameterToSet.eClass() +// .getEStructuralFeature("expression"); +// editingDomain.getCommandStack().execute(new SetCommand(editingDomain, parameterToSet, +// eStructuralFeatureExpression, parameter.getValue())); +// } +// } +// } + } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } - return false; } @Override - public boolean insertDirector(CompositeActor actor, String directorName, String entityClass, + public boolean insertDirector(CompositeEntity actor, String directorName, String entityClass, Map params) { LOGGER.debug(MessageFormat.format("Creating director {0} of type {1} with parameters {2}", directorName, entityClass, params.toString())); @@ -163,35 +235,60 @@ public boolean insertDirector(CompositeActor actor, String directorName, String } @Override - public boolean insertPort(Actor actor, String portName, String entityClass, Map params) { + public boolean insertPort(Entity actor, String portName, String entityClass, Map params) { LOGGER.debug(MessageFormat.format("Creating port {0} of type {1} with parameters {2}", portName, entityClass, params.toString())); return false; } @Override - public boolean insertParameter(Actor actor, String parameterName, String entityClass, Map params) { + public boolean insertParameter(Entity actor, String parameterName, String entityClass, Map params) { LOGGER.debug(MessageFormat.format("Creating parameter {0} of type {1} with parameters {2}", parameterName, entityClass, params.toString())); return false; } @Override - public CompositeActor getParent(Actor actor) { + public CompositeEntity getParent(Entity actor) { LOGGER.debug("go to parent"); - return null; + return (CompositeEntity) actor.getContainer(); } @Override - public Actor getChild(String name) { + public Entity getChild(CompositeEntity parent,String name) { // TODO Auto-generated method stub LOGGER.debug("go into child " + name); - return null; + return (Entity) parent.getChild(name); } @Override - public boolean connect(CompositeActor currentActor, String from, String to) { + public boolean connect(CompositeEntity currentActor, String from, String to) { LOGGER.debug(MessageFormat.format("Connecting {0} to {1}", from, to)); + + ConnectionCreateFeature feature = new ConnectionCreateFeature(getFeatureProvider()); + CreateConnectionContext createContext = new CreateConnectionContext(); + EList children = currentActor.eContents(); + +// for (Shape shape : children) { +// EList anchors = shape.getAnchors(); +// for (Anchor anchor : anchors) { +// EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(anchor); +// if (bo instanceof Port) { +// Port port = (Port) bo; +// String fullName = port.getFullName(); +// if(fullName.endsWith(from)) +// { +// createContext.setSourceAnchor(anchor); +// } +// if(fullName.endsWith(to)) +// { +// createContext.setTargetAnchor(anchor); +// } +// } +// } +// } + + editor.getDiagramBehavior().executeFeature(feature, createContext); return false; }