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()) {