if (!tabbedPane.getSelectedComponent().equals(hcb)) { globalCommandLineMenuItem.setEnabled(false); newHostMenuItem.setEnabled(false); newNodeMenu.setEnabled(false); commandLineMenuItem.setEnabled(false); describeHostMenuItem.setEnabled(false); describeNodeMenuItem.setEnabled(false); hostTypeMenuItem.setEnabled(false); hostLocationMenuItem.setEnabled(false); deleteHostMenuItem.setEnabled(false); deleteNodeMenuItem.setEnabled(false);
Component selectedComponent = tabbedPane.getSelectedComponent(); boolean communityEnabled = selectedComponent.equals(communityPanel); newCommunityMenuItem.setEnabled(communityEnabled); viewCommunityMenuItem.setEnabled(communityEnabled); boolean hcbEnabled = selectedComponent.equals(hcb); globalCommandLineMenuItem.setEnabled(hcbEnabled); newHostMenuItem.setEnabled(hcbEnabled); newNodeMenu.setEnabled(hcbEnabled); commandLineMenuItem.setEnabled(hcbEnabled); describeHostMenuItem.setEnabled(hcbEnabled); describeNodeMenuItem.setEnabled(hcbEnabled); hostTypeMenuItem.setEnabled(hcbEnabled); hostLocationMenuItem.setEnabled(hcbEnabled); deleteHostMenuItem.setEnabled(hcbEnabled); deleteNodeMenuItem.setEnabled(hcbEnabled); if (!hcbEnabled)
      public void menuSelected(MenuEvent e) {        // if host configuration builder not selected        // disable all the menu commands for it        if (!tabbedPane.getSelectedComponent().equals(hcb)) {          globalCommandLineMenuItem.setEnabled(false);          newHostMenuItem.setEnabled(false);          newNodeMenu.setEnabled(false);          commandLineMenuItem.setEnabled(false);          describeHostMenuItem.setEnabled(false);          describeNodeMenuItem.setEnabled(false);          hostTypeMenuItem.setEnabled(false);          hostLocationMenuItem.setEnabled(false);          deleteHostMenuItem.setEnabled(false);          deleteNodeMenuItem.setEnabled(false);          return;        }        // enable "global command line" command         // if either root, or any set of hosts or nodes is selected        DefaultMutableTreeNode[] hostsInHostTree =           hcb.getSelectedHostsInHostTree();        DefaultMutableTreeNode[] nodesInHostTree =           hcb.getSelectedNodesInHostTree();        DefaultMutableTreeNode[] nodesInNodeTree =           hcb.getSelectedNodesInNodeTree();        boolean isHostRootSelected = hcb.isHostTreeRootSelected();        boolean isNodeRootSelected = hcb.isNodeTreeRootSelected();        newHostMenuItem.setEnabled(isHostRootSelected);        if (isHostRootSelected || isNodeRootSelected ||            (hostsInHostTree != null) ||            (nodesInHostTree != null) ||            (nodesInNodeTree != null))          globalCommandLineMenuItem.setEnabled(true);        else          globalCommandLineMenuItem.setEnabled(false);        // enable "new node" command if unassigned nodes root is selected        // or one host is selected in the host tree        newUnassignedNodeMenuItem.setEnabled(isNodeRootSelected);        if (hostsInHostTree != null && hostsInHostTree.length == 1) {          newAssignedNodeMenuItem.setText("On " +                                           hostsInHostTree[0].toString());          newAssignedNodeMenuItem.setEnabled(true);        } else           newAssignedNodeMenuItem.setEnabled(false);        newNodeMenu.setEnabled(newAssignedNodeMenuItem.isEnabled() ||                               newUnassignedNodeMenuItem.isEnabled());        // enable "new host" command if host tree root is selected        newHostMenuItem.setEnabled(isHostRootSelected);        // if a single node is selected        // enable "command line arguments"        int nodeCount = 0;        if (nodesInHostTree != null)          nodeCount = nodesInHostTree.length;        if (nodesInNodeTree != null)          nodeCount += nodesInNodeTree.length;        commandLineMenuItem.setEnabled(nodeCount == 1);        describeHostMenuItem.setEnabled(hostsInHostTree != null);        describeNodeMenuItem.setEnabled(nodesInHostTree != null ||                                        nodesInNodeTree != null);        hostTypeMenuItem.setEnabled(hostsInHostTree != null);        hostLocationMenuItem.setEnabled(hostsInHostTree != null);        deleteHostMenuItem.setEnabled(hostsInHostTree != null);        deleteNodeMenuItem.setEnabled(nodesInHostTree != null ||                                      nodesInNodeTree != null);      }