Package org.eclipse.graphiti.features.context

Examples of org.eclipse.graphiti.features.context.IAddConnectionContext


    /**
     * Draws a polyline between elements.
     */
    public PictogramElement add(IAddContext context) {

        IAddConnectionContext addConContext = (IAddConnectionContext) context;

        ConnectionStatement addedConn =
            (ConnectionStatement) context.getNewObject();
        IPeCreateService peCreateService = Graphiti.getPeCreateService();
       
        // CONNECTION WITH POLYLINE

        Connection connection = peCreateService
            .createFreeFormConnection(getDiagram());
        connection.setStart(addConContext.getSourceAnchor());
        connection.setEnd(addConContext.getTargetAnchor());

        IGaService gaService = Graphiti.getGaService();
        Polyline polyline = gaService.createPolyline(connection);
        polyline.setStyle(StyleUtil.getStyleForConn(getDiagram()));
        ConnectionDecorator cd = peCreateService.createConnectionDecorator(
View Full Code Here


  /* (non-Javadoc)
   * @see org.eclipse.graphiti.func.IAdd#add(org.eclipse.graphiti.features.context.IAddContext)
   */
  @Override
  public PictogramElement add(IAddContext context) {
    IAddConnectionContext addConContext = (IAddConnectionContext) context;
    Flow addedEReference = (Flow) context.getNewObject();

    IPeCreateService peCreateService = Graphiti.getPeCreateService();
    // CONNECTION WITH POLYLINE
    Connection connection = peCreateService.createFreeFormConnection(getDiagram());
    connection.setStart(addConContext.getSourceAnchor());
    connection.setEnd(addConContext.getTargetAnchor());
   
    IGaService gaService = Graphiti.getGaService();
    Polyline polyline = gaService.createPolyline(connection);
    polyline.setStyle(StyleUtil.getStyleForEClass(getDiagram()));
    polyline.setForeground(manageColor(StyleUtil.getColorConstant(PreferenceManager.getInstance().loadPreferenceAsString(PreferencesConstants.EDITOR_CONNECTION_COLOR))));
View Full Code Here

  public PictogramElement add(IAddContext context) {
    IPeService peService = Graphiti.getPeService();
    IGaService gaService = Graphiti.getGaService();

    BaseElement element = (BaseElement) context.getNewObject();
    IAddConnectionContext addConContext = (IAddConnectionContext) context;

    Connection connection = peService.createFreeFormConnection(getDiagram());

    Object importProp = context.getProperty(DIImport.IMPORT_PROPERTY);
    if (importProp != null && (Boolean) importProp) {
      connection.setStart(addConContext.getSourceAnchor());
      connection.setEnd(addConContext.getTargetAnchor());
    } else {
      ContainerShape sourceContainer = (ContainerShape) addConContext.getSourceAnchor().eContainer();
      ContainerShape targetContainer = (ContainerShape) addConContext.getTargetAnchor().eContainer();
      Tuple<FixPointAnchor, FixPointAnchor> anchors = AnchorUtil.getSourceAndTargetBoundaryAnchors(
          sourceContainer, targetContainer, connection);

      connection.setStart(anchors.getFirst());
      connection.setEnd(anchors.getSecond());
View Full Code Here

    super(fp);
  }

  @SuppressWarnings("unchecked")
  public PictogramElement add(IAddContext context) {
    IAddConnectionContext addConContext = (IAddConnectionContext) context;
    SequenceFlow addedSequenceFlow = (SequenceFlow) context.getNewObject();
   
    Anchor sourceAnchor = null;
    Anchor targetAnchor = null;
    if(addConContext.getSourceAnchor() == null) {
      EList<Shape> shapeList = getDiagram().getChildren();
      for (Shape shape : shapeList) {
        FlowNode flowNode = (FlowNode) getBusinessObjectForPictogramElement(shape.getGraphicsAlgorithm().getPictogramElement());
        if(flowNode == null || flowNode.getId() == null || addedSequenceFlow.getSourceRef() == null ||
                addedSequenceFlow.getTargetRef() == null) continue;
        if(flowNode.getId().equals(addedSequenceFlow.getSourceRef())) {
          EList<Anchor> anchorList = ((ContainerShape) shape).getAnchors();
          for (Anchor anchor : anchorList) {
            if(anchor instanceof ChopboxAnchor) {
              sourceAnchor = anchor;
              break;
            }
          }
        }
       
        if(flowNode.getId().equals(addedSequenceFlow.getTargetRef())) {
          EList<Anchor> anchorList = ((ContainerShape) shape).getAnchors();
          for (Anchor anchor : anchorList) {
            if(anchor instanceof ChopboxAnchor) {
              targetAnchor = anchor;
              break;
            }
          }
        }
      }
    } else {
      sourceAnchor = addConContext.getSourceAnchor();
      targetAnchor = addConContext.getTargetAnchor();
    }
   
    if(sourceAnchor == null || targetAnchor == null) {
      return null;
    }

    IPeCreateService peCreateService = Graphiti.getPeCreateService();
    // CONNECTION WITH POLYLINE
    FreeFormConnection connection = peCreateService.createFreeFormConnection(getDiagram());
    connection.setStart(sourceAnchor);
    connection.setEnd(targetAnchor);
    sourceAnchor.getOutgoingConnections().add(connection);
    targetAnchor.getIncomingConnections().add(connection);

    Bpmn2MemoryModel model = ModelHandler.getModel(EcoreUtil.getURI(getDiagram()));
   
    FlowElement sourceElement = model.getFlowElement(addedSequenceFlow.getSourceRef());
    FlowElement targetElement = model.getFlowElement(addedSequenceFlow.getTargetRef());
   
    GraphicsAlgorithm sourceGraphics = getPictogramElement(sourceElement).getGraphicsAlgorithm();
    GraphicsAlgorithm targetGraphics = getPictogramElement(targetElement).getGraphicsAlgorithm();
   
    List<GraphicInfo> bendpointList = null;
    if(addConContext.getProperty("org.activiti.designer.bendpoints") != null) {
      bendpointList = (List<GraphicInfo>) addConContext.getProperty("org.activiti.designer.bendpoints");
    }
   
    if(bendpointList != null && bendpointList.size() >= 0) {
      for (GraphicInfo graphicInfo : bendpointList) {
        Point bendPoint = StylesFactory.eINSTANCE.createPoint();
        bendPoint.setX((int)graphicInfo.getX());
        bendPoint.setY((int)graphicInfo.getY());
        connection.getBendpoints().add(bendPoint);
      }
     
    } else {
     
      Shape sourceShape = (Shape) getPictogramElement(sourceElement);
      ILocation sourceShapeLocation = Graphiti.getLayoutService().getLocationRelativeToDiagram(sourceShape);
      int sourceX = sourceShapeLocation.getX();
      int sourceY = sourceShapeLocation.getY();
     
      Shape targetShape = (Shape) getPictogramElement(targetElement);
      ILocation targetShapeLocation = Graphiti.getLayoutService().getLocationRelativeToDiagram(targetShape);
      int targetX = targetShapeLocation.getX();
      int targetY = targetShapeLocation.getY();
     
      if (sourceElement instanceof Gateway && targetElement instanceof Gateway == false) {
        if (((sourceGraphics.getY() + 10) < targetGraphics.getY()
            || (sourceGraphics.getY() - 10) > targetGraphics.getY())  &&
            (sourceGraphics.getX() + (sourceGraphics.getWidth() / 2)) < targetGraphics.getX()) {
         
          boolean subProcessWithBendPoint = false;
          if(targetElement instanceof SubProcess) {
            int middleSub = targetGraphics.getY() + (targetGraphics.getHeight() / 2);
            if((sourceGraphics.getY() + 20) < middleSub || (sourceGraphics.getY() - 20) > middleSub) {
              subProcessWithBendPoint = true;
            }
          }
         
          if(targetElement instanceof SubProcess == false || subProcessWithBendPoint == true) {
            Point bendPoint = StylesFactory.eINSTANCE.createPoint();
            bendPoint.setX(sourceX + 20);
            bendPoint.setY(targetY + (targetGraphics.getHeight() / 2));
            connection.getBendpoints().add(bendPoint);
          }
        }
      } else if (targetElement instanceof Gateway) {
        if (((sourceGraphics.getY() + 10) < targetGraphics.getY()
            || (sourceGraphics.getY() - 10) > targetGraphics.getY()) &&
            (sourceGraphics.getX() + sourceGraphics.getWidth()) < targetGraphics.getX()) {
         
          boolean subProcessWithBendPoint = false;
          if(sourceElement instanceof SubProcess) {
            int middleSub = sourceGraphics.getY() + (sourceGraphics.getHeight() / 2);
            if((middleSub + 20) < targetGraphics.getY() || (middleSub - 20) > targetGraphics.getY()) {
              subProcessWithBendPoint = true;
            }
          }
         
          if(sourceElement instanceof SubProcess == false || subProcessWithBendPoint == true) {
            Point bendPoint = StylesFactory.eINSTANCE.createPoint();
            bendPoint.setX(targetX + 20);
            bendPoint.setY(sourceY + (sourceGraphics.getHeight() / 2));
            connection.getBendpoints().add(bendPoint);
          }
        }
      } else if (targetElement instanceof EndEvent) {
        int middleSource = sourceGraphics.getY() + (sourceGraphics.getHeight() / 2);
        int middleTarget = targetGraphics.getY() + (targetGraphics.getHeight() / 2);
        if (((middleSource + 10) < middleTarget &&
            (sourceGraphics.getX() + sourceGraphics.getWidth()) < targetGraphics.getX()) ||
           
            ((middleSource - 10) > middleTarget &&
            (sourceGraphics.getX() + sourceGraphics.getWidth()) < targetGraphics.getX())) {
         
          Point bendPoint = StylesFactory.eINSTANCE.createPoint();
          bendPoint.setX(targetX + (targetGraphics.getWidth() / 2));
          bendPoint.setY(sourceY + (sourceGraphics.getHeight() / 2));
          connection.getBendpoints().add(bendPoint);
        }
      }
    }

    IGaService gaService = Graphiti.getGaService();
    Polyline polyline = gaService.createPolyline(connection);
    polyline.setLineStyle(LineStyle.SOLID);
    polyline.setForeground(Graphiti.getGaService().manageColor(getDiagram(), IColorConstant.BLACK));

    // create link and wire it
    link(connection, addedSequenceFlow);

    // add dynamic text decorator for the reference name
    ConnectionDecorator textDecorator = peCreateService.createConnectionDecorator(connection, true, 0.5, true);
    MultiText text = gaService.createDefaultMultiText(getDiagram(), textDecorator);
    text.setStyle(StyleUtil.getStyleForTask((getDiagram())));
    text.setHorizontalAlignment(Orientation.ALIGNMENT_LEFT);
    text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
    if (OSUtil.getOperatingSystem() == OSEnum.Mac) {
      text.setFont(gaService.manageFont(getDiagram(), text.getFont().getName(), 11));
    }
   
    if(addConContext.getProperty("org.activiti.designer.connectionlabel") != null) {
      GraphicInfo labelLocation = (GraphicInfo) addConContext.getProperty("org.activiti.designer.connectionlabel");
      gaService.setLocation(text, (int)labelLocation.getX(), (int)labelLocation.getY());
    } else {
      gaService.setLocation(text, 10, 0);
    }
   
View Full Code Here

            && context.getNewObject() instanceof Association;
  }

  @Override
  public PictogramElement add(final IAddContext context) {   
    final IAddConnectionContext addConnectionContext = (IAddConnectionContext) context;
    final Association association = (Association) context.getNewObject();
   
    Anchor sourceAnchor = addConnectionContext.getSourceAnchor();
    Anchor targetAnchor = addConnectionContext.getTargetAnchor();
   
    if (sourceAnchor == null) {
      final List<Shape> shapes = getDiagram().getChildren();
     
      for (final Shape shape : shapes) {
        final BaseElement baseElement
          = (BaseElement) getBusinessObjectForPictogramElement(shape.getGraphicsAlgorithm()
                                                                  .getPictogramElement());
        if (baseElement == null || baseElement.getId() == null
                || association.getSourceRef() == null || association.getTargetRef() == null) {
          continue;
        }
       
        if (baseElement.getId().equals(association.getSourceRef())) {
          final List<Anchor> anchors = ((ContainerShape) shape).getAnchors();
          for (final Anchor anchor : anchors) {
            if (anchor instanceof ChopboxAnchor) {
              sourceAnchor = anchor;
             
              break;
            }
          }
        }
       
        if (baseElement.getId().equals(association.getTargetRef())) {
          final List<Anchor> anchors = ((ContainerShape) shape).getAnchors();
          for (final Anchor anchor : anchors) {
            if (anchor instanceof ChopboxAnchor) {
              targetAnchor = anchor;
             
              break;
            }
          }
        }
      }
    }
   
    if (sourceAnchor == null || targetAnchor == null) {
      return null;
    }
   
    final IPeCreateService peCreateService = Graphiti.getPeCreateService();
   
    // CONNECTION WITH POLYLINE
    final FreeFormConnection connection = peCreateService.createFreeFormConnection(getDiagram());
   
    connection.setStart(sourceAnchor);
    connection.setEnd(targetAnchor);
   
    sourceAnchor.getOutgoingConnections().add(connection);
    targetAnchor.getIncomingConnections().add(connection);
   
    Bpmn2MemoryModel model = ModelHandler.getModel(EcoreUtil.getURI(getDiagram()));
   
    BaseElement sourceElement = model.getFlowElement(association.getSourceRef());
    if (sourceElement == null) {
      sourceElement = model.getArtifact(association.getSourceRef());
    }
    BaseElement targetElement = model.getFlowElement(association.getTargetRef());
    if (targetElement == null) {
      targetElement = model.getArtifact(association.getTargetRef());
    }

    final GraphicsAlgorithm sourceGraphics = getPictogramElement(sourceElement).getGraphicsAlgorithm();
    GraphicsAlgorithm targetGraphics = getPictogramElement(targetElement).getGraphicsAlgorithm();
   
    @SuppressWarnings("unchecked")
    List<GraphicInfo> bendpointList = (List<GraphicInfo>) addConnectionContext.getProperty("org.activiti.designer.bendpoints");
  
    if(bendpointList != null && bendpointList.size() >= 0) {
      for (GraphicInfo graphicInfo : bendpointList) {
        Point bendPoint = StylesFactory.eINSTANCE.createPoint();
        bendPoint.setX((int)graphicInfo.getX());
View Full Code Here

TOP

Related Classes of org.eclipse.graphiti.features.context.IAddConnectionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.