Skip to content

Commit

Permalink
eclipse-archived#190 In progress TqCL - interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
rtotaro committed Jan 24, 2017
1 parent ef645ee commit b7332d4
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceObjects;
import org.osgi.framework.ServiceReference;

public class TqCLServices implements BundleActivator {
Expand Down Expand Up @@ -62,7 +63,9 @@ public ModelBuilderService getModelBuilderService(Class<?> modelClass) {
Collection<ServiceReference<ModelBuilderService>> serviceReferences = getContext()
.getServiceReferences(ModelBuilderService.class, null);
for (ServiceReference<ModelBuilderService> serviceReference : serviceReferences) {
ModelBuilderService service = getContext().getService(serviceReference);
//TODO:Release service when done
ServiceObjects<ModelBuilderService> serviceObjects = getContext().getServiceObjects(serviceReference);
ModelBuilderService service = serviceObjects.getService();
if (service.getSupportedModelClass() == modelClass) {
return service;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface ModelBuilderService<CompositeActor,Actor> {

public Class<?> getSupportedModelClass();

public CompositeActor createNewModel(String modelName);
public CompositeActor createNewModel(String modelName, String folderPath);

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

Expand All @@ -31,4 +31,5 @@ public interface ModelBuilderService<CompositeActor,Actor> {
public Actor getChild(String name);

public boolean connect(CompositeActor currentActor, String from, String to);

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public void launch(ISelection selection, String mode) {
java.net.URI rawLocationURI = file.getRawLocationURI();

IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();
MessageConsole messageConsole = new MessageConsole(file.getName(), "TqCL", null, true);
MessageConsole messageConsole = new MessageConsole(file.getName(), "TqCL", null, false);
consoleManager.addConsoles(new IConsole[]{messageConsole});
MessageConsoleStream newMessageStream = messageConsole.newMessageStream();
// newMessageStream

TqclInterpreter interpreter = new TqclInterpreter();
interpreter.interpret(file.getName(),file.getContents(), rawLocationURI);
interpreter.interpret(file.getName(),file.getContents(), file.getParent().getLocationURI());
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion org.eclipse.triquetrum.commands.xtext/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ Require-Bundle: org.eclipse.xtext,
org.eclipse.emf.transaction;bundle-version="1.9.0",
org.eclipse.triquetrum.commands.api
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.apache.log4j
Import-Package: org.apache.commons.lang;version="2.6.0",
org.apache.log4j,
org.slf4j;version="1.7.2"
Export-Package: org.eclipse.triquetrum.commands,
org.eclipse.triquetrum.commands.generator,
org.eclipse.triquetrum.commands.interpreter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.triquetrum.commands.TqclRuntimeModule;
import org.eclipse.triquetrum.commands.TqclStandaloneSetup;
import org.eclipse.triquetrum.commands.api.TqCLServices;
import org.eclipse.triquetrum.commands.api.services.ModelBuilderService;
import org.eclipse.triquetrum.commands.api.services.TcQLException;
import org.eclipse.xtext.EcoreUtil2;
import org.eclipse.xtext.linking.lazy.LazyLinkingResource;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.parser.IParseResult;
Expand All @@ -25,12 +22,17 @@
import org.eclipse.xtext.util.CancelIndicator;
import org.eclipse.xtext.validation.IConcreteSyntaxDiagnosticProvider.IConcreteSyntaxDiagnostic;
import org.eclipse.xtext.validation.IConcreteSyntaxValidator.IDiagnosticAcceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.inject.Injector;

import ptolemy.util.StringUtilities;

public class TqclInterpreter<CompositeActor,Actor> {

private static Map<EClass, TqclInterpreterComponent> components = new HashMap<>();
private final static Logger LOGGER = LoggerFactory.getLogger(TqclInterpreter.class);

static
{
Expand All @@ -54,7 +56,7 @@ public void interpret(String modelName,InputStream script, java.net.URI uri) {
Injector injector = new TqclStandaloneSetup().createInjectorAndDoEMFRegistration();
IResourceFactory resourceFactory = injector.getInstance(IResourceFactory.class);

XtextResource resource = (XtextResource) resourceFactory.createResource(URI.createURI(uri.getPath()));
XtextResource resource = (XtextResource) resourceFactory.createResource(URI.createURI(uri.getPath()+"/"+modelName));
resource.load(script, null);
IParseResult parseResult = resource.getParseResult();

Expand Down Expand Up @@ -83,7 +85,7 @@ public void accept(IConcreteSyntaxDiagnostic arg0) {
}, Collections.EMPTY_MAP);

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

} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Contributors:
# Erwin De Ley - initial API and implementation and/or initial documentation
###############################################################################
log4j.rootLogger=INFO,CONSOLE
log4j.rootLogger=DEBUG,CONSOLE

#log4j.logger.org.eclipse.triquetrum.workflow.editor = ALL
log4j.logger.org.eclipse.triquetrum.processing.service = ALL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,76 +1,197 @@
package org.eclipse.triquetrum.workflow.editor;

import java.io.ObjectInputStream.GetField;
import java.net.URI;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.lang.StringUtils;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
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.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.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.ui.PartInitException;
import org.osgi.framework.Version;
import org.ptolemy.commons.ThreeDigitVersionSpecification;
import org.ptolemy.commons.VersionSpecification;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TriquetrumModelBuilderService implements ModelBuilderService<CompositeActor, Actor> {

private static final Logger LOGGER = LoggerFactory.getLogger(TriquetrumModelBuilderService.class);
private Diagram diagram;
private TriqDiagramEditor editor;

@Override
public Class<CompositeActor> getSupportedModelClass() {
return CompositeActor.class;
}

@Override
public CompositeActor createNewModel(String modelName) {
public CompositeActor createNewModel(String modelName, String folderPath) {

IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
URI locationURI = root.getLocationURI();
if (folderPath.startsWith(locationURI.toString())) {
String relativePath = StringUtils.removeStart(folderPath, locationURI.toString());
IResource modelContainer = root.findMember(relativePath);
IProject project = null;
if (modelContainer instanceof IProject) {
project = (IProject) modelContainer;
modelContainer = null;
} else {
project = modelContainer.getProject();
}
diagram = WizardUtils.createDiagramAndFile("Triquetrum workflow", modelName, project,
(IFolder) modelContainer);
try {
editor = WizardUtils.openDiagramInEditor(diagram);
} catch (PartInitException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
// TODO exception to manage
throw new RuntimeException("file not in workspace");
}

return null;
}

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(CompositeActor parent, String actorName, String actorclass,
Map<String, String> parameters) {
// TODO Auto-generated method stub
System.out.println(MessageFormat.format("Creating actor {0} of type {1} with parameters {2}", actorName, actorclass,

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<String, org.eclipse.triquetrum.workflow.model.Parameter> 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<String, String> 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;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


return false;
}

@Override
public boolean insertDirector(CompositeActor actor, String directorName, String entityClass,
Map<String, String> params) {
System.out.println(MessageFormat.format("Creating director {0} of type {1} with parameters {2}", directorName, entityClass,
params.toString()));
LOGGER.debug(MessageFormat.format("Creating director {0} of type {1} with parameters {2}", directorName,
entityClass, params.toString()));
return false;
}

@Override
public boolean insertPort(Actor actor, String portName, String entityClass, Map<String, String> params) {
System.out.println(MessageFormat.format("Creating port {0} of type {1} with parameters {2}", portName, entityClass,
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<String, String> params) {
System.out.println(MessageFormat.format("Creating parameter {0} of type {1} with parameters {2}", parameterName, entityClass,
params.toString()));
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) {
System.out.println("go to parent");
LOGGER.debug("go to parent");
return null;
}

@Override
public Actor getChild(String name) {
// TODO Auto-generated method stub
System.out.println("go into child "+name);
LOGGER.debug("go into child " + name);
return null;
}

@Override
public boolean connect(CompositeActor currentActor, String from, String to) {
System.out.println(MessageFormat.format("Connecting {0} to {1}", from,to));
LOGGER.debug(MessageFormat.format("Connecting {0} to {1}", from, to));
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.triquetrum.workflow.editor.TriqDiagramEditor;
import org.eclipse.triquetrum.workflow.editor.util.FileService;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;

Expand Down Expand Up @@ -92,7 +93,7 @@ public static Diagram createDiagramAndFile(final String diagramTypeId, final Str
return diagram;
}

public static void openDiagramInEditor(Diagram diagram) throws PartInitException {
public static TriqDiagramEditor openDiagramInEditor(Diagram diagram) throws PartInitException {
String editorID = TriqDiagramEditor.EDITOR_ID;
String diagramTypeProviderId = GraphitiUi.getExtensionManager().getDiagramTypeProviderId(diagram.getDiagramTypeId());
String namingConventionID = diagramTypeProviderId + ".editor"; //$NON-NLS-1$
Expand All @@ -105,7 +106,7 @@ public static void openDiagramInEditor(Diagram diagram) throws PartInitException
String providerId = GraphitiUi.getExtensionManager().getDiagramTypeProviderId(diagram.getDiagramTypeId());
DiagramEditorInput editorInput = new DiagramEditorInput(EcoreUtil.getURI(diagram), providerId);

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput, editorID);
return (TriqDiagramEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput, editorID);
}

/**
Expand Down

0 comments on commit b7332d4

Please sign in to comment.