Skip to content

Commit

Permalink
Add copy/paste of Association and Data(Store|Object|Input|Output)
Browse files Browse the repository at this point in the history
Change-Id: Id74e2f1b23133b3598008e44024fc205f1778b9a
  • Loading branch information
Stephane Drapeau authored and Stephane Drapeau committed Apr 3, 2024
1 parent 32158b9 commit 4e9285b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,29 @@
import org.obeonetwork.bpmn2.design.util.GMFStyleCopier;
import org.obeonetwork.bpmn2.design.util.SiriusHelper;
import org.obeonetwork.bpmn2.design.util.SiriusStyleCopier;
import org.obeonetwork.dsl.bpmn2.Association;
import org.obeonetwork.dsl.bpmn2.BoundaryEvent;
import org.obeonetwork.dsl.bpmn2.DataInput;
import org.obeonetwork.dsl.bpmn2.DataObject;
import org.obeonetwork.dsl.bpmn2.DataOutput;
import org.obeonetwork.dsl.bpmn2.DataStore;
import org.obeonetwork.dsl.bpmn2.FlowNode;
import org.obeonetwork.dsl.bpmn2.SequenceFlow;

public class CopySiriusGMFStylesHelper {

public static void copyStyles(EObject newElement, DDiagramElement containerView, String oldId, String newId) {
if (newElement instanceof BoundaryEvent) {
copyBoundaryEvent((BoundaryEvent) newElement, containerView, oldId, newId);
} else if (newElement instanceof FlowNode) {
copyFlowNode((FlowNode) newElement, containerView, oldId, newId);
} else if (newElement instanceof SequenceFlow) {
copySequenceFlow((SequenceFlow) newElement, containerView, oldId, newId);
copyBoundaryNode(newElement, containerView, oldId, newId);
} else if (newElement instanceof FlowNode || newElement instanceof DataStore || newElement instanceof DataObject
|| newElement instanceof DataInput || newElement instanceof DataOutput) {
copyNode(newElement, containerView, oldId, newId);
} else if (newElement instanceof SequenceFlow || newElement instanceof Association) {
copyEdge(newElement, containerView, oldId, newId);
}
}

private static void copyBoundaryEvent(BoundaryEvent newElement, DDiagramElement containerView, String oldId,
private static void copyBoundaryNode(EObject newElement, DDiagramElement containerView, String oldId,
String newId) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage[] pages = workbench.getActiveWorkbenchWindow().getPages();
Expand Down Expand Up @@ -104,7 +110,7 @@ protected void doExecute() {
}
}

private static void copyFlowNode(FlowNode newElement, DDiagramElement containerView, String oldId, String newId) {
private static void copyNode(EObject newElement, DDiagramElement containerView, String oldId, String newId) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage[] pages = workbench.getActiveWorkbenchWindow().getPages();
AbstractDNode oldAbstractDNode = SiriusHelper.getAbstractDNode(oldId, pages);
Expand All @@ -119,8 +125,7 @@ private static void copyFlowNode(FlowNode newElement, DDiagramElement containerV
}
}

private static void copySequenceFlow(SequenceFlow newElement, DDiagramElement containerView, String oldId,
String newId) {
private static void copyEdge(EObject newElement, DDiagramElement containerView, String oldId, String newId) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage[] pages = workbench.getActiveWorkbenchWindow().getPages();
// Update edges asynchronously.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,28 @@
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.EcoreUtil.Copier;
import org.eclipse.sirius.diagram.DDiagramElement;
import org.obeonetwork.dsl.bpmn2.Association;
import org.obeonetwork.dsl.bpmn2.BoundaryEvent;
import org.obeonetwork.dsl.bpmn2.Bpmn2Factory;
import org.obeonetwork.dsl.bpmn2.Bpmn2Package;
import org.obeonetwork.dsl.bpmn2.ChoreographyTask;
import org.obeonetwork.dsl.bpmn2.Collaboration;
import org.obeonetwork.dsl.bpmn2.ComplexGateway;
import org.obeonetwork.dsl.bpmn2.DataInput;
import org.obeonetwork.dsl.bpmn2.DataObject;
import org.obeonetwork.dsl.bpmn2.DataOutput;
import org.obeonetwork.dsl.bpmn2.DataStore;
import org.obeonetwork.dsl.bpmn2.Definitions;
import org.obeonetwork.dsl.bpmn2.EndEvent;
import org.obeonetwork.dsl.bpmn2.EventBasedGateway;
import org.obeonetwork.dsl.bpmn2.ExclusiveGateway;
import org.obeonetwork.dsl.bpmn2.ExtensionAttributeValue;
import org.obeonetwork.dsl.bpmn2.FlowElement;
import org.obeonetwork.dsl.bpmn2.FlowElementsContainer;
import org.obeonetwork.dsl.bpmn2.FlowNode;
import org.obeonetwork.dsl.bpmn2.ImplicitThrowEvent;
import org.obeonetwork.dsl.bpmn2.InclusiveGateway;
import org.obeonetwork.dsl.bpmn2.InputOutputSpecification;
import org.obeonetwork.dsl.bpmn2.InteractionNode;
import org.obeonetwork.dsl.bpmn2.IntermediateCatchEvent;
import org.obeonetwork.dsl.bpmn2.Lane;
Expand Down Expand Up @@ -130,13 +137,66 @@ public static void paste(EObject newContainer, DDiagramElement containerView, EO
lane.getFlowNodeRefs().add((FlowNode) newElement);
}
}
FlowElementsContainer flowElementsContainer = getFlowElementsContainer(newContainer);
flowElementsContainer.getFlowElements().add((FlowElement) newElement);
if (newElement instanceof FlowElement) {
FlowElementsContainer flowElementsContainer = getFlowElementsContainer(newContainer);
flowElementsContainer.getFlowElements().add((FlowElement) newElement);
} else if (newElement instanceof DataStore || newElement instanceof DataObject
|| newElement instanceof DataInput || newElement instanceof DataOutput) {
setDataInContainer(newContainer, newElement);
} else if (newElement instanceof Association) {
Process process = ServiceHelper.getProcess(newContainer);
if (process != null) {
process.getArtifacts().add((Association) newElement);
}
}

// Copy Sirius and GMF styles
CopySiriusGMFStylesHelper.copyStyles(newElement, containerView, oldId, newId);
}

private static void setDataInContainer(EObject newContainer, EObject newElement) {
if (newContainer instanceof Lane) {
Lane lane = (Lane) newContainer;
if (newElement instanceof DataStore || newElement instanceof DataObject) {
ExtensionAttributeValue extensionAttributeValue = Bpmn2Factory.eINSTANCE
.createExtensionAttributeValue();
lane.getExtensionValues().add(extensionAttributeValue);
extensionAttributeValue.setValue(newElement);
} else if (newElement instanceof DataInput || newElement instanceof DataOutput) {
if (lane.getPartitionElement() == null) {
InputOutputSpecification ioSpec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
lane.setPartitionElement(ioSpec);
}
if (newElement instanceof DataInput) {
((InputOutputSpecification) lane.getPartitionElement()).getDataInputs().add((DataInput) newElement);
} else if (newElement instanceof DataOutput) {
((InputOutputSpecification) lane.getPartitionElement()).getDataOutputs()
.add((DataOutput) newElement);
}
}
} else if (newContainer instanceof SubProcess) {
SubProcess process = (SubProcess) newContainer;
if (newElement instanceof DataStore || newElement instanceof DataObject) {
ExtensionAttributeValue extensionAttributeValue = Bpmn2Factory.eINSTANCE
.createExtensionAttributeValue();
process.getExtensionValues().add(extensionAttributeValue);
extensionAttributeValue.setValue(newElement);
} else if (newElement instanceof DataInput || newElement instanceof DataOutput) {
if (process.getIoSpecification() == null) {
InputOutputSpecification ioSpec = Bpmn2Factory.eINSTANCE.createInputOutputSpecification();
process.setIoSpecification(ioSpec);
}
if (newElement instanceof DataInput) {
((InputOutputSpecification) process.getIoSpecification()).getDataInputs()
.add((DataInput) newElement);
} else if (newElement instanceof DataOutput) {
((InputOutputSpecification) process.getIoSpecification()).getDataOutputs()
.add((DataOutput) newElement);
}
}
}
}

public EList<FlowElement> getSubElements(EObject eo) {
if (eo instanceof SubProcess) {
return ((SubProcess) eo).getFlowElements();
Expand Down

0 comments on commit 4e9285b

Please sign in to comment.