}
Set<ExtraCopyAction> elements = new HashSet<ExtraCopyAction>();
List<Node> sourceNodeList = copyBuffer.extractSourceNodes();
// add nodes
for (Node node : sourceNodeList) {
GEFElementCreationFactory factory = null;
if (node instanceof StartState && targetDefinition.getChildren(StartState.class).size() == 0) {
factory = new GEFElementCreationFactory("start-state", targetDefinition);
} else if (node instanceof EndState && targetDefinition.getChildren(EndState.class).size() == 0) {
factory = new GEFElementCreationFactory("end-state", targetDefinition);
} else if (targetDefinition.getNodeByName(node.getName()) == null) {
factory = new GEFElementCreationFactory(node.getTypeName(), targetDefinition);
}
if (factory != null) {
Node copy = (Node) factory.getNewObject();
copy.setName(node.getName());
copy.setConstraint(node.getConstraint());
if (node instanceof ITimed && ((ITimed) node).timerExist()) {
((ITimed) copy).setDueDate(((ITimed) node).getDuration().getDuration());
String variableName = ((ITimed) node).getDuration().getVariableName();
if (variableName != null) {
Variable variable = copyBuffer.getSourceDefinition().getVariablesMap().get(variableName);
CopyVariableAction copyAction = new CopyVariableAction(variable);
elements.add(copyAction);
}
}
if (node instanceof State) {
((State) copy).setMinimizedView(((State) node).isMinimizedView());
}
if (node instanceof Decision) {
copy.setDelegationConfiguration(node.getDelegationConfiguration());
copy.setDelegationClassName(node.getDelegationClassName());
}
if (node instanceof Subprocess) {
((Subprocess) copy).setSubProcessName(((Subprocess) node).getSubProcessName());
List<VariableMapping> variables = ((Subprocess) node).getVariablesList();
((Subprocess) copy).setVariablesList(variables);
for (VariableMapping varMapping : variables) {
Variable variable = copyBuffer.getSourceDefinition().getVariablesMap().get(varMapping.getProcessVariable());
if (variable != null) {
CopyVariableAction copyAction = new CopyVariableAction(variable);
elements.add(copyAction);
}
}
copy.setDelegationClassName(node.getDelegationClassName());
}
targetDefinition.addChild(copy);
targetNodeList.put(copy.getName(), copy);
if (node instanceof FormNode) {
FormNode formNode = (FormNode) node;
if (formNode.hasForm() || formNode.hasFormValidation()) {
CopyFormFilesAction copyAction = new CopyFormFilesAction(formNode, (FormNode) copy);
copyAction.setSourceFolder(copyBuffer.getSourceFolder());
copyAction.setTargetFolder(targetFolder);
elements.add(copyAction);
}
Map<String, Integer> variables = formNode.getFormVariables(copyBuffer.getSourceFolder());
for (String varName : variables.keySet()) {
Variable variable = copyBuffer.getSourceDefinition().getVariablesMap().get(varName);
if (variable != null) {
CopyVariableAction copyAction = new CopyVariableAction(variable);
elements.add(copyAction);
}
}
}
if (node instanceof SwimlanedNode) {
Swimlane swimlane = ((SwimlanedNode) node).getSwimlane();
if (swimlane != null) {
CopySwimlaneAction copyAction = new CopySwimlaneAction(swimlane);
elements.add(copyAction);
}
}
if (node instanceof Active) {
List<? extends org.jbpm.ui.common.model.Action> actions = ((Active) node).getActions();
for (org.jbpm.ui.common.model.Action action : actions) {
AddActionHandlerAction copyAction = new AddActionHandlerAction((Active) copy, action);
elements.add(copyAction);
}
}
}
}
// add transitions
GEFElementCreationFactory trFactory = new GEFElementCreationFactory("transition", targetDefinition);
for (Node node : sourceNodeList) {
List<Transition> transitions = node.getChildren(Transition.class);
for (Transition transition : transitions) {
Node source = targetNodeList.get(transition.getSource().getName());
Node target = targetNodeList.get(transition.getTarget().getName());
if (source != null && target != null) {
Transition tr = (Transition) trFactory.getNewObject(source);
tr.setName(transition.getName());
tr.setTarget(target);
for (Bendpoint bp : transition.getBendpoints()) {
tr.getBendpoints().add(new Bendpoint(bp.getX(), bp.getY()));
}