/** * @see org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy#getConnectionCreateCommand(org.eclipse.gef.requests.CreateConnectionRequest) */ @Override protected Command getConnectionCreateCommand(CreateConnectionRequest request) { CreateConnectionCommand command = new CreateConnectionCommand(); AbstractConnection connection = (AbstractConnection) request.getNewObject(); AbstractView objNode = (AbstractNode) (getHost().getModel()); if (objNode instanceof AbstractConnection) { return null; } AbstractNode abstractNode = (AbstractNode) objNode; if (!UMLPolicyManager.isConnectableFromSource(connection.getRelationType(), abstractNode.getNodeType())) { return null; } ConnectionAnchor sourceAnchor = ((NodeEditPart) getHost()).getSourceConnectionAnchor(request); command.setSourceAnchorPoint(sourceAnchor.getLocation(request.getLocation())); command.setConnection(connection); command.setSource((AbstractNode) getHost().getModel()); request.setStartCommand(command); request.setSourceEditPart(getHost()); return command; }
/** * Returns the <code>ConnectionAnchor</code> for the <i>source</i> end of * the connection. If the source is an instance of {@link NodeEditPart}, * that interface will be used to determine the proper ConnectionAnchor. If * the source is not an instance of <code>NodeEditPart</code>, this method * should be overridden to return the correct ConnectionAnchor. Failure to * do this will cause a default anchor to be used so that the connection * figure will be made visible to the developer. * * @return ConnectionAnchor for the source end of the Connection */ protected ConnectionAnchor getSourceConnectionAnchor() { if (getSource() != null) { if (getSource() instanceof NodeEditPart) { NodeEditPart editPart = (NodeEditPart) getSource(); return editPart.getSourceConnectionAnchor(this); } IFigure f = ((GraphicalEditPart) getSource()).getFigure(); return new ChopboxAnchor(f); } return DEFAULT_SOURCE_ANCHOR; }
/** * Returns the <code>ConnectionAnchor</code> for the <i>target</i> end of * the connection. If the target is an instance of {@link NodeEditPart}, * that interface will be used to determine the proper ConnectionAnchor. If * the target is not an instance of <code>NodeEditPart</code>, this method * should be overridden to return the correct ConnectionAnchor. Failure to * do this will cause a default anchor to be used so that the connection * figure will be made visible to the developer. * * @return ConnectionAnchor for the target end of the Connection */ protected ConnectionAnchor getTargetConnectionAnchor() { if (getTarget() != null) { if (getTarget() instanceof NodeEditPart) { NodeEditPart editPart = (NodeEditPart) getTarget(); return editPart.getTargetConnectionAnchor(this); } IFigure f = ((GraphicalEditPart) getTarget()).getFigure(); return new ChopboxAnchor(f); } return DEFAULT_TARGET_ANCHOR; }
/** * @see org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy#getConnectionCompleteCommand(org.eclipse.gef.requests.CreateConnectionRequest) */ @Override protected Command getConnectionCompleteCommand(CreateConnectionRequest request) { CreateConnectionCommand startCommand = (CreateConnectionCommand) request.getStartCommand(); AbstractNode source; AbstractNode target; AbstractView objNode = (AbstractNode) (getHost().getModel()); if (objNode instanceof AbstractConnection) { return null; } source = (AbstractNode) startCommand.getSource(); target = (AbstractNode) objNode; if (!UMLPolicyManager.isConnectableToTarget(startCommand.getConnection().getRelationType(), source.getNodeType(), target.getNodeType())) { return null; } startCommand.setTarget(target); if (!(getHost().getParent().getModel() instanceof Diagram) && !(getHost().getParent().getModel() instanceof ContainerNode)) { startCommand.setParent((AbstractNode) getHost().getParent().getParent().getModel()); } else { startCommand.setParent((AbstractNode) getHost().getParent().getModel()); } ConnectionAnchor targetAnchor = ((NodeEditPart) getHost()).getTargetConnectionAnchor(request); startCommand.setTargetAnchorPoint(targetAnchor.getLocation(request.getLocation())); // Relation relation = null; Element sourceElement = ((AbstractNode) request.getSourceEditPart().getModel()).getUmlModel(); Element targetElement = ((AbstractNode) request.getTargetEditPart().getModel()).getUmlModel(); if (sourceElement instanceof Actor || sourceElement instanceof UseCase) { if (sourceElement.equals(targetElement)) { return null; } } if (startCommand.canExecute()) { return startCommand; } return null; }
/** * @see org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy#getReconnectSourceCommand(org.eclipse.gef.requests.ReconnectRequest) */ @Override protected Command getReconnectSourceCommand(ReconnectRequest request) { ReconnectConnectionCommand command = new ReconnectConnectionCommand(); command.setConnectionModel(request.getConnectionEditPart().getModel()); command.setNewSource(getHost().getModel()); command.setDiagram((Diagram) (getHost().getParent()).getModel()); ConnectionAnchor sourceAnchor = ((NodeEditPart) getHost()).getSourceConnectionAnchor(request); command.setSourceAnchorPoint(sourceAnchor.getLocation(request.getLocation())); Relation relation = null; Attachement attachement = null; if (request.getConnectionEditPart().getModel() instanceof Relation) { relation = (Relation) request.getConnectionEditPart().getModel(); AbstractNode source, target; source = (AbstractNode) command.getNewSource(); target = (AbstractNode) relation.getTarget(); if (!UMLPolicyManager.isConnectableToTarget(relation.getRelationType(), source.getNodeType(), target.getNodeType())) { return null; } } else if (request.getConnectionEditPart().getModel() instanceof Attachement) { attachement = (Attachement) request.getConnectionEditPart().getModel(); AbstractNode source, target; source = (AbstractNode) command.getNewSource(); target = (AbstractNode) attachement.getTarget(); if (!UMLPolicyManager.isConnectableToTarget(attachement.getRelationType(), source.getNodeType(), target.getNodeType())) { return null; } } // if (relation != null) { // if (relation.getTarget() instanceof AbstractNode) { // if (!((AbstractNode) // relation.getTarget()).getNodeType().equals(command.getNewSource().getNodeType())) // { // return null; // } // } // } // // if (relation != null) { // if (relation.getTarget() instanceof AbstractNode) { // if (((AbstractNode) // relation.getTarget()).getNodeType().equals(NodeType.ACTOR) // || ((AbstractNode) // relation.getTarget()).getNodeType().equals(NodeType.USE_CASE)) { // if // ((relation.getTarget().getUmlModel()).equals(command.getNewSource().getUmlModel())) // { // return null; // } // } // } // } return command; }
/** * @see org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy#getReconnectTargetCommand(org.eclipse.gef.requests.ReconnectRequest) */ @Override protected Command getReconnectTargetCommand(ReconnectRequest request) { ReconnectConnectionCommand command = new ReconnectConnectionCommand(); command.setConnectionModel(request.getConnectionEditPart().getModel()); command.setNewTarget(getHost().getModel()); command.setDiagram((Diagram) (getHost().getParent()).getModel()); ConnectionAnchor targetAnchor = ((NodeEditPart) getHost()).getTargetConnectionAnchor(request); command.setTargetAnchorPoint(targetAnchor.getLocation(request.getLocation())); Relation relation = null; Attachement attachement = null; if (request.getConnectionEditPart().getModel() instanceof Relation) { relation = (Relation) request.getConnectionEditPart().getModel(); AbstractNode source, target; source = (AbstractNode) relation.getSource(); target = (AbstractNode) command.getNewTarget(); if (!UMLPolicyManager.isConnectableToTarget(relation.getRelationType(), source.getNodeType(), target.getNodeType())) { return null; } } else if (request.getConnectionEditPart().getModel() instanceof Attachement) { attachement = (Attachement) request.getConnectionEditPart().getModel(); AbstractNode source, target; source = (AbstractNode) attachement.getSource(); target = (AbstractNode) command.getNewTarget(); if (!UMLPolicyManager.isConnectableToTarget(attachement.getRelationType(), source.getNodeType(), target.getNodeType())) { return null; } } // if (relation != null) { // if (relation.getSource() instanceof AbstractNode) { // if (!((AbstractNode) // relation.getSource()).getNodeType().equals(command.getNewTarget().getNodeType())) // { // return null; // } // } // } // if (relation != null) { // if (relation.getTarget() instanceof AbstractNode) { // if (((AbstractNode) // relation.getTarget()).getNodeType().equals(NodeType.ACTOR) // || ((AbstractNode) // relation.getTarget()).getNodeType().equals(NodeType.USE_CASE)) { // if // ((relation.getSource().getUmlModel()).equals(command.getNewTarget().getUmlModel())) // { // return null; // } // } // } // } return command; }
@Override protected ConnectionAnchor getSourceConnectionAnchor() { EditPart calculatedSource = getSource(); if(calculatedSource == null) { Object model = this.getModel(); if(model instanceof Link) { Link link = (Link)model; Object source = link.getSource(); Map<?, ?> editPartRegistry = this.getViewer().getEditPartRegistry(); if(editPartRegistry == null) { LogUtil.warn("edit part registry is null, can't lookup edit part. try refreshing constraints."); } else { Object object = editPartRegistry.get(source); if(object instanceof GraphicalEditPart) { calculatedSource = (EditPart) object; } else if(object instanceof Collection<?>) { Collection<?> collection = (Collection<?>)object; for(Object collectionObject : collection) { if(collectionObject instanceof GraphicalEditPart) { calculatedSource = (EditPart) collectionObject; } } } // make the target the same as the source, at least we get an icon else if(object == null) { calculatedSource = getTarget(); } } } } if (calculatedSource != null) { if (calculatedSource instanceof NodeEditPart) { NodeEditPart editPart = (NodeEditPart) calculatedSource; return editPart.getSourceConnectionAnchor(this); } GraphicalEditPart graphicalEditPart = (GraphicalEditPart)getSource(); if (graphicalEditPart != null) { IFigure f = graphicalEditPart.getFigure(); return new ChopboxAnchor(f); } } return null; }
/** * Called during the display of creation feedback to snap the feedback to * the nearest source ConnectionAnchor. * * @param request * CreateConnectionRequest * @return <code>null</code> or the nearest source ConnectionAnchor */ protected ConnectionAnchor getSourceConnectionAnchor( CreateConnectionRequest request) { EditPart source = request.getSourceEditPart(); return source instanceof NodeEditPart ? ((NodeEditPart) source) .getSourceConnectionAnchor(request) : null; }
/** * Called during the display of creation feedback to snap the feedback to * the nearest target ConnectionAnchor. * * @param request * CreateConnectionRequest * @return <code>null</code> or the nearest target ConnectionAnchor */ protected ConnectionAnchor getTargetConnectionAnchor( CreateConnectionRequest request) { EditPart target = request.getTargetEditPart(); return target instanceof NodeEditPart ? ((NodeEditPart) target) .getTargetConnectionAnchor(request) : null; }