@Override public boolean canExecute() { List<DiagramNodeModel> nodes = getDiagramConnectionModel().getDiagramModel().getNodes(); Point location = getLocation(); for (DiagramNodeModel node : nodes) { if (pointInBounds(location, node.getShapePresentation().getFigure().getBounds())) { return false; } } return true; }
@Override public void execute() { DiagramModel diagramModel = node.getDiagramModel(); // Make a copy of all the connections that are attached to this node before setting the // node label. List<DiagramConnectionModel> connModels = diagramModel.getConnections(); List<DiagramConnectionPart> connParts1 = new ArrayList<DiagramConnectionPart>(); List<DiagramConnectionPart> connParts2 = new ArrayList<DiagramConnectionPart>(); for (DiagramConnectionModel connModel : connModels) { // Need to disable connection part listeners so the attached connections don't get deleted. // Will re-enable them once the end points are refreshed. if (connModel.getSourceNode().equals(node) || (connModel.getTargetNode().equals(node))) { DiagramConnectionPart connPart = connModel.getModelPart(); connPart.removeModelListener(); connPart.getDiagramConnectionTemplate().removeModelListener(); if (connModel.getSourceNode().equals(node)) { connParts1.add(connModel.getModelPart()); } else if (connModel.getTargetNode().equals(node)) { connParts2.add(connModel.getModelPart()); } } } Value<?> prop = FunctionUtil.getFunctionProperty( this.textPart.getLocalModelElement(), this.textPart.getContentFunction()); prop.write(this.labelText); // Refreshing endpoints of attached connections and re-enable listeners on them. for (DiagramConnectionPart connPart : connParts1) { if (!connPart.disposed()) { connPart.resetEndpoint1(); connPart.addModelListener(); connPart.getDiagramConnectionTemplate().addModelListener(); } } for (DiagramConnectionPart connPart : connParts2) { if (!connPart.disposed()) { connPart.resetEndpoint2(); connPart.addModelListener(); connPart.getDiagramConnectionTemplate().addModelListener(); } } }