From 2e27071c4b152ab9922ca17d77c58b9521d02365 Mon Sep 17 00:00:00 2001 From: Rodolfo Totaro Date: Sat, 17 Dec 2016 19:17:50 +0100 Subject: [PATCH] #190 POC: in progress model changes --- .../commands/tests/.TqclParsingTest.xtendbin | Bin 2879 -> 2879 bytes .../ui/editor/TriquetrumCommandEditor.java | 34 +++++ .../commands/ui/.TqclUiModule.xtendbin | Bin 2067 -> 2067 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 | 8 +- .../commands/generator/TqclGenerator.java | 134 ++++++++++++++++-- .../commands/.TqclRuntimeModule.xtendbin | Bin 1649 -> 1649 bytes .../commands/.TqclStandaloneSetup.xtendbin | Bin 1900 -> 1900 bytes 11 files changed, 165 insertions(+), 11 deletions(-) create mode 100644 org.eclipse.triquetrum.commands.xtext.ui/src/main/java/org/eclipse/triquetrum/commands/ui/editor/TriquetrumCommandEditor.java 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 237a2929494b3d3a9b1dee8060242b26652f79fa..e172c0437264d65fca83d38cb57583b69982939d 100644 GIT binary patch delta 58 zcmdllwqJ}Vz?+#xgn@&DgW+S#MxMVcOdne|bF)@4gXngSAB;eHawC@oh}zBN0HXeK GIROAJf)!8z delta 58 zcmdllwqJ}Vz?+#xgn@&DgQ1vdBhOzJredbe+^kj1AiAC72P2T4+{k4CqIPpRfT+J* FP5_^O4^RLA 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 a5dbb7896ac37b063a72ac8afb754f07ed89e96b..ebdf51e180a83ac8c6e6bb43e7895eed599f99be 100644 GIT binary patch delta 58 zcmbO%Fj;^nz?+#xgn@&DgJDMRMxJv_Ofz~n-(j*~2GL?{wv0e}awxk6i0Wr|08tm& FodDDX5v%|J delta 58 zcmbO%Fj;^nz?+#xgn@&DgCR9)BhNV|rqrm-cbF`gL9`f~EhCVg9LjD1qWak#K-5Kc FCjgrY4@dw2 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 ba76a52cb3887d265134bba9d82e7801b614475e..15d6c2b8cc0a8e0dbf28d3c8fe236ef2da2bc4fd 100644 GIT binary patch delta 58 zcmcb}cae`Lz?+#xgn@&DgQ2r`BTpj}Q)lnyex^@gx|x-a5y+oBnau)3on>Jj1z@MdNaVc_84VCd}K$kWTr)Y-dvHnRnozRFh42;@)pJ*0) E0M1+yuK)l5 delta 58 zcmeAX>Jj1z@MdNaVc_84U`UPH$kWTrlp3{pHnRnozRFh42;@)pJ*0) E0G;p;r2qf` 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 f370dd824ffc635a84ec229e7de7ca16a64abfe9..e45e7163be4cf7c160fc93c16075571a20c3f289 100644 GIT binary patch delta 58 zcmX@cdyJPSz?+#xgn@&DgQ2r`BToYpQ)lnyKBf#X{ey*%5y+p+!Da!XoY)*dR12FE E0NExH3;+NC delta 58 zcmX@cdyJPSz?+#xgn@&DgCR9)BToYpQ)<-aKBf#X{ey*%5y+p+!Da!XoY)*dR12FE E0I0eT0ssI2 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 8d627d3713e1e920b9e17d2c12dafe509d056e82..4dde9da60b88aeae6470471a33bdf5700d6b42b5 100644 GIT binary patch delta 58 zcmZ3^yPTINz?+#xgn@&DgQ2r`BTq6DQ)lnyLZ&n@eUpWc5y+qXlGOr4DYH3%s8lv5 E0L?iO6#xJL delta 58 zcmZ3^yPTINz?+#xgn@&DgCR9)BTq6DQ)<-aLZ&n@eUpWc5y+qXlGOr4DYH3%s8lv5 E0G!Pa3jhEB 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 636c717b9cc9f928c7a1ea22baf0c12612497305..72a08bd92b2cd30e35ee1b9234057cb4f2b64f48 100644 GIT binary patch delta 58 zcmey!^O1)qz?+#xgn@&DgW>eljXYXROsA)AwqVKx(~DX77=irBn^`SD)LT{u5T(!N F1ONtt6B_^k delta 58 zcmey!^O1)qz?+#xgn@&DgQ1vdBaapnQ!&$K3#Lpky_kiM5y+psnbiVBy=8R(QTl97 E0E6ERnE(I) 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 e4d64c5f174cff05fc3ed99ea607a34668007c03..eff5acd6ec9857238f8983d185effc942561bc7c 100644 GIT binary patch delta 58 zcmaFE_lA!rz?+#xgn@&DgW>eljXV;}OsA)AR%5ne0?|pVUW`C`@;WvP5cPu10YquB GI{^UsMiR6D delta 58 zcmaFE_lA!rz?+#xgn@&DgQ1vdBaZ|#Q!&$KHD)U&5S_&8#R#M)uVb?SQ7_mWK$I4{ F699Iy4Ke@#