From b7332d4d4dd37c643e83d9b97521823c16566869 Mon Sep 17 00:00:00 2001 From: Rodolfo Totaro Date: Tue, 24 Jan 2017 22:36:05 +0100 Subject: [PATCH] #190 In progress TqCL - interpreter --- .../triquetrum/commands/api/TqCLServices.java | 5 +- .../api/services/ModelBuilderService.java | 3 +- .../xtext/ide/TqCLLaunchShortcut.java | 4 +- .../commands/tests/.TqclParsingTest.xtendbin | Bin 2879 -> 2879 bytes .../.TqclDescriptionLabelProvider.xtendbin | Bin 1873 -> 1873 bytes .../ui/labeling/.TqclLabelProvider.xtendbin | Bin 2316 -> 2316 bytes .../outline/.TqclOutlineTreeProvider.xtendbin | Bin 1734 -> 1734 bytes .../quickfix/.TqclQuickfixProvider.xtendbin | Bin 1703 -> 1703 bytes .../META-INF/MANIFEST.MF | 4 +- .../commands/interpreter/TqclInterpreter.java | 14 +- .../src/main/resources/log4j.properties | 2 +- .../editor/TriquetrumModelBuilderService.java | 143 ++++++++++++++++-- .../workflow/editor/wizard/WizardUtils.java | 5 +- 13 files changed, 155 insertions(+), 25 deletions(-) diff --git a/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/TqCLServices.java b/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/TqCLServices.java index a0fb2a31..0834e1f3 100644 --- a/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/TqCLServices.java +++ b/org.eclipse.triquetrum.commands.api/src/main/java/org/eclipse/triquetrum/commands/api/TqCLServices.java @@ -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 { @@ -62,7 +63,9 @@ public ModelBuilderService getModelBuilderService(Class modelClass) { Collection> serviceReferences = getContext() .getServiceReferences(ModelBuilderService.class, null); for (ServiceReference serviceReference : serviceReferences) { - ModelBuilderService service = getContext().getService(serviceReference); + //TODO:Release service when done + ServiceObjects serviceObjects = getContext().getServiceObjects(serviceReference); + ModelBuilderService service = serviceObjects.getService(); if (service.getSupportedModelClass() == modelClass) { return service; } 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 d5a32c6c..01f88106 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 @@ -16,7 +16,7 @@ public interface ModelBuilderService { 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 parameters); @@ -31,4 +31,5 @@ public interface ModelBuilderService { public Actor getChild(String name); public boolean connect(CompositeActor currentActor, String from, String to); + } 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 72d29747..2d761d32 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 @@ -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(); 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 19390f0140d290e7d5beefbc4211f8217ff4638d..1be9c20f8a65b4cc2d72f70547a9763ee5c75fa1 100644 GIT binary patch delta 64 zcmdllwqJ}lz?+#xgn@&DgW>QJ^NqZJSeSwIW**i`W-z0J<2xgWF}aD$98B-wvIo=u GxEukEFBVJy delta 64 zcmdllwqJ}lz?+#xgn@&DgCTl{;YQv+EX+W9GY@MeGnmoA@tqOGnB2r=4yN~T*@NkS GT#f)zNfa;u 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 f7316c62bd8bb60a4307410686d1fcba9eba2981..8389bfbc7bcb0953b8d4fabed811cd8aed261055 100644 GIT binary patch delta 64 zcmcb}cae`bz?+#xgn@&DgW<>$^NqX>Ow2%f^8}`k5Jn3tFC$1~@)S06Fnx~A9!v|c GI|2ZPaTOW> delta 64 zcmcb}cae`bz?+#xgn@&DgCTZ@;YQvDCT1YLc>>c%2&09Smk}f~c?z33m_Em552gj! F9RW--69fPN 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 14146135959e5ce8c35afaa00796acccf8e60cd6..32a39f65943b3a166a27cc02b3cd89b1d31853c3 100644 GIT binary patch delta 64 zcmeAX>Jj1%@MdNaVc_84U^ueGd?RlUGc%ChJcrpF!nnp(#t0Ib?9X8iraL+8!Srbk FM*v?;6zc#0 delta 64 zcmeAX>Jj1%@MdNaVc_84V2IsexRJMqnHflLp2KVoVO(P?V+4sz_UAAM)14glVEQzN FBLF2064d|z 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 f584886602c0008747c3d308877c9ebbe00be809..8a930fb06462298591dfeaa65bca600ba0de05d3 100644 GIT binary patch delta 64 zcmX@cdyJPiz?+#xgn@&DgW<>$^NqaqOw2%fb3ao$gz=Mwmk}f~nUl>NOgppLgXvZ_ FM*wRe6i5I7 delta 64 zcmX@cdyJPiz?+#xgn@&DgCTZ@;YQwiCT1YLxt}Q=!uZL;%Lo#g%*kdBrk&aB!E`H| FBLFbr5;6b) 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 824b4927c1f45dc910f3104364a98b8d66d1c2aa..ddf2ab584f6a58e07b307ce4f90dbfbdc201255e 100644 GIT binary patch delta 64 zcmZ3^yPTIdz?+#xgn@&DgW<>$^NqYoOw2%fa}iT2gmH_7mk}f~`4y` { private static Map components = new HashMap<>(); + private final static Logger LOGGER = LoggerFactory.getLogger(TqclInterpreter.class); static { @@ -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(); @@ -83,7 +85,7 @@ public void accept(IConcreteSyntaxDiagnostic arg0) { }, Collections.EMPTY_MAP); ModelBuilderService 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(this,model,modelBuilderService)); } catch (IOException e) { diff --git a/org.eclipse.triquetrum.logging.dvp/src/main/resources/log4j.properties b/org.eclipse.triquetrum.logging.dvp/src/main/resources/log4j.properties index 30533356..f836a6fb 100644 --- a/org.eclipse.triquetrum.logging.dvp/src/main/resources/log4j.properties +++ b/org.eclipse.triquetrum.logging.dvp/src/main/resources/log4j.properties @@ -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 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 7c0b457e..e294b9e9 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,17 +1,44 @@ 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 { private static final Logger LOGGER = LoggerFactory.getLogger(TriquetrumModelBuilderService.class); + private Diagram diagram; + private TriqDiagramEditor editor; @Override public Class getSupportedModelClass() { @@ -19,58 +46,152 @@ public Class getSupportedModelClass() { } @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 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 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())); + } + + } + } + + } + } + } + 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 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 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 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; } diff --git a/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/wizard/WizardUtils.java b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/wizard/WizardUtils.java index 2a1e1442..c047b47d 100644 --- a/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/wizard/WizardUtils.java +++ b/org.eclipse.triquetrum.workflow.editor/src/main/java/org/eclipse/triquetrum/workflow/editor/wizard/WizardUtils.java @@ -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; @@ -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$ @@ -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); } /**