示例#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;
  }
  @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();
        }
      }
    }
  }
示例#3
0
 public DIGenerator(DIImport importer) {
   this.importer = importer;
   elements = importer.getImportedElements();
   diagnostics = importer.getDiagnostics();
   editor = importer.getEditor();
   diagram = editor.getDiagramTypeProvider().getDiagram();
   bpmnDiagram = BusinessObjectUtil.getFirstElementOfType(diagram, BPMNDiagram.class);
   definitions = ModelUtil.getDefinitions(bpmnDiagram);
   preferences = Bpmn2Preferences.getInstance(definitions);
 }
  public static void updateCategoryValues(IFeatureProvider fp, PictogramElement pe) {

    Resource resource = ObjectPropertyProvider.getResource(pe);
    if (Bpmn2Preferences.getInstance(resource).getPropagateGroupCategories()) {
      // only do this if User Preference is enabled: assign the Group's CategoryValue
      // to the FlowElement represented by the given PictogramElement
      Diagram diagram = fp.getDiagramTypeProvider().getDiagram();
      FlowElement flowElement = BusinessObjectUtil.getFirstElementOfType(pe, FlowElement.class);
      if (flowElement == null) return;
      // remove any previous Category Values from this FlowElement
      flowElement.getCategoryValueRef().clear();

      // find all Groups in this Resource and check if it contains the given FlowElement
      if (pe instanceof ContainerShape) {
        for (Group group : ModelUtil.getAllObjectsOfType(resource, Group.class)) {
          CategoryValue cv = group.getCategoryValueRef();
          if (cv == null) continue;

          for (PictogramElement groupShape :
              Graphiti.getLinkService().getPictogramElements(diagram, group)) {
            if (groupShape instanceof ContainerShape) {
              for (ContainerShape flowElementShape :
                  FeatureSupport.findGroupedShapes((ContainerShape) groupShape)) {
                FlowElement fe =
                    BusinessObjectUtil.getFirstElementOfType(flowElementShape, FlowElement.class);
                if (fe == flowElement) {
                  fe.getCategoryValueRef().add(cv);
                  break;
                }
              }
            }
          }
        }
      } else if (pe instanceof Connection && flowElement instanceof SequenceFlow) {
        SequenceFlow sf = (SequenceFlow) flowElement;
        FlowNode source = sf.getSourceRef();
        FlowNode target = sf.getTargetRef();

        sf.getCategoryValueRef().clear();
        sf.getCategoryValueRef().addAll(source.getCategoryValueRef());
        sf.getCategoryValueRef().addAll(target.getCategoryValueRef());
      }
    }
  }
  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);
  }