Skip to content

Commit

Permalink
eclipse-archived#190 Completed interpreter to run application
Browse files Browse the repository at this point in the history
  • Loading branch information
rtotaro committed Jan 27, 2017
1 parent 24c3e57 commit 333a404
Show file tree
Hide file tree
Showing 17 changed files with 459 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.Map;


public interface ModelBuilderService<CompositeActor,Actor> {

public Class<?> getSupportedModelClass();
Expand All @@ -20,16 +21,18 @@ public interface ModelBuilderService<CompositeActor,Actor> {

public boolean insertActor(CompositeActor parent,String actorName,String actorclass,Map<String,String> parameters);

public boolean insertDirector(CompositeActor actor,String directorClass, String entityClass, Map<String, String> params);
public boolean insertDirector(CompositeActor actor,String directorName, String entityClass, Map<String, String> params);

public boolean insertPort(Actor actor, String portClass, String entityClass, Map<String, String> params);

public boolean insertParameter(Actor actor, String parameterClass, String entityClass, Map<String, String> params);

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);



}
Original file line number Diff line number Diff line change
Expand Up @@ -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"

24 changes: 24 additions & 0 deletions org.eclipse.triquetrum.commands.xtext.ide/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@
</enablement>
</contextualLaunch>
</shortcut>
<shortcut
class="org.eclipse.triquetrum.commands.xtext.ide.TqCLPtolemyLaunchShortcut"
id="org.eclipse.triquetrum.commands.xtext.shortcut.tqcl4Ptolemy"
label="Triquetrum Application"
modes="run">
<contextualLaunch>
<enablement>
<with
variable="selection">
<count
value="1">
</count>
<iterate
ifEmpty="false"
operator="or">
<test
property="org.eclipse.debug.ui.matchesPattern"
value="*.tqcl">
</test>
</iterate>
</with>
</enablement>
</contextualLaunch>
</shortcut>
</extension>

</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

}
}

}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public InterpretContext(TqclInterpreter<CompositeActor,Actor> interpreter,Compos
super();
this.interpreter = interpreter;
this.model = model;
this.currentActor = (Actor) model;
this.modelBuilderService = modelBuilderService;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -84,14 +84,19 @@ public void accept(IConcreteSyntaxDiagnostic arg0) {
}
}, Collections.EMPTY_MAP);

ModelBuilderService<CompositeActor,Actor> modelBuilderService = TqCLServices.getInstance().getModelBuilderService(org.eclipse.triquetrum.workflow.model.CompositeActor.class);
ModelBuilderService<CompositeActor,Actor> modelBuilderService = TqCLServices.getInstance().getModelBuilderService(modelClass);
CompositeActor model = modelBuilderService.createNewModel(StringUtils.removeEnd(modelName, ".tqcl"), uri.toString());

interpret(root, new InterpretContext<CompositeActor,Actor>(this,model,modelBuilderService));

return model;

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return null;
}

void interpret(EObject element, InterpretContext<CompositeActor,Actor> context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.triquetrum.workflow.editor.PtolemyModelBuilderService">
<implementation class="org.eclipse.triquetrum.workflow.editor.PtolemyModelBuilderService"/>
<service>
<provide interface="org.eclipse.triquetrum.commands.api.services.ModelBuilderService"/>
</service>
</scr:component>
Original file line number Diff line number Diff line change
@@ -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<CompositeEntity, ComponentEntity<?>> {

@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<String, String> 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<String, String> 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<String, String> 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<String, String> 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;
}

}
Loading

0 comments on commit 333a404

Please sign in to comment.