Example usage for javax.swing.tree DefaultTreeModel getRoot

List of usage examples for javax.swing.tree DefaultTreeModel getRoot

Introduction

In this page you can find the example usage for javax.swing.tree DefaultTreeModel getRoot.

Prototype

public Object getRoot() 

Source Link

Document

Returns the root of the tree.

Usage

From source file:com.yosanai.java.aws.console.panel.InstancesPanel.java

/** Creates new form InstancesPanel */
public InstancesPanel() {
    initComponents();//from   ww  w . j av  a2  s.co  m
    DefaultTreeModel treeModel = (DefaultTreeModel) trInstances.getModel();
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot();
    rootNode.setAllowsChildren(true);
    rootNode.setUserObject("Instances");
    instancesTableModel = (DefaultTableModel) tblInstances.getModel();
    instanceTableModel = new ObjectEditorTableModel();
    instanceTableModel.setEditable(false);
    instanceTableModel.setExpandAllProperties(true);
    trInstances.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
}

From source file:com.yosanai.java.aws.console.panel.InstancesPanel.java

public void loadInstances() {
    new Thread(new Runnable() {

        @Override/*from   w  ww .j  a va2 s .c om*/
        public void run() {
            DefaultTreeModel treeModel = (DefaultTreeModel) trInstances.getModel();
            DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) treeModel.getRoot();
            tblInstances.clearSelection();
            trInstances.clearSelection();
            rootNode.removeAllChildren();
            treeModel.reload();
            tblInstances.setModel(instancesTableModel);
            DescribeInstancesResult result = awsConnectionProvider.getConnection().describeInstances();
            while (0 < instancesTableModel.getRowCount()) {
                instancesTableModel.removeRow(0);
            }
            for (Reservation reservation : result.getReservations()) {
                for (Instance instance : reservation.getInstances()) {
                    String name = null;
                    StringBuilder tags = new StringBuilder();
                    for (Tag tag : instance.getTags()) {
                        tags.append(tag.getKey());
                        tags.append("=");
                        tags.append(tag.getValue());
                        if (StringUtils.equalsIgnoreCase(nameTag, tag.getKey())) {
                            name = tag.getValue();
                        }
                    }
                    try {
                        boolean apiTermination = awsConnectionProvider
                                .getApiTermination(instance.getInstanceId());
                        instancesTableModel.addRow(new Object[] { instance.getInstanceId(),
                                instance.getPublicDnsName(), instance.getPublicIpAddress(),
                                instance.getPrivateDnsName(), instance.getPrivateIpAddress(),
                                apiTermination ? "Yes" : "No", instance.getState().getName(),
                                instance.getInstanceType(), instance.getKeyName(),
                                StringUtils.join(reservation.getGroupNames(), ","),
                                instance.getPlacement().getAvailabilityZone(),
                                DATE_FORMAT.format(instance.getLaunchTime()), tags.toString() });
                        DefaultMutableTreeNode instanceNode = new DefaultMutableTreeNode(
                                new InstanceObjectWrapper(instance, name), false);
                        rootNode.add(instanceNode);
                        treeModel.reload();
                    } catch (Exception ex) {
                        Logger.getLogger(InstancesPanel.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
    }).start();
}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java

public void propertyChange(PropertyChangeEvent evt) {
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    model.nodeChanged((TreeNode) model.getRoot());

    previewPanel.rebuild(selectedAltView.getMode() == AltViewIFace.CreationMode.EDIT);
}

From source file:dataviewer.DataViewer.java

private void fill_tree() {
    txt_count.setText("");

    DefaultTreeModel tm = (DefaultTreeModel) tr_files.getModel();
    DefaultMutableTreeNode top;/*from  www . j  av a2  s  .  com*/
    cur_path = new File(cur_path).getAbsolutePath();
    if (cur_path.charAt(cur_path.length() - 1) == '.') {
        cur_path = cur_path.substring(0, cur_path.length() - 1);
    }
    if (cur_path.charAt(cur_path.length() - 1) == File.separatorChar) {
        cur_path = cur_path.substring(0, cur_path.length() - 1);
    }
    if (tm != null) {
        top = (DefaultMutableTreeNode) tm.getRoot();
        top.removeAllChildren();
        top.setUserObject(cur_path);
    } else {
        top = new DefaultMutableTreeNode(cur_path);
    }

    // get all children nodes and remove them
    // rename the user object
    ArrayList<String> files = this.getAllFileNames(cur_path);
    Collections.sort(files);

    int j = 1;
    int selected_index = -1;
    for (String f : files) {
        String ex = this.getExtension(f);
        boolean is_folder = (new File(cur_path + File.separator + f)).isDirectory();
        if (is_folder || ex.equals(".txt") || ex.equals(".dat") || ex.equals(".csv") || ex.equals(".tsv")) {
            DefaultMutableTreeNode node = new DefaultMutableTreeNode(f);
            top.add(node);
            if (f.equals(selected_file)) {
                selected_index = j;
            }
            j++;
        }
    }

    //DefaultTreeModel treeModel = new DefaultTreeModel(top);
    //tr_files.setModel(treeModel);
    if (tm == null) {
        tr_files.setModel(new DefaultTreeModel(top));
    } else {
        try {
            tm.reload();
        } catch (Exception e) {
            tm.reload();
        }
    }

    if (selected_index > -1) {
        tr_files.setSelectionRow(selected_index);
    }

    tr_files.grabFocus();
}

From source file:com.SE.myPlayer.MusicPlayerGUI.java

private void treeReferesh() {
        DefaultTreeModel myModel = (DefaultTreeModel) folder_Playlist_Tree.getModel();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode) myModel.getRoot();
        root.removeAllChildren();//from   www  .  j a v a2s  . c o m

        DefaultMutableTreeNode library = new DefaultMutableTreeNode("library");
        DefaultMutableTreeNode playlist = new DefaultMutableTreeNode("playlist");

        myModel.insertNodeInto(library, root, root.getChildCount());
        myModel.insertNodeInto(playlist, root, root.getChildCount());

        try {
            con = db.getCon();
            stmt = con.createStatement();
            String node;

            ResultSet rs = stmt.executeQuery("select pn_name from playlist_name");

            while (rs.next()) {
                node = rs.getString(1);
                DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(node);
                myModel.insertNodeInto(newNode, playlist, playlist.getChildCount());
            }

            if (con != null) {
                stmt.close();
                con.close();
            }
        } catch (SQLException e) {
            System.out.println("Error in Stmt " + e);
        }

        myModel.reload();
        folder_Playlist_Tree.setModel(myModel);
    }

From source file:com.SE.myPlayer.MusicPlayerGUI.java

private void folder_Playlist_TreeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_folder_Playlist_TreeMouseClicked
        DefaultMutableTreeNode selectedNode;

        if (evt.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(evt)) {
            selectedNode = (DefaultMutableTreeNode) folder_Playlist_Tree.getSelectionPath().getLastPathComponent();
            getSongTable(selectedNode.toString());
            lastOpen = selectedNode.toString();
            for (ObjectBean list1 : list) {
                if (list1.getTitle().equals("library")) {
                    list1.setLastOpen(lastOpen);
                }//  w  w w  .  ja  v  a 2  s.c  o  m
            }
        } else if (SwingUtilities.isRightMouseButton(evt)) {
            DefaultTreeModel myModel = (DefaultTreeModel) folder_Playlist_Tree.getModel();
            DefaultMutableTreeNode root = (DefaultMutableTreeNode) myModel.getRoot();

            TreeNode[] nodes = myModel.getPathToRoot(root);
            TreePath treepath = new TreePath(nodes);
            folder_Playlist_Tree.setSelectionPath(treepath);
            folder_Playlist_Tree.scrollPathToVisible(treepath);

            TreePath path = folder_Playlist_Tree.getPathForLocation(evt.getX(), evt.getY());
            folder_Playlist_Tree.setSelectionPath(path);
            folder_Playlist_Tree.scrollPathToVisible(path);
            if (!folder_Playlist_Tree.isSelectionEmpty()) {
                selectedNode = (DefaultMutableTreeNode) folder_Playlist_Tree.getSelectionPath()
                        .getLastPathComponent();
                if (!"playlist".equals(selectedNode.toString()) && !"library".equals(selectedNode.toString())) {
                    folderTree_PopUp.show(folder_Playlist_Tree, evt.getX(), evt.getY());
                }
            }
        }
    }

From source file:com.SE.myPlayer.MusicPlayerGUI.java

private void createPlaylistActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createPlaylistActionPerformed
        String input = JOptionPane.showInputDialog("Enter playlist Name: ");
        if (input == null) {
        } else if (!input.equals("")) {
            int validInput = sd.newTreeNode(input);
            if (validInput == 1) {
                treeReferesh();/*from w w w  .  j  a  v  a 2s. c  o  m*/
                DefaultTreeModel model = (DefaultTreeModel) folder_Playlist_Tree.getModel();
                DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
                DefaultMutableTreeNode playlist = (DefaultMutableTreeNode) model.getChild(root, 1);
                DefaultMutableTreeNode newPlaylist = (DefaultMutableTreeNode) model.getChild(playlist,
                        model.getChildCount(playlist) - 1);

                getSongTable(newPlaylist.toString());

                TreeNode[] nodes = model.getPathToRoot(newPlaylist);
                TreePath treepath = new TreePath(nodes);

                folder_Playlist_Tree.setExpandsSelectedPaths(true);
                folder_Playlist_Tree.setSelectionPath(treepath);
                folder_Playlist_Tree.scrollPathToVisible(treepath);

                addJMenuItemsToPopUP();

                lastOpen = input;
                for (ObjectBean list1 : list) {
                    if (list1.getTitle().equals("library")) {
                        list1.setLastOpen(lastOpen);
                    }
                }
            } else {
                createPlaylistActionPerformed(evt);
            }
        } else {
            JOptionPane.showMessageDialog(null, "Please Enter Valid Playlist Name", "Error in Name",
                    JOptionPane.ERROR_MESSAGE);
            createPlaylistActionPerformed(evt);
        }
    }

From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java

/**
 * Adds a new row in the right position (above).
 *///from  ww  w . ja va  2s .  c  o  m
protected void addRow() {
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();

    FormRow newRow = new FormRow();

    DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(newRow);
    newNode.setUserObject(newRow);

    DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getSelectionModel().getSelectionPath()
            .getLastPathComponent();
    DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) selectedNode.getParent();
    if (parentNode == null) {
        parentNode = (DefaultMutableTreeNode) model.getRoot();
        selectedNode = null;
    }

    int position;
    if (selectedRow == null || parentNode.getUserObject() instanceof String) {
        formViewDef.getRows().add(newRow);
        position = formViewDef.getRows().size() - 1;

    } else {
        position = formViewDef.getRows().indexOf(selectedRow);
        formViewDef.getRows().insertElementAt(newRow, (byte) position);
    }

    model.insertNodeInto(newNode, parentNode, position);

    renumberRows(formViewDef.getRows());
    updateTreeNodes((DefaultMutableTreeNode) model.getRoot(), model, false);

    Object[] newPath = new Object[2];
    newPath[0] = parentNode;
    newPath[1] = newNode;

    final TreePath newTreePath = new TreePath(newPath);
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            tree.setSelectionPath(newTreePath);
        }
    });

    previewPanel.rebuild(false);
}

From source file:GUI.MainWindow.java

private void showNotes() {
    DefaultTreeModel dtm = (DefaultTreeModel) VulnTree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm.getRoot();
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) VulnTree.getLastSelectedPathComponent();
    Object obj = node.getUserObject();
    if (obj instanceof Vulnerability) {
        ShowNotesWindow shownotes = new ShowNotesWindow(this, this.VulnTree, true, node, null,
                this.fileChooser.getCurrentDirectory().getAbsolutePath());
        shownotes.setVisible(true);//from w w w  .  ja  v  a 2s  . c om
    }
}

From source file:GUI.MainWindow.java

private void VulnTreeFilterCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_VulnTreeFilterCaretUpdate
    String search_term = VulnTreeFilter.getText();

    DefaultTreeModel dtm = (DefaultTreeModel) VulnTree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm.getRoot();
    TreeUtils tu = new TreeUtils();

    if (search_term == null || search_term.equals("")) {
        // Clear the highlighted attribute on all nodes
        tu.clearHighlighting(root);/*from  www.  j a va  2  s.  com*/

    } else {
        // Loop through the tree and mark nodes that are highlighted.
        tu.searchTree(root, search_term);
    }
    root = tu.sortVulns(root);
    dtm.setRoot(root);
}