newNodeMenuItem_actionPerformed(e);
createUnassignedNode();
  private void initDisplay() {    // host split pane contains host tree and     // the bottom split pane which contains the node and agent trees    JSplitPane hostPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);    // tree of hosts and assigned nodes and agents    DefaultMutableTreeNode root =       new DefaultMutableTreeNode(new ConsoleTreeObject("Hosts", 		       "org.cougaar.tools.csmart.ui.component.HostComponent"));    // setting "askAllowsChildren" forces empty nodes that can have    // children to be displayed as "folders" rather than leaf nodes    DefaultTreeModel model = createModel(experiment, root, true);    hostTree = new ConsoleDNDTree(model);    hostTree.setExpandsSelectedPaths(true);    // cell editor returns false if user tries to edit root node    DefaultCellEditor myEditor = new DefaultCellEditor(new JTextField()) {      public boolean isCellEditable(EventObject e) {	if (super.isCellEditable(e) && e instanceof MouseEvent) {	  TreePath path = hostTree.getPathForLocation(((MouseEvent)e).getX(),						      ((MouseEvent)e).getY());	  if (path == null)	    return false;	  Object o = path.getLastPathComponent();          DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)o;	  if (treeNode.isRoot() ||              ((ConsoleTreeObject)treeNode.getUserObject()).isAgent())	    return false;	}	return super.isCellEditable(e);      }      public boolean stopCellEditing() {        TreePath path = hostTree.getEditingPath();        DefaultMutableTreeNode node =          (DefaultMutableTreeNode)path.getLastPathComponent();        int result = 0;        if (node.getUserObject() instanceof ConsoleTreeObject) {          ConsoleTreeObject cto = (ConsoleTreeObject)node.getUserObject();          if (cto.isHost()) {            // stop cell editing, accept new unique value            if (isHostNameUnique((String)getCellEditorValue()))              return super.stopCellEditing();            // tell user that value isn't unique            result = JOptionPane.showConfirmDialog(hostConfigurationBuilder,                                                   "Use an unique name",                                                   "Host Name Not Unique",                                                   JOptionPane.OK_CANCEL_OPTION,                                                   JOptionPane.ERROR_MESSAGE);          } else if (cto.isNode()) {            // stop cell editing, accept new unique value            if (isNodeNameUnique((String)getCellEditorValue()))              return super.stopCellEditing();            // tell user that value isn't unique            result = JOptionPane.showConfirmDialog(hostConfigurationBuilder,                                                   "Use an unique name",                                                   "Node Name Not Unique",                                                   JOptionPane.OK_CANCEL_OPTION,                                                   JOptionPane.ERROR_MESSAGE);          }        } else          return super.stopCellEditing();        // user cancelled the message dialog, so cancel the editing        if (result != JOptionPane.OK_OPTION) {          cancelCellEditing();          return true;        }        // user entered non-unique value, not done editing        return false;      }    };    hostTree.setCellEditor(myEditor);    JScrollPane hostTreeScrollPane = new JScrollPane(hostTree);    hostTreeScrollPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));    hostPane.setTopComponent(hostTreeScrollPane);    //    hostTree.getModel().addTreeModelListener(this);    // create popup menus for host tree    hostRootMenu = new JPopupMenu();    hostHostMenu = new JPopupMenu();    hostNodeMenu = new JPopupMenu();    JMenuItem newHostMenuItem = new JMenuItem(NEW_HOST_MENU_ITEM);    newHostMenuItem.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	newHostMenuItem_actionPerformed(e);      }    });    JMenuItem deleteHostMenuItem = new JMenuItem(DELETE_MENU_ITEM);    deleteHostMenuItem.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	deleteHostMenuItem_actionPerformed(e);      }    });    newNodeInHostMenuItem = new JMenuItem(NEW_NODE_MENU_ITEM);    newNodeInHostMenuItem.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	newNodeInHostMenuItem_actionPerformed(e);      }    });    JMenuItem hostDescriptionMenuItem =       new JMenuItem(DESCRIPTION_MENU_ITEM);    hostDescriptionMenuItem.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	hostDescriptionMenuItem_actionPerformed(e);      }    });    JMenuItem hostLocationMenuItem = new JMenuItem(HOST_LOCATION_MENU_ITEM);    hostLocationMenuItem.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	hostLocationMenuItem_actionPerformed(e);      }    });    JMenuItem hostTypeMenuItem = new JMenuItem(HOST_TYPE_MENU_ITEM);    hostTypeMenuItem.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	hostTypeMenuItem_actionPerformed(e);      }    });    JMenuItem describeNodeInHostMenuItem =       new JMenuItem(DESCRIPTION_MENU_ITEM);    describeNodeInHostMenuItem.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        describeNodeMenuItem_actionPerformed(hostTree);      }    });    cmdLineNodeInHostMenuItem =       new JMenuItem(NODE_COMMAND_LINE_MENU_ITEM);    cmdLineNodeInHostMenuItem.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        cmdLineNodeMenuItem_actionPerformed(hostTree);      }    });    cmdLineNodeInHostMenuItem.setEnabled(true);    Action globalCmdLineAction = new AbstractAction(GLOBAL_COMMAND_LINE_MENU_ITEM) {      public void actionPerformed(ActionEvent e) {        globalCmdLineMenuItem_actionPerformed();      }    };    JMenuItem deleteNodeInHostMenuItem = new JMenuItem(DELETE_MENU_ITEM);    deleteNodeInHostMenuItem.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	deleteNodeInHostMenuItem_actionPerformed(e);      }    });    // init pop-up menus    hostRootMenu.add(newHostMenuItem);    hostRootMenu.add(globalCmdLineAction);    hostHostMenu.add(hostDescriptionMenuItem);    hostHostMenu.add(hostTypeMenuItem);    hostHostMenu.add(hostLocationMenuItem);    hostHostMenu.add(newNodeInHostMenuItem);    hostHostMenu.add(globalCmdLineAction);    hostHostMenu.add(deleteHostMenuItem);    hostNodeMenu.add(describeNodeInHostMenuItem);    hostNodeMenu.add(cmdLineNodeInHostMenuItem);    hostNodeMenu.add(globalCmdLineAction);    hostNodeMenu.add(deleteNodeInHostMenuItem);        // attach a mouse listener to the host tree to display menu     MouseListener hostTreeMouseListener = new MouseAdapter() {      public void mouseClicked(MouseEvent e) {	if (!hostTree.isEditable()) return;	if (e.isPopupTrigger()) displayHostTreeMenu(e);      }      public void mousePressed(MouseEvent e) {	if (!hostTree.isEditable()) return;	if (e.isPopupTrigger()) displayHostTreeMenu(e);      }      public void mouseReleased(MouseEvent e) {	if (!hostTree.isEditable()) return;	if (e.isPopupTrigger()) displayHostTreeMenu(e);      }    };    hostTree.addMouseListener(hostTreeMouseListener);    // bottom split pane contains the node and agent trees    JSplitPane bottomPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);    // tree of unassigned nodes    ConsoleTreeObject cto = new ConsoleTreeObject("Nodes (unassigned)",                  "org.cougaar.tools.csmart.ui.component.NodeComponent");    root = new DefaultMutableTreeNode(cto, true);    model = createModel(experiment, root, true);    nodeTree = new ConsoleDNDTree(model);    // cell editor returns false if try to edit agent names or root name    DefaultCellEditor nodeEditor = new DefaultCellEditor(new JTextField()) {      public boolean isCellEditable(EventObject e) {	if (super.isCellEditable(e) && e instanceof MouseEvent) {	  TreePath path = hostTree.getPathForLocation(((MouseEvent)e).getX(),						      ((MouseEvent)e).getY());	  if (path == null)	    return false;	  Object o = path.getLastPathComponent();	  DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)o;	  if (treeNode.isRoot() ||	      ((ConsoleTreeObject)treeNode.getUserObject()).isAgent())	    return false;	}	return super.isCellEditable(e);      }      public boolean stopCellEditing() {        // stop cell editing, accept new unique value        if (isNodeNameUnique((String)getCellEditorValue()))          return super.stopCellEditing();        // tell user that value isn't unique        int ok = JOptionPane.showConfirmDialog(hostConfigurationBuilder,                                               "Use an unique name",                                               "Node Name Not Unique",                                               JOptionPane.OK_CANCEL_OPTION,                                               JOptionPane.ERROR_MESSAGE);        // user cancelled the message dialog, so cancel the editing        if (ok != JOptionPane.OK_OPTION) {          cancelCellEditing();          return true;        }        // user entered non-unique value, not done editing        return false;      }    };    nodeTree.setCellEditor(nodeEditor);    nodeTree.setExpandsSelectedPaths(true);    JScrollPane nodeTreeScrollPane = new JScrollPane(nodeTree);    nodeTreeScrollPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));    bottomPane.setTopComponent(nodeTreeScrollPane);    // popup menu for creating and deleting nodes    nodeRootMenu = new JPopupMenu();    nodeNodeMenu = new JPopupMenu();    JMenuItem newNodeMenuItem = new JMenuItem(NEW_NODE_MENU_ITEM);    newNodeMenuItem.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	newNodeMenuItem_actionPerformed(e);      }    });    nodeRootMenu.add(newNodeMenuItem);    nodeRootMenu.add(globalCmdLineAction);    JMenuItem describeNodeMenuItem = new JMenuItem(DESCRIPTION_MENU_ITEM);    describeNodeMenuItem.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	describeNodeMenuItem_actionPerformed(nodeTree);      }    });    cmdLineNodeMenuItem = new JMenuItem(NODE_COMMAND_LINE_MENU_ITEM);    cmdLineNodeMenuItem.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	cmdLineNodeMenuItem_actionPerformed(nodeTree);      }    });    cmdLineNodeMenuItem.setEnabled(true);    JMenuItem globalCmdLineMenuItem =       new JMenuItem(GLOBAL_COMMAND_LINE_MENU_ITEM);    globalCmdLineMenuItem.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        globalCmdLineMenuItem_actionPerformed();      }    });    globalCmdLineMenuItem.setEnabled(true);    JMenuItem deleteNodeMenuItem = new JMenuItem(DELETE_MENU_ITEM);    deleteNodeMenuItem.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {	deleteNodeMenuItem_actionPerformed(e);      }    });    nodeNodeMenu.add(describeNodeMenuItem);    nodeNodeMenu.add(cmdLineNodeMenuItem);    nodeNodeMenu.add(globalCmdLineAction);    nodeNodeMenu.add(deleteNodeMenuItem);    // attach a mouse listener to the node tree to display menu     MouseListener nodeTreeMouseListener = new MouseAdapter() {      public void mouseClicked(MouseEvent e) {	if (!nodeTree.isEditable()) return;	if (e.isPopupTrigger()) displayNodeTreeMenu(e);      }      public void mousePressed(MouseEvent e) {	if (!nodeTree.isEditable()) return;	if (e.isPopupTrigger()) displayNodeTreeMenu(e);      }      public void mouseReleased(MouseEvent e) {	if (!nodeTree.isEditable()) return;	if (e.isPopupTrigger()) displayNodeTreeMenu(e);      }    };    nodeTree.addMouseListener(nodeTreeMouseListener);    // tree of unassigned agents    cto = new ConsoleTreeObject("Agents (unassigned)", 		"org.cougaar.tools.csmart.ui.component.AgentComponent");    root = new DefaultMutableTreeNode(cto, true);    model = createModel(experiment, root, true);    agentTree = new ConsoleDNDTree(model);    // cell editor returns false; can't edit agent names or root name    DefaultCellEditor agentEditor = new DefaultCellEditor(new JTextField()) {      public boolean isCellEditable(EventObject e) {	return false;      }    };    agentTree.setCellEditor(agentEditor);    agentTree.setExpandsSelectedPaths(true);    JScrollPane agentTreeScrollPane = new JScrollPane(agentTree);    agentTreeScrollPane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));    bottomPane.setBottomComponent(agentTreeScrollPane);    hostPane.setBottomComponent(bottomPane);    setLayout(new BorderLayout());    add(hostPane, BorderLayout.CENTER);    hostPane.setDividerLocation(100);    bottomPane.setDividerLocation(100);  }