Esempio n. 1
0
 private boolean isMissingDIElement(BaseElement be) {
   // ignore DataStores - there are bound to be references
   // to these, which *should* be rendered
   if (be instanceof DataStore) return false;
   BPMNDiagram bpmnDiagram = DIUtils.findBPMNDiagram(be);
   if (bpmnDiagram != null) return false;
   // couldn't find a BPMNDiagram entry for this BaseElement
   // check its container to see if it has a BPMNDiagram
   FlowElementsContainer container = this.getRootElementContainer(be);
   bpmnDiagram = DIUtils.findBPMNDiagram(container);
   if (bpmnDiagram != null) {
     // is the BaseElement defined as a BPMNShape or BPMNEdge in its
     // container's BPMNDiagram?
     if (bpmnDiagram.getPlane().getPlaneElement().contains(be)) return false;
   }
   boolean missing = (elements.get(be) == null && diagnostics.get(be) == null);
   if (missing)
     GraphicsUtil.dump(
         "Missing DI element for: "
             + be.eClass().getName()
             + " '"
             + ExtendedPropertiesProvider.getTextValue(be)
             + "'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   return missing;
 }
  @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);
      }
    }
  }
  @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 updateConnectionIfNeeded(DataAssociation association, ItemAwareElement value) {
      DiagramEditor diagramEditor = ModelUtil.getDiagramEditor(association);
      if (diagramEditor == null) return;
      boolean hasDoneChanges = false;
      Diagram diagram = diagramEditor.getDiagramTypeProvider().getDiagram();
      IFeatureProvider fp = diagramEditor.getDiagramTypeProvider().getFeatureProvider();
      Shape taskShape = null;
      EObject container = association.eContainer();
      if (container instanceof Activity || container instanceof Event) {
        for (PictogramElement pe :
            Graphiti.getLinkService().getPictogramElements(diagram, container)) {
          if (pe instanceof Shape
              && BusinessObjectUtil.getFirstElementOfType(pe, BPMNShape.class) != null) {
            taskShape = (Shape) pe;
            break;
          }
        }
      }

      Shape dataShape = null;
      if (value instanceof DataObject
          || value instanceof DataObjectReference
          || value instanceof DataStore
          || value instanceof DataStoreReference
          || value instanceof DataInput
          || value instanceof DataOutput) {
        List<PictogramElement> pes =
            Graphiti.getLinkService().getPictogramElements(diagram, (EObject) value);
        for (PictogramElement p : pes) {
          if (BusinessObjectUtil.getFirstElementOfType(p, BPMNShape.class) != null) {
            dataShape = (Shape) p;
            break;
          }
        }
      }

      Connection connection =
          DataAssociationFeatureContainer.findDataAssociation(diagram, association);
      if (connection != null) {
        // There's an existing DataAssociation connection which needs to
        // either be reconnected or deleted, depending on what the combobox
        // selection is.
        if (dataShape != null) {
          // need to reconnect the DataAssociation
          ReconnectionContext rc = null;
          if (association instanceof DataInputAssociation) {
            Point p = GraphicsUtil.createPoint(connection.getStart());
            Anchor a = AnchorUtil.createAnchor((AnchorContainer) dataShape, p);
            rc = new ReconnectionContext(connection, connection.getStart(), a, null);
            rc.setTargetPictogramElement(dataShape);
            rc.setTargetLocation(Graphiti.getPeService().getLocationRelativeToDiagram(a));
            rc.setReconnectType(ReconnectionContext.RECONNECT_SOURCE);
          } else {
            Point p = GraphicsUtil.createPoint(connection.getEnd());
            Anchor a = AnchorUtil.createAnchor(dataShape, p);
            rc = new ReconnectionContext(connection, a, connection.getEnd(), null);
            rc.setTargetPictogramElement(dataShape);
            rc.setTargetLocation(Graphiti.getPeService().getLocationRelativeToDiagram(a));
            rc.setReconnectType(ReconnectionContext.RECONNECT_TARGET);
          }
          IReconnectionFeature rf = fp.getReconnectionFeature(rc);
          if (rf.canReconnect(rc)) {
            rf.reconnect(rc);
            hasDoneChanges = true;
          }
        } else {
          // need to delete the DataAssociation connection
          DeleteContext dc = new DeleteContext(connection);
          connection.getLink().getBusinessObjects().remove(0);
          IDeleteFeature df = fp.getDeleteFeature(dc);
          df.delete(dc);
        }
      } else if (dataShape != null) {
        // There is no existing DataAssociation connection, but the newly selected source or target
        // is some kind of data object shape, so we need to create a connection between the Activity
        // (or Throw/Catch Event) that owns the DataAssociation, and the new data object shape.
        Point p = GraphicsUtil.createPoint((AnchorContainer) dataShape);
        Anchor ownerAnchor = AnchorUtil.createAnchor(taskShape, p);
        p = GraphicsUtil.createPoint(taskShape);
        Anchor peAnchor = AnchorUtil.createAnchor((AnchorContainer) dataShape, p);
        AddConnectionContext ac = null;
        if (association instanceof DataOutputAssociation) {
          ac = new AddConnectionContext(ownerAnchor, peAnchor);
        } else {
          ac = new AddConnectionContext(peAnchor, ownerAnchor);
        }
        ac.putProperty(GraphitiConstants.BUSINESS_OBJECT, association);
        ac.setNewObject(association);
        IAddFeature af = fp.getAddFeature(ac);
        if (af.canAdd(ac)) {
          PictogramElement pe = af.add(ac);
          if (pe instanceof Connection) {
            connection = (Connection) pe;
            hasDoneChanges = true;
          }
        }
      }
      if (hasDoneChanges) {
        FeatureSupport.updateConnection(
            diagramEditor.getDiagramTypeProvider().getFeatureProvider(), connection);
      }
    }