Пример #1
0
  private BPMNShape createDIShape(
      BPMNDiagram bpmnDiagram, BaseElement bpmnElement, float x, float y, boolean doImport) {

    BPMNPlane plane = bpmnDiagram.getPlane();
    BPMNShape bpmnShape = null;
    for (DiagramElement de : plane.getPlaneElement()) {
      if (de instanceof BPMNShape) {
        if (bpmnElement == ((BPMNShape) de).getBpmnElement()) {
          bpmnShape = (BPMNShape) de;
          break;
        }
      }
    }

    if (bpmnShape == null) {
      bpmnShape = BpmnDiFactory.eINSTANCE.createBPMNShape();
      bpmnShape.setBpmnElement(bpmnElement);
      Bounds bounds = DcFactory.eINSTANCE.createBounds();
      bounds.setX(x);
      bounds.setY(y);
      ShapeStyle ss = preferences.getShapeStyle(bpmnElement);
      bounds.setWidth(ss.getDefaultWidth());
      bounds.setHeight(ss.getDefaultHeight());
      bpmnShape.setBounds(bounds);
      plane.getPlaneElement().add(bpmnShape);
      preferences.applyBPMNDIDefaults(bpmnShape, null);

      ModelUtil.setID(bpmnShape);
      if (doImport) importer.importShape(bpmnShape);
    }

    return bpmnShape;
  }
Пример #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();
        }
      }
    }
  }