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 237a2929..e172c043 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/java/org/eclipse/triquetrum/commands/ui/editor/TriquetrumCommandEditor.java b/org.eclipse.triquetrum.commands.xtext.ui/src/main/java/org/eclipse/triquetrum/commands/ui/editor/TriquetrumCommandEditor.java new file mode 100644 index 00000000..e1b173ef --- /dev/null +++ b/org.eclipse.triquetrum.commands.xtext.ui/src/main/java/org/eclipse/triquetrum/commands/ui/editor/TriquetrumCommandEditor.java @@ -0,0 +1,34 @@ +package org.eclipse.triquetrum.commands.ui.editor; + +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.xtext.ui.editor.XtextEditor; +import org.eclipse.xtext.ui.editor.model.IXtextDocument; + +public class TriquetrumCommandEditor extends XtextEditor { + + @Override + public void createPartControl(Composite parent) { + super.createPartControl(parent); + getSourceViewer().getTextWidget().addKeyListener(new KeyAdapter() { + + @Override + public void keyPressed(KeyEvent e) { + + if(((e.stateMask & SWT.CTRL) == SWT.CTRL) && (e.keyCode == SWT.CR)) + { + IXtextDocument document = getDocument(); + + + } + + } + }); + + } + +} diff --git a/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/.TqclUiModule.xtendbin b/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/.TqclUiModule.xtendbin index a5dbb789..ebdf51e1 100644 Binary files a/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/.TqclUiModule.xtendbin and b/org.eclipse.triquetrum.commands.xtext.ui/src/main/xtend-gen/org/eclipse/triquetrum/commands/ui/.TqclUiModule.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 ba76a52c..15d6c2b8 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 7cee4069..afc6703f 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 f370dd82..e45e7163 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 8d627d37..4dde9da6 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/META-INF/MANIFEST.MF b/org.eclipse.triquetrum.commands.xtext/META-INF/MANIFEST.MF index f1722596..19f075d1 100644 --- a/org.eclipse.triquetrum.commands.xtext/META-INF/MANIFEST.MF +++ b/org.eclipse.triquetrum.commands.xtext/META-INF/MANIFEST.MF @@ -18,7 +18,13 @@ Require-Bundle: org.eclipse.xtext, org.objectweb.asm;bundle-version="[5.0.1,6.0.0)";resolution:=optional, org.eclipse.xtext.xbase.ui, org.eclipse.xtext.ui, - org.eclipse.xtext.generator;bundle-version="2.10.0" + org.eclipse.xtext.generator;bundle-version="2.10.0", + org.ptolemy.commons;bundle-version="11.0.0", + ptolemy.core;bundle-version="11.0.0", + org.eclipse.triquetrum.workflow.model;bundle-version="0.1.0", + org.eclipse.graphiti;bundle-version="0.13.0", + org.eclipse.triquetrum.workflow.editor;bundle-version="0.1.0", + org.eclipse.graphiti.ui;bundle-version="0.13.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Import-Package: org.apache.log4j Export-Package: org.eclipse.triquetrum.commands.tqcl, diff --git a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/generator/TqclGenerator.java b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/generator/TqclGenerator.java index 52b86652..90785470 100644 --- a/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/generator/TqclGenerator.java +++ b/org.eclipse.triquetrum.commands.xtext/src/main/java/org/eclipse/triquetrum/commands/generator/TqclGenerator.java @@ -3,7 +3,40 @@ */ package org.eclipse.triquetrum.commands.generator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.TreeIterator; +import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.graphiti.features.ICreateFeature; +import org.eclipse.graphiti.features.context.ICreateContext; +import org.eclipse.graphiti.features.context.impl.AddContext; +import org.eclipse.graphiti.features.context.impl.CreateContext; +import org.eclipse.graphiti.mm.pictograms.Diagram; +import org.eclipse.graphiti.services.Graphiti; +import org.eclipse.swt.widgets.Display; +import org.eclipse.triquetrum.commands.services.TqclGrammarAccess.TriquetrumScriptElements; +import org.eclipse.triquetrum.commands.tqcl.Command; +import org.eclipse.triquetrum.commands.tqcl.Insert; +import org.eclipse.triquetrum.commands.tqcl.NamedObj; +import org.eclipse.triquetrum.commands.tqcl.TriquetrumScript; +import org.eclipse.triquetrum.workflow.editor.TriqDiagramEditor; +import org.eclipse.triquetrum.workflow.editor.TriqDiagramTypeProvider; +import org.eclipse.triquetrum.workflow.editor.TriqEditorPlugin; +import org.eclipse.triquetrum.workflow.editor.TriqFeatureProvider; +import org.eclipse.triquetrum.workflow.editor.features.ModelElementCreateFeature; +import org.eclipse.triquetrum.workflow.model.Actor; +import org.eclipse.triquetrum.workflow.model.TriqFactory; +import org.eclipse.triquetrum.workflow.model.impl.ActorImpl; +import org.eclipse.triquetrum.workflow.model.impl.TriqFactoryImpl; +import org.eclipse.triquetrum.workflow.model.util.PtolemyUtil; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IEditorReference; +import org.eclipse.ui.PlatformUI; import org.eclipse.xtext.generator.AbstractGenerator; import org.eclipse.xtext.generator.IFileSystemAccess2; import org.eclipse.xtext.generator.IGeneratorContext; @@ -11,20 +44,101 @@ /** * Generates code from your model files on save. * - * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation + * See + * https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation */ public class TqclGenerator extends AbstractGenerator { + private Map featuresMap = new HashMap<>(); + @Override public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) { -// Iterator filtered = Iterators.filter(resource.getAllContents(), Greeting.class); -// Iterator names = Iterators.transform(filtered, new Function() { -// -// @Override -// public String apply(Greeting greeting) { -// return greeting.getName(); -// } -// }); -// fsa.generateFile("greetings.txt", "People to greet: " + IteratorExtensions.join(names, ", ")); + + initFeatureMap(); + EList contents = resource.getContents(); + for (EObject eObject : contents) { + if (eObject instanceof TriquetrumScript) { + + Display.getDefault().syncExec(new Runnable() { + + @Override + public void run() { + // TODO Auto-generated method stub + IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .getActivePage().getEditorReferences(); + TriqDiagramEditor triqDiagramEditor = null; + for (IEditorReference iEditorReference : editorReferences) { + + IEditorPart editor = iEditorReference.getEditor(true); + if (editor instanceof TriqDiagramEditor) { + triqDiagramEditor = (TriqDiagramEditor) editor; + break; + } + } + +// triqDiagramEditor. + + TriqFeatureProvider provider = new TriqFeatureProvider(new TriqDiagramTypeProvider()); + Diagram diagram = Graphiti.getCreateService().createDiagram("Triquetrum workflow", + resource.getURI().lastSegment()); + + // TriqFactory triqFactory = TriqFactoryImpl.init(); + + TriquetrumScript triquetrumScript = (TriquetrumScript) eObject; + EList commands = triquetrumScript.getCommands(); + for (Command command : commands) { + if (command instanceof Insert) { + Insert insert = (Insert) command; + NamedObj name = insert.getName(); + AddContext addContext = new AddContext(); + NamedObj obj = insert.getObj(); + String paleteKey = obj.getName(); + ModelElementCreateFeature modelElementCreateFeature = featuresMap + .get(paleteKey.replaceAll("\"", "")); + CreateContext createContext = new CreateContext(); + createContext.setTargetContainer(diagram); + Object[] created = modelElementCreateFeature.create(createContext); + + Object newObject = created[0]; + addContext.setNewObject(newObject); + addContext.setTargetContainer(diagram); + addContext.setX(10); + addContext.setY(10); + provider.getAddFeature(addContext).add(addContext); + + } + } + } + }); + + } + } + + // Iterator filtered = + // Iterators.filter(resource.getAllContents(), Greeting.class); + // Iterator names = Iterators.transform(filtered, new + // Function() { + // + // @Override + // public String apply(Greeting greeting) { + // return greeting.getName(); + // } + // }); + // fsa.generateFile("greetings.txt", "People to greet: " + + // IteratorExtensions.join(names, ", ")); + } + + private void initFeatureMap() { + if (featuresMap.isEmpty()) { + TriqFeatureProvider featureProvider = new TriqFeatureProvider(new TriqDiagramTypeProvider()); + ICreateFeature[] createFeatures = featureProvider.getCreateFeatures(); + for (ICreateFeature feature : createFeatures) { + if (feature instanceof ModelElementCreateFeature) { + ModelElementCreateFeature modelfeature = (ModelElementCreateFeature) feature; + String key = modelfeature.getGroup() + "." + modelfeature.getName(); + featuresMap.put(key, modelfeature); + } + } + } } } diff --git a/org.eclipse.triquetrum.commands.xtext/src/main/xtend-gen/org/eclipse/triquetrum/commands/.TqclRuntimeModule.xtendbin b/org.eclipse.triquetrum.commands.xtext/src/main/xtend-gen/org/eclipse/triquetrum/commands/.TqclRuntimeModule.xtendbin index 636c717b..72a08bd9 100644 Binary files a/org.eclipse.triquetrum.commands.xtext/src/main/xtend-gen/org/eclipse/triquetrum/commands/.TqclRuntimeModule.xtendbin and b/org.eclipse.triquetrum.commands.xtext/src/main/xtend-gen/org/eclipse/triquetrum/commands/.TqclRuntimeModule.xtendbin differ diff --git a/org.eclipse.triquetrum.commands.xtext/src/main/xtend-gen/org/eclipse/triquetrum/commands/.TqclStandaloneSetup.xtendbin b/org.eclipse.triquetrum.commands.xtext/src/main/xtend-gen/org/eclipse/triquetrum/commands/.TqclStandaloneSetup.xtendbin index e4d64c5f..eff5acd6 100644 Binary files a/org.eclipse.triquetrum.commands.xtext/src/main/xtend-gen/org/eclipse/triquetrum/commands/.TqclStandaloneSetup.xtendbin and b/org.eclipse.triquetrum.commands.xtext/src/main/xtend-gen/org/eclipse/triquetrum/commands/.TqclStandaloneSetup.xtendbin differ