Skip to content

Commit

Permalink
eclipse-archived#190 POC: Added actor to the diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodolfo Totaro committed Dec 17, 2016
1 parent 2e27071 commit cd362ee
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 65 deletions.
3 changes: 2 additions & 1 deletion org.eclipse.triquetrum.commands.xtext/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Require-Bundle: org.eclipse.xtext,
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"
org.eclipse.graphiti.ui;bundle-version="0.13.0",
org.eclipse.emf.transaction;bundle-version="1.9.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 @@ -4,36 +4,28 @@
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.emf.transaction.TransactionalEditingDomain;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.ICreateFeature;
import org.eclipse.graphiti.features.context.ICreateContext;
import org.eclipse.graphiti.features.IFeatureProvider;
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.graphiti.ui.editor.DiagramBehavior;
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;
Expand All @@ -51,67 +43,61 @@ public class TqclGenerator extends AbstractGenerator {

private Map<String, ModelElementCreateFeature> featuresMap = new HashMap<>();

TriqDiagramEditor triqDiagramEditor = null;

@Override
public void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {

initFeatureMap();
EList<EObject> contents = resource.getContents();
for (EObject eObject : contents) {
if (eObject instanceof TriquetrumScript) {

Display.getDefault().syncExec(new Runnable() {

Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().getEditorReferences();
for (IEditorReference iEditorReference : editorReferences) {

@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;
}
}
}
});
DiagramBehavior diagramBehavior = triqDiagramEditor.getDiagramBehavior();
IDiagramTypeProvider diagramTypeProvider = triqDiagramEditor.getDiagramTypeProvider();
IFeatureProvider featureProvider = diagramTypeProvider.getFeatureProvider();
Diagram diagram = diagramTypeProvider.getDiagram();

initFeatureMap(featureProvider);

IEditorPart editor = iEditorReference.getEditor(true);
if (editor instanceof TriqDiagramEditor) {
triqDiagramEditor = (TriqDiagramEditor) editor;
break;
}
}
EList<EObject> contents = resource.getContents();
for (EObject eObject : contents) {
if (eObject instanceof TriquetrumScript) {

// triqDiagramEditor.
// Graphiti.getLinkService().getLinkForPictogramElement(triqDiagramEditor.getDiagramBehavior().getDiagramContainer());
// TriqFactory triqFactory = TriqFactoryImpl.init();


TriquetrumScript triquetrumScript = (TriquetrumScript) eObject;
final EList<Command> commands = triquetrumScript.getCommands();

// editingDomain.

for (Command command : commands) {
if (command instanceof Insert) {
InsertActor(diagramBehavior, diagram, command);

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);

}
}
System.out.println();

}
});

}

}

}

// Iterator<Greeting> filtered =
Expand All @@ -128,9 +114,22 @@ public void run() {
// IteratorExtensions.join(names, ", "));
}

private void initFeatureMap() {
private void InsertActor(DiagramBehavior diagramBehavior, Diagram diagram, Command command) {
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 executeFeature = diagramBehavior.executeFeature(modelElementCreateFeature, createContext);
}

private void initFeatureMap(IFeatureProvider featureProvider) {
if (featuresMap.isEmpty()) {
TriqFeatureProvider featureProvider = new TriqFeatureProvider(new TriqDiagramTypeProvider());
ICreateFeature[] createFeatures = featureProvider.getCreateFeatures();
for (ICreateFeature feature : createFeatures) {
if (feature instanceof ModelElementCreateFeature) {
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit cd362ee

Please sign in to comment.