@Nullable
 private TreePath findOption(@NotNull Object nodeObject, @NotNull DescriptorMatcher matcher) {
   for (int i = 0; i < myTreeModel.getChildCount(nodeObject); i++) {
     Object childObject = myTreeModel.getChild(nodeObject, i);
     if (childObject instanceof MyTreeNode) {
       Object data = ((MyTreeNode) childObject).getUserObject();
       if (matcher.matches(data)) {
         return new TreePath(myTreeModel.getPathToRoot((MyTreeNode) childObject));
       }
     }
     TreePath pathInChild = findOption(childObject, matcher);
     if (pathInChild != null) return pathInChild;
   }
   return null;
 }
Exemplo n.º 2
0
  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)));
    }
  }