Skip to content

Commit

Permalink
eclipse-archived#190 POC: in progress model changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodolfo Totaro committed Dec 17, 2016
1 parent 3f12f4b commit 2e27071
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 11 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -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();


}

}
});

}

}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 7 additions & 1 deletion org.eclipse.triquetrum.commands.xtext/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,142 @@
*/
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;

/**
* 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<String, ModelElementCreateFeature> featuresMap = new HashMap<>();

@Override
public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
// Iterator<Greeting> filtered = Iterators.filter(resource.getAllContents(), Greeting.class);
// Iterator<String> names = Iterators.transform(filtered, new Function<Greeting, String>() {
//
// @Override
// public String apply(Greeting greeting) {
// return greeting.getName();
// }
// });
// fsa.generateFile("greetings.txt", "People to greet: " + IteratorExtensions.join(names, ", "));

initFeatureMap();
EList<EObject> 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<Command> 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<Greeting> filtered =
// Iterators.filter(resource.getAllContents(), Greeting.class);
// Iterator<String> names = Iterators.transform(filtered, new
// Function<Greeting, String>() {
//
// @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);
}
}
}
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit 2e27071

Please sign in to comment.