Ejemplo n.º 1
0
  /**
   * Method to initialize the tree model of the current tree mode. This method should be called
   * whenever the tree mode is changed, it won't initialize anything if not necessary.
   *
   * <p>This method will also actually change the model of the tree.
   */
  protected void initModel() {
    // build default tree structure
    switch (treeMode) {
      case DEPENDENCY:
        // don't re-init anything
        if (rootDependency == null) {
          rootDependency = new DefaultMutableTreeNode();
          depNode = new DefaultMutableTreeNode(); // dependent objects
          indNode = new DefaultMutableTreeNode();
          auxiliaryNode = new DefaultMutableTreeNode();

          // independent objects
          rootDependency.add(indNode);
          rootDependency.add(depNode);
        }

        // set the root
        model.setRoot(rootDependency);

        // add auxiliary node if neccessary
        if (app.showAuxiliaryObjects) {
          if (!auxiliaryNode.isNodeChild(rootDependency)) {
            model.insertNodeInto(auxiliaryNode, rootDependency, rootDependency.getChildCount());
          }
        }
        break;
      case ORDER:
        if (rootOrder == null) {
          rootOrder = new DefaultMutableTreeNode();
        }

        // always try to remove the auxiliary node
        if (app.showAuxiliaryObjects && auxiliaryNode != null) {
          removeAuxiliaryNode();
        }

        // set the root
        model.setRoot(rootOrder);
        break;

      case TYPE:
        // don't re-init anything
        if (rootType == null) {
          rootType = new DefaultMutableTreeNode();
          typeNodesMap = new HashMap<String, DefaultMutableTreeNode>(5);
        }

        // always try to remove the auxiliary node
        if (app.showAuxiliaryObjects && auxiliaryNode != null) {
          removeAuxiliaryNode();
        }

        // set the root
        model.setRoot(rootType);
        break;
      case LAYER:
        // don't re-init anything
        if (rootLayer == null) {
          rootLayer = new DefaultMutableTreeNode();
          layerNodesMap = new HashMap<Integer, DefaultMutableTreeNode>(10);
        }

        // always try to remove the auxiliary node
        if (app.showAuxiliaryObjects && auxiliaryNode != null) {
          removeAuxiliaryNode();
        }

        // set the root
        model.setRoot(rootLayer);
        break;
    }
  }