private void removeDuplicates(List<DiagramElementTreeNode> children) {
    List<DiagramElementTreeNode> duplicates = new ArrayList<DiagramElementTreeNode>();
    for (DiagramElementTreeNode node : children) {
      if (node.hasChildren()) removeDuplicates(node.getChildren());

      BaseElement be = node.getBaseElement();
      if (be instanceof Collaboration) {
        Collaboration c = (Collaboration) be;
        for (Participant p : c.getParticipants()) {
          for (DiagramElementTreeNode n : children) {
            if (n.getBaseElement() == p.getProcessRef()) {
              duplicates.add(n);
            }
          }
        }
      } else if (be instanceof ChoreographyActivity) {
        ChoreographyActivity c = (ChoreographyActivity) be;
        for (Participant p : c.getParticipantRefs()) {
          for (DiagramElementTreeNode n : children) {
            if (n.getBaseElement() == p) {
              duplicates.add(n);
            }
          }
        }
      }
    }
    if (!duplicates.isEmpty()) children.removeAll(duplicates);
  }
  private BPMNShape createMissingDIElement(
      DiagramElementTreeNode node, int x, int y, List<BaseElement> created) {
    BaseElement element = node.getBaseElement();
    BPMNShape bpmnShape = null;
    BPMNDiagram bpmnDiagram = createDIDiagram(element);

    if (element instanceof Lane) {
      Lane lane = (Lane) element;
      bpmnShape = createDIShape(bpmnDiagram, lane, x, y);
      node.setBpmnShape(bpmnShape);

      y = createMissingDIElementChildren(node, x, y, created);
      created.add(lane);
    } else if (element instanceof FlowElementsContainer) {
      FlowElementsContainer container = (FlowElementsContainer) element;

      if (container instanceof SubProcess || container instanceof SubChoreography) {
        bpmnShape = createDIShape(bpmnDiagram, container, x, y);
        node.setBpmnShape(bpmnShape);
        created.add(container);
      }

      y = createMissingDIElementChildren(node, x, y, created);
    } else if (element instanceof Collaboration) {
      y = createMissingDIElementChildren(node, x, y, created);
    } else if (element instanceof Artifact) {
      bpmnShape = createDIShape(bpmnDiagram, element, x, y);
      node.setBpmnShape(bpmnShape);
      created.add(element);
    } else if (element instanceof Participant) {
      boolean doImport = true;
      if (node.getParent().getBaseElement() instanceof ChoreographyActivity) {
        // this is a Participant Band in a Choreography Activity
        doImport = false;
      }

      bpmnShape = createDIShape(bpmnDiagram, element, x, y, doImport);
      node.setBpmnShape(bpmnShape);
      created.add(element);
      if (!doImport) {
        ChoreographyActivity ca = (ChoreographyActivity) node.getParent().getBaseElement();
        bpmnShape.setChoreographyActivityShape(node.getParent().getBpmnShape());
        if (ca.getParticipantRefs().get(0) == element)
          bpmnShape.setParticipantBandKind(ParticipantBandKind.TOP_INITIATING);
        else bpmnShape.setParticipantBandKind(ParticipantBandKind.BOTTOM_NON_INITIATING);
      }
      createMissingDIElementChildren(node, x, y, created);
    } else if (element instanceof ConversationNode) {
      bpmnShape = createDIShape(bpmnDiagram, element, x, y);
      node.setBpmnShape(bpmnShape);
      created.add(element);
    } else if (element instanceof FlowNode) {
      boolean doImport = !(element instanceof ChoreographyActivity);
      bpmnShape = createDIShape(bpmnDiagram, element, x, y, doImport);
      node.setBpmnShape(bpmnShape);
      created.add(element);
      y = createMissingDIElementChildren(node, x, y, created);
      if (!doImport) importer.importShape(bpmnShape);
    } else if (isDataElement(element)) {
      bpmnShape = createDIShape(bpmnDiagram, element, x, y);
      node.setBpmnShape(bpmnShape);
      created.add(element);
    }
    return bpmnShape;
  }