false));
setName("Subprocess " + model.getNameValue());
// Switch editor to use the model element container of the subprocess
ModelElementContainer container = model.getSimpleTransContainer();
getModelProcessor().setElementContainer(container);
model.getCreationMap().setSubElementContainer(container);
// Get list of input nodes, presume that there is exactly one source and one sink,
// which is a valid assumption for sub processes and should have been verified before
// this constructor is called
Set<AbstractPetriNetElementModel> sources = NetAlgorithms
.getDirectlyConnectedNodes(model,
NetAlgorithms.connectionTypeINBOUND);
Iterator<AbstractPetriNetElementModel> sourceKeyIterator = sources.iterator();
AbstractPetriNetElementModel sourceModel = sourceKeyIterator.next();
setSubprocessInput(sourceModel);
// Check whether the source element already exists
if (container.getElementById(sourceModel.getId()) == null) {
CreationMap sourceCreationMap = sourceModel.getCreationMap();
if (((EditorVC) parentEditor).isCopyFlag() == false) {
container.getArcMap().clear();
container.getIdMap().clear();
}
sourceCreationMap.setPosition(10, 160);
sourceCreationMap.setReadOnly(true);
sourceCreationMap.setNamePosition(30, 200);
sourceCreationMap.setEditOnCreation(false);
sourceCreationMap.setUpperElement(sourceModel);
createElement(sourceCreationMap, true, true);
} else {
container.getElementById(sourceModel.getId()).setNameValue(
getSubprocessInput().getNameValue());
container.getElementById(sourceModel.getId()).setReadOnly(true);
}
// Get list of output nodes
Set<AbstractPetriNetElementModel> targets = NetAlgorithms
.getDirectlyConnectedNodes(model,
NetAlgorithms.connectionTypeOUTBOUND);
Iterator<AbstractPetriNetElementModel> targetKeyIterator = targets.iterator();
AbstractPetriNetElementModel targetModel = targetKeyIterator.next();
setSubprocessOutput(targetModel);
// Check whether the target element already exists
if (container.getElementById(targetModel.getId()) == null) {
CreationMap targetCreationMap = targetModel.getCreationMap();
targetCreationMap.setPosition(520, 160);
targetCreationMap.setReadOnly(true);
targetCreationMap.setNamePosition(540, 200);
targetCreationMap.setEditOnCreation(false);
targetCreationMap.setUpperElement(targetModel);
createElement(targetCreationMap, true, true);
} else {
container.getElementById(targetModel.getId()).setNameValue(
getSubprocessOutput().getNameValue());
container.getElementById(targetModel.getId()).setReadOnly(true);
}
// We must create a JGraph model
// representation of the new model element container
// Disable undo while doing so just as we do for loading a PNML file
if (getGraph().getUndoManager() != null) {
((WoPeDUndoManager) getGraph().getUndoManager()).setEnabled(false);
}
getGraph().drawNet(getModelProcessor());
if (getGraph().getUndoManager() != null) {
((WoPeDUndoManager) getGraph().getUndoManager()).setEnabled(true);
}
updateNet();
// Clear selection, we do not want newly created elements to be selected
getGraph().clearSelection();
// Keep the tree model of the parent editor up to date
if ((parentEditor != null) && (getEditorPanel().GetTreeModel() != null)
&& (parentEditor instanceof EditorVC)) {
getEditorPanel().GetTreeModel().addTreeModelListener(((EditorVC) parentEditor)
.getEditorPanel().GetTreeModel());
}
// Try to retrieve saved layout information from the Model Element
// container
// and set it for this editor window
EditorLayoutInfo layoutInfo = container.getEditorLayoutInfo();
if (layoutInfo != null) {
getEditorPanel().setSavedLayoutInfo(layoutInfo);
}
// Copy resources from parentEditor to subprocessEditor
Vector<ResourceModel> res = ((PetriNetModelProcessor) (parentEditor
.getModelProcessor())).getResources();
((PetriNetModelProcessor) (getModelProcessor())).setResources(res);
HashMap<String, Vector<String>> mapping = ((PetriNetModelProcessor) (parentEditor
.getModelProcessor())).getResourceMapping();
((PetriNetModelProcessor) (getModelProcessor()))
.setResourceMapping(mapping);
Vector<ResourceClassModel> units = ((PetriNetModelProcessor) (parentEditor
.getModelProcessor())).getOrganizationUnits();
((PetriNetModelProcessor) (getModelProcessor()))
.setOrganizationUnits(units);
Vector<ResourceClassModel> roles = ((PetriNetModelProcessor) (parentEditor
.getModelProcessor())).getRoles();
((PetriNetModelProcessor) (getModelProcessor())).setRoles(roles);
Map<String, AbstractPetriNetElementModel> transitions;
TransitionModel trans;
if (!(transitions = container.getElementsByType(2)).isEmpty()) {
Iterator<AbstractPetriNetElementModel> iterTrans = transitions.values().iterator();
while (iterTrans.hasNext()) {
trans = (TransitionModel) iterTrans.next();
if (trans.isIncommingTarget())
createArc(this.m_subprocessInput.getId(), trans.getId());