@Override
  protected void postMoveShape(final IMoveShapeContext context) {
    super.postMoveShape(context);
    PictogramElement containerShape = context.getPictogramElement();
    Activity activity = BusinessObjectUtil.getFirstElementOfType(containerShape, Activity.class);
    GraphicsUtil.sendToFront(context.getShape());

    new AbstractBoundaryEventOperation() {
      @Override
      protected void doWorkInternal(ContainerShape container) {
        GraphicsAlgorithm ga = container.getGraphicsAlgorithm();

        MoveShapeContext newContext = new MoveShapeContext(container);
        newContext.setDeltaX(context.getDeltaX());
        newContext.setDeltaY(context.getDeltaY());
        newContext.setSourceContainer(context.getSourceContainer());
        newContext.setTargetContainer(context.getTargetContainer());
        newContext.setTargetConnection(context.getTargetConnection());
        newContext.setLocation(ga.getX(), ga.getY());
        newContext.putProperty(ACTIVITY_MOVE_PROPERTY, true);

        IMoveShapeFeature moveFeature = getFeatureProvider().getMoveShapeFeature(newContext);
        if (moveFeature.canMoveShape(newContext)) {
          moveFeature.moveShape(newContext);
        }
      }
    }.doWork(activity, getDiagram());

    if (containerShape.eContainer() instanceof ContainerShape) {
      PictogramElement pe = (PictogramElement) containerShape.eContainer();
      if (BusinessObjectUtil.containsElementOfType(pe, SubProcess.class)) {
        layoutPictogramElement(pe);
      }
    }
  }
  public void paste(IPasteContext context) {
    // we already verified, that we paste directly in the diagram
    KickstartProcessMemoryModel model =
        ModelHandler.getKickstartProcessModel(EcoreUtil.getURI(getDiagram()));
    List<FlowElement> copyList = model.getClipboard();

    for (FlowElement element : copyList) {
      FlowElement clone = CloneUtil.clone(element, getDiagram());

      AddContext addContext = new AddContext(new AreaContext(), clone);
      IAddFeature addFeature = getFeatureProvider().getAddFeature(addContext);
      PictogramElement pictogram =
          getFeatureProvider().getPictogramElementForBusinessObject(element);
      addContext.setLocation(
          pictogram.getGraphicsAlgorithm().getX() + PASTE_OFFSET,
          pictogram.getGraphicsAlgorithm().getY() + PASTE_OFFSET);
      addContext.setSize(
          pictogram.getGraphicsAlgorithm().getWidth(),
          pictogram.getGraphicsAlgorithm().getHeight());
      addContext.setTargetContainer(getDiagram());
      if (addFeature.canAdd(addContext)) {
        addFeature.add(addContext);
      }
    }
  }
  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);
            }
          }
        }
      }
    }
  }
    private void calculate() {
      int minX = Integer.MAX_VALUE;
      int minY = Integer.MAX_VALUE;
      minWidth = 0;
      minHeight = 0;

      for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) {
        GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
        if (ga != null) {
          int x = ga.getX();
          int y = ga.getY();
          if (x < minX) minX = x;
          if (y < minY) minY = y;
        }
      }

      shiftX = minX;
      shiftY = minY;

      for (PictogramElement pe : FeatureSupport.getContainerChildren(containerShape)) {
        GraphicsAlgorithm ga = pe.getGraphicsAlgorithm();
        if (ga != null) {
          int w = ga.getX() - minX + ga.getWidth();
          int h = ga.getY() - minY + ga.getHeight();
          if (w > minWidth) minWidth = w;
          if (h > minHeight) minHeight = h;
        }
      }
      if (minWidth <= 0) minWidth = GraphicsUtil.TASK_DEFAULT_WIDTH;
      if (minHeight <= 0) minHeight = GraphicsUtil.TASK_DEFAULT_HEIGHT;
    }
 public boolean canLayout(ILayoutContext context) {
   // return true, if pictogram element is linked to an EClass
   PictogramElement pe = context.getPictogramElement();
   if (!(pe instanceof ContainerShape)) return false;
   EList<EObject> businessObjects = pe.getLink().getBusinessObjects();
   return businessObjects.size() == 1 && businessObjects.get(0) instanceof EClass;
 }
  public static void updateDIShape(PictogramElement element) {

    PictogramLink link = element.getLink();
    if (link == null) {
      return;
    }

    BPMNShape bpmnShape = BusinessObjectUtil.getFirstElementOfType(element, BPMNShape.class);
    if (bpmnShape == null) {
      return;
    }

    ILocation loc = Graphiti.getLayoutService().getLocationRelativeToDiagram((Shape) element);
    Bounds bounds = bpmnShape.getBounds();

    bounds.setX(loc.getX());
    bounds.setY(loc.getY());

    GraphicsAlgorithm graphicsAlgorithm = element.getGraphicsAlgorithm();
    IDimension size = Graphiti.getGaService().calculateSize(graphicsAlgorithm);
    bounds.setHeight(size.getHeight());
    bounds.setWidth(size.getWidth());

    if (element instanceof ContainerShape) {
      EList<Shape> children = ((ContainerShape) element).getChildren();
      for (Shape shape : children) {
        if (shape instanceof ContainerShape) {
          updateDIShape(shape);
        }
      }
    }
  }
  public void execute(ICustomContext context) {
    if (context.getPictogramElements() == null) return;

    for (final PictogramElement pictogramElement : context.getPictogramElements()) {
      if (getBusinessObjectForPictogramElement(pictogramElement) == null) continue;
      final Object boObject = getBusinessObjectForPictogramElement(pictogramElement);
      if (boObject instanceof SequenceFlow == true) {
        final SequenceFlow sequenceFlow = (SequenceFlow) boObject;

        getDiagram().getPictogramLinks().remove(pictogramElement.getLink());
        getDiagram().getConnections().remove(pictogramElement);
        if (sequenceFlow.getSourceRef() != null) {
          sequenceFlow.getSourceRef().getOutgoing().remove(sequenceFlow);
        }
        if (sequenceFlow.getTargetRef() != null) {
          sequenceFlow.getTargetRef().getIncoming().remove(sequenceFlow);
        }

        List<Process> processes =
            ModelHandler.getModel(EcoreUtil.getURI(getDiagram())).getProcesses();
        for (Process process : processes) {
          process.getFlowElements().remove(sequenceFlow);
          removeFlow(sequenceFlow, process.getFlowElements());
        }
      }
    }
  }
  /** {@inheritDoc} */
  @Override
  public void paste(IPasteContext context) {
    // already verified, that pasting is allowed just directly in the diagram
    PictogramElement[] pes = context.getPictogramElements();
    Diagram diagram = (Diagram) pes[0];

    // get the PictogramElements from the clipboard and the linked business object.
    Object[] objects = getFromClipboard();
    for (Object object : objects) {
      PictogramElement pictogramElement = (PictogramElement) object;
      rootCon boRef = (rootCon) getBusinessObjectForPictogramElement(pictogramElement);
      rootCon bo = EcoreUtil.copy(boRef);
      addBusinessObjectToContainer(bo, pictogramElement);

      // create a new AddContext for the creation of a new shape.
      AddContext ac = new AddContext(new AddContext(), bo);
      ac.setLocation(0, 0); // for simplicity paste at (0, 0)
      ac.setTargetContainer(diagram); // paste on diagram
      // copy all properties from the shape (e.g. ALIAS etc.)
      for (Property prop : pictogramElement.getProperties()) {
        ac.putProperty(prop.getKey(), prop.getValue());
      }
      getFeatureProvider().addIfPossible(ac);
    }
  }
Esempio n. 9
0
 private void movePin(Pin pin, IMoveShapeContext context) {
   PictogramElement pinShape = getPinShape(pin);
   if (pinShape != null) {
     GraphicsAlgorithm pinArea = pinShape.getGraphicsAlgorithm();
     pinArea.setX(pinArea.getX() + context.getDeltaX());
     pinArea.setY(pinArea.getY() + context.getDeltaY());
   }
 }
Esempio n. 10
0
  public static boolean canApplyTo(PictogramElement element) {
    if (element.getLink() == null || !(element instanceof ContainerShape)) {
      return false;
    }

    EList<EObject> objects = element.getLink().getBusinessObjects();

    for (EObject eObject : objects) {
      if (eObject instanceof Event && !(eObject instanceof BoundaryEvent)) {
        return true;
      }
    }

    return false;
  }
Esempio n. 11
0
 private static <T> T getBusinessObjectByClass(PictogramElement pelem, Class<T> class1) {
   PictogramLink link = pelem.getLink();
   if (link == null) return null;
   for (EObject businessObject : link.getBusinessObjects()) {
     if (class1.isAssignableFrom(businessObject.getClass())) return (T) businessObject;
   }
   return null;
 }
 private File getFileDomainObject(IContext context) {
   if (context instanceof ICustomContext) {
     PictogramElement[] pictogramElements = ((ICustomContext) context).getPictogramElements();
     if (pictogramElements.length == 1) {
       PictogramElement pictogramElement = pictogramElements[0];
       Object domainObject = getBusinessObjectForPictogramElement(pictogramElement);
       if (domainObject instanceof File) {
         if (pictogramElement instanceof Shape
             && pictogramElement.eContainer() instanceof ContainerShape
             && pictogramElement.eContainer().eContainer() instanceof ContainerShape) {
           if (getBusinessObjectForPictogramElement(
                   (ContainerShape) pictogramElement.eContainer().eContainer())
               instanceof Folder) {
             return (File) domainObject;
           }
         }
       }
     }
   }
   return null;
 }
  @Override
  public Connection create(ICreateConnectionContext context) {
    Connection newConnection = null;
    // get EClasses which should be connected
    StandardNode source = getStandardNode(context.getSourcePictogramElement());
    StandardNode target = getStandardNode(context.getTargetPictogramElement());

    if (source != null && target != null && target != source) {
      // create new business object

      Link l = createLink(source, target);
      if (l == null) {
        return null;
      }

      // add connection for business object
      AddConnectionContext addContext =
          new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor());
      addContext.setNewObject(l);
      newConnection = (Connection) getFeatureProvider().addIfPossible(addContext);

      PictogramElement pes = context.getSourcePictogramElement();
      PictogramElement pet = context.getTargetPictogramElement();

      if (source.getEdge().getChildNode().size() == 0) {
        pet.getGraphicsAlgorithm().setX(pes.getGraphicsAlgorithm().getX());
        pet.getGraphicsAlgorithm()
            .setY(pes.getGraphicsAlgorithm().getY() + pes.getGraphicsAlgorithm().getHeight() + 45);
      }
    }

    return newConnection;
  }
  @Override
  public boolean appliesTo(IWorkbenchPart part, ISelection selection) {

    // should we delegate to the section to determine whether it should be included in this tab?
    if (sectionClass instanceof IBpmn2PropertySection) {
      return ((IBpmn2PropertySection) sectionClass).appliesTo(part, selection);
    }

    // if an input description was specified, check if the selected business object is of this
    // description.
    if (appliesToClass != null) {
      PictogramElement pe = BusinessObjectUtil.getPictogramElementForSelection(selection);
      // this is a special hack to allow selection of connection decorator labels:
      // the connection decorator does not have a business object linked to it,
      // but its parent (the connection) does.
      if (pe.getLink() == null && pe.eContainer() instanceof PictogramElement)
        pe = (PictogramElement) pe.eContainer();

      // check all linked BusinessObjects for a match
      if (pe.getLink() != null) {
        for (EObject eObj : pe.getLink().getBusinessObjects()) {
          if (appliesToClass.isInstance(eObj)) {
            return true;
          }
        }
      }
      return false;
    }
    return true;
  }
Esempio n. 15
0
 public static ContainerShape getLastLaneInContainer(ContainerShape root) {
   List<PictogramElement> laneShapes = BusinessObjectUtil.getChildElementsOfType(root, Lane.class);
   if (!laneShapes.isEmpty()) {
     Iterator<PictogramElement> iterator = laneShapes.iterator();
     PictogramElement result = iterator.next();
     if (result instanceof ContainerShape) {
       GraphicsAlgorithm ga = result.getGraphicsAlgorithm();
       if (isHorizontal(root)) {
         while (iterator.hasNext()) {
           PictogramElement currentShape = iterator.next();
           if (currentShape instanceof ContainerShape) {
             if (currentShape.getGraphicsAlgorithm().getY() > ga.getY()) {
               result = currentShape;
             }
           }
         }
       } else {
         while (iterator.hasNext()) {
           PictogramElement currentShape = iterator.next();
           if (currentShape instanceof ContainerShape) {
             if (currentShape.getGraphicsAlgorithm().getX() > ga.getX()) {
               result = currentShape;
             }
           }
         }
       }
       return (ContainerShape) result;
     }
   }
   return root;
 }
Esempio n. 16
0
 public static boolean isChoreographyParticipantBand(PictogramElement element) {
   if (element != null) {
     EObject container = element.eContainer();
     if (container instanceof PictogramElement) {
       PictogramElement containerElem = (PictogramElement) container;
       Object bo =
           Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(containerElem);
       if (bo instanceof ChoreographyActivity) {
         return true;
       }
     }
   }
   return false;
 }
    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());
      }
    }
Esempio n. 18
0
 public static boolean setHidden(PictogramElement pe, boolean hidden) {
   if (hidden) {
     pe.eSetDeliver(false);
     Graphiti.getPeService()
         .setPropertyValue(pe, GraphitiConstants.IS_HIDDEN, Boolean.TRUE.toString());
     pe.setVisible(false);
     pe.eSetDeliver(true);
   } else {
     pe.eSetDeliver(false);
     Graphiti.getPeService().removeProperty(pe, GraphitiConstants.IS_HIDDEN);
     pe.setVisible(true);
     pe.eSetDeliver(true);
   }
   return false;
 }
Esempio n. 19
0
 public static GraphicsAlgorithm[] getClickArea(PictogramElement element) {
   Collection<PictogramElement> children =
       Graphiti.getPeService().getPictogramElementChildren(element);
   PictogramElement first = children.iterator().next();
   return new GraphicsAlgorithm[] {first.getGraphicsAlgorithm()};
 }
 public static GraphicsAlgorithm getSelectionBorder(PictogramElement element) {
   Collection<PictogramElement> children =
       Graphiti.getPeService().getPictogramElementChildren(element);
   PictogramElement first = children.iterator().next();
   return first.getGraphicsAlgorithm();
 }
  @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);
  }
Esempio n. 22
0
 public static GraphicsAlgorithm getSelectionBorder(PictogramElement element) {
   Collection<Shape> children =
       Graphiti.getPeService().getAllContainedShapes((ContainerShape) element);
   PictogramElement first = children.iterator().next();
   return first.getGraphicsAlgorithm();
 }