getGraph().setMinPreferredHeight(0);
getEditor().setLastMousePosition(e.getPoint());
// If in drawing mode, create new node at current position
if (getEditor().isDrawingMode() && firstPort == null) {
CreationMap map = CreationMap.createMap();
if (getEditor().getCreateElementType() > 100 && getEditor().getCreateElementType() < 110) {
map.setType(AbstractPetriNetElementModel.TRANS_OPERATOR_TYPE);
map.setOperatorType(getEditor().getCreateElementType());
getEditor().create(map);
}
else {
map.setType(getEditor().getCreateElementType());
getEditor().create(map);
}
return;
}
// Set normal cursor and determine current position of mouse click
getGraph().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
Object currentCell = getGraph().getFirstCellForLocation(e.getX(), e.getY());
// Set selection to object under cursor unless group selection is active
if (currentCell != null && getGraph().getSelectionCount() <= 1)
getGraph().setSelectionCell(currentCell);
// Handle right mouse button behaviour
if (SwingUtilities.isRightMouseButton(e)) {
if (!getEditor().isDrawingMode()) {
VisualController.getInstance().setArcpointSelection(isArcPoint(e));
e.consume();
PopupMenuPetrinet.setMediator(mediator);
PopupMenuPetrinet.getInstance().show(currentCell, getGraph(),
(int) (getEditor().getLastMousePosition().getX()),
(int) (getEditor().getLastMousePosition().getY()));
}
return;
}
else {
if (e.getClickCount() == 2) {
// Handle single left mouse double click behaviour
while (currentCell instanceof GroupModel) {
currentCell = ((GroupModel) currentCell).getMainElement();
}
// Double click on subprocess element opens subprocess editor
if (currentCell instanceof SubProcessModel) {
getEditor().fireViewEvent(
new ViewEvent(this, AbstractViewEvent.VIEWEVENTTYPE_GUI,
AbstractViewEvent.OPEN_SUBPROCESS));
}
// Double click on normal element opens property dialog
else {
getEditor().setLastMousePosition(e.getPoint());
getEditor().fireViewEvent(
new EditorViewEvent(this, AbstractViewEvent.VIEWEVENTTYPE_EDIT,
AbstractViewEvent.OPEN_PROPERTIES));
}
}
else {
// Handle single left mouse button click behaviour
if (ConfigurationManager.getConfiguration().isSmartEditing()
&& port == null && firstPort != null && firstPort != port) {
// Smart editing is enabled, i. e. create elements on the fly
CreationMap[] maps = new CreationMap[2];
boolean allowConnection = true;
Object element = ((firstPort != null) ? ((DefaultPort) firstPort.getCell()).getParent() : null);
if (element instanceof AbstractPetriNetElementModel) {
allowConnection = ((AbstractPetriNetElementModel) element).getAllowOutgoingConnections();
}
// Check if connection is between valid nodes
if (allowConnection) {
DefaultPort source = (DefaultPort) firstPort.getCell();
CreationMap map = CreationMap.createMap();
if (source.getParent() instanceof TransitionModel) {
map.setType(AbstractPetriNetElementModel.PLACE_TYPE);
map.setId(getEditor().getModelProcessor().getNewElementId(map.getType()));
maps[0] = map;
}
else {
if (source.getParent() instanceof PlaceModel) {
map.setType(AbstractPetriNetElementModel.TRANS_SIMPLE_TYPE);
map.setId(getEditor().getModelProcessor().getNewElementId(map.getType()));
maps[0] = map;
}
}
String targetId = map.getId();
map = CreationMap.createMap();
map.setArcSourceId(((AbstractPetriNetElementModel) (source).getParent()).getId());
map.setArcTargetId(targetId);
maps[1] = map;
}
GraphCell[] result = getEditor().createAll(maps);
getGraph().startEditingAtCell(result[0]);
}
else {
// No smart editing, just draw connections
if (e != null && !e.isConsumed() && port != null && firstPort != null && firstPort != port) {
// Fetch the underlying source and target port
Port source = (Port) firstPort.getCell();
Port target = (Port) port.getCell();
// Check if connection is valid
CreationMap map = CreationMap.createMap();
map.setArcSourceId(((AbstractPetriNetElementModel) ((DefaultPort) source).getParent()).getId());
map.setArcTargetId(((AbstractPetriNetElementModel) ((DefaultPort) target).getParent()).getId());
getEditor().create(map);
e.consume();
}
}