Exemplo n.º 1
0
  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());
      }
    }
  }