// ===============================================================
  // ===============================================================
  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);
    }
  }
 // ===============================================================
 // ===============================================================
 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;
 }
Example #3
0
  // {{{ removeSelectedNode() method
  private void removeSelectedNode() {
    TreePath path = resultTree.getSelectionPath();
    if (path == null) return;

    MutableTreeNode value = (MutableTreeNode) path.getLastPathComponent();

    if (path.getPathCount() > 1) {
      // Adjust selection so that repeating some removals
      // behave naturally.
      TreePath parentPath = path.getParentPath();
      MutableTreeNode parent = (MutableTreeNode) parentPath.getLastPathComponent();
      int removingIndex = parent.getIndex(value);
      int nextIndex = removingIndex + 1;
      if (nextIndex < parent.getChildCount()) {
        TreeNode next = parent.getChildAt(nextIndex);
        resultTree.setSelectionPath(parentPath.pathByAddingChild(next));
      } else {
        resultTree.setSelectionPath(parentPath);
      }

      resultTreeModel.removeNodeFromParent(value);
    }

    HyperSearchOperationNode.removeNodeFromCache(value);
    if (resultTreeRoot.getChildCount() == 0) {
      hideDockable();
    }
  } // }}}
 void deleteNodeParent(DefaultMutableTreeNode parent) throws Exception {
   while (parent.getChildCount() != 0) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent.getFirstChild();
     deleteNodeParent(node);
   }
   deleteNode(parent);
 }
Example #5
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;
  }
 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;
 }
  // ===============================================================
  // ===============================================================
  DefaultMutableTreeNode addThreadNode() {

    PollThread new_thread = new PollThread(getNextThreadNum());
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(new_thread);
    treeModel.insertNodeInto(node, root, root.getChildCount());
    return node;
  }
Example #8
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()));
   }
 }
 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;
 }
 // ===============================================================
 // ===============================================================
 private int getNextThreadNum() {
   int num = 0;
   for (int i = 0; i < root.getChildCount(); i++) {
     DefaultMutableTreeNode th_node = (DefaultMutableTreeNode) root.getChildAt(i);
     num = ((PollThread) th_node.getUserObject()).num;
   }
   return ++num;
 }
Example #11
0
    // {{{ getTreeCellRendererComponent() method
    @Override
    protected void configureTreeCellRendererComponent(
        JTree tree,
        Object value,
        boolean sel,
        boolean expanded,
        boolean leaf,
        int row,
        boolean hasFocus) {
      setIcon(null);
      DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;

      if (node.getUserObject() instanceof HyperSearchOperationNode) {
        setFont(boldFont);

        CountNodes countNodes = new CountNodes();
        traverseNodes(node, countNodes);

        setText(
            jEdit.getProperty(
                "hypersearch-results.result-caption",
                new Object[] {
                  node.toString(),
                  Integer.valueOf(countNodes.resultCount),
                  Integer.valueOf(countNodes.bufferCount)
                }));
      } else if (node.getUserObject() instanceof HyperSearchFolderNode) {
        setFont(plainFont);
        setText(node.toString() + " (" + node.getChildCount() + " files/folders)");
      } else if (node.getUserObject() instanceof HyperSearchFileNode) {
        // file name
        setFont(boldFont);
        HyperSearchFileNode hyperSearchFileNode = (HyperSearchFileNode) node.getUserObject();
        setText(
            jEdit.getProperty(
                "hypersearch-results.file-caption",
                new Object[] {
                  hyperSearchFileNode,
                  Integer.valueOf(hyperSearchFileNode.getCount()),
                  Integer.valueOf(node.getChildCount())
                }));
      } else {
        setFont(plainFont);
      }
    } // }}}
Example #12
0
 public static void sort(final DefaultMutableTreeNode node, final Comparator comparator) {
   final List<TreeNode> children = childrenToArray(node);
   Collections.sort(children, comparator);
   node.removeAllChildren();
   addChildrenTo(node, children);
   for (int i = 0; i < node.getChildCount(); i++) {
     sort((DefaultMutableTreeNode) node.getChildAt(i), comparator);
   }
 }
 private static DefaultMutableTreeNode findInChildren(
     DefaultMutableTreeNode currentTreeNode, AbstractTreeNode topPathElement) {
   for (int i = 0; i < currentTreeNode.getChildCount(); i++) {
     TreeNode child = currentTreeNode.getChildAt(i);
     if (((DefaultMutableTreeNode) child).getUserObject().equals(topPathElement)) {
       return (DefaultMutableTreeNode) child;
     }
   }
   return null;
 }
  // ===============================================================
  // ===============================================================
  private void moveLeaf(
      DefaultMutableTreeNode collec_node, DefaultMutableTreeNode leaf_node, int pos) {
    Object obj = collec_node.getUserObject();
    if (obj instanceof PollThread) {
      treeModel.removeNodeFromParent(leaf_node);
      if (pos < 0) treeModel.insertNodeInto(leaf_node, collec_node, collec_node.getChildCount());
      else treeModel.insertNodeInto(leaf_node, collec_node, pos);

      expandNode(leaf_node);
    }
  }
 // ===============================================================
 // ===============================================================
 private void expandChildren(DefaultMutableTreeNode node) {
   boolean level_done = false;
   for (int i = 0; i < node.getChildCount(); i++) {
     DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i);
     if (child.isLeaf()) {
       if (!level_done) {
         expandNode(child);
         level_done = true;
       }
     } else expandChildren(child);
   }
 }
 private void _storePaths(DefaultMutableTreeNode root) {
   ArrayList<TreeNode> childNodes = childrenToArray(root);
   for (final Object childNode1 : childNodes) {
     DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) childNode1;
     TreePath path = new TreePath(childNode.getPath());
     if (myTree.isPathSelected(path)) {
       addPathToList(childNode, mySelectionPaths);
     }
     if ((myTree.isExpanded(path) || childNode.getChildCount() == 0) && !childNode.isLeaf()) {
       addPathToList(childNode, myPathsToExpand);
       _storePaths(childNode);
     }
   }
 }
Example #17
0
 public void addMessages(AntMessage[] messages) {
   DefaultMutableTreeNode parentNode =
       (DefaultMutableTreeNode) myParentPath.getLastPathComponent();
   int[] indices = new int[messages.length];
   for (int i = 0; i < messages.length; i++) {
     AntMessage message = messages[i];
     MessageNode messageNode = createMessageNode(message);
     indices[i] = parentNode.getChildCount();
     parentNode.insert(messageNode, indices[i]);
     myMessageItems.add(messageNode);
   }
   myTreeModel.nodesWereInserted(parentNode, indices);
   handleExpansion();
 }
 private void restoreUsageExpandState(final Collection<UsageState> states) {
   // always expand the last level group
   final DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTree.getModel().getRoot();
   for (int i = root.getChildCount() - 1; i >= 0; i--) {
     final DefaultMutableTreeNode child = (DefaultMutableTreeNode) root.getChildAt(i);
     if (child instanceof GroupNode) {
       final TreePath treePath = new TreePath(child.getPath());
       myTree.expandPath(treePath);
     }
   }
   myTree.getSelectionModel().clearSelection();
   for (final UsageState usageState : states) {
     usageState.restore();
   }
 }
    public void storePaths() {
      myPathsToExpand = new ArrayList<String>();
      mySelectionPaths = new ArrayList<String>();

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

      TreePath path = new TreePath(root.getPath());
      if (myTree.isPathSelected(path)) {
        addPathToList(root, mySelectionPaths);
      }
      if (myTree.isExpanded(path) || root.getChildCount() == 0) {
        addPathToList(root, myPathsToExpand);
        _storePaths(root);
      }
    }
Example #20
0
 @Nullable
 public static DefaultMutableTreeNode findNodeWithObject(
     final DefaultMutableTreeNode aRoot, final Object aObject) {
   if (Comparing.equal(aRoot.getUserObject(), aObject)) {
     return aRoot;
   } else {
     for (int i = 0; i < aRoot.getChildCount(); i++) {
       final DefaultMutableTreeNode candidate =
           findNodeWithObject((DefaultMutableTreeNode) aRoot.getChildAt(i), aObject);
       if (null != candidate) {
         return candidate;
       }
     }
     return null;
   }
 }
 private void captureUsagesExpandState(TreePath pathFrom, final Collection<UsageState> states) {
   if (!myTree.isExpanded(pathFrom)) {
     return;
   }
   final DefaultMutableTreeNode node = (DefaultMutableTreeNode) pathFrom.getLastPathComponent();
   final int childCount = node.getChildCount();
   for (int idx = 0; idx < childCount; idx++) {
     final TreeNode child = node.getChildAt(idx);
     if (child instanceof UsageNode) {
       final Usage usage = ((UsageNode) child).getUsage();
       states.add(
           new UsageState(
               usage,
               myTree.getSelectionModel().isPathSelected(pathFrom.pathByAddingChild(child))));
     } else {
       captureUsagesExpandState(pathFrom.pathByAddingChild(child), states);
     }
   }
 }
Example #22
0
  /**
   * @param searchNode the result node
   * @param selectNode the node that must be selected, or null
   * @since jEdit 4.3pre12
   */
  public void searchDone(
      final DefaultMutableTreeNode searchNode, final DefaultMutableTreeNode selectNode) {
    stop.setEnabled(false);
    final int nodeCount = searchNode.getChildCount();
    if (nodeCount < 1) {
      searchFailed();
      return;
    }

    caption.setText(
        jEdit.getProperty("hypersearch-results.done", new String[] {trimSearchString()}));

    EventQueue.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            if (!multiStatus) {
              for (int i = 0; i < resultTreeRoot.getChildCount(); i++) {
                resultTreeRoot.remove(0);
              }
            }

            resultTreeRoot.add(searchNode);
            resultTreeModel.reload(resultTreeRoot);

            for (int i = 0; i < nodeCount; i++) {
              TreePath lastNode =
                  new TreePath(((DefaultMutableTreeNode) searchNode.getChildAt(i)).getPath());

              resultTree.expandPath(lastNode);
            }
            TreePath treePath;
            if (selectNode == null) {
              treePath = new TreePath(new Object[] {resultTreeRoot, searchNode});
            } else {
              treePath = new TreePath(selectNode.getPath());
            }
            resultTree.setSelectionPath(treePath);
            resultTree.scrollPathToVisible(treePath);
          }
        });
  } // }}}
Example #23
0
 private DefaultMutableTreeNode findIDorURL(DefaultMutableTreeNode node, ID id, URL url) {
   SearchTOCItem item = (SearchTOCItem) node.getUserObject();
   if (item != null) {
     ID testID = item.getID();
     if (testID != null && id != null && testID.equals(id)) {
       return node;
     } else {
       URL testURL = item.getURL();
       if (testURL != null && url != null && url.sameFile(testURL)) {
         return node;
       }
     }
   }
   int size = node.getChildCount();
   for (int i = 0; i < size; i++) {
     DefaultMutableTreeNode tmp = (DefaultMutableTreeNode) node.getChildAt(i);
     DefaultMutableTreeNode test = findIDorURL(tmp, id, url);
     if (test != null) {
       return test;
     }
   }
   return null;
 }
  // ===============================================================
  // ===============================================================
  void removeThread() {
    DefaultMutableTreeNode node = getSelectedNode();

    if (node != null) {
      Object obj = node.getUserObject();
      if (obj instanceof PollThread) {
        //	Check if device(s) associated.
        if (node.getChildCount() == 0) {
          //	get future selected node
          DefaultMutableTreeNode next_node = getFutureSelectedNode(node);
          //	Remove selected one
          treeModel.removeNodeFromParent(node);
          PollThread pt = (PollThread) obj;
          threadsInfo.remove(pt);
          //	And select the found node
          TreeNode[] tree_node = next_node.getPath();
          TreePath path = new TreePath(tree_node);
          setSelectionPath(path);
          scrollPathToVisible(path);
        } else Utils.popupError(parent, "Cannot remove a not empty thread !");
      }
    }
  }
  void onAdd() {
    DefaultTreeModel model = (DefaultTreeModel) m_tree.getModel();
    TreePath path = m_tree.getSelectionPath();
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    OrganizationEditorDlg dlg = null;

    if (node == model.getRoot())
      dlg =
          new OrganizationEditorDlg(
              pohaci.gumunda.cgui.GumundaMainFrame.getMainFrame(), m_conn, m_sessionid, null);
    else
      dlg =
          new OrganizationEditorDlg(
              pohaci.gumunda.cgui.GumundaMainFrame.getMainFrame(), m_conn, m_sessionid, node);
    dlg.setVisible(true);

    if (dlg.getResponse() == JOptionPane.OK_OPTION) {
      Organization org = new Organization(dlg.getOrganization(), dlg.getOrganization().getCode());
      DefaultMutableTreeNode child = new DefaultMutableTreeNode(org);
      model.insertNodeInto(child, node, node.getChildCount());
      m_tree.scrollPathToVisible(new TreePath(model.getPathToRoot(child)));
    }
  }
Example #26
0
 public void finishBuild(String messageText) {
   collapseTargets();
   DefaultMutableTreeNode root = (DefaultMutableTreeNode) myTreeModel.getRoot();
   myStatusNode = new DefaultMutableTreeNode(messageText);
   myTreeModel.insertNodeInto(myStatusNode, root, root.getChildCount());
 }