/** {@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);
 }
  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();
    }
  }
 /**
  * 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);
               }
             }
           }
         }
       }
     }
   }
 }
  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);
            }
          }
        }
      }
    }
  }
 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;
 }
 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;
 }
 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);
     }
   }
 }
 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;
 }
 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;
 }
    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());
      }
    }
示例#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;
  }
  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;
  }
  // 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;
  }
  private Link createLink(StandardNode source, StandardNode target) {
    if (GraphBTUtil.isAncestor(target, source)) {
      return null;
    }
    if (target.isLeaf()) {
      return null;
    }
    Edge edge = source.getEdge();
    if (edge == null) {
      edge = GraphBTUtil.getBEFactory().createEdge();
      edge.setComposition(Composition.SEQUENTIAL);
      source.setEdge(edge);
      edge.setContainer(source);
    } else {
      for (int i = 0; i < edge.getChildNode().size(); i++) {
        if (edge.getChildNode().get(i).getTarget() == (target)) {
          return null;
        }
      }
      if (edge.getChildNode().size() == 1) {
        HashMap<Integer, String> map = new HashMap<Integer, String>();
        WizardDialog wizardDialog =
            new WizardDialog(
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
                new ManageBranchWizardGraphBtFeature(map, getDiagram()));

        if (wizardDialog.open() != Window.OK) {
          return null;
        }

        edge.setBranch(Branch.get(map.get(1)));

        StandardNode sn = (StandardNode) edge.getChildNode().get(0).getTarget();

        ContainerShape cs = null;
        if (sn == null) {
          return null;
        }
        for (PictogramElement pe :
            Graphiti.getLinkService().getPictogramElements(getDiagram(), sn.getParent())) {
          if (pe instanceof ContainerShape) {
            cs = (ContainerShape) pe;
          }
        }
        //        		ContainerShape cs = (ContainerShape) pe;

        Iterator<Shape> s = cs.getChildren().iterator();
        while (s.hasNext()) {
          Shape n = s.next();

          Object bo =
              Graphiti.getLinkService()
                  .getBusinessObjectForLinkedPictogramElement((PictogramElement) n);
          if (bo instanceof AlternativeClass) {
            updatePictogramElement(n);
          }
        }
      }
    }
    Link l = GraphBTUtil.getBEFactory().createLink();
    l.setSource(source);
    l.setTarget(target);
    edge.getChildNode().add(l);
    target.setParent(source);
    target.setLeaf(true);
    return l;
  }