/** @generated */
 protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
   if (request instanceof CreateConnectionRequestEx) {
     if (request.getStartCommand() == null || !request.getStartCommand().canExecute()) {
       return UnexecutableCommand.INSTANCE;
     }
     CreateConnectionRequestEx requestEx = (CreateConnectionRequestEx) request;
     if (!DiagramEditPart.MODEL_ID.equals(requestEx.getModelID())) {
       return null;
     }
     int[] visualIds = requestEx.getVisualIds();
     CompoundCommand result = new CompoundCommand();
     for (int i = 0; i < visualIds.length; i++) {
       int nextVisualId = visualIds[i];
       switch (nextVisualId) {
         case TransitionEditPart.VISUAL_ID:
           result.appendIfCanExecute(new CreateTransition4001Command(requestEx));
           break;
       }
     }
     if (result.getCommandList().size() != 1 || !result.canExecute()) {
       // Cannot create several connections at once.
       return UnexecutableCommand.INSTANCE;
     }
     return request
         .getStartCommand()
         .chain(
             new WrappingCommand(
                 TransactionUtil.getEditingDomain(
                     ((Node) getHost().getModel()).getDiagram().getElement()),
                 result));
   }
   return null;
 }
 @Override
 protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
   DiagramNodeModel source = (DiagramNodeModel) getHost().getModel();
   Object def = request.getNewObjectType();
   CreateConnectionCommand cmd = new CreateConnectionCommand(source, (IDiagramConnectionDef) def);
   request.setStartCommand(cmd);
   return cmd;
 }
 @Override
 protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
   int style = ((Integer) request.getNewObjectType()).intValue();
   Activity source = getActivity();
   NextConnectionCreateCommand cmd =
       new NextConnectionCreateCommand(source.getDiagram().getTextEditor(), style);
   cmd.setSource(source);
   request.setStartCommand(cmd);
   return cmd;
 }
	protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
		if (getHost().getModel() instanceof LFWBasicElementObj) {
			LFWBasicElementObj sour = (LFWBasicElementObj) getHost().getModel();
			Class conCls = (Class) request.getNewObject();
			Command command = new MenuRelationConnectionCommand(sour, conCls);
			request.setStartCommand(command);
			return command;
		}
		return null;
	}
 private void identifySourceFigure(Request req) {
   if (req instanceof CreateConnectionRequest) {
     CreateConnectionRequest r = (CreateConnectionRequest) req;
     if (r.getSourceEditPart() instanceof AbstractGraphicalEditPart) {
       AbstractGraphicalEditPart ep = (AbstractGraphicalEditPart) r.getSourceEditPart();
       rec = ep.getFigure().getBounds();
     }
   } else {
     rec = null;
   }
 }
 @SuppressWarnings("unchecked") // $NON-NLS-1$
 protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
   Node source = (Node) getHost().getModel();
   if (source.isReadOnly()) {
     return null;
   }
   String style = (String) request.getNewObjectType();
   ConnectionCreateCommand cmd =
       new ConnectionCreateCommand(source, style, (List<Object>) request.getNewObject());
   request.setStartCommand(cmd);
   return cmd;
 }
 /** @generated */
 protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
   if (request instanceof CreateConnectionRequestEx) {
     CreateConnectionRequestEx requestEx = (CreateConnectionRequestEx) request;
     if (!DiagramEditPart.MODEL_ID.equals(requestEx.getModelID())) {
       return null;
     }
     int[] visualIds = requestEx.getVisualIds();
     CompoundCommand result = new CompoundCommand();
     for (int i = 0; i < visualIds.length; i++) {
       int nextVisualId = visualIds[i];
       switch (nextVisualId) {
         case TransitionEditPart.VISUAL_ID:
           result.appendIfCanExecute(new CreateTransition4001StartCommand(requestEx));
           break;
       }
     }
     if (!result.canExecute()) {
       return null;
     }
     Command wrappedResult =
         new WrappingCommand(
             TransactionUtil.getEditingDomain(
                 ((Node) getHost().getModel()).getDiagram().getElement()),
             result);
     request.setStartCommand(wrappedResult);
     return wrappedResult;
   }
   return null;
 }
 @Override
 protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
   WorkflowNode source = (WorkflowNode) getHost().getModel();
   ConnectionDrawCommand cmd =
       new ConnectionDrawCommand((WorkflowDescription) getParent().getModel(), source);
   request.setStartCommand(cmd);
   return cmd;
 }
  /**
   * @see
   *     org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy#getConnectionCreateCommand(org.eclipse.gef.requests.CreateConnectionRequest)
   */
  protected Command getConnectionCreateCommand(CreateConnectionRequest request) {

    // check meta node policy
    Object m = getHost().getModel();
    if (m instanceof MetaNode) {
      String edgeType = ((MetaNode) m).getEdgeType();
      if (edgeType != null && !edgeType.equals(request.getNewObjectType())) {
        return null;
      }
    }

    ConnectionCommand command = new ConnectionCommand();
    command.setSourceNode((INode) getHost().getModel());
    command.setType((String) request.getNewObjectType());
    request.setStartCommand(command);
    return command;
  }
	protected Command getConnectionCompleteCommand(
			CreateConnectionRequest request) {
		MenuRelationConnectionCommand comd = (MenuRelationConnectionCommand) request.getStartCommand();

		LFWBasicElementObj target = (LFWBasicElementObj) getHost().getModel();
		comd.setTarget(target);
		return comd;
	}
  /**
   * @see
   *     org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy#getConnectionCompleteCommand(org.eclipse.gef.requests.CreateConnectionRequest)
   */
  protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
    ConnectionCommand command = (ConnectionCommand) request.getStartCommand();

    // dont allow connection if there is already a connection between source and target
    // and of the same type.
    EdgeContainer ec = ((INode) getHost().getModel()).getRoot().getEdgeContainer();
    if (ec.containsEdge(command.getSourceNode(), (INode) getHost().getModel(), command.getType())) {
      return null;
    }

    // dont allow connection if source node is an ancestor of target
    AbstractAsset parent = (AbstractAsset) getHost().getModel();
    while (parent != null) {
      parent = parent.getParent();
      if (parent == command.getSourceNode()) {
        return null;
      }
    }

    // check meta node policy
    Object m = getHost().getModel();
    if (m instanceof MetaNode) {
      String edgeType = ((MetaNode) m).getEdgeType();
      if (edgeType != null && !edgeType.equals(command.getType())) {
        return null;
      }
    }

    // dont allow self-connection
    if (command.getSourceNode() == getHost().getModel()) {
      return null;
    }

    // dont allow connection if target node is an ancestor of source
    parent = (AbstractAsset) command.getSourceNode();
    while (parent != null) {
      parent = parent.getParent();
      if (parent == (AbstractAsset) getHost().getModel()) {
        return null;
      }
    }

    command.setTargetNode((INode) getHost().getModel());

    return command;
  }
Exemple #12
0
 @Override
 protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
   ConnectionDrawCommand cmd = (ConnectionDrawCommand) request.getStartCommand();
   cmd.setTarget((WorkflowNode) getHost().getModel());
   return cmd;
 }
 @Override
 public void execute() {
   // configure the request
   EditPart source = request.getSourceEditPart();
   EditPart target = request.getTargetEditPart();
   PointList list = feedback.getPoints();
   DiagramEditPart diagramEditPart = null;
   if (source.getParent() instanceof DiagramEditPart) {
     diagramEditPart = (DiagramEditPart) source.getParent();
   } else if (source instanceof DiagramEditPart) {
     diagramEditPart = (DiagramEditPart) source;
   } else {
     if (source.getParent().getParent() instanceof DiagramEditPart) {
       diagramEditPart = (DiagramEditPart) source.getParent().getParent();
     }
   }
   if (diagramEditPart == null) {
     return;
   }
   if (!(source instanceof DiagramEditPart || target instanceof DiagramEditPart)) {
     // one must be whitespace, we make it the target
     request.setTargetEditPart(diagramEditPart);
     // additionally we must cut the drawn connection
     // in half to share room with the element that will
     // be auto-created
     PointList newList = new PointList();
     newList.addPoint(list.getFirstPoint());
     if (list.size() == 4) {
       // rectilinear routing will have a three points
       newList.addPoint(list.getPoint(1));
     }
     newList.addPoint(list.getMidpoint());
     feedback.setPoints(newList);
   }
   // create the active tool's element first
   CreateConnectionCommand command = new CreateConnectionCommand(request, feedback);
   command.execute();
   Connector_c newConnector = command.result;
   if (newConnector == null) {
     return;
   }
   // we need to now refresh the diagram to get the new edit part
   source.refresh();
   source.getParent().refresh();
   GraphicalEditPart newPart =
       (GraphicalEditPart) source.getViewer().getEditPartRegistry().get(newConnector);
   // transfer the feedback connection points to the newly created
   // edit part
   ((Connection) newPart.getFigure()).setPoints(feedback.getPoints().getCopy());
   // now adjust the request for the new element to be created for each
   // terminal specification that requires auto-creation
   createElementForTerminalSpec(
       autoStartSpec,
       ((NonRootModelElement) diagramEditPart.getModel()).getModelRoot(),
       list,
       newPart,
       target,
       diagramEditPart);
   createElementForTerminalSpec(
       autoEndSpec,
       ((NonRootModelElement) diagramEditPart.getModel()).getModelRoot(),
       list,
       newPart,
       target,
       diagramEditPart);
 }
  private void createElementForTerminalSpec(
      TerminalSpecification_c autoCreationSpec,
      ModelRoot modelRoot,
      PointList line,
      EditPart newPart,
      EditPart targetPart,
      final DiagramEditPart diagramEditPart) {
    ElementSpecification_c specification =
        ElementSpecification_c.getOneGD_ESOnR209(autoCreationSpec);
    if (specification != null && request instanceof GraphicsConnectionCreateRequest) {
      // deactivate the current tool
      ModelTool_c activeTool =
          ModelTool_c.ModelToolInstance(
              modelRoot,
              new ClassQueryInterface_c() {

                @Override
                public boolean evaluate(Object candidate) {
                  return ((ModelTool_c) candidate).getActive();
                }
              });
      activeTool.setActive(false);
      // find the new tool and activate it
      ModelTool_c newTool =
          ModelTool_c.getOneCT_MTLOnR103(
              specification,
              new ClassQueryInterface_c() {

                @Override
                public boolean evaluate(Object candidate) {
                  ModelTool_c tool = (ModelTool_c) candidate;
                  return Model_c.getOneGD_MDOnR100(tool) == diagramEditPart.getModel();
                }
              });
      newTool.setActive(true);
      // create the new element
      if (specification.getSymboltype().equals("connector")) { // $NON-NLS-1$
        // creating a connector
        // we want to create the new connector from the
        // midpoint of the drawn line to the end of the
        // drawn line
        PointList newLine = new PointList();
        newLine.addPoint(line.getLastPoint());
        if (line.size() == 4) {
          // rectilinear routing will have a three points
          newLine.addPoint(line.getPoint(2));
        }
        newLine.addPoint(line.getMidpoint());
        feedback.setPoints(newLine);
        // we also need to adjust the request's source and
        // target edit part, we swap the original target as the
        // source as if the new connection was drawn from
        // the original destination element
        request.setTargetEditPart(newPart);
        request.setSourceEditPart(targetPart);
        // need to update the location in the request for
        // those connectors that end on whitespace
        request.setLocation(line.getMidpoint());
        // we need to configure the proper tool id in the
        // request
        GraphicsConnectionCreateRequest gRequest = (GraphicsConnectionCreateRequest) request;
        gRequest.setToolId(newTool.getTool_id());
        CreateConnectionCommand command = new CreateConnectionCommand(request, feedback);
        command.disableCropping();
        command.execute();
        // reset the active tool states
        newTool.setActive(false);
        activeTool.setActive(true);
      } else if (specification.getSymboltype().equals("shape")) { // $NON-NLS-1$
        // TODO: support shape auto creation
      }
    }
    // otherwise this is not an auto create specification
  }
 public ConnectionAnchor getTargetConnectionAnchor(Request request) {
   CreateConnectionRequest r = (CreateConnectionRequest) request;
   if (r.getNewObjectType().equals(NoteConnectionEditPart.NOTE_CONNECTION)
       || r.getNewObjectType() == Relationship.class) return getConnectionAnchor();
   return null;
 }
 @Override
 protected Command getConnectionCompleteCommand(CreateConnectionRequest request) {
   CreateConnectionCommand cmd = (CreateConnectionCommand) request.getStartCommand();
   cmd.setTarget((DiagramNodeModel) getHost().getModel());
   return cmd;
 }