public IReason updateNeeded(IUpdateContext context) {
    // retrieve name from pictogram model
    String pictogramName = null;
    PictogramElement pictogramElement = context.getPictogramElement();
    if (pictogramElement instanceof ContainerShape) {
      ContainerShape cs = (ContainerShape) pictogramElement;
      for (Shape shape : cs.getChildren()) {
        if (shape.getGraphicsAlgorithm() instanceof Text) {
          Text text = (Text) shape.getGraphicsAlgorithm();
          pictogramName = text.getValue();
        }
      }
    }

    // retrieve name from business model
    String businessName = null;
    Object bo = getBusinessObjectForPictogramElement(pictogramElement);
    if (bo instanceof EClass) {
      EClass eClass = (EClass) bo;
      businessName = eClass.getName();
    }

    // update needed, if names are different
    boolean updateNameNeeded =
        ((pictogramName == null && businessName != null)
            || (pictogramName != null && !pictogramName.equals(businessName)));
    if (updateNameNeeded) {
      return Reason.createTrueReason("Name is out of date");
    } else {
      return Reason.createFalseReason();
    }
  }
Пример #2
0
  @Override
  public void execute(ICustomContext context) {
    PictogramElement[] pes = context.getPictogramElements();
    if (pes != null && pes.length == 1) {
      PictogramElement pe0 = pes[0];
      Object bo = getBusinessObjectForPictogramElement(pe0);
      if (pe0 instanceof ContainerShape && bo instanceof FlowNode) {
        ContainerShape containerShape = (ContainerShape) pe0;
        FlowNode flowNode = (FlowNode) bo;
        try {
          BPMNShape bpmnShape = DIUtils.findBPMNShape(flowNode);
          if (bpmnShape.isIsExpanded()) {
            Bpmn2Preferences preferences = Bpmn2Preferences.getInstance(getDiagram());
            ShapeStyle ss = preferences.getShapeStyle("TASKS");

            // SubProcess is expanded - resize to standard Task size
            // NOTE: children tasks will be set not-visible in LayoutExpandableActivityFeature

            bpmnShape.setIsExpanded(false);

            GraphicsAlgorithm ga = containerShape.getGraphicsAlgorithm();
            ResizeShapeContext resizeContext = new ResizeShapeContext(containerShape);
            IResizeShapeFeature resizeFeature =
                getFeatureProvider().getResizeShapeFeature(resizeContext);
            IDimension oldSize = FeatureSupport.getCollapsedSize(containerShape);
            int oldWidth = ga.getWidth();
            int oldHeight = ga.getHeight();
            FeatureSupport.setExpandedSize(containerShape, oldWidth, oldHeight);

            int newWidth = ss.getDefaultWidth();
            int newHeight = ss.getDefaultHeight();
            if (newWidth < oldSize.getWidth()) oldSize.setWidth(newWidth);
            if (newHeight < oldSize.getHeight()) oldSize.setHeight(newHeight);
            newWidth = oldSize.getWidth();
            newHeight = oldSize.getHeight();
            resizeContext.setX(ga.getX() + oldWidth / 2 - newWidth / 2);
            resizeContext.setY(ga.getY() + oldHeight / 2 - newHeight / 2);
            resizeContext.setWidth(newWidth);
            resizeContext.setHeight(newHeight);
            resizeFeature.resizeShape(resizeContext);

            UpdateContext updateContext = new UpdateContext(containerShape);
            IUpdateFeature updateFeature = getFeatureProvider().getUpdateFeature(updateContext);
            if (updateFeature.updateNeeded(updateContext).toBoolean())
              updateFeature.update(updateContext);

            getDiagramEditor().selectPictogramElements(new PictogramElement[] {});
          }

        } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
  }
 /** {@inheritDoc} */
 @Override
 public GraphicsAlgorithm getSelectionBorder(PictogramElement pe) {
   boolean isFromDsl = SprayLayoutService.isShapeFromDsl(pe);
   if (isFromDsl) {
     ContainerShape container = (ContainerShape) pe;
     if (!container.getChildren().isEmpty()) {
       return container.getChildren().get(0).getGraphicsAlgorithm();
     }
   }
   return super.getSelectionBorder(pe);
 }
  private Point getLocation(ContainerShape containerShape) {
    if (containerShape instanceof Diagram == true) {
      return new Point(
          containerShape.getGraphicsAlgorithm().getX(),
          containerShape.getGraphicsAlgorithm().getY());
    }

    Point location = getLocation(containerShape.getContainer());
    return new Point(
        location.x + containerShape.getGraphicsAlgorithm().getX(),
        location.y + containerShape.getGraphicsAlgorithm().getY());
  }
    private static void updateSPPFigure(SPPRef spp, PictogramElement pe, Color dark, Color bright) {
      ContainerShape container = (ContainerShape) pe;

      // we clear the figure and rebuild it
      GraphicsAlgorithm invisibleRect = pe.getGraphicsAlgorithm();
      invisibleRect.getGraphicsAlgorithmChildren().clear();

      createSPPFigure(spp, false, container, invisibleRect, dark, bright);

      GraphicsAlgorithm ga = container.getChildren().get(0).getGraphicsAlgorithm();
      if (ga instanceof Text) {
        ((Text) ga).setValue(spp.getName());
      }
    }
Пример #6
0
 /**
  * Collects all Shapes and any Connections attached to them, that are children or descendants of
  * the given Lane or Pool container. Only Shapes that are NOT Lanes are collected.
  *
  * @param containerShape the current Pool or Lane shape. This method is recursive and is initially
  *     invoked for the root container.
  * @param descendants the list of descendant Shapes and attached Connections
  * @param includeLanes if true, includes all Lane shapes in the results list
  */
 public static void collectChildren(
     ContainerShape containerShape, List<PictogramElement> descendants, boolean includeLanes) {
   for (PictogramElement pe : containerShape.getChildren()) {
     if (pe instanceof ContainerShape) {
       if (isLane(pe)) {
         if (includeLanes) descendants.add(pe);
         collectChildren((ContainerShape) pe, descendants, includeLanes);
       } else {
         if (isBpmnShape(pe)) {
           descendants.add(pe);
           for (Anchor a : ((ContainerShape) pe).getAnchors()) {
             for (Connection c : a.getIncomingConnections()) {
               if (c instanceof FreeFormConnection && !descendants.contains(c)) {
                 descendants.add(c);
               }
             }
             for (Connection c : a.getOutgoingConnections()) {
               if (c instanceof FreeFormConnection && !descendants.contains(c)) {
                 descendants.add(c);
               }
             }
           }
         }
       }
     }
   }
 }
Пример #7
0
  public static void setContainerChildrenVisible(
      IFeatureProvider fp, ContainerShape container, boolean visible) {
    List<PictogramElement> list = new ArrayList<PictogramElement>();
    list.addAll(container.getChildren());
    for (PictogramElement pe : list) {
      if (ShapeDecoratorUtil.isActivityBorder(pe)) continue;

      if (ShapeDecoratorUtil.isEventSubProcessDecorator(pe)) {
        pe.setVisible(!visible);
      } else pe.setVisible(visible);

      if (visible) FeatureSupport.updateLabel(fp, pe, null);
      if (pe instanceof AnchorContainer) {
        AnchorContainer ac = (AnchorContainer) pe;
        for (Anchor a : ac.getAnchors()) {
          for (Connection c : a.getOutgoingConnections()) {
            c.setVisible(visible);
            if (visible) FeatureSupport.updateLabel(fp, c, null);
            for (ConnectionDecorator decorator : c.getConnectionDecorators()) {
              decorator.setVisible(visible);
            }
          }
        }
      }
    }
  }
Пример #8
0
 public static List<PictogramElement> getContainerDecorators(ContainerShape container) {
   List<PictogramElement> list = new ArrayList<PictogramElement>();
   for (PictogramElement pe : container.getChildren()) {
     if (ShapeDecoratorUtil.isActivityBorder(pe)) list.add(pe);
   }
   return list;
 }
  private PictogramElement addContainerElement(
      BaseElement element, BpmnMemoryModel model, ContainerShape parent) {
    GraphicInfo graphicInfo = model.getBpmnModel().getGraphicInfo(element.getId());
    if (graphicInfo == null) {
      return null;
    }

    final IFeatureProvider featureProvider = getDiagramTypeProvider().getFeatureProvider();

    AddContext context = new AddContext(new AreaContext(), element);
    IAddFeature addFeature = featureProvider.getAddFeature(context);
    context.setNewObject(element);
    context.setSize((int) graphicInfo.getWidth(), (int) graphicInfo.getHeight());
    context.setTargetContainer(parent);

    int x = (int) graphicInfo.getX();
    int y = (int) graphicInfo.getY();

    if (parent instanceof Diagram == false) {
      x = x - parent.getGraphicsAlgorithm().getX();
      y = y - parent.getGraphicsAlgorithm().getY();
    }

    context.setLocation(x, y);

    PictogramElement pictElement = null;
    if (addFeature.canAdd(context)) {
      pictElement = addFeature.add(context);
      featureProvider.link(pictElement, new Object[] {element});
    }

    return pictElement;
  }
Пример #10
0
 public static ContainerShape getRootContainer(ContainerShape container) {
   ContainerShape parent = container.getContainer();
   EObject bo = BusinessObjectUtil.getFirstElementOfType(parent, BaseElement.class);
   if (bo != null && (bo instanceof Lane || bo instanceof Participant)) {
     return getRootContainer(parent);
   }
   return container;
 }
Пример #11
0
  public boolean layout(ILayoutContext context) {
    boolean anythingChanged = false;
    ContainerShape containerShape = (ContainerShape) context.getPictogramElement();
    GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm();
    // the containerGa is the invisible rectangle
    // containing the visible rectangle as its (first and only) child
    GraphicsAlgorithm rectangle = containerGa.getGraphicsAlgorithmChildren().get(0);

    // height of invisible rectangle
    if (containerGa.getHeight() < MIN_HEIGHT) {
      containerGa.setHeight(MIN_HEIGHT);
      anythingChanged = true;
    }

    // height of visible rectangle (same as invisible rectangle)
    if (rectangle.getHeight() != containerGa.getHeight()) {
      rectangle.setHeight(containerGa.getHeight());
      anythingChanged = true;
    }

    // width of invisible rectangle
    if (containerGa.getWidth() < MIN_WIDTH) {
      containerGa.setWidth(MIN_WIDTH);
      anythingChanged = true;
    }

    // width of visible rectangle (smaller than invisible rectangle)
    int rectangleWidth = containerGa.getWidth() - AddNodeFeature.INVISIBLE_RIGHT_SPACE;
    if (rectangle.getWidth() != rectangleWidth) {
      rectangle.setWidth(rectangleWidth);
      anythingChanged = true;
    }

    // width of text and line (same as visible rectangle)
    for (Shape shape : containerShape.getChildren()) {
      GraphicsAlgorithm graphicsAlgorithm = shape.getGraphicsAlgorithm();
      IGaService gaService = Graphiti.getGaService();
      IDimension size = gaService.calculateSize(graphicsAlgorithm);
      if (rectangleWidth != size.getWidth()) {
        gaService.setWidth(graphicsAlgorithm, rectangleWidth);
        anythingChanged = true;
      }
    }

    return anythingChanged;
  }
Пример #12
0
  public static List<ContainerShape> findGroupedShapes(ContainerShape groupShape) {
    Diagram diagram = null;
    EObject parent = groupShape.eContainer();
    while (parent != null) {
      if (parent instanceof Diagram) {
        diagram = (Diagram) parent;
        break;
      }
      parent = parent.eContainer();
    }

    // find all shapes that are inside this Group
    // these will be moved along with the Group
    List<ContainerShape> list = new ArrayList<ContainerShape>();
    if (diagram != null && isGroupShape(groupShape)) {
      TreeIterator<EObject> iter = diagram.eAllContents();
      while (iter.hasNext()) {
        EObject child = iter.next();
        if (child instanceof ContainerShape
            && child != groupShape
            && !list.contains(child)
            && !isLabelShape((ContainerShape) child)) {
          ContainerShape shape = (ContainerShape) child;
          if (isGroupShape(shape)) {
            if (GraphicsUtil.contains(groupShape, shape)) {
              if (!list.contains(shape)) {
                list.add(shape);
              }
            }
          } else if (GraphicsUtil.contains(groupShape, shape)) {
            if (!list.contains(shape)) {
              list.add(shape);
            }
            // find this shape's parent ContainerShape if it has one
            while (!(shape.getContainer() instanceof Diagram)) {
              shape = shape.getContainer();
            }
            if (!list.contains(shape) && shape != groupShape) {
              list.add(shape);
            }
          }
        }
      }
    }
    return list;
  }
Пример #13
0
 public static List<PictogramElement> getPoolOrLaneChildren(ContainerShape containerShape) {
   List<PictogramElement> children = new ArrayList<PictogramElement>();
   for (PictogramElement pe : containerShape.getChildren()) {
     BaseElement be = BusinessObjectUtil.getFirstElementOfType(pe, BaseElement.class);
     if (pe instanceof ContainerShape && !isLane(pe) && be != null) children.add(pe);
   }
   return children;
 }
Пример #14
0
    protected static void createSPPFigure(
        SPPRef spp,
        boolean refspp,
        ContainerShape containerShape,
        GraphicsAlgorithm invisibleRectangle,
        Color darkColor,
        Color brightDolor) {

      boolean relay = ValidationUtil.isRelay(spp);

      int size = refspp ? ITEM_SIZE_SMALL : ITEM_SIZE;
      int line = refspp ? LINE_WIDTH / 2 : LINE_WIDTH;

      Color bg = brightDolor;
      if (refspp) {
        bg = darkColor;
      } else {
        if (relay) bg = brightDolor;
        else bg = darkColor;
      }

      IGaService gaService = Graphiti.getGaService();

      // TODOHRR: depicting SPPs as diamond using polygon didn't work
      //			int s2 = size/2;
      //			int xy[] = new int[] { s2, 0, size, s2, s2, size, 0, s2};
      //			Polygon rect = gaService.createPolygon(invisibleRectangle, xy);
      //			rect.setForeground(darkColor);
      //			rect.setBackground(bg);
      //			rect.setLineWidth(line);
      //			gaService.setLocation(rect, s2, s2);
      // Rectangle rect = gaService.createRectangle(invisibleRectangle);

      Ellipse rect = gaService.createEllipse(invisibleRectangle);
      rect.setForeground(darkColor);
      rect.setBackground(bg);
      rect.setLineWidth(line);
      gaService.setLocationAndSize(rect, size / 2, size / 2, size, size);

      if (containerShape.getAnchors().isEmpty()) {
        // here we place our anchor
        IPeCreateService peCreateService = Graphiti.getPeCreateService();
        //				FixPointAnchor anchor = peCreateService.createFixPointAnchor(containerShape);
        //				anchor.setLocation(gaService.createPoint(xy[0], xy[1]));
        //				anchor = peCreateService.createFixPointAnchor(containerShape);
        //				anchor.setLocation(gaService.createPoint(xy[2], xy[3]));
        //				anchor = peCreateService.createFixPointAnchor(containerShape);
        //				anchor.setLocation(gaService.createPoint(xy[4], xy[5]));
        //				anchor = peCreateService.createFixPointAnchor(containerShape);
        //				anchor.setLocation(gaService.createPoint(xy[6], xy[7]));
        // TODOHRR:  EllipseAnchor would be nice
        ChopboxAnchor anchor = peCreateService.createChopboxAnchor(containerShape);
        anchor.setReferencedGraphicsAlgorithm(rect);
      } else {
        // we just set the referenced GA
        // containerShape.getAnchors().get(0).setReferencedGraphicsAlgorithm(rect);
      }
    }
  @Override
  public IReason updateNeeded(IUpdateContext context) {
    if (!canUpdate(context)) {
      return Reason.createFalseReason();
    }

    ContainerShape cs = (ContainerShape) context.getPictogramElement();
    Reference reference = (Reference) getBusinessObjectForPictogramElement(cs);

    // make sure the component still exists in the model
    if (!GraphitiInternal.getEmfService().isObjectAlive(reference)) {
      return Reason.createTrueReason(
          String.format("Reference {0} has been removed.", reference.getName()));
    }

    // retrieve name from pictogram model
    String pictogramName = null;
    Text foundText = GraphitiUtil.findChildGA(cs.getGraphicsAlgorithm(), Text.class);
    if (foundText != null) {
      pictogramName = foundText.getValue();
    }

    // update needed, if names are different
    String businessName = reference.getName();
    boolean updateNameNeeded =
        ((pictogramName == null && businessName != null)
            || (pictogramName != null && !pictogramName.contentEquals(businessName)));
    if (updateNameNeeded) {
      return Reason.createTrueReason("Reference name is out of date");
    }

    // check the wiring
    final Set<Contract> existingConnections = getExistingConnections(cs);
    for (ComponentReference promotedReference : reference.getPromote()) {
      if (promotedReference != null && !existingConnections.remove(promotedReference)) {
        return Reason.createTrueReason("Update connections.");
      }
    }

    if (existingConnections.size() > 0) {
      return Reason.createTrueReason("Update connections.");
    }

    return Reason.createFalseReason();
  }
 protected void linkShapes(ContainerShape conShape, Component addedModelElement) {
   link(conShape, addedModelElement);
   for (Shape childShape : conShape.getChildren()) {
     if (childShape instanceof ContainerShape) {
       linkShapes((ContainerShape) childShape, addedModelElement);
     } else {
       link(childShape, addedModelElement);
     }
   }
 }
Пример #17
0
 public static List<PictogramElement> getContainerChildren(ContainerShape container) {
   List<PictogramElement> list = new ArrayList<PictogramElement>();
   for (PictogramElement pe : container.getChildren()) {
     if (ShapeDecoratorUtil.isActivityBorder(pe)) continue;
     if (ShapeDecoratorUtil.isValidationDecorator(pe)) continue;
     if (isLabelShape(pe)) continue;
     list.add(pe);
   }
   return list;
 }
 protected List<Shape> getFlowElementChildren(ContainerShape containerShape) {
   List<Shape> children = new ArrayList<Shape>();
   for (Shape s : containerShape.getChildren()) {
     FlowElement bo = BusinessObjectUtil.getFirstElementOfType(s, FlowElement.class);
     if (s instanceof ContainerShape && bo != null) {
       children.add(s);
     }
   }
   return children;
 }
Пример #19
0
  public static void updateCategoryValues(IFeatureProvider fp, List<ContainerShape> shapes) {
    // Update CategoryValues for SequenceFlows also
    List<Connection> connections = new ArrayList<Connection>();
    for (ContainerShape cs : shapes) {
      updateCategoryValues(fp, cs);

      for (Anchor a : cs.getAnchors()) {
        for (Connection c : a.getIncomingConnections()) {
          if (!connections.contains(c)) connections.add(c);
        }
        for (Connection c : a.getOutgoingConnections()) {
          if (!connections.contains(c)) connections.add(c);
        }
      }
    }
    for (Connection c : connections) {
      updateCategoryValues(fp, c);
    }
  }
Пример #20
0
  @Override
  public void delete(IDeleteContext context) {
    ContainerShape laneContainerShape = (ContainerShape) context.getPictogramElement();
    ContainerShape parentContainerShape = laneContainerShape.getContainer();

    if (parentContainerShape != null) {
      boolean before = false;
      ContainerShape neighborContainerShape = FeatureSupport.getLaneAfter(laneContainerShape);
      if (neighborContainerShape == null) {
        neighborContainerShape = FeatureSupport.getLaneBefore(laneContainerShape);
        if (neighborContainerShape == null) {
          super.delete(context);
          return;
        } else {
          before = true;
        }
      }
      boolean isHorizontal = FeatureSupport.isHorizontal(laneContainerShape);
      GraphicsAlgorithm ga = laneContainerShape.getGraphicsAlgorithm();
      GraphicsAlgorithm neighborGA = neighborContainerShape.getGraphicsAlgorithm();
      ResizeShapeContext newContext = new ResizeShapeContext(neighborContainerShape);
      if (!before) {
        Graphiti.getGaService().setLocation(neighborGA, ga.getX(), ga.getY());
      }
      newContext.setLocation(neighborGA.getX(), neighborGA.getY());
      if (isHorizontal) {
        newContext.setHeight(neighborGA.getHeight() + ga.getHeight());
        newContext.setWidth(neighborGA.getWidth());
      } else {
        newContext.setHeight(neighborGA.getHeight());
        newContext.setWidth(neighborGA.getWidth() + ga.getWidth());
      }

      IResizeShapeFeature resizeFeature = getFeatureProvider().getResizeShapeFeature(newContext);
      if (resizeFeature.canResizeShape(newContext)) {
        super.delete(context);
        resizeFeature.resizeShape(newContext);
        return;
      }
    }
    super.delete(context);
  }
  /** {@inheritDoc} */
  @Override
  public PictogramElement add(final IAddContext context) {
    final Component addedModelElement = (Component) context.getNewObject();
    // NEW stuff
    Object target = getBusinessObjectForPictogramElement(context.getTargetContainer());
    final ContainerShape targetContainer = context.getTargetContainer();
    final ISprayStyle style = new BcmSpray3DefaultStyle();
    final ISprayShape shape = new ComponentShape(getFeatureProvider());
    final ContainerShape conShape = shape.getShape(targetContainer, style);
    final IGaService gaService = Graphiti.getGaService();
    gaService.setLocation(conShape.getGraphicsAlgorithm(), context.getX(), context.getY());
    link(conShape, addedModelElement);
    linkShapes(conShape, addedModelElement);

    setDoneChanges(true);
    updatePictogramElement(conShape);
    layout(conShape);

    return conShape;
  }
  // Creates the business object for the relationship
  @Override
  public Connection create(ICreateConnectionContext context) {
    Connection newConnection = null;
    // get TNodeTemplates which should be connected
    TNodeTemplate source = getTNodeTemplate(context.getSourceAnchor());
    TNodeTemplate target = getTNodeTemplate(context.getTargetAnchor());
    if (source != null && target != null) {
      // create new business object
      TRelationshipTemplate newClass = ToscaFactory.eINSTANCE.createTRelationshipTemplate();
      newClass.setName("Relation");
      newClass.setId(("R" + (Integer) newClass.hashCode()).toString());
      newClass.setType(new QName("Bidirected"));
      //      newClass.setType( new QName("Peer - Peer") );
      SourceElementType se = ToscaFactory.eINSTANCE.createSourceElementType();
      se.setRef(source.getId());
      newClass.setSourceElement(se);
      TargetElementType te = ToscaFactory.eINSTANCE.createTargetElementType();
      te.setRef(target.getId());
      newClass.setTargetElement(te);

      ContainerShape sourceContainer = (ContainerShape) context.getSourcePictogramElement();
      Object parentObject =
          getFeatureProvider().getBusinessObjectForPictogramElement(sourceContainer.getContainer());
      TServiceTemplate serviceTemplate = null;
      if (parentObject == null) return null;
      if (parentObject instanceof TServiceTemplate) {
        serviceTemplate = (TServiceTemplate) parentObject;
      }
      TTopologyTemplate topology = null;
      topology = serviceTemplate.getTopologyTemplate();
      topology.getRelationshipTemplate().add(newClass);
      // add connection for business object
      AddConnectionContext addContext =
          new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor());
      addContext.setNewObject(newClass);
      newConnection = (Connection) getFeatureProvider().addIfPossible(addContext);
    }
    return newConnection;
  }
  private void resizeLaneWidth(IResizeShapeContext context) {
    ContainerShape participantShape = (ContainerShape) context.getShape();
    GraphicsAlgorithm ga = participantShape.getGraphicsAlgorithm();

    int dHeight = context.getHeight() - ga.getHeight();
    int dWidth = context.getWidth() - ga.getWidth();

    if ((dWidth != 0 && FeatureSupport.isHorizontal(participantShape))
        || (dHeight != 0 && !FeatureSupport.isHorizontal(participantShape))) {
      List<PictogramElement> childrenShapes =
          FeatureSupport.getChildsOfBusinessObjectType(participantShape, Lane.class);
      for (PictogramElement currentPicElem : childrenShapes) {
        if (currentPicElem instanceof ContainerShape) {
          ContainerShape currentContainerShape = (ContainerShape) currentPicElem;
          GraphicsAlgorithm laneGA = currentContainerShape.getGraphicsAlgorithm();

          ResizeShapeContext newContext = new ResizeShapeContext(currentContainerShape);

          newContext.setLocation(laneGA.getX(), laneGA.getY());
          if (FeatureSupport.isHorizontal(participantShape)) {
            newContext.setWidth(laneGA.getWidth() + dWidth);
            newContext.setHeight(laneGA.getHeight());
          } else {
            newContext.setHeight(laneGA.getHeight() + dHeight);
            newContext.setWidth(laneGA.getWidth());
          }

          newContext.putProperty(POOL_RESIZE_PROPERTY, true);

          IResizeShapeFeature resizeFeature =
              getFeatureProvider().getResizeShapeFeature(newContext);
          if (resizeFeature.canResizeShape(newContext)) {
            resizeFeature.resizeShape(newContext);
          }
        }
      }
    }
  }
Пример #24
0
  public boolean layout(ILayoutContext context) {
    boolean anythingChanged = false;
    ContainerShape containerShape = (ContainerShape) context.getPictogramElement();
    GraphicsAlgorithm containerGa = containerShape.getGraphicsAlgorithm();

    // height
    if (containerGa.getHeight() < MIN_HEIGHT) {
      containerGa.setHeight(MIN_HEIGHT);
      anythingChanged = true;
    }

    // width
    if (containerGa.getWidth() < MIN_WIDTH) {
      containerGa.setWidth(MIN_WIDTH);
      anythingChanged = true;
    }

    int containerWidth = containerGa.getWidth();

    for (Shape shape : containerShape.getChildren()) {
      GraphicsAlgorithm graphicsAlgorithm = shape.getGraphicsAlgorithm();
      IGaService gaService = Graphiti.getGaService();
      IDimension size = gaService.calculateSize(graphicsAlgorithm);
      if (containerWidth != size.getWidth()) {
        if (graphicsAlgorithm instanceof Polyline) {
          Polyline polyline = (Polyline) graphicsAlgorithm;
          Point secondPoint = polyline.getPoints().get(1);
          Point newSecondPoint = gaService.createPoint(containerWidth, secondPoint.getY());
          polyline.getPoints().set(1, newSecondPoint);
          anythingChanged = true;
        } else {
          gaService.setWidth(graphicsAlgorithm, containerWidth);
          anythingChanged = true;
        }
      }
    }
    return anythingChanged;
  }
  public boolean update(IUpdateContext context) {
    // retrieve name from business model
    String businessName = null;
    PictogramElement pictogramElement = context.getPictogramElement();
    Object bo = getBusinessObjectForPictogramElement(pictogramElement);
    if (bo instanceof EClass) {
      EClass eClass = (EClass) bo;
      businessName = eClass.getName();
    }

    // Set name in pictogram model
    if (pictogramElement instanceof ContainerShape) {
      ContainerShape cs = (ContainerShape) pictogramElement;
      for (Shape shape : cs.getChildren()) {
        if (shape.getGraphicsAlgorithm() instanceof Text) {
          Text text = (Text) shape.getGraphicsAlgorithm();
          text.setValue(businessName);
          return true;
        }
      }
    }

    return false;
  }
Пример #26
0
  public static boolean isHorizontal(ContainerShape container) {
    EObject parent = container.eContainer();
    if (parent instanceof PictogramElement) {
      // participant bands are always "vertical" so that
      // the label is drawn horizontally by the LayoutFeature
      if (BusinessObjectUtil.getFirstElementOfType(
              (PictogramElement) parent, ChoreographyActivity.class)
          != null) return false;
    }

    String v =
        Graphiti.getPeService()
            .getPropertyValue(container, GraphitiConstants.IS_HORIZONTAL_PROPERTY);
    if (v == null) {
      BPMNShape bpmnShape =
          DIUtils.findBPMNShape(BusinessObjectUtil.getFirstBaseElement(container));
      if (bpmnShape != null) return bpmnShape.isIsHorizontal();
      return Bpmn2Preferences.getInstance(container).isHorizontalDefault();
    }
    return Boolean.parseBoolean(v);
  }
  @Override
  public void resizeShape(IResizeShapeContext context) {

    ResizeShapeContext resizeShapeContext = (ResizeShapeContext) context;

    ContainerShape containerShape = (ContainerShape) context.getPictogramElement();
    Activity activity = BusinessObjectUtil.getFirstElementOfType(containerShape, Activity.class);
    try {
      BPMNShape shape =
          (BPMNShape)
              ModelHandlerLocator.getModelHandler(getDiagram().eResource()).findDIElement(activity);

      if (shape.isIsExpanded()) {

        // SubProcess is expanded

        GraphicsAlgorithm parentGa = containerShape.getGraphicsAlgorithm();
        int newWidth = resizeShapeContext.getWidth();
        int newHeight = resizeShapeContext.getHeight();
        SizeCalculator sizeCalc = new SizeCalculator(containerShape);
        int shiftX = sizeCalc.shiftX;
        int shiftY = sizeCalc.shiftY;
        int minWidth = sizeCalc.minWidth;
        int minHeight = sizeCalc.minHeight;

        if (shiftX < 0) {
          for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) {
            GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm();
            if (childGa != null) {
              int x = childGa.getX() - shiftX + MARGIN;
              childGa.setX(x);
            }
          }
          resizeShapeContext.setX(resizeShapeContext.getX() + shiftX - MARGIN);
          shiftX = MARGIN;
        }

        if (shiftY < 0) {
          for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) {
            GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm();
            if (childGa != null) {
              int y = childGa.getY() - shiftY + MARGIN;
              childGa.setY(y);
            }
          }
          resizeShapeContext.setY(resizeShapeContext.getY() + shiftY - MARGIN);
          shiftX = MARGIN;
        }

        if (shiftX < MARGIN) shiftX = MARGIN;
        if (shiftY < MARGIN) shiftY = MARGIN;
        minWidth += 2 * MARGIN;
        minHeight += 2 * MARGIN;

        if (newWidth < minWidth) {
          parentGa.setWidth(minWidth);
        }
        if (newWidth < shiftX + minWidth) {
          int shift = shiftX + minWidth - newWidth;
          if (shift > shiftX - MARGIN) {
            shift = shiftX - MARGIN;
          }
          if (shift > 0) {
            for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) {
              GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm();
              if (childGa != null) {
                int x = childGa.getX() - shift;
                childGa.setX(x);
              }
            }
          }
        }
        if (newHeight < minHeight) {
          parentGa.setHeight(minHeight);
        }
        if (newHeight < shiftY + minHeight) {
          int shift = shiftY + minHeight - newHeight;
          if (shift > shiftY - MARGIN) {
            shift = shiftY - MARGIN;
          }
          if (shift > 0) {
            for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) {
              GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm();
              if (childGa != null) {
                int y = childGa.getY() - shift;
                childGa.setY(y);
              }
            }
          }
        }

        if (resizeShapeContext.getWidth() < minWidth) resizeShapeContext.setWidth(minWidth);
        if (resizeShapeContext.getHeight() < minHeight) resizeShapeContext.setHeight(minHeight);
      } else {

        // SubProcess is collapsed

        for (PictogramElement pe : FeatureSupport.getContainerDecorators(containerShape)) {
          GraphicsAlgorithm childGa = pe.getGraphicsAlgorithm();
          if (childGa != null) {
            childGa.setWidth(GraphicsUtil.getActivitySize(getDiagram()).getWidth());
            childGa.setHeight(GraphicsUtil.getActivitySize(getDiagram()).getHeight());
          }
        }

        resizeShapeContext.setWidth(GraphicsUtil.getActivitySize(getDiagram()).getWidth());
        resizeShapeContext.setHeight(GraphicsUtil.getActivitySize(getDiagram()).getHeight());
      }

    } catch (Exception e) {
      Activator.logError(e);
    }
    Graphiti.getPeService().sendToBack(containerShape);

    super.resizeShape(context);
  }
  private void drawAssociation(Association association, BpmnMemoryModel model) {

    Anchor sourceAnchor = null;
    Anchor targetAnchor = null;
    BaseElement sourceElement = model.getFlowElement(association.getSourceRef());
    if (sourceElement == null) {
      sourceElement = model.getArtifact(association.getSourceRef());
    }
    if (sourceElement == null) {
      return;
    }
    ContainerShape sourceShape =
        (ContainerShape)
            getDiagramTypeProvider()
                .getFeatureProvider()
                .getPictogramElementForBusinessObject(sourceElement);

    if (sourceShape == null) {
      return;
    }

    EList<Anchor> anchorList = sourceShape.getAnchors();
    for (Anchor anchor : anchorList) {
      if (anchor instanceof ChopboxAnchor) {
        sourceAnchor = anchor;
        break;
      }
    }

    BaseElement targetElement = model.getFlowElement(association.getTargetRef());
    if (targetElement == null) {
      targetElement = model.getArtifact(association.getTargetRef());
    }
    if (targetElement == null) {
      return;
    }
    ContainerShape targetShape =
        (ContainerShape)
            getDiagramTypeProvider()
                .getFeatureProvider()
                .getPictogramElementForBusinessObject(targetElement);

    if (targetShape == null) {
      return;
    }

    anchorList = targetShape.getAnchors();
    for (Anchor anchor : anchorList) {
      if (anchor instanceof ChopboxAnchor) {
        targetAnchor = anchor;
        break;
      }
    }

    AddConnectionContext addContext = new AddConnectionContext(sourceAnchor, targetAnchor);

    List<GraphicInfo> bendpointList = new ArrayList<GraphicInfo>();
    if (model.getBpmnModel().getFlowLocationMap().containsKey(association.getId())) {
      List<GraphicInfo> pointList =
          model.getBpmnModel().getFlowLocationGraphicInfo(association.getId());
      if (pointList.size() > 2) {
        for (int i = 1; i < pointList.size() - 1; i++) {
          bendpointList.add(pointList.get(i));
        }
      }
    }

    addContext.putProperty("org.activiti.designer.bendpoints", bendpointList);

    addContext.setNewObject(association);
    getDiagramTypeProvider().getFeatureProvider().addIfPossible(addContext);
  }
  protected void drawMessageFlows(
      final Collection<MessageFlow> messageFlows, final BpmnMemoryModel model) {

    for (final MessageFlow messageFlow : messageFlows) {

      Anchor sourceAnchor = null;
      Anchor targetAnchor = null;
      ContainerShape sourceShape =
          (ContainerShape)
              getDiagramTypeProvider()
                  .getFeatureProvider()
                  .getPictogramElementForBusinessObject(
                      model.getFlowElement(messageFlow.getSourceRef()));

      if (sourceShape == null) {
        continue;
      }

      EList<Anchor> anchorList = sourceShape.getAnchors();
      for (Anchor anchor : anchorList) {
        if (anchor instanceof ChopboxAnchor) {
          sourceAnchor = anchor;
          break;
        }
      }

      ContainerShape targetShape =
          (ContainerShape)
              getDiagramTypeProvider()
                  .getFeatureProvider()
                  .getPictogramElementForBusinessObject(
                      model.getFlowElement(messageFlow.getTargetRef()));

      if (targetShape == null) {
        continue;
      }

      anchorList = targetShape.getAnchors();
      for (Anchor anchor : anchorList) {
        if (anchor instanceof ChopboxAnchor) {
          targetAnchor = anchor;
          break;
        }
      }

      AddConnectionContext addContext = new AddConnectionContext(sourceAnchor, targetAnchor);

      List<GraphicInfo> bendpointList = new ArrayList<GraphicInfo>();
      if (model.getBpmnModel().getFlowLocationMap().containsKey(messageFlow.getId())) {
        List<GraphicInfo> pointList =
            model.getBpmnModel().getFlowLocationGraphicInfo(messageFlow.getId());
        if (pointList.size() > 2) {
          for (int i = 1; i < pointList.size() - 1; i++) {
            bendpointList.add(pointList.get(i));
          }
        }
      }
      addContext.putProperty("org.activiti.designer.bendpoints", bendpointList);
      addContext.putProperty(
          "org.activiti.designer.connectionlabel",
          model.getBpmnModel().getLabelGraphicInfo(messageFlow.getId()));

      addContext.setNewObject(messageFlow);
      getDiagramTypeProvider().getFeatureProvider().addIfPossible(addContext);
    }
  }
Пример #30
0
  // Adds a User Application figure to the target object
  @Override
  public PictogramElement add(final IAddContext context) {

    TDeploymentArtifact addedClass = (TDeploymentArtifact) context.getNewObject();

    ContainerShape targetDiagram = (ContainerShape) context.getTargetContainer();
    Object[] targetDiagrams = targetDiagram.getChildren().toArray();
    int ySD = 0;
    int interdist = 0;
    for (int i = 0; i < targetDiagrams.length; i++) {
      Object o = getBusinessObjectForPictogramElement((Shape) targetDiagrams[i]);
      if (o instanceof UserApplication) interdist = 3;
    }
    for (int i = 0; i < targetDiagrams.length; i++) {
      Object o = getBusinessObjectForPictogramElement((Shape) targetDiagrams[i]);
      if (((Shape) targetDiagrams[i]).getGraphicsAlgorithm() instanceof Rectangle
          || (o instanceof SoftwareDependency)) {
        if (((Shape) targetDiagrams[i]).getGraphicsAlgorithm() instanceof Rectangle) {
          ySD = ((Shape) targetDiagrams[i]).getGraphicsAlgorithm().getY();
        }
        ((Shape) targetDiagrams[i])
            .getGraphicsAlgorithm()
            .setY(((Shape) targetDiagrams[i]).getGraphicsAlgorithm().getY() + 20 + interdist);
      }
    }
    // CONTAINER SHAPE WITH ROUNDED RECTANGLE
    IPeCreateService peCreateService = Graphiti.getPeCreateService();
    ContainerShape containerShape = peCreateService.createContainerShape(targetDiagram, true);
    final int width = StyleUtil.SOFT_DEPENDENCY_WIDTH;
    final int height = 20;
    IGaService gaService = Graphiti.getGaService();
    RoundedRectangle roundedRectangle;
    {
      // create and set graphics algorithm
      int x = (StyleUtil.APP_COMPONENT_WIDTH - width) / 2;
      roundedRectangle = gaService.createRoundedRectangle(containerShape, 5, 5);
      roundedRectangle.setForeground(manageColor(E_CLASS_FOREGROUND));
      roundedRectangle.setBackground(manageColor(E_CLASS_BACKGROUND));
      roundedRectangle.setLineWidth(2);
      gaService.setLocationAndSize(roundedRectangle, x, ySD - 10 + interdist, width, height);
      if (addedClass.eResource() == null) {
        getDiagram().eResource().getContents().add(addedClass);
      }
      // create link and wire it
      link(containerShape, addedClass);
    }
    // SHAPE WITH LINE
    {
      // create shape for line
      Shape shape = peCreateService.createShape(containerShape, false);
      // create and set graphics algorithm
      Polyline polyline = gaService.createPolyline(shape, new int[] {0, 20, width, 20});
      polyline.setForeground(manageColor(E_CLASS_FOREGROUND));
      polyline.setLineWidth(2);
    }
    // SHAPE WITH TEXT
    {
      // create shape for text
      Shape shape = peCreateService.createShape(containerShape, false);
      // create and set text graphics algorithm
      Text text = gaService.createText(shape, addedClass.getName());
      text.setForeground(manageColor(E_CLASS_TEXT_FOREGROUND));
      text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
      // vertical alignment has as default value "center"
      text.setFont(gaService.manageDefaultFont(getDiagram(), false, true));
      gaService.setLocationAndSize(text, 0, 0, width, 20);
      // create link and wire it
      link(shape, addedClass);
    }
    return containerShape;
  }