Exemplo n.º 1
0
  /**
   * Gets the owner {@link PictogramElement} of a Label from a given PictogramElement. The given PE
   * may already be the owner of the Label, in which case the given value is returned. See also
   * {@link FeatureSupport#getLabelOwner(IContext)}
   *
   * @param pe a PictogramElement that represents the Label shape. This may be either the Label
   *     shape or its owner.
   * @return the PictogramElement that is the owner of a Label shape.
   */
  public static PictogramElement getLabelOwner(PictogramElement pe) {
    DiagramElement de = BusinessObjectUtil.getFirstElementOfType(pe, DiagramElement.class);
    if (de != null) return pe;
    ContainerShape cs = BusinessObjectUtil.getFirstElementOfType(pe, ContainerShape.class);
    de = BusinessObjectUtil.getFirstElementOfType(cs, DiagramElement.class);
    if (de != null) return cs;

    // Messages attached to MessageFlows do not have a BPMNShape element, their
    // visibility is controlled by a setting on the BPMNEdge for the MessageFlow
    Message msg = BusinessObjectUtil.getFirstElementOfType(cs, Message.class);
    if (msg != null) return cs;
    // If this is the ContainerShape of the MessageFlow Message, then it is the label owner.
    if (pe instanceof ContainerShape) {
      Shape labelShape = BusinessObjectUtil.getFirstElementOfType(pe, Shape.class);
      if (FeatureSupport.isLabelShape(labelShape)) return pe;
    }

    Connection c = BusinessObjectUtil.getFirstElementOfType(pe, Connection.class);
    de = BusinessObjectUtil.getFirstElementOfType(c, DiagramElement.class);
    if (de != null) return c;
    return null;
  }