public TriggersTree(TriggersConfigurationDialog tcd) { super(new GridLayout(1, 0)); this.tcd = tcd; rootNode = new DefaultMutableTreeNode("Root Node"); treeModel = new DefaultTreeModel(rootNode); tree = new JTree(treeModel); treeRender = new TriggersTreeRender(); treeCellEditor = new TriggersTreeCellEditor(tree, treeRender); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setShowsRootHandles(false); tree.setRootVisible(false); tree.setDragEnabled(true); tree.setEditable(true); tree.addTreeSelectionListener(this); tree.setCellEditor(treeCellEditor); ToolTipManager.sharedInstance().registerComponent(tree); tree.setCellRenderer(treeRender); JScrollPane scrollPane = new JScrollPane(tree); add(scrollPane); reload(); for (Trigger trigger : Main.getTriggerManager().getTriggers()) { setSelectedTrigger(trigger); return; } }
public void reload() { removeNodes(); DefaultMutableTreeNode hostNode = new DefaultMutableTreeNode(Main.getLocalhost()); treeModel.insertNodeInto(hostNode, rootNode, rootNode.getChildCount()); for (Trigger trigger : Main.getTriggerManager().getTriggers()) { DefaultMutableTreeNode triggerNode = new DefaultMutableTreeNode(trigger); treeModel.insertNodeInto(triggerNode, hostNode, hostNode.getChildCount()); } expandAll(); }