Example usage for javax.swing.tree DefaultTreeModel DefaultTreeModel

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

Introduction

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

Prototype

@ConstructorProperties({ "root" })
public DefaultTreeModel(TreeNode root) 

Source Link

Document

Creates a tree in which any node can have children.

Usage

From source file:org.codinjutsu.tools.jenkins.view.BrowserPanel.java

private Tree createTree(final List<JenkinsSettings.FavoriteJob> favoriteJobs) {

    SimpleTree tree = new SimpleTree();
    tree.getEmptyText().setText(LOADING);
    tree.setCellRenderer(new JenkinsTreeRenderer(favoriteJobs));
    tree.setName("jobTree");
    tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode(jenkins)));

    new TreeSpeedSearch(tree, new Convertor<TreePath, String>() {

        @Override//from ww  w.  j  av a 2  s. c om
        public String convert(TreePath treePath) {
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
            final Object userObject = node.getUserObject();
            if (userObject instanceof Job) {
                return ((Job) userObject).getName();
            }
            return "<empty>";
        }
    });

    return tree;
}

From source file:org.codinjutsu.tools.nosql.redis.view.RedisFragmentedKeyTreeModel.java

private void updateFilteredModel() {
    DefaultMutableTreeNode sourceRoot = (DefaultMutableTreeNode) super.getRoot();
    DefaultMutableTreeNode targetRoot = (DefaultMutableTreeNode) sourceRoot.clone();
    wrapNodes(sourceRoot, separator);//from   w  ww .  j a  va  2 s.  com
    fragmentedKeyModel = new DefaultTreeModel(targetRoot);
    Object[] listeners = listenerList.getListenerList();
    for (int i = listeners.length - 2; i >= 0; i -= 2) {
        if (listeners[i] == TreeModelListener.class) {
            fragmentedKeyModel.addTreeModelListener((TreeModelListener) listeners[i + 1]);
        }
    }
    fireSeparatorChanged();
}

From source file:org.fhaes.gui.AnalysisResultsPanel.java

/**
 * Set up the AnalysisResults GUI// w w w .  j  a v a2s. c o  m
 */
private void initGUI() {

    setLayout(new BorderLayout(0, 0));
    if (Platform.isOSX())
        setBackground(MainWindow.MAC_BACKGROUND_COLOR);

    ImageIcon iconMultipleTables = Builder.getImageIcon("multipletables16.png");
    ImageIcon iconTable = Builder.getImageIcon("table16.png");

    // ImageIcon iconChart = Builder.getImageIcon("chart16.png");

    // Categories
    rootNode = new FHAESCategoryTreeNode("FHAES analysis results");
    categoryGeneral = new FHAESCategoryTreeNode("Descriptive summaries",
            Builder.getImageIcon("interval16.png"));
    categoryInterval = new FHAESCategoryTreeNode("Interval analysis", Builder.getImageIcon("interval16.png"));
    categorySeasonality = new FHAESCategoryTreeNode("Seasonality", Builder.getImageIcon("seasonality16.png"));
    categoryBinarySummaryMatrices = new FHAESCategoryTreeNode("Binary summary matrices",
            Builder.getImageIcon("matrix16.png"));
    categoryBinaryMatrices = new FHAESCategoryTreeNode("Binary comparison matrices",
            Builder.getImageIcon("matrix16.png"));
    categorySimMatrices = new FHAESCategoryTreeNode("Similarity matrices",
            Builder.getImageIcon("matrix16.png"));
    categoryDisSimMatrices = new FHAESCategoryTreeNode("Dissimilarity matrices",
            Builder.getImageIcon("matrix16.png"));

    // Menu actions

    // Results

    itemJaccard = new FHAESResultTreeNode(FHAESResult.JACCARD_SIMILARITY_MATRIX, iconMultipleTables);
    itemJaccard.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(SJACFile, new CSVFileFilter());
        }
    });

    itemCohen = new FHAESResultTreeNode(FHAESResult.COHEN_SIMILARITITY_MATRIX, iconMultipleTables);
    itemCohen.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(SCOHFile, new CSVFileFilter());
        }
    });

    itemJaccardD = new FHAESResultTreeNode(FHAESResult.JACCARD_SIMILARITY_MATRIX_D, iconMultipleTables);
    itemJaccardD.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(DSJACFile, new CSVFileFilter());
        }
    });

    itemCohenD = new FHAESResultTreeNode(FHAESResult.COHEN_SIMILARITITY_MATRIX_D, iconMultipleTables);
    itemCohenD.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(DSCOHFile, new CSVFileFilter());
        }
    });

    itemIntervalSummary = new FHAESResultTreeNode(FHAESResult.INTERVAL_SUMMARY, iconMultipleTables);
    itemIntervalSummary.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(intervalsSummaryFile, new CSVFileFilter());
        }
    });

    itemExceedence = new FHAESResultTreeNode(FHAESResult.INTERVAL_EXCEEDENCE_TABLE, iconMultipleTables);
    itemExceedence.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(intervalsExceedenceFile, new CSVFileFilter());
        }
    });

    itemSeasonalitySummary = new FHAESResultTreeNode(FHAESResult.SEASONALITY_SUMMARY, iconMultipleTables);
    itemSeasonalitySummary.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(seasonalitySummaryFile, new CSVFileFilter());
        }
    });

    itemBin00 = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_00, iconMultipleTables);
    itemBin00.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(bin00File, new CSVFileFilter());
        }
    });

    itemBin01 = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_01, iconMultipleTables);
    itemBin01.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(bin01File, new CSVFileFilter());
        }
    });

    itemBin10 = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_10, iconMultipleTables);
    itemBin10.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(bin10File, new CSVFileFilter());
        }
    });

    itemBin11 = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_11, iconMultipleTables);
    itemBin11.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(bin11File, new CSVFileFilter());
        }
    });

    itemBinSum = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_SUM, iconMultipleTables);
    itemBinSum.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(binSumFile, new CSVFileFilter());
        }

    });
    itemBinSiteSummary = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_SITE, iconMultipleTables);
    itemBinSiteSummary.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(siteSummaryFile, new CSVFileFilter());
        }
    });
    itemBinSiteSummary.addAction(new FHAESAction("Export to shapefile", "formatshp.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            new ShapeFileDialog(App.mainFrame, fhm);

        }
    });

    itemBinTreeSummary = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_TREE, iconMultipleTables);
    itemBinTreeSummary.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(treeSummaryFile, new CSVFileFilter());
        }
    });

    itemNTP = new FHAESResultTreeNode(FHAESResult.BINARY_MATRIX_NTP, iconMultipleTables);
    itemNTP.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(NTPFile, new CSVFileFilter());
        }
    });

    this.itemGeneralSummary = new FHAESResultTreeNode(FHAESResult.GENERAL_SUMMARY, iconMultipleTables);
    itemGeneralSummary.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(generalSummaryFile, new CSVFileFilter());
        }

    });

    this.itemSingleFileSummary = new FHAESResultTreeNode(FHAESResult.SINGLE_FILE_SUMMARY, iconTable);
    itemSingleFileSummary.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(singleFileSummaryFile, new CSVFileFilter());
        }

    });

    this.itemSingleEventSummary = new FHAESResultTreeNode(FHAESResult.SINGLE_EVENT_SUMMARY, iconTable);
    itemSingleEventSummary.addAction(new FHAESAction("Save to CSV", "formatcsv.png") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent event) {

            saveFileToDisk(singleEventSummaryFile, new CSVFileFilter());
        }

    });

    // Add results to categories
    categoryGeneral.add(itemGeneralSummary);
    categoryGeneral.add(itemSingleFileSummary);
    categoryGeneral.add(itemSingleEventSummary);
    categorySimMatrices.add(itemJaccard);
    categorySimMatrices.add(itemCohen);
    categoryDisSimMatrices.add(itemJaccardD);
    categoryDisSimMatrices.add(itemCohenD);
    categoryInterval.add(itemIntervalSummary);
    categoryInterval.add(itemExceedence);
    categorySeasonality.add(itemSeasonalitySummary);
    categoryBinaryMatrices.add(itemBin11);
    categoryBinaryMatrices.add(itemBin01);
    categoryBinaryMatrices.add(itemBin10);
    categoryBinaryMatrices.add(itemBin00);
    categoryBinaryMatrices.add(itemBinSum);
    categoryBinarySummaryMatrices.add(itemBinSiteSummary);
    categoryBinarySummaryMatrices.add(itemBinTreeSummary);
    categoryBinarySummaryMatrices.add(itemNTP);

    // Add categories to root of tree
    rootNode.add(categoryGeneral);
    rootNode.add(categoryInterval);
    rootNode.add(categorySeasonality);
    rootNode.add(categoryBinarySummaryMatrices);
    rootNode.add(categoryBinaryMatrices);
    rootNode.add(categorySimMatrices);
    rootNode.add(categoryDisSimMatrices);

    treeModel = new DefaultTreeModel(rootNode);

    splitPane = new JSplitPane();
    if (Platform.isOSX())
        splitPane.setBackground(MainWindow.MAC_BACKGROUND_COLOR);

    splitPane.setResizeWeight(0.9);
    add(splitPane, BorderLayout.CENTER);

    JPanel panelTree = new JPanel();
    splitPane.setRightComponent(panelTree);
    panelTree.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
    panelTree.setLayout(new BorderLayout(0, 0));

    // Build tree
    treeResults = new JTree();
    panelTree.add(treeResults);
    treeResults.setModel(treeModel);

    treeResults.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    treeResults.setCellRenderer(new FHAESResultTreeRenderer());

    pickResultPanel = new PickResultPanel();
    runAnalysisPanel = new RunAnalysisPanel();

    cards = new JPanel();
    cl = new CardLayout();
    cards.setLayout(cl);
    cards.add(pickResultPanel, PICKRESULTPANEL);
    cards.add(runAnalysisPanel, RUNANALYSIS);
    cards.add(emptyPanel, EMPTYPANEL);

    splitPane.setLeftComponent(cards);

    cl.show(cards, RUNANALYSIS);

    splitPaneResult = new JSplitPane();
    splitPaneResult.setOneTouchExpandable(true);
    splitPaneResult.setOrientation(JSplitPane.VERTICAL_SPLIT);
    cards.add(splitPaneResult, RESULTSPANEL);

    panelResult = new JPanel();

    panelResult.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    panelResult.setLayout(new BorderLayout(0, 0));

    goldFishPanel = new GoldFishPanel();
    splitPaneResult.setRightComponent(goldFishPanel);

    // Build table
    scrollPane = new JScrollPane();

    panelResult.add(scrollPane);
    table = new JXTable();
    adapter = new JTableSpreadsheetByRowAdapter(table);

    table.setModel(new DefaultTableModel());
    table.setHorizontalScrollEnabled(true);
    scrollPane.setViewportView(table);
    splitPaneResult.setLeftComponent(panelResult);

    // OSX Style hack
    if (Platform.isOSX())
        panelResult.setBackground(MainWindow.MAC_BACKGROUND_COLOR);
    if (Platform.isOSX())
        scrollPane.setBackground(MainWindow.MAC_BACKGROUND_COLOR);

    // Expand all nodes
    for (int i = 0; i < treeResults.getRowCount(); i++) {
        treeResults.expandRow(i);
    }

    treeResults.addTreeSelectionListener(this);

    treeResults.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {

            if (SwingUtilities.isRightMouseButton(e)) {
                int x = e.getX();
                int y = e.getY();
                JTree tree = (JTree) e.getSource();
                TreePath path = tree.getPathForLocation(x, y);
                if (path == null)
                    return;
                if (!tree.isEnabled())
                    return;

                tree.setSelectionPath(path);
                Component mc = e.getComponent();

                if (path != null && path.getLastPathComponent() instanceof FHAESResultTreeNode) {
                    FHAESResultTreeNode node = (FHAESResultTreeNode) path.getLastPathComponent();

                    if (!node.isEnabled())
                        return;

                    FHAESResultPopupMenu popupMenu = new FHAESResultPopupMenu(node.getArrayOfActions());
                    popupMenu.show(mc, e.getX(), e.getY());
                }
            }
        }

        @Override
        public void mouseEntered(MouseEvent arg0) {

        }

        @Override
        public void mouseExited(MouseEvent arg0) {

        }

        @Override
        public void mousePressed(MouseEvent arg0) {

        }

        @Override
        public void mouseReleased(MouseEvent arg0) {

        }

    });

    this.splitPaneResult.setDividerLocation(10000);
    this.splitPaneResult.setDividerSize(3);
    this.splitPaneResult.setResizeWeight(1);
}

From source file:org.icefaces.application.showcase.view.builder.ApplicationBuilder.java

/**
 * Gets/searches for a node that has the specified id and returns a fully
 * contstructed DefaultTreeModel for the found nodes children.
 *
 * @param nodeId unique id for a given node
 * @return found Node, otherwise null/*  w w  w  .j a va  2  s  .  c  om*/
 */
public DefaultTreeModel getChildNodeTree(String nodeId) {
    Node parentNode = nodeSearch(application.getNavigation().getNode(), nodeId);
    // if we have a node build up our tree. 
    if (parentNode != null) {
        // create root node, which will be hidden by component attribute
        // settings.
        DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
        NavigationTreeNode userObject = new NavigationTreeNode(rootNode);
        userObject.setText("rootNode");
        userObject.setExpanded(true);
        rootNode.setUserObject(userObject);

        // build a tree based on child nodes of parentNode.
        buildChildNodes(rootNode, parentNode.getNode());
        return new DefaultTreeModel(rootNode);
    }
    return null;
}

From source file:org.isatools.gui.datamanager.exportisa.ExportISAGUI.java

private void createDummyTree() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("  no studies found");

    DefaultTreeModel model = new DefaultTreeModel(root);
    studyAvailabilityTree = new CheckableTree(model);

}

From source file:org.isatools.gui.datamanager.exportisa.ExportISAGUI.java

private void createTree() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("  available studies");

    for (String key : availableStudies.keySet()) {
        System.out.println("adding " + key + " to tree");
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(new CheckableNode(key));

        if (availableStudies.get(key) != null) {
            for (String study : availableStudies.get(key)) {
                CheckableNode studyNode = new CheckableNode(study);
                node.add(new DefaultMutableTreeNode(studyNode));
            }/*  w  w w  . j  av a 2s  .  com*/
        }

        root.add(node);
    }

    DefaultTreeModel model = new DefaultTreeModel(root);
    studyAvailabilityTree = new CheckableTree(model);

}

From source file:org.isatools.gui.datamanager.studyaccess.StudyAccessionGUI.java

private void createTree() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("  available studies");

    for (String key : availableStudies.keySet()) {
        log.info("adding " + key + " to tree");
        DefaultMutableTreeNode node = new DefaultMutableTreeNode(new CheckableNode(key));

        if (availableStudies.get(key) != null) {
            for (String study : availableStudies.get(key)) {
                CheckableNode studyNode = new CheckableNode(study);
                node.add(new DefaultMutableTreeNode(studyNode));
            }/*from   w ww . j  ava  2s  .  c om*/
        }
        root.add(node);
    }

    DefaultTreeModel model = new DefaultTreeModel(root);
    studyAvailabilityTree = new CheckableTree(model);
    configureTreeLook();
}

From source file:org.isatools.isacreator.filechooser.FileChooserUI.java

/**
 * Create the Navigation Tree panel/*from  w  w w. j a  v  a 2  s. c  o m*/
 *
 * @return @see JPanel containing the navigation tree to browse a file system.
 */
private JPanel createNavTree() {
    JPanel treeContainer = new JPanel(new BorderLayout());
    treeContainer.setBackground(UIHelper.BG_COLOR);
    treeContainer
            .setBorder(new TitledBorder(UIHelper.GREEN_ROUNDED_BORDER, "", TitledBorder.DEFAULT_JUSTIFICATION,
                    TitledBorder.DEFAULT_POSITION, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR));

    JPanel navigationControls = new JPanel();
    navigationControls.setLayout(new BoxLayout(navigationControls, BoxLayout.LINE_AXIS));
    navigationControls.setOpaque(false);

    final JLabel navToParentDir = new JLabel(upIcon);
    navToParentDir.setOpaque(false);
    navToParentDir.addMouseListener(new CommonMouseAdapter() {

        public void mousePressed(MouseEvent event) {
            super.mousePressed(event);
            navToParentDir.setIcon(upIcon);
            try {
                updateTree(fileBrowser.getParentDirectory());
            } catch (IOException e) {
                errorAction("problem occurred!");
            }
        }

        public void mouseEntered(MouseEvent event) {
            super.mouseEntered(event);
            navToParentDir.setIcon(upIconOver);
        }

        public void mouseExited(MouseEvent event) {
            super.mouseExited(event);
            navToParentDir.setIcon(upIcon);
        }
    });

    navigationControls.add(navToParentDir);
    navigationControls.add(Box.createHorizontalStrut(5));

    final JLabel navToHomeDir = new JLabel(homeIcon);
    navToHomeDir.setOpaque(false);
    navToHomeDir.addMouseListener(new CommonMouseAdapter() {

        public void mousePressed(MouseEvent event) {
            super.mousePressed(event);
            navToHomeDir.setIcon(homeIcon);
            try {
                updateTree(fileBrowser.getHomeDirectory());

            } catch (IOException e) {
                if (e instanceof ConnectionException) {
                    status.setText("<html>status: not connected!</html>");
                }
                FileBrowserTreeNode defaultFTPNode = new FileBrowserTreeNode("problem occurred!", false,
                        FileBrowserTreeNode.DIRECTORY);
                updateTree(defaultFTPNode);
            }
        }

        public void mouseEntered(MouseEvent event) {
            super.mouseEntered(event);
            navToHomeDir.setIcon(homeIconOver);
        }

        public void mouseExited(MouseEvent event) {
            super.mouseExited(event);
            navToHomeDir.setIcon(homeIcon);
        }
    });

    navigationControls.add(navToHomeDir);
    navigationControls.add(Box.createGlue());

    treeContainer.add(navigationControls, BorderLayout.NORTH);

    try {
        treeModel = new DefaultTreeModel(fileBrowser.getHomeDirectory());
        directoryTree = new JTree(treeModel);
        directoryTree.setFont(UIHelper.VER_11_PLAIN);
        directoryTree.setCellRenderer(new FileSystemTreeCellRenderer());
    } catch (IOException e) {
        FileBrowserTreeNode defaultFTPNode = new FileBrowserTreeNode("problem occurred!", false,
                FileBrowserTreeNode.DIRECTORY);
        updateTree(defaultFTPNode);
    }

    directoryTree.addMouseListener(new CommonMouseAdapter() {

        public void mousePressed(MouseEvent event) {
            super.mousePressed(event);
            int selRow = directoryTree.getRowForLocation(event.getX(), event.getY());

            TreePath selPath = directoryTree.getPathForLocation(event.getX(), event.getY());

            if (selRow != -1) {
                final FileBrowserTreeNode node = (FileBrowserTreeNode) selPath.getLastPathComponent();

                if (SwingUtilities.isLeftMouseButton(event)) {

                    if (event.getClickCount() == 2) {
                        if ((node.getType() == FileBrowserTreeNode.DIRECTORY) && (node.getLevel() != 0)) {

                            String newPath;
                            if (fileBrowser instanceof LocalBrowser) {
                                newPath = ((File) fileBrowser.getDirFiles().get(node.toString())).getPath();
                            } else {
                                newPath = node.toString();
                            }
                            updateTree(fileBrowser.changeDirectory(newPath));
                        }

                        // else, if a leaf node, then add file to to list
                        if (node.isLeaf() && (node.getType() != FileBrowserTreeNode.DIRECTORY)) {
                            String extension = node.toString().substring(node.toString().lastIndexOf(".") + 1)
                                    .trim().toUpperCase();

                            FileChooserFile toAdd = null;

                            for (Object o : fileBrowser.getFileMap().get(extension)) {
                                String fileName;
                                String filePath;
                                if (fileBrowser instanceof LocalBrowser) {
                                    File file = (File) o;
                                    fileName = file.getName();
                                    filePath = file.getPath();

                                    if (fileName.equals(node.toString())) {
                                        toAdd = new CustomFile(filePath);
                                        break;
                                    }
                                } else {
                                    FTPFile ftpFile = (FTPFile) o;
                                    fileName = ftpFile.getName();
                                    filePath = fileBrowser.getAbsoluteWorkingDirectory() + File.separator
                                            + ftpFile.getName();

                                    if (fileName.equals(node.toString())) {
                                        toAdd = new CustomFTPFile(ftpFile, filePath);
                                        break;
                                    }
                                }

                            }

                            if (toAdd != null && !checkIfInList(toAdd)) {
                                selectedFiles.addFileItem(toAdd);
                            }
                        }
                    }
                } else {
                    if ((node.getType() == FileBrowserTreeNode.DIRECTORY) && (node.getLevel() != 0)) {

                        // show popup to add the directory to the selected files
                        JPopupMenu popup = new JPopupMenu();

                        JMenuItem addDirectory = new JMenuItem("add directory");
                        addDirectory.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent ae) {

                                Object fileToAdd = fileBrowser.getDirFiles().get(node.toString());
                                FileChooserFile toAdd;

                                if (fileToAdd instanceof File) {
                                    toAdd = new CustomFile(((File) fileToAdd).getPath());
                                } else {
                                    FTPFile ftpFile = (FTPFile) fileToAdd;
                                    String filePath = fileBrowser.getAbsoluteWorkingDirectory() + File.separator
                                            + ftpFile.getName();

                                    toAdd = new CustomFTPFile(ftpFile, filePath);
                                }

                                if (!checkIfInList(toAdd)) {
                                    selectedFiles.addDirectoryItem(toAdd);
                                }
                            }
                        });

                        popup.add(addDirectory);
                        popup.show(directoryTree, event.getX(), event.getY());
                    }
                }
            }
        }

    });

    BasicTreeUI ui = new BasicTreeUI() {
        public Icon getCollapsedIcon() {
            return null;
        }

        public Icon getExpandedIcon() {
            return null;
        }
    };

    directoryTree.setUI(ui);
    directoryTree.setFont(UIHelper.VER_12_PLAIN);

    JScrollPane treeScroll = new JScrollPane(directoryTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    treeScroll.setPreferredSize(new Dimension(300, 200));
    treeScroll.setBorder(new EmptyBorder(0, 0, 0, 0));
    treeContainer.add(treeScroll, BorderLayout.CENTER);

    IAppWidgetFactory.makeIAppScrollPane(treeScroll);

    return treeContainer;
}

From source file:org.jbpcc.admin.beans.navigation.TreeBean.java

/**
 * Initialises tree root and calls method to build tree of configuration schema changes
 *//* ww  w.j a v  a2 s.c om*/
public TreeBean() {

    DefaultMutableTreeNode rootTreeNode = new DefaultMutableTreeNode();
    UrlNodeUserObject rootObject = new UrlNodeUserObject(rootTreeNode, this);
    rootObject.setText("Empty root");
    rootObject.setExpanded(true);

    Document dom = readDOM();
    Element docElement = dom.getDocumentElement(); // get root element

    if (!docElement.getNodeName().equals(ELEM_APP)) {
        throw new IllegalArgumentException("Illegal tree menu configuration");
    }

    rootObject.setUrl(APP_CONTEXT_PATH + docElement.getAttribute(ATTR_URL));
    rootObject.setIconUrl(docElement.getAttribute(ATTR_ICON));
    rootObject.setSelectedNode(true);
    rootTreeNode.setUserObject(rootObject);
    rootNodeObject = (UrlNodeUserObject) rootTreeNode.getUserObject();
    rootNodeObject.setSelectedNode(true);

    model = new DefaultTreeModel(rootTreeNode);

    buildTree(rootTreeNode, docElement);
}

From source file:org.kepler.objectmanager.cache.LocalRepositoryManager.java

/**
 * Refresh the folder model for the specified local repository.
 * //from  ww w .  j a  va  2  s. c  o m
 * @param repo
 */
public void refreshFolderModelForRepo(LocalRepository repo) {
    if (isDebugging)
        log.debug("refreshFolderModelForRepo(" + repo.toString() + ")");

    String repoName = getLocalRepositories().get(repo);
    if (repoName == null) {
        log.warn("Error: not a local repository: " + repo);
        return;
    }

    TreeModel tm = getFolderModel(repoName);
    if (tm == null) {
        tm = new DefaultTreeModel(new DefaultMutableTreeNode(repo));
        _folderModel.put(repoName, tm);
    }

    DefaultMutableTreeNode root = (DefaultMutableTreeNode) tm.getRoot();
    root.removeAllChildren();

    for (File dir : repo.getDirectories()) {
        findKarsRecursive(dir, 20, root);
    }
}