Beispiel #1
0
  private static DefaultMutableTreeNode findMatchedChild(
      DefaultMutableTreeNode parent, PathElement pathElement) {

    for (int j = 0; j < parent.getChildCount(); j++) {
      final TreeNode child = parent.getChildAt(j);
      if (!(child instanceof DefaultMutableTreeNode)) continue;
      final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child;
      final Object userObject = childNode.getUserObject();
      if (pathElement.matchedWithByObject(userObject)) return childNode;
    }

    for (int j = 0; j < parent.getChildCount(); j++) {
      final TreeNode child = parent.getChildAt(j);
      if (!(child instanceof DefaultMutableTreeNode)) continue;
      final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child;
      final Object userObject = childNode.getUserObject();
      if (!(userObject instanceof NodeDescriptor)) continue;
      final NodeDescriptor nodeDescriptor = (NodeDescriptor) userObject;
      if (pathElement.matchedWith(nodeDescriptor)) return childNode;
    }

    if (parent.getChildCount() > 0) {
      int index = pathElement.myItemIndex;
      if (index >= parent.getChildCount()) {
        index = parent.getChildCount() - 1;
      }
      final TreeNode child = parent.getChildAt(index);
      if (child instanceof DefaultMutableTreeNode) {
        return (DefaultMutableTreeNode) child;
      }
    }

    return null;
  }
  // ===============================================================
  // ===============================================================
  void putPoolThreadInfo() {
    //  ToDo
    //	Get configuration from tree
    int nbThreads = root.getChildCount();
    ArrayList<String> lines = new ArrayList<String>();
    for (int i = 0; i < root.getChildCount(); i++) {
      DefaultMutableTreeNode threadNode = (DefaultMutableTreeNode) root.getChildAt(i);
      int deviceNumber = threadNode.getChildCount();
      if (deviceNumber > 0) {
        String s = "";
        for (int j = 0; j < deviceNumber; j++) {
          s += threadNode.getChildAt(j).toString();
          if (j < deviceNumber - 1) s += ",";
        }
        lines.add(s);
      }
    }
    //  Check for maximum length of lines
    lines = manageMaxLength(lines);

    //	Convert tree to device(admin) property.
    String[] config = new String[lines.size()];
    for (int i = 0; i < lines.size(); i++) config[i] = lines.get(i);

    //	And send it to database.
    try {
      DbDatum[] argin = new DbDatum[2];
      argin[0] = new DbDatum(propertyNames[NB_THREADS], nbThreads);
      argin[1] = new DbDatum(propertyNames[THREADS_CONFIG], config);
      server.put_property(argin);
    } catch (DevFailed e) {
      ErrorPane.showErrorMessage(parent, null, e);
    }
  }
  /**
   * @param defaultTreeModel
   * @param root
   * @see BuildingTree
   */
  public void toTree(final DefaultTreeModel defaultTreeModel, DefaultMutableTreeNode root) {
    ArrayList a = (ArrayList) DataToTest.getBuildingCollection();
    DefaultMutableTreeNode bNode;
    DefaultMutableTreeNode fNode;
    DefaultMutableTreeNode rNode;
    for (Iterator i = a.iterator(); i.hasNext(); ) {
      Building building = (Building) i.next();
      bNode = new DefaultMutableTreeNode(building);
      defaultTreeModel.insertNodeInto(bNode, root, root.getChildCount());

      if (building.getFloor().length > 0) {
        for (int floorCount = 0; floorCount < building.getFloor().length; floorCount++) {
          Floor fl = (Floor) building.getFloor()[floorCount];
          fNode = new DefaultMutableTreeNode(fl);
          defaultTreeModel.insertNodeInto(fNode, bNode, bNode.getChildCount());

          if (fl.getRoom().length > 0) {
            for (int roomIterator = 0; roomIterator < fl.getRoom().length; roomIterator++) {
              Room r = (Room) fl.getRoom()[roomIterator];
              rNode = new DefaultMutableTreeNode(r);
              defaultTreeModel.insertNodeInto(rNode, fNode, fNode.getChildCount());
            }
          }
        }
      }
    }
  }
Beispiel #4
0
  /**
   * Remove this node from the model.
   *
   * @param node
   * @param model
   */
  private void removeFromModel(DefaultMutableTreeNode node, DefaultTreeModel model) {
    model.removeNodeFromParent(node);
    nodeTable.remove(node.getUserObject());

    // remove the type branch if there are no more children
    switch (treeMode) {
      case TYPE:
        String typeString = ((GeoElement) node.getUserObject()).getObjectType();
        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) typeNodesMap.get(typeString);

        // this has been the last node
        if (parent.getChildCount() == 0) {
          typeNodesMap.remove(typeString);
          model.removeNodeFromParent(parent);
        }
        break;
      case LAYER:
        int layer = ((GeoElement) node.getUserObject()).getLayer();
        parent = (DefaultMutableTreeNode) layerNodesMap.get(layer);

        // this has been the last node
        if (parent.getChildCount() == 0) {
          layerNodesMap.remove(layer);
          model.removeNodeFromParent(parent);
        }

        break;
    }
  }
Beispiel #5
0
  /**
   * 参数条件树上增加节点
   *
   * @param conditionNodeObj
   */
  private TreeNode addParaTreNode(IStatisticCaliber aCal) {
    // 得到父节点
    DefaultTreeModel treeModel = (DefaultTreeModel) treWhere.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot();
    // 判断增加的父节点是否已存在,默认父节点不存在
    boolean sFlag = false;
    IStatisticCaliber curCal = null;
    DefaultMutableTreeNode curNode = null;
    int iChildCount = root.getChildCount();
    // 得到根节点下的子节点
    for (int i = 0; i < iChildCount; i++) {
      curNode = (DefaultMutableTreeNode) root.getChildAt(i);
      curCal = ((Caliber) curNode.getUserObject()).getACal();
      if (aCal.getSourceID().equals(curCal.getSourceID())) {
        sFlag = true;
        break;
      }
    }

    DefaultMutableTreeNode ANode = null;
    if (!sFlag) { // 父节点不存在
      // 增加父节点
      ICustomStatisticCaliber parCal = new MySummaryStatisticCaliberImpl();
      parCal.setSourceID(aCal.getSourceID());
      // 数据源名称
      String sDataSourceName = dataSourceCbx.getRefModel().getNameByValue(aCal.getSourceID());
      parCal.setValue(sDataSourceName);
      ANode = new DefaultMutableTreeNode(new Caliber(parCal));
      treeModel.insertNodeInto(ANode, root, root.getChildCount());
      curNode = (DefaultMutableTreeNode) root.getLastChild();
    }
    ANode = new DefaultMutableTreeNode(new Caliber(aCal));
    treeModel.insertNodeInto(ANode, curNode, curNode.getChildCount());
    return ANode;
  }
  public void reload() {
    removeNodes();

    DefaultMutableTreeNode hostNode = new DefaultMutableTreeNode(Main.getLocalhost());
    treeModel.insertNodeInto(hostNode, rootNode, rootNode.getChildCount());

    for (Trigger trigger : Main.getTriggerManager().getTriggers()) {
      DefaultMutableTreeNode triggerNode = new DefaultMutableTreeNode(trigger);
      treeModel.insertNodeInto(triggerNode, hostNode, hostNode.getChildCount());
    }
    expandAll();
  }
Beispiel #7
0
  /**
   * Obtain a default dir, if there is one, which would have been passed in via a -p argument. Try
   * to expand the dir in the file tree.
   */
  public void expandDefaultDir() {

    // do an overall try catch. Don't want an exception here bringing down
    // the app.

    try {

      String defaultDir = FileUtilities.getDefaultDir();

      if (defaultDir == null) {
        return;
      }

      File file = new File(defaultDir);
      if (!file.exists() || !file.isDirectory()) {
        return;
      }

      String path = file.getCanonicalPath();

      // break the path into components
      String tokens[] = FileUtilities.tokenizePath(path);
      if (tokens == null) {
        return;
      }

      DefaultMutableTreeNode root = (DefaultMutableTreeNode) getModel().getRoot();

      if ((root == null) || (root.getChildCount() < 1)) {
        return;
      }

      int tokenIndex = 0;
      while ((root != null) && (root.getChildCount() > 0) && (tokenIndex < tokens.length)) {

        String token = tokens[tokenIndex];
        tokenIndex++;

        DefaultMutableTreeNode newRoot = getChild(root, token);
        if (newRoot != null) {
          TreeNode pathnodes[] = ((DefaultTreeModel) getModel()).getPathToRoot(newRoot);
          TreePath cpath = new TreePath(pathnodes);
          scrollPathToVisible(cpath);
          expandPath(cpath);
          newRoot = getChild(root, token);
          pathnodes = ((DefaultTreeModel) getModel()).getPathToRoot(newRoot);
        }
        root = newRoot;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 /**
  * A helper method to search for a class node.
  *
  * @param cls
  * @return
  */
 private DefaultMutableTreeNode searchClassNode(SchemaClass cls) {
   SchemaClass displayedCls = getDisplayedPESubclass(cls);
   DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
   if (root.getChildCount() == 0) {
     return null;
   }
   for (int i = 0; i < root.getChildCount(); i++) {
     DefaultMutableTreeNode child = (DefaultMutableTreeNode) root.getChildAt(i);
     if (child.getUserObject() == displayedCls) return child;
   }
   return null;
 }
  private void removeModificationListenerRecursiv(DefaultMutableTreeNode node) {
    int childCount = 0;
    if (node instanceof UserNode) {
      ((UserNode) node).removeModificationListener();
      if (((UserNode) node).isInitialized()) childCount = node.getChildCount();
    } else childCount = node.getChildCount();

    if (childCount > 0) {
      for (int i = 0; i < childCount; i++) {
        removeModificationListenerRecursiv((DefaultMutableTreeNode) node.getChildAt(i));
      }
    }
  }
 // ===============================================================
 // ===============================================================
 private DefaultMutableTreeNode getFutureSelectedNode(DefaultMutableTreeNode node) {
   //	Get the future selectd node, after remove.
   DefaultMutableTreeNode parent_node = (DefaultMutableTreeNode) node.getParent();
   DefaultMutableTreeNode ret_node = parent_node;
   for (int i = 0; i < parent_node.getChildCount(); i++) {
     DefaultMutableTreeNode child_node = (DefaultMutableTreeNode) parent_node.getChildAt(i);
     if (child_node == node) {
       if (i == parent_node.getChildCount() - 1) {
         if (i > 0) ret_node = (DefaultMutableTreeNode) parent_node.getChildAt(i - 1);
       } else ret_node = (DefaultMutableTreeNode) parent_node.getChildAt(i + 1);
     }
   }
   return ret_node;
 }
Beispiel #11
0
  /**
   * Selecciona la unidad y la lista con sus hijos, para poder ser eliminados de la base de datos.
   *
   * @param raiz Nodo por el que se comienza a contar las unidades que se van a eliminar.
   * @return Lista con todas las unidades que se van a eliminar.
   */
  private ArrayList<Unidad> seleccionarAEliminar(DefaultMutableTreeNode raiz) {

    ArrayList<Unidad> aEliminar = new ArrayList<Unidad>();

    if (raiz.getChildCount() != 0) {
      for (int i = 0; i < raiz.getChildCount(); i++) {
        aEliminar.addAll(seleccionarAEliminar((DefaultMutableTreeNode) raiz.getChildAt(i)));
      }
    }

    aEliminar.add(((UnidadUserObject) raiz.getUserObject()).getUnidad());

    return aEliminar;
  }
Beispiel #12
0
 public synchronized void buildFilteredModel(String text) {
   filtered_root.removeAllChildren();
   ArrayList<DefaultMutableTreeNode> rows = new ArrayList<>();
   if (staff.getChildCount() > 0) {
     DefaultMutableTreeNode filtered = new DefaultMutableTreeNode("Staff");
     filterNode(staff, text, filtered);
     if (filtered.getChildCount() > 0) {
       filtered_root.add(filtered);
       rows.add(filtered);
     }
   }
   if (admins.getChildCount() > 0) {
     DefaultMutableTreeNode filtered = new DefaultMutableTreeNode("Admins");
     filterNode(admins, text, filtered);
     if (filtered.getChildCount() > 0) {
       filtered_root.add(filtered);
       rows.add(filtered);
     }
   }
   if (global_mods.getChildCount() > 0) {
     DefaultMutableTreeNode filtered = new DefaultMutableTreeNode("Global Moderators");
     filterNode(global_mods, text, filtered);
     if (filtered.getChildCount() > 0) {
       filtered_root.add(filtered);
       rows.add(filtered);
     }
   }
   if (mods.getChildCount() > 0) {
     DefaultMutableTreeNode filtered = new DefaultMutableTreeNode("Moderators");
     filterNode(mods, text, filtered);
     if (filtered.getChildCount() > 0) {
       filtered_root.add(filtered);
       rows.add(filtered);
     }
   }
   if (viewers.getChildCount() > 0) {
     DefaultMutableTreeNode filtered = new DefaultMutableTreeNode("Viewers");
     filterNode(viewers, text, filtered);
     if (filtered.getChildCount() > 0) {
       filtered_root.add(filtered);
       rows.add(filtered);
     }
   }
   setViewerTreeModel(new DefaultTreeModel(filtered_root));
   for (DefaultMutableTreeNode row : rows) {
     TreePath tp = new TreePath(row.getPath());
     viewerTree.expandPath(tp);
   }
 }
Beispiel #13
0
 private synchronized void updateRoot(Enumeration<TreePath> userPath) {
   DefaultMutableTreeNode root = default_root;
   root.removeAllChildren();
   if (staff.getChildCount() > 0) root.add(staff);
   if (admins.getChildCount() > 0) root.add(admins);
   if (global_mods.getChildCount() > 0) root.add(global_mods);
   if (mods.getChildCount() > 0) root.add(mods);
   root.add(viewers);
   if (!isFiltering) defaultModel.reload(root);
   if (userPath != null) {
     while (userPath.hasMoreElements()) {
       viewerTree.expandPath(userPath.nextElement());
     }
   }
 }
Beispiel #14
0
  private void buildTreeFromString(DefaultTreeModel model, final String str) {
    // Fetch the root node
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();

    // Split the string around the delimiter
    String[] strings = str.split("/");

    // Create a node object to use for traversing down the tree as it
    // is being created
    DefaultMutableTreeNode node = root;
    // Iterate of the string array
    for (String s : strings) {
      // Look for the index of a node at the current level that
      // has a value equal to the current string
      int index = childIndex(node, s);

      // Index less than 0, this is a new node not currently present on
      // the tree
      if (index < 0) {
        // Add the new node
        DefaultMutableTreeNode newChild = new DefaultMutableTreeNode(s);
        node.insert(newChild, node.getChildCount());
        node = newChild;
      }
      // Else, existing node, skip to the next string
      else {
        node = (DefaultMutableTreeNode) node.getChildAt(index);
      }
    }
  }
 private static boolean isMoveSupported(JTree tree, int dir) {
   final TreePath[] selectionPaths = tree.getSelectionPaths();
   if (selectionPaths != null) {
     DefaultMutableTreeNode parent = null;
     for (TreePath treePath : selectionPaths)
       if (treePath.getLastPathComponent() != null) {
         final DefaultMutableTreeNode node =
             (DefaultMutableTreeNode) treePath.getLastPathComponent();
         if (parent == null) {
           parent = (DefaultMutableTreeNode) node.getParent();
         }
         if (parent != node.getParent()) {
           return false;
         }
         if (dir > 0) {
           if (parent.getIndex(node) == parent.getChildCount() - 1) {
             return false;
           }
         } else {
           if (parent.getIndex(node) == 0) {
             return false;
           }
         }
       }
     return true;
   }
   return false;
 }
  public void updateClientState(Node nodeUpdate) {
    for (int i = 0; i < rootNode.getChildCount(); i++) {
      TreeNode treeNode = rootNode.getChildAt(i);
      //            System.out.println(treeNode.toString());
      if (treeNode.toString().equals(nodeUpdate.getName())) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeNode;
        if (nodeUpdate.isOnline() && nodeUpdate.isValid()) {
          // 删除”状态:在线,可信“ 那一行
          node.remove(2);

          node.add(new DefaultMutableTreeNode("状态:在线,可信"));
          Log.i(this.getClass().getName(), nodeUpdate.getName() + " 已登录,状态可信.");

        } else if (nodeUpdate.isOnline() && !nodeUpdate.isValid()) {
          node.remove(2);
          node.add(new DefaultMutableTreeNode("状态:在线,不可信"));
          Log.v(
              this.getClass().getName(),
              nodeUpdate.getName() + "状态不可信,IP地址为:" + nodeUpdate.getIP());
        } else {
          node.remove(2);
          node.add(new DefaultMutableTreeNode("状态:离线"));
          Log.i(
              this.getClass().getName(), nodeUpdate.getName() + "不在线,IP地址为:" + nodeUpdate.getIP());
        }
        this.jTree.updateUI();
        return;
      }
    }
  }
 private ArrayList<TreeNode> childrenToArray(DefaultMutableTreeNode node) {
   ArrayList<TreeNode> arrayList = new ArrayList<TreeNode>();
   for (int i = 0; i < node.getChildCount(); i++) {
     arrayList.add(node.getChildAt(i));
   }
   return arrayList;
 }
Beispiel #18
0
 private void collapseTargets() {
   DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTreeModel.getRoot();
   for (int i = 0; i < root.getChildCount(); i++) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i);
     myTree.collapsePath(new TreePath(node.getPath()));
   }
 }
Beispiel #19
0
  public void removeMarker(LogMarker marker) {
    DefaultMutableTreeNode node;
    for (int i = 0; i < markersNode.getChildCount(); i++) {
      node = (DefaultMutableTreeNode) markersNode.getChildAt(i);
      if (node.getUserObject() == marker) {
        markersNode.remove(node);
      }
    }
    if (markersNode.getChildCount() == 0) {
      root.remove(markersNode);
      markersNode = null;
    }

    treeModel.nodeStructureChanged(root);
    expandAllTree();
  }
Beispiel #20
0
  /**
   * Draw all primitives in this layer but do not draw modified ones (they are drawn by the edit
   * layer). Draw nodes last to overlap the ways they belong to.
   */
  @SuppressWarnings("unchecked")
  @Override
  public void paint(final Graphics2D g, final MapView mv, Bounds bounds) {
    updateCount = Main.map.validatorDialog.tree.getUpdateCount();
    DefaultMutableTreeNode root = Main.map.validatorDialog.tree.getRoot();
    if (root == null || root.getChildCount() == 0) return;

    PaintVisitor paintVisitor = new PaintVisitor(g, mv);

    DefaultMutableTreeNode severity = (DefaultMutableTreeNode) root.getLastChild();
    while (severity != null) {
      Enumeration<DefaultMutableTreeNode> errorMessages = severity.breadthFirstEnumeration();
      while (errorMessages.hasMoreElements()) {
        Object tn = errorMessages.nextElement().getUserObject();
        if (tn instanceof TestError) {
          paintVisitor.visit(((TestError) tn));
        }
      }

      // Severities in inverse order
      severity = severity.getPreviousSibling();
    }

    paintVisitor.clearPaintedObjects();
  }
  private void jTree1MouseClicked1(
      java.awt.event.MouseEvent evt) { // GEN-FIRST:event_jTree1MouseClicked1

    if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1) {
      DefaultMutableTreeNode tn =
          (DefaultMutableTreeNode) jTree1.getSelectionPath().getLastPathComponent();

      if (tn.getChildCount() > 0) return;

      /*if (!jTree1.isCollapsed( jTree1.getSelectionPath() ))
      {
          jTree1.collapsePath( jTree1.getSelectionPath() );
          return;
      }
           *
           */
      if (tn.getUserObject() instanceof TreeJRField) {
        TreeJRField jrf = (TreeJRField) tn.getUserObject();
        if (!jrf.getObj().isPrimitive() && !jrf.getObj().getName().startsWith("java.lang.")) {
          exploreBean(
              tn,
              jrf.getObj().getName(),
              isPathOnDescription()
                  ? Misc.nvl(jrf.getField().getDescription(), "")
                  : Misc.nvl(jrf.getField().getName(), ""));
        }
      }
    }
  } // GEN-LAST:event_jTree1MouseClicked1
  // ===============================================================
  // ===============================================================
  DefaultMutableTreeNode addThreadNode() {

    PollThread new_thread = new PollThread(getNextThreadNum());
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(new_thread);
    treeModel.insertNodeInto(node, root, root.getChildCount());
    return node;
  }
  private ArrayList<?> updateSelectedGeos(TreePath[] selPath) {
    selectionList.clear();

    if (selPath != null) {
      // add all selected paths
      for (int i = 0; i < selPath.length; i++) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath[i].getLastPathComponent();

        if (node == node.getRoot()) {
          // root: add all objects
          selectionList.clear();
          selectionList.addAll(app.getKernel().getConstruction().getGeoSetLabelOrder());
          i = selPath.length;
        } else if (node.getParent() == node.getRoot()) {
          // type node: select all children
          for (int k = 0; k < node.getChildCount(); k++) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(k);
            selectionList.add(child.getUserObject());
          }
        } else {
          // GeoElement
          selectionList.add(node.getUserObject());
        }
      }
    }

    return selectionList;
  }
  void onOK() {
    TreePath path = m_tree.getSelectionPath();
    if (path == null) {
      JOptionPane.showMessageDialog(this, "Departement not yet been selected");
      return;
    }

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();

    if (!m_isroot) {
      if (node.getChildCount() > 0) return;

      if (node.getUserObject() instanceof Organization) {
        m_org = (Organization) node.getUserObject();
        m_iResponse = JOptionPane.OK_OPTION;
        dispose();
      }
    } else {
      if (node.getUserObject() instanceof Organization) {
        m_org = (Organization) node.getUserObject();
        m_iResponse = JOptionPane.OK_OPTION;
        dispose();
      } else {
        m_org = new Organization("", "", "Department");
        m_iResponse = JOptionPane.OK_OPTION;
        dispose();
      }
    }
  }
  public void setWsdlModel(WSDLModel wsdlModel) {
    if (this.wsdlModel == wsdlModel) {
      return;
    }

    this.wsdlModel = wsdlModel;
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    for (Port port : Util.getSortedPorts(wsdlModel)) {
      Binding binding = port.getBinding().get();
      List<BindingOperation> bindingOps = Util.getSortedBindingOperations(binding);
      if (bindingOps != null && bindingOps.size() > 0) {
        DefaultMutableTreeNode portNode = new DefaultMutableTreeNode(port);
        root.add(portNode);
        for (BindingOperation bindingOp : bindingOps) {
          DefaultMutableTreeNode bindingOpNode = new DefaultMutableTreeNode(bindingOp);
          portNode.add(bindingOpNode);
          bindingOpNode.setAllowsChildren(false);
        }
      }
    }
    DefaultTreeModel dtm = new DefaultTreeModel(root);
    mTree.setModel(dtm);
    int cnt = root.getChildCount();
    for (int i = 0; i < cnt; i++) {
      mTree.expandPath(new TreePath(((DefaultMutableTreeNode) root.getChildAt(i)).getPath()));
    }
  }
 void deleteNodeParent(DefaultMutableTreeNode parent) throws Exception {
   while (parent.getChildCount() != 0) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent.getFirstChild();
     deleteNodeParent(node);
   }
   deleteNode(parent);
 }
 /** Expand the current node and return the list of leaves (MaterialVO objects). */
 private ArrayList getComponents(DefaultMutableTreeNode node) {
   ArrayList list = new ArrayList();
   for (int i = 0; i < node.getChildCount(); i++)
     list.addAll(getComponents((DefaultMutableTreeNode) node.getChildAt(i)));
   if (node.isLeaf()) list.add(node.getUserObject());
   return list;
 }
 public DomainDiagramTreeNode addSubDiagram(DomainDiagram diagram, DefaultTreeModel tree) {
   DomainDiagramTreeNode diagramNode = new DomainDiagramTreeNode(diagram, this.projectContext);
   this.subdiagramsNode.add(diagramNode);
   int index = subdiagramsNode.getChildCount() - 1;
   tree.nodesWereInserted(subdiagramsNode, new int[] {index});
   return diagramNode;
 }
  public void treeWillExpand(TreeExpansionEvent e) {

    // get the tree path which will be expanded
    TreePath path = e.getPath();
    if (path == null) {
      return;
    }

    // get the directory at the node
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    File selDir = (File) node.getUserObject();

    // remove old entries
    if (node.getChildCount() > 0) {
      node.removeAllChildren();
    }

    // get all the subdirectories
    File childDirs[] = selDir.listFiles(this);
    if (childDirs == null) {
      return;
    }

    // add the subdirectories
    Arrays.sort(childDirs);
    for (int i = 0; i < childDirs.length; i++) {
      if (childDirs[i].isHidden()) {
        if (showHidden) {
          node.add(new DefaultMutableTreeNode(childDirs[i]));
        }
      } else {
        node.add(new DefaultMutableTreeNode(childDirs[i]));
      }
    }
  }
Beispiel #30
0
  public boolean restoreSelection(TreeSelection treeSelection) {
    if (treeSelection.isEmpty()) return false;

    DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTreeModel.getRoot();
    for (int i = 0; i < root.getChildCount(); i++) {
      TreeNode node = root.getChildAt(i);
      if (node instanceof MessageNode) {
        MessageNode messageNode = (MessageNode) node;
        String[] text = messageNode.getText();
        if (text.length == 0) continue;
        if (Comparing.equal(treeSelection.mySelectedTarget, text[0])) {
          TreePath pathToSelect = new TreePath(messageNode.getPath());
          for (Enumeration enumeration = messageNode.children(); enumeration.hasMoreElements(); ) {
            Object o = enumeration.nextElement();
            if (o instanceof MessageNode) {
              messageNode = (MessageNode) o;
              if (Comparing.equal(treeSelection.mySelectedTask, text[0])) {
                pathToSelect = new TreePath(messageNode.getPath());
                break;
              }
            }
          }
          TreeUtil.selectPath(myTree, pathToSelect);
          myTree.expandPath(pathToSelect);
          return true;
        }
      }
    }

    return false;
  }