editor.getGraph().getModel().remove(allDeletedObjects.toArray());
editor.updateNet();
}
public ArcModel createArc(CreationMap map, boolean insertIntoCache) {
ArcModel arc = null;
String sourceId = map.getArcSourceId();
String targetId = map.getArcTargetId();
List<?> points = map.getArcPoints();
Point2D[] pointArray = new Point2D[points.size()];
for (int i = 0; i < points.size(); i++) {
if (points.get(i) instanceof Point2D) {
pointArray[i] = (Point2D) points.get(i);
} else
if (points.get(i) instanceof IntPair) {
pointArray[i] = new Point2D.Double(((IntPair) points.get(i)).getX1(), ((IntPair) points.get(i))
.getX2());
}
}
AbstractPetriNetElementModel source = editor.getModelProcessor().getElementContainer().getElementById(sourceId);
source = source != null ? source : tStar;
AbstractPetriNetElementModel target = editor.getModelProcessor().getElementContainer().getElementById(targetId);
target = target != null ? target : tStar;
if (editor.getGraph().isValidConnection(source, target)) {
if (!editor.getModelProcessor().getElementContainer().hasReference(sourceId, targetId)) {
String id = map.getArcId();
// if the id isn't set or the id set already belongs to an
// existing arc then fetch a new one
if (id == null | editor.getModelProcessor().getElementContainer().getArcById(id) != null) {
id = editor.getModelProcessor().getNexArcId();
}
// if aalst source or target -> update Model
arc = ModelElementFactory.createArcModel(id, (DefaultPort) source.getChildAt(0), (DefaultPort) target
.getChildAt(0));
arc.setPoints(pointArray);
GraphConstants.setSelectable(arc.getAttributes(), false);
GraphConstants.setLineColor(arc.getAttributes(), T_STAR_COLOR);
OperatorTransitionModel operatorModel;
if (source.getType() == AbstractPetriNetElementModel.TRANS_OPERATOR_TYPE) {
operatorModel = (OperatorTransitionModel) source;
operatorModel.addElement(target);
operatorModel.registerOutgoingConnection((PetriNetModelProcessor) editor.getModelProcessor(),
target);
} else
if (target.getType() == AbstractPetriNetElementModel.TRANS_OPERATOR_TYPE) {
operatorModel = (OperatorTransitionModel) target;
operatorModel.addElement(source);
operatorModel.registerIncomingConnection((PetriNetModelProcessor) editor.getModelProcessor(),
source);
}
editor.getModelProcessor().getElementContainer().addReference(arc);
editor.getGraph().connect(arc, insertIntoCache);
for (int i = 0; i < pointArray.length; ++i) {
arc.addPoint(pointArray[i]);
Map<ArcModel, AttributeMap> arcMap = new HashMap<ArcModel, AttributeMap>();
arcMap.put(arc, arc.getAttributes());
editor.getGraph().getModel().edit(arcMap, null, null, null);
}
arc.setProbability(map.getArcProbability());
arc.setDisplayOn(map.getDisplayArcProbability());
if (map.getArcLabelPosition() != null) {
arc.setLabelPosition(new Point2D.Double(map.getArcLabelPosition().getX(), map.getArcLabelPosition()
.getY()));
}
}
}
return arc;