Skip to content

Commit

Permalink
eclipse-archived#190 POC: Added connection creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodolfo Totaro committed Dec 17, 2016
1 parent ca0eb36 commit f90940b
Showing 1 changed file with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,25 @@
import org.eclipse.graphiti.features.ICreateFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.impl.AddContext;
import org.eclipse.graphiti.features.context.impl.CreateConnectionContext;
import org.eclipse.graphiti.features.context.impl.CreateContext;
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.ui.editor.DiagramBehavior;
import org.eclipse.swt.widgets.Display;
import org.eclipse.triquetrum.commands.tqcl.Command;
import org.eclipse.triquetrum.commands.tqcl.Connect;
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.TriqFeatureProvider;
import org.eclipse.triquetrum.workflow.editor.features.ConnectionCreateFeature;
import org.eclipse.triquetrum.workflow.editor.features.ModelElementCreateFeature;
import org.eclipse.triquetrum.workflow.model.Port;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.PlatformUI;
Expand Down Expand Up @@ -87,21 +94,40 @@ public void run() {
for (EObject eObject : contents) {
if (eObject instanceof TriquetrumScript) {

// 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);
insertActor(diagramBehavior, diagram, command);
}
else if (command instanceof Connect) {
Connect connect = (Connect) command;
ConnectionCreateFeature feature = new ConnectionCreateFeature(featureProvider);
CreateConnectionContext createContext = new CreateConnectionContext();
EList<Shape> children = diagram.getChildren();

for (Shape shape : children) {
EList<Anchor> anchors = shape.getAnchors();
for (Anchor anchor : anchors) {
EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(anchor);
if (bo instanceof Port) {
Port port = (Port) bo;
String fullName = port.getFullName();
if(fullName.endsWith(connect.getFrom().getName()))
{
createContext.setSourceAnchor(anchor);
}
if(fullName.endsWith(connect.getTo().getName()))
{
createContext.setTargetAnchor(anchor);
}
}
}
}

diagramBehavior.executeFeature(feature, createContext);

System.out.println();

}

}
Expand All @@ -124,7 +150,7 @@ public void run() {
// IteratorExtensions.join(names, ", "));
}

private void InsertActor(DiagramBehavior diagramBehavior, Diagram diagram, Command command) {
private void insertActor(DiagramBehavior diagramBehavior, Diagram diagram, Command command) {
Insert insert = (Insert) command;
NamedObj name = insert.getName();
AddContext addContext = new AddContext();
Expand Down

0 comments on commit f90940b

Please sign in to comment.