/* Simple tree node factory method - set's parent and user object.
   */
  private DefaultMutableTreeNode makeNode(Object userObject, MutableTreeNode parent) {

    DefaultMutableTreeNode node = new DefaultMutableTreeNode(userObject);

    if (parent != null) {
      treeModel.insertNodeInto(node, parent, parent.getChildCount());
    }

    return node;
  }
Ejemplo 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)));
    }
  }