Example usage for javax.swing.event TreeSelectionEvent getPath

List of usage examples for javax.swing.event TreeSelectionEvent getPath

Introduction

In this page you can find the example usage for javax.swing.event TreeSelectionEvent getPath.

Prototype

public TreePath getPath() 

Source Link

Document

Returns the first path element.

Usage

From source file:de.tbuchloh.kiskis.gui.MainView.java

/**
 * @see javax.swing.event.TreeSelectionListener#valueChanged(javax.swing.event.TreeSelectionEvent)
 *//*  www  .  j  a  va2s .c o m*/
@Override
public void valueChanged(final TreeSelectionEvent e) {
    _selectedPath = e.getPath();
    if (_selectedPath != null && _lastSelected != _selectedPath.getLastPathComponent()) {
        _lastSelected = (MyTreeNode) _selectedPath.getLastPathComponent();
        createDetailView();
    }
    LOG.debug(_lastSelected + " selected."); //$NON-NLS-1$
}

From source file:org.jfree.chart.demo.SuperDemo.java

public void valueChanged(TreeSelectionEvent treeselectionevent) {
    TreePath treepath = treeselectionevent.getPath();
    Object obj = treepath.getLastPathComponent();
    if (obj != null) {
        DefaultMutableTreeNode defaultmutabletreenode = (DefaultMutableTreeNode) obj;
        Object obj1 = defaultmutabletreenode.getUserObject();
        if (obj1 instanceof DemoDescription) {
            DemoDescription demodescription = (DemoDescription) obj1;
            SwingUtilities.invokeLater(new DisplayDemo(this, demodescription));
        } else {//w  w w .j  a va  2s .c  o  m
            chartContainer.removeAll();
            chartContainer.add(createNoDemoSelectedPanel());
            displayPanel.validate();
            displayDescription("select.html");
        }
    }
    System.out.println(obj);
}

From source file:com.clough.android.adbv.view.MainFrame.java

public MainFrame(IOManager ioManager, HistoryManager historyManager) {
    this();/* w ww  .  j ava2 s . co  m*/
    this.ioManager = ioManager;
    this.historyManager = historyManager;
    ioManager.addConnectionLostListener(new IOManager.ConnectionLostListener() {
        @Override
        public void onDisconnect() {
            showDeviceDisconnectedDialog();
        }
    });

    new SwingWorker<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
            }
            try {
                applicationID = MainFrame.this.ioManager.getApplicationID();
                deviceName = MainFrame.this.ioManager.getDeviceName();
                databaseName = MainFrame.this.ioManager.getDatabaseName();
                setTitle(ValueHolder.WINDOW_TITLE + " - (" + deviceName + " - " + applicationID + ")");
            } catch (IOManagerException ex) {
                showDeviceDisconnectedDialog();
            }
            return null;
        }

        @Override
        protected void done() {
            closeProgressDialog();
        }

    }.execute();
    showProgressDialog(true, 0, "Waiting for device/app info");

    refreshDatabase();

    tableInfoTree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
                boolean leaf, int row, boolean hasFocus) {
            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
            DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) value;
            String nodeString = String.valueOf(dmtn.getUserObject());
            ImageIcon selectedImageIcon = null;
            if (nodeString.equals(databaseName)) {
                selectedImageIcon = ValueHolder.Icons.DATABASE;
            } else {
                l: for (int i = 0; i < tables.length; i++) {
                    String tableName = tables[i];
                    if (tableName.equals(nodeString)) {
                        selectedImageIcon = ValueHolder.Icons.TABLE;
                        break;
                    } else if (i == tables.length - 1) {
                        for (int p = 0; p < tables.length; p++) {
                            for (int j = 0; j < columns[p].length; j++) {
                                String columnName = columns[p][j];
                                if (columnName.equals(nodeString)) {
                                    selectedImageIcon = ValueHolder.Icons.PENCIL;
                                    break l;
                                } else if (j == columns[p].length - 1) {
                                    for (int q = 0; q < tables.length; q++) {
                                        for (int r = 0; r < columns[q].length; r++) {
                                            for (int k = 0; k < columnInfos[q][r].length; k++) {
                                                String columnInfo = columnInfos[q][r][k];
                                                if (columnInfo.equals(nodeString)) {
                                                    switch (k) {
                                                    case 0: {
                                                        selectedImageIcon = ValueHolder.Icons.HASH_TAG;
                                                        break l;
                                                    }
                                                    case 1: {
                                                        selectedImageIcon = ValueHolder.Icons.BLUE;
                                                        break l;
                                                    }
                                                    case 2: {
                                                        selectedImageIcon = ValueHolder.Icons.ORANGE;
                                                        break l;
                                                    }
                                                    case 3: {
                                                        selectedImageIcon = ValueHolder.Icons.GREEN;
                                                        break l;
                                                    }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            setIcon(selectedImageIcon);
            return this;
        }

    });

    tableInfoTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent evt) {
            Object[] data = evt.getPath().getPath();
            selectedTreeNodeValue = String.valueOf(data[data.length - 1]);
        }
    });

    tableInfoTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            if (evt.getButton() == MouseEvent.BUTTON3) {
                if (selectedTreeNodeValue.equals(databaseName)) {
                    showTreeNodePopup(evt.getX(), evt.getY(), true);
                } else {
                    for (String table : tables) {
                        if (table.equals(selectedTreeNodeValue)) {
                            showTreeNodePopup(evt.getX(), evt.getY(), false);
                            break;
                        }
                    }
                }
            } else if (evt.getClickCount() >= 2) {
                queryingTextArea.setText(queryingTextArea.getText() + "`" + selectedTreeNodeValue + "`");
            }
        }

    });

    currentHistoryList = historyManager.getHistoryList();
    for (int i = 0; i < currentHistoryList.size(); i++) {
        String[] history = currentHistoryList.get(i);
        historyContainingPanel.add(
                new HistoryItemPanel(i + 1, history[0].equals(applicationID), history[1], queryingTextArea));
    }
    adjustHistoryScrollbar();
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                MainFrame.this.historyManager.saveApplicationDb();
            } catch (HistoryManagerException ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage(), "Application history saving",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }));

}

From source file:com.lp.client.frame.component.PanelDokumentenablage.java

public void valueChanged(TreeSelectionEvent arg0) {

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

    if (tree.getPathBounds(arg0.getPath()) != null)
        tree.scrollRectToVisible(tree.getPathBounds(arg0.getPath()));

    jcrDocDto = null;//from w ww  . j  ava  2  s.  co m
    file = null;
    clearComponents();
    enableAllComponents(this, false);
    wcbVersteckteAnzeigen.setEnabled(true);
    wtfSuche.setEditable(true);
    wbuSuche.setEnabled(true);
    wmcMedia.setMimeType(null);
    if (node != null) {
        enableToolsPanelButtons(false, PanelBasis.ACTION_SAVE, PanelBasis.ACTION_DISCARD);
        if (node.getUserObject() instanceof DocNodeBase) {
            Object[] objectPath = node.getUserObjectPath();
            DocPath selectionDocPath = new DocPath();
            for (Object object : objectPath) {
                if (object instanceof DocNodeBase) {
                    selectionDocPath.add((DocNodeBase) object);
                } else if (object instanceof String) {
                    selectionDocPath.add(new DocNodeLiteral(object.toString() + "_string"));
                }
            }
            DocNodeBase selectedDocNode = (DocNodeBase) node.getUserObject();

            if (selectedDocNode.getNodeType() == DocNodeBase.FILE && node.isLeaf()) {
                jcrDocDto = ((DocNodeFile) selectedDocNode).getJcrDocDto();
            } else if (selectedDocNode.getNodeType() == DocNodeBase.VERSION) {
                jcrDocDto = ((DocNodeVersion) selectedDocNode).getJCRDocDto();
            } else {
                jcrDocDto = null;
            }
            if (jcrDocDto != null) {
                if (!jcrDocDto.getbVersteckt() || bVersteckteAnzeigen) {
                    dto2Components();
                    dropArea.setVisible(false);
                    enableToolsPanelButtons(false, PanelBasis.ACTION_NEW, BUTTON_SCAN);
                    enableToolsPanelButtons(
                            selectedDocNode.getNodeType() == DocNodeBase.FILE
                                    || selectedDocNode.getNodeType() == DocNodeBase.VERSION
                                            && bHatMindestensEineSicherheitsStufe() && bHatDokumentenablage,
                            PanelBasis.ACTION_UPDATE);

                    wbuShowDoc.setEnabled(true);
                    wbuSaveDoc.setEnabled(true);
                }
            } else {
                enableToolsPanelButtons(false, PanelBasis.ACTION_UPDATE);
                boolean b = fullDocPath.asDocNodeList().size() > 0 && selectedDocNode instanceof DocNodeJCR
                        && bHatMindestensEineSicherheitsStufe() && bHatDokumentenablage;
                enableToolsPanelButtons(b, PanelBasis.ACTION_NEW, BUTTON_SCAN);
                dropArea.setVisible(b);
            }
        }
    } else {
        enableToolsPanelButtons(false, ACTION_UPDATE, PanelBasis.ACTION_NEW, BUTTON_SCAN);
        dropArea.setVisible(false);
    }
}

From source file:com.pironet.tda.TDA.java

/**
 * Required by TreeSelectionListener interface.
 *///from  ww w  . ja  v a  2 s .  co  m
public void valueChanged(TreeSelectionEvent e) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();

    if (node == null) {
        return;
    }

    Object nodeInfo = node.getUserObject();
    if (nodeInfo instanceof ThreadInfo) {
        displayThreadInfo(nodeInfo);
        setThreadDisplay(true);
    } else if (nodeInfo instanceof ThreadDumpInfo) {
        displayThreadDumpInfo(nodeInfo);
    } else if (nodeInfo instanceof HistogramInfo) {
        HistogramInfo tdi = (HistogramInfo) nodeInfo;
        displayTable((HistogramTableModel) tdi.content);
        setThreadDisplay(false);
    } else if (nodeInfo instanceof LogFileContent) {
        displayLogFileContent(nodeInfo);
    } else if (nodeInfo instanceof Logfile
            && ((String) ((Logfile) nodeInfo).getContent()).startsWith("Thread Dumps")) {
        displayLogFile();
        setThreadDisplay(false);
    } else if (nodeInfo instanceof Category) {
        displayCategory(nodeInfo);
        setThreadDisplay(true);
    } else {
        setThreadDisplay(false);
        displayContent(null);
    }
}

From source file:com.pironet.tda.TDA.java

/**
 * add a tree listener for enabling/disabling menu and toolbar ICONS.
 *
 * @param tree JTree//from   w  w  w .j a  v a  2  s . co m
 */
private void addTreeListener(JTree tree) {
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        ViewScrollPane emptyView = null;

        public void valueChanged(TreeSelectionEvent e) {
            getMainMenu().getCloseMenuItem().setEnabled(e.getPath() != null);
            if (getMainMenu().getCloseToolBarButton() != null) {
                getMainMenu().getCloseToolBarButton().setEnabled(e.getPath() != null);
            }
            // reset right pane of the top view:

            if (emptyView == null) {
                JEditorPane emptyPane = new JEditorPane("text/html",
                        "<html><body bgcolor=\"ffffff\"></body></html>");
                emptyPane.setEditable(false);
                emptyPane.setSize(Const.EMPTY_DIMENSION);

                emptyView = new ViewScrollPane(emptyPane, runningAsVisualVMPlugin);
            }

            if (e.getPath() == null || !(((DefaultMutableTreeNode) e.getPath().getLastPathComponent())
                    .getUserObject() instanceof Category)) {
                resetPane();
            }
        }

        private void resetPane() {
            final Rectangle bounds = topSplitPane.getBounds();
            final int width = bounds.width;
            int dividerLocation = topSplitPane.getDividerLocation();
            if (width - dividerLocation < Const.MIN_RIGHT_PANE_SIZE
                    && width - Const.MIN_RIGHT_PANE_SIZE > 300) {
                dividerLocation = width - Const.MIN_RIGHT_PANE_SIZE;
            }
            topSplitPane.setRightComponent(emptyView);
            topSplitPane.setDividerLocation(dividerLocation);
        }

    });
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositPresenter.java

private void treeValueChanged(javax.swing.event.TreeSelectionEvent evt) {
    JTree sourceTree = (JTree) evt.getSource();
    TreePath[] paths = sourceTree.getSelectionPaths();
    if (paths != null) {
        theNodeInClipboard.clear();/*from w  ww  .  j  av a 2 s  .com*/
        for (TreePath path : paths) {
            theNodeInClipboard.add((DefaultMutableTreeNode) path.getLastPathComponent());
        }
    }

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) evt.getPath().getLastPathComponent();
    JTree tree = (JTree) evt.getSource();
    if (getTreeType(tree).equals(ETreeType.FileSystemTree)) {
        if (node.getUserObject() instanceof FileSystemObject) {
            tree.setEditable(false);
        }
    }
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
    while (parent != null && parent.getUserObject() instanceof FileSystemObject) {
        node = parent;
        parent = (DefaultMutableTreeNode) node.getParent();
    }
    tree.setEditable(true);
    if ((parent != null) && (parent.getUserObject() instanceof StructMap)) {
        if (node.getUserObject() instanceof FileSystemObject) {
            tree.setEditable(false);
        }
    }
}

From source file:org.apache.cayenne.modeler.ProjectTreeView.java

private void initController() {
    treeSelectionListener = new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            TreePath[] paths = getSelectionPaths();

            if (paths != null) {
                if (paths.length > 1) {
                    ConfigurationNode projectParentPath = null;
                    ConfigurationNode[] projectPaths = new ConfigurationNode[paths.length];
                    boolean commonParentPath = true;

                    for (int i = 0; i < paths.length; i++) {
                        projectPaths[i] = createProjectPath(paths[i]);

                        TreePath parentPath = paths[i].getParentPath();
                        if (i > 0 && parentPath != null && !parentPath.equals(paths[i - 1].getParentPath())) {
                            commonParentPath = false;
                        }//from   w  w w  .ja va 2  s. com
                    }

                    if (commonParentPath) {
                        TreePath parentPath = paths[0].getParentPath();
                        projectParentPath = createProjectPath(parentPath);
                    }

                    mediator.fireMultipleObjectsDisplayEvent(
                            new MultipleObjectsDisplayEvent(this, projectPaths, projectParentPath));
                } else if (paths.length == 1) {
                    processSelection(paths[0]);
                }
            }
        }

        /**
         * Converts TreePath to Object
         */
        private ConfigurationNode createProjectPath(TreePath treePath) {
            Object[] path = treePath.getPath();
            ConfigurationNode projectPath = (ConfigurationNode) ((DefaultMutableTreeNode) path[path.length - 1])
                    .getUserObject();

            return projectPath;
        }
    };

    treeWillExpandListener = new TreeWillExpandListener() {
        @Override
        public void treeWillExpand(TreeExpansionEvent e) throws ExpandVetoException {
            TreePath path = e.getPath();
            if (!isPathSelected(path) && !isSelectionEmpty()) {
                setSelectionPath(path);
            }
        }

        @Override
        public void treeWillCollapse(TreeExpansionEvent e) throws ExpandVetoException {
            TreePath path = e.getPath();
            if (!isPathSelected(path) && !isSelectionEmpty()) {
                setSelectionPath(path);
            }
        }
    };

    addTreeSelectionListener(treeSelectionListener);
    addTreeWillExpandListener(treeWillExpandListener);

    addMouseListener(new PopupHandler());

    mediator.addDomainListener(this);
    mediator.addDomainDisplayListener(this);
    mediator.addDataNodeListener(this);
    mediator.addDataNodeDisplayListener(this);
    mediator.addDataMapListener(this);
    mediator.addDataMapDisplayListener(this);
    mediator.addObjEntityListener(this);
    mediator.addObjEntityDisplayListener(this);
    mediator.addDbEntityListener(this);
    mediator.addDbEntityDisplayListener(this);
    mediator.addEmbeddableDisplayListener(this);
    mediator.addEmbeddableListener(this);
    mediator.addProcedureListener(this);
    mediator.addProcedureDisplayListener(this);
    mediator.addQueryListener(this);
    mediator.addQueryDisplayListener(this);
    mediator.addMultipleObjectsDisplayListener(this);

    mediator.getApplication().getActionManager().setupCutCopyPaste(this, CutAction.class, CopyAction.class);
}

From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultTreeView.java

@Override
public void refreshView(final ViewState state) {
    Rectangle visibleRect = null;
    if (this.tree != null) {
        visibleRect = this.tree.getVisibleRect();
    }//from  w w  w  . j  av a 2  s.co  m

    this.removeAll();

    this.actionsMenu = this.createPopupMenu(state);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("WORKFLOWS");
    for (ModelGraph graph : state.getGraphs()) {
        root.add(this.buildTree(graph, state));
    }
    tree = new JTree(root);
    tree.setShowsRootHandles(true);
    tree.setRootVisible(false);
    tree.add(this.actionsMenu);

    if (state.getSelected() != null) {
        // System.out.println("SELECTED: " + state.getSelected());
        TreePath treePath = this.getTreePath(root, state.getSelected());
        if (state.getCurrentMetGroup() != null) {
            treePath = this.getTreePath(treePath, state);
        } else if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_STATIC_METADATA))) {
            DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();
            for (int i = 0; i < baseNode.getChildCount(); i++) {
                if (((DefaultMutableTreeNode) baseNode.getChildAt(i)).getUserObject()
                        .equals("static-metadata")) {
                    treePath = new TreePath(((DefaultMutableTreeNode) baseNode.getChildAt(i)).getPath());
                    break;
                }
            }
        } else if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_PRECONDITIONS))) {
            if (treePath == null) {
                treePath = this.getTreePath(root, state.getSelected().getPreConditions());
            }
            DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();
            for (int i = 0; i < baseNode.getChildCount(); i++) {
                if (((DefaultMutableTreeNode) baseNode.getChildAt(i)).getUserObject()
                        .equals("pre-conditions")) {
                    treePath = new TreePath(((DefaultMutableTreeNode) baseNode.getChildAt(i)).getPath());
                    break;
                }
            }
        } else if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_POSTCONDITIONS))) {
            if (treePath == null) {
                treePath = this.getTreePath(root, state.getSelected().getPostConditions());
            }
            DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();
            for (int i = 0; i < baseNode.getChildCount(); i++) {
                if (((DefaultMutableTreeNode) baseNode.getChildAt(i)).getUserObject()
                        .equals("post-conditions")) {
                    treePath = new TreePath(((DefaultMutableTreeNode) baseNode.getChildAt(i)).getPath());
                    break;
                }
            }
        }
        this.tree.expandPath(treePath);
        this.tree.setSelectionPath(treePath);
    }

    tree.addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            if (e.getPath().getLastPathComponent() instanceof DefaultMutableTreeNode) {
                DefaultTreeView.this.resetProperties(state);
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();
                if (node.getUserObject() instanceof ModelGraph) {
                    state.setSelected((ModelGraph) node.getUserObject());
                    state.setCurrentMetGroup(null);
                    DefaultTreeView.this.notifyListeners();
                } else if (node.getUserObject().equals("static-metadata")
                        || node.getUserObject().equals("pre-conditions")
                        || node.getUserObject().equals("post-conditions")) {
                    state.setSelected((ModelGraph) ((DefaultMutableTreeNode) node.getParent()).getUserObject());
                    state.setCurrentMetGroup(null);
                    state.setProperty(EXPAND_STATIC_METADATA,
                            Boolean.toString(node.getUserObject().equals("static-metadata")));
                    state.setProperty(EXPAND_PRECONDITIONS,
                            Boolean.toString(node.getUserObject().equals("pre-conditions")));
                    state.setProperty(EXPAND_POSTCONDITIONS,
                            Boolean.toString(node.getUserObject().equals("post-conditions")));
                    DefaultTreeView.this.notifyListeners();
                } else if (node.getUserObject() instanceof ConcurrentHashMap) {
                    DefaultMutableTreeNode metNode = null;
                    String group = null;
                    Object[] path = e.getPath().getPath();
                    for (int i = path.length - 1; i >= 0; i--) {
                        if (((DefaultMutableTreeNode) path[i]).getUserObject() instanceof ModelGraph) {
                            metNode = (DefaultMutableTreeNode) path[i];
                            break;
                        } else if (((DefaultMutableTreeNode) path[i])
                                .getUserObject() instanceof ConcurrentHashMap) {
                            if (group == null) {
                                group = (String) ((ConcurrentHashMap<String, String>) ((DefaultMutableTreeNode) path[i])
                                        .getUserObject()).keySet().iterator().next();
                            } else {
                                group = (String) ((ConcurrentHashMap<String, String>) ((DefaultMutableTreeNode) path[i])
                                        .getUserObject()).keySet().iterator().next() + "/" + group;
                            }
                        }
                    }
                    ModelGraph graph = (ModelGraph) metNode.getUserObject();
                    state.setSelected(graph);
                    state.setCurrentMetGroup(group);
                    DefaultTreeView.this.notifyListeners();
                } else {
                    state.setSelected(null);
                    DefaultTreeView.this.notifyListeners();
                }
            }
        }

    });
    tree.setCellRenderer(new TreeCellRenderer() {

        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                boolean expanded, boolean leaf, int row, boolean hasFocus) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
            if (node.getUserObject() instanceof String) {
                JPanel panel = new JPanel();
                panel.setLayout(new BorderLayout());
                JLabel label = new JLabel((String) node.getUserObject());
                label.setForeground(Color.blue);
                panel.add(label, BorderLayout.CENTER);
                panel.setBackground(selected ? Color.lightGray : Color.white);
                return panel;
            } else if (node.getUserObject() instanceof ModelGraph) {
                JPanel panel = new JPanel();
                panel.setLayout(new BorderLayout());
                JLabel iconLabel = new JLabel(
                        ((ModelGraph) node.getUserObject()).getModel().getExecutionType() + ": ");
                iconLabel.setForeground(((ModelGraph) node.getUserObject()).getModel().getColor());
                iconLabel.setBackground(Color.white);
                JLabel idLabel = new JLabel(((ModelGraph) node.getUserObject()).getModel().getModelName());
                idLabel.setBackground(Color.white);
                panel.add(iconLabel, BorderLayout.WEST);
                panel.add(idLabel, BorderLayout.CENTER);
                panel.setBackground(selected ? Color.lightGray : Color.white);
                return panel;
            } else if (node.getUserObject() instanceof ConcurrentHashMap) {
                JPanel panel = new JPanel();
                panel.setLayout(new BorderLayout());
                String group = (String) ((ConcurrentHashMap<String, String>) node.getUserObject()).keySet()
                        .iterator().next();
                JLabel nameLabel = new JLabel(group + " : ");
                nameLabel.setForeground(Color.blue);
                nameLabel.setBackground(Color.white);
                JLabel valueLabel = new JLabel(
                        ((ConcurrentHashMap<String, String>) node.getUserObject()).get(group));
                valueLabel.setForeground(Color.darkGray);
                valueLabel.setBackground(Color.white);
                panel.add(nameLabel, BorderLayout.WEST);
                panel.add(valueLabel, BorderLayout.EAST);
                panel.setBackground(selected ? Color.lightGray : Color.white);
                return panel;
            } else {
                return new JLabel();
            }
        }

    });
    tree.addMouseListener(new MouseListener() {
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3 && DefaultTreeView.this.tree.getSelectionPath() != null) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) DefaultTreeView.this.tree
                        .getSelectionPath().getLastPathComponent();
                if (node.getUserObject() instanceof String && !(node.getUserObject().equals("pre-conditions")
                        || node.getUserObject().equals("post-conditions"))) {
                    return;
                }
                orderSubMenu.setEnabled(node.getUserObject() instanceof ModelGraph
                        && !((ModelGraph) node.getUserObject()).isCondition()
                        && ((ModelGraph) node.getUserObject()).getParent() != null);
                DefaultTreeView.this.actionsMenu.show(DefaultTreeView.this.tree, e.getX(), e.getY());
            }
        }

        public void mouseEntered(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseReleased(MouseEvent e) {
        }
    });
    this.scrollPane = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    this.add(this.scrollPane, BorderLayout.CENTER);
    if (visibleRect != null) {
        this.tree.scrollRectToVisible(visibleRect);
    }

    this.revalidate();
}

From source file:org.objectstyle.cayenne.modeler.ProjectTreeView.java

private void initController() {
    treeSelectionListener = new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            processSelection(e.getPath());
        }// w w w. j  a  v a2 s  . c o m
    };

    addTreeSelectionListener(treeSelectionListener);

    mediator.addDomainListener(this);
    mediator.addDomainDisplayListener(this);
    mediator.addDataNodeListener(this);
    mediator.addDataNodeDisplayListener(this);
    mediator.addDataMapListener(this);
    mediator.addDataMapDisplayListener(this);
    mediator.addObjEntityListener(this);
    mediator.addObjEntityDisplayListener(this);
    mediator.addDbEntityListener(this);
    mediator.addDbEntityDisplayListener(this);
    mediator.addProcedureListener(this);
    mediator.addProcedureDisplayListener(this);
    mediator.addQueryListener(this);
    mediator.addQueryDisplayListener(this);
}