public Lane createLane(Object target) {
   Lane lane = FACTORY.createLane();
   //		lane.setId(EcoreUtil.generateUUID());
   ModelUtil.setID(lane, resource);
   FlowElementsContainer container = getFlowElementContainer(target);
   if (container.getLaneSets().isEmpty()) {
     LaneSet laneSet = FACTORY.createLaneSet();
     //			laneSet.setId(EcoreUtil.generateUUID());
     container.getLaneSets().add(laneSet);
   }
   container.getLaneSets().get(0).getLanes().add(lane);
   ModelUtil.setID(lane);
   return lane;
 }
 /* (non-Javadoc)
  * @see org.eclipse.bpmn2.modeler.core.validation.validators.AbstractBpmn2ElementValidator#validate(org.eclipse.bpmn2.BaseElement)
  */
 @Override
 public IStatus validate(FlowElementsContainer object) {
   FlowNodeValidator validator = new FlowNodeValidator(this);
   for (FlowElement fe : object.getFlowElements()) {
     if (fe instanceof FlowNode) validator.validate((FlowNode) fe);
   }
   return getResult();
 }
 public void moveFlowNode(FlowNode node, Object source, Object target) {
   FlowElementsContainer sourceContainer = getFlowElementContainer(source);
   FlowElementsContainer targetContainer = getFlowElementContainer(target);
   sourceContainer.getFlowElements().remove(node);
   targetContainer.getFlowElements().add(node);
   for (SequenceFlow flow : node.getOutgoing()) {
     sourceContainer.getFlowElements().remove(flow);
     targetContainer.getFlowElements().add(flow);
   }
 }
  private void findMissingDIElements(DiagramElementTreeNode missing, BaseElement be) {
    if (be instanceof FlowElementsContainer) {
      // handles Process/SubProcess and Choreography/SubChoreography
      FlowElementsContainer container = (FlowElementsContainer) be;
      DiagramElementTreeNode parentNode = null;

      List<FlowElement> laneElements = new ArrayList<FlowElement>();
      for (LaneSet laneSet : container.getLaneSets()) {
        findMissingDIElements(missing, laneSet, laneElements);
      }

      for (FlowElement fe : container.getFlowElements()) {
        if (isMissingDIElement(fe) && !laneElements.contains(fe)) {
          if (fe instanceof SequenceFlow || fe instanceof DataObject || fe instanceof DataStore)
            continue;
          if (parentNode == null) parentNode = missing.addChild(container);
          parentNode.addChild(fe);
          if (fe instanceof FlowElementsContainer || fe instanceof ChoreographyActivity) {
            findMissingDIElements(parentNode, fe);
          }
        }
      }
      List<Artifact> artifacts = getArtifacts(container);
      if (artifacts != null) {
        for (Artifact a : artifacts) {
          if (isMissingDIElement(a) && !(a instanceof Association)) {
            if (parentNode == null) parentNode = missing.addChild(container);
            parentNode.addChild(a);
          }
        }
      }
    }

    // Choreography inherits both Collaboration and FlowElementsContainer
    if (be instanceof Collaboration) {
      // also handle Choreography
      Collaboration container = (Collaboration) be;
      DiagramElementTreeNode parentNode = null;
      for (Artifact a : container.getArtifacts()) {
        if (isMissingDIElement(a) && !(a instanceof Association)) {
          if (parentNode == null) parentNode = missing.addChild(container);
          parentNode.addChild(a);
        }
      }
      for (Participant p : container.getParticipants()) {
        boolean isParticipantBand = false;
        if (p.eContainer() instanceof Choreography) {
          // this may be a Choreography Activity Participant band
          Choreography choreography = (Choreography) p.eContainer();
          for (FlowElement fe : choreography.getFlowElements()) {
            if (fe instanceof ChoreographyActivity) {
              if (((ChoreographyActivity) fe).getParticipantRefs().contains(p)) {
                isParticipantBand = true;
                break;
              }
            }
          }
        }
        if (isMissingDIElement(p)
            && p.getProcessRef() != null
            && isMissingDIElement(p.getProcessRef())
            && !isParticipantBand) {
          if (parentNode == null) parentNode = missing.addChild(container);
          parentNode.addChild(p);
        }
      }
      for (ConversationNode c : container.getConversations()) {
        if (isMissingDIElement(c)) {
          if (parentNode == null) parentNode = missing.addChild(container);
          parentNode.addChild(c);
        }
      }
    } else if (be instanceof Participant) {
      Participant container = (Participant) be;
      if (container.getProcessRef() != null) {
        DiagramElementTreeNode parentNode = missing.addChild(container);
        parentNode.addChild(container.getProcessRef());
      }
    } else if (be instanceof ChoreographyActivity) {
      ChoreographyActivity container = (ChoreographyActivity) be;
      DiagramElementTreeNode parentNode = null;
      for (Participant p : container.getParticipantRefs()) {
        if (isMissingDIElement(p)) {
          if (parentNode == null) parentNode = missing.addChild(container);
          DiagramElementTreeNode child = parentNode.addChild(p);
          if (p.getProcessRef() != null) findMissingDIElements(child, p.getProcessRef());
        }
      }
    } else if (isDataElement(be)) {
      if (isMissingDIElement(be)) {
        missing.addChild(be);
      }
    }
  }
 /**
  * @param <T>
  * @param target object that this element is being added to
  * @param elem flow element to be added
  * @return
  */
 public <T extends FlowElement> T addFlowElement(Object target, T elem) {
   FlowElementsContainer container = getFlowElementContainer(target);
   container.getFlowElements().add(elem);
   return elem;
 }
  public static List<Object> getFlowElementsContainerChildren(FlowElementsContainer container) {
    List<Object> retList = new ArrayList<Object>();
    List<FlowElement> flowElements = new ArrayList<FlowElement>();
    for (FlowElement fe : container.getFlowElements()) {
      if (!(fe instanceof BoundaryEvent)) flowElements.add(fe);
    }

    if (container.getLaneSets().size() == 0) retList.addAll(flowElements);
    else {
      for (LaneSet ls : container.getLaneSets()) {
        retList.addAll(ls.getLanes());
      }
      // only add the flow element if it's not contained in a Lane
      List<Object> laneElements = new ArrayList<Object>();
      for (FlowElement fe : flowElements) {
        boolean inLane = false;
        for (LaneSet ls : container.getLaneSets()) {
          if (isInLane(fe, ls)) {
            inLane = true;
            break;
          }
        }
        if (inLane) laneElements.add(fe);
        else retList.add(fe);
      }

      // don't include any sequence flows that connect flow
      // nodes that are contained in Lanes
      List<SequenceFlow> flows = new ArrayList<SequenceFlow>();
      for (Object fn : laneElements) {
        if (fn instanceof FlowNode) {
          for (SequenceFlow sf : ((FlowNode) fn).getIncoming()) {
            if (laneElements.contains(sf.getSourceRef())
                && laneElements.contains(sf.getTargetRef())
                && !flows.contains(sf)) {
              flows.add(sf);
            }
          }
          for (SequenceFlow sf : ((FlowNode) fn).getOutgoing()) {
            if (laneElements.contains(sf.getSourceRef())
                && laneElements.contains(sf.getTargetRef())
                && !flows.contains(sf)) {
              flows.add(sf);
            }
          }
        }
      }
      retList.removeAll(flows);
    }

    // add the list of Artifacts
    if (container instanceof Process) {
      retList.addAll(((Process) container).getArtifacts());
    } else if (container instanceof SubProcess) {
      retList.addAll(((SubProcess) container).getArtifacts());
    }
    if (container instanceof SubChoreography) {
      retList.addAll(((SubChoreography) container).getArtifacts());
    }
    if (container instanceof Choreography) {
      // Add Pools as children if the Pool has a Process associated with it,
      // or if the Participant is NOT referenced by a Choreography Activity.
      for (Participant p : ((Choreography) container).getParticipants()) {
        if (p.getProcessRef() != null) retList.add(p);
        else {
          for (FlowElement fe : flowElements) {
            if (fe instanceof ChoreographyActivity) {
              if (!((ChoreographyActivity) fe).getParticipantRefs().contains(p)) {
                retList.add(p);
              }
            }
          }
        }
      }
    }
    return retList;
  }