Search in sources :

Example 11 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project felix by apache.

the class OBRPlugin method createEventListeners.

private void createEventListeners() {
    // Create action listeners.
    m_addRepoButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            synchronized (OBRPlugin.this) {
                if (m_repoAdmin == null) {
                    return;
                }
                String s = JOptionPane.showInputDialog(OBRPlugin.this, "Enter repository URL:");
                if (s != null) {
                    try {
                        m_repoAdmin.addRepository(new URL(s));
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
                // Update the table.
                initializeRootNode();
            }
        }
    });
    m_removeRepoButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            synchronized (OBRPlugin.this) {
                if (m_repoAdmin == null) {
                    return;
                }
                TreePath[] paths = m_bundleTree.getSelectionPaths();
                for (int i = 0; i < paths.length; i++) {
                    SimpleTreeNode node = (SimpleTreeNode) paths[i].getLastPathComponent();
                    if (node.getObject() instanceof Repository) {
                        m_repoAdmin.removeRepository(((Repository) ((SimpleTreeNode) paths[i].getLastPathComponent()).getObject()).getURL());
                    }
                }
                // Update the table.
                initializeRootNode();
            }
        }
    });
    m_refreshRepoButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            synchronized (OBRPlugin.this) {
                if (m_repoAdmin == null) {
                    return;
                }
                TreePath[] paths = m_bundleTree.getSelectionPaths();
                for (int i = 0; i < paths.length; i++) {
                    SimpleTreeNode node = (SimpleTreeNode) paths[i].getLastPathComponent();
                    if (node.getObject() instanceof Repository) {
                        try {
                            // Adding the repository again causes it to be reparsed.
                            m_repoAdmin.addRepository(((Repository) node.getObject()).getURL());
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                }
                // Update the table.
                initializeRootNode();
            }
        }
    });
    ActionListener al = new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            boolean start = event.getActionCommand().equals(START_BUTTON);
            synchronized (OBRPlugin.this) {
                if (m_repoAdmin == null) {
                    return;
                }
                Resolver resolver = m_repoAdmin.resolver();
                TreePath[] paths = m_bundleTree.getSelectionPaths();
                for (int i = 0; i < paths.length; i++) {
                    SimpleTreeNode node = (SimpleTreeNode) paths[i].getLastPathComponent();
                    if (node.getObject() instanceof Resource) {
                        resolver.add((Resource) node.getObject());
                    }
                }
                if ((resolver.getAddedResources() != null) && (resolver.getAddedResources().length > 0)) {
                    if (resolver.resolve()) {
                        m_out.println("Target resource(s):");
                        printUnderline(m_out, 19);
                        Resource[] resources = resolver.getAddedResources();
                        for (int resIdx = 0; (resources != null) && (resIdx < resources.length); resIdx++) {
                            m_out.println("   " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
                        }
                        resources = resolver.getRequiredResources();
                        if ((resources != null) && (resources.length > 0)) {
                            m_out.println("\nRequired resource(s):");
                            printUnderline(m_out, 21);
                            for (int resIdx = 0; resIdx < resources.length; resIdx++) {
                                m_out.println("   " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
                            }
                        }
                        resources = resolver.getOptionalResources();
                        if ((resources != null) && (resources.length > 0)) {
                            m_out.println("\nOptional resource(s):");
                            printUnderline(m_out, 21);
                            for (int resIdx = 0; resIdx < resources.length; resIdx++) {
                                m_out.println("   " + resources[resIdx].getPresentationName() + " (" + resources[resIdx].getVersion() + ")");
                            }
                        }
                        try {
                            m_out.print("\nDeploying...");
                            resolver.deploy(start);
                            m_out.println("done.");
                        } catch (IllegalStateException ex) {
                            m_out.println(ex);
                        }
                    } else {
                        Requirement[] reqs = resolver.getUnsatisfiedRequirements();
                        if ((reqs != null) && (reqs.length > 0)) {
                            m_out.println("Unsatisfied requirement(s):");
                            printUnderline(m_out, 27);
                            for (int reqIdx = 0; reqIdx < reqs.length; reqIdx++) {
                                m_out.println("   " + reqs[reqIdx].getFilter());
                                Resource[] resources = resolver.getResources(reqs[reqIdx]);
                                for (int resIdx = 0; resIdx < resources.length; resIdx++) {
                                    m_out.println("      " + resources[resIdx].getPresentationName());
                                }
                            }
                        } else {
                            m_out.println("Could not resolve targets.");
                        }
                    }
                    m_out.println("");
                }
            }
        }
    };
    m_deployButton.addActionListener(al);
    m_startButton.addActionListener(al);
    m_infoButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            synchronized (OBRPlugin.this) {
                if (m_repoAdmin == null) {
                    return;
                }
                TreePath[] paths = m_bundleTree.getSelectionPaths();
                for (int i = 0; i < paths.length; i++) {
                    if (i != 0) {
                        m_out.println("");
                    }
                    printInfo(m_out, ((SimpleTreeNode) paths[i].getLastPathComponent()).getObject());
                }
                m_out.println("");
            }
        }
    });
    m_clearButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            synchronized (OBRPlugin.this) {
                m_soa.setText("");
            }
        }
    });
    m_bundleTree.addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            if (m_repoAdmin == null) {
                return;
            }
            TreePath[] paths = m_bundleTree.getSelectionPaths();
            boolean repoOnly = true;
            if (paths != null) {
                for (int i = 0; repoOnly && (i < paths.length); i++) {
                    SimpleTreeNode node = (SimpleTreeNode) paths[i].getLastPathComponent();
                    if (!(node.getObject() instanceof Repository)) {
                        repoOnly = false;
                    }
                }
            }
            m_removeRepoButton.setEnabled((paths != null) && repoOnly);
            m_refreshRepoButton.setEnabled((paths != null) && repoOnly);
            m_infoButton.setEnabled((paths != null) && (paths.length > 0));
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) TreeSelectionListener(javax.swing.event.TreeSelectionListener) URL(java.net.URL) ActionListener(java.awt.event.ActionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 12 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project JMRI by JMRI.

the class TreePaneDemo method testWithSelect.

@Test
public void testWithSelect() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    frame.setTitle("listener test");
    pane.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            JTree tree = (JTree) e.getSource();
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            if (node == null) {
                return;
            }
            System.out.print("Test prints selected treenode " + node);
            if (node.getUserObject() instanceof NodeTreeRep.SelectionKey) {
                System.out.println(" and invokes");
                ((NodeTreeRep.SelectionKey) node.getUserObject()).select(node);
            } else {
                System.out.println();
            }
        }
    });
    Message msg;
    msg = new ProducerIdentifiedMessage(nid2, eventA, EventState.Unknown);
    store.put(msg, null);
    store.put(pipmsg, null);
    msg = new SimpleNodeIdentInfoReplyMessage(nid2, nid2, new byte[] { 0x01, 0x31, 0x32, 0x33, 0x41, 0x42, (byte) 0xC2, (byte) 0xA2, 0x44, 0x00 });
    store.put(msg, null);
}
Also used : JTree(javax.swing.JTree) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SimpleNodeIdentInfoReplyMessage(org.openlcb.SimpleNodeIdentInfoReplyMessage) Message(org.openlcb.Message) ProducerIdentifiedMessage(org.openlcb.ProducerIdentifiedMessage) ProtocolIdentificationReplyMessage(org.openlcb.ProtocolIdentificationReplyMessage) SimpleNodeIdentInfoReplyMessage(org.openlcb.SimpleNodeIdentInfoReplyMessage) NodeTreeRep(org.openlcb.swing.networktree.NodeTreeRep) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ProducerIdentifiedMessage(org.openlcb.ProducerIdentifiedMessage) Test(org.junit.Test)

Example 13 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project JMRI by JMRI.

the class CatalogPanel method init.

protected void init(boolean treeDnD) {
    _model = new DefaultTreeModel(new CatalogTreeNode("mainRoot"));
    if (treeDnD) {
        // index editor (right pane)
        _dTree = new DropJTree(_model);
        _noDrag = true;
    } else {
        // Catalog (left pane index editor or all icon editors)
        _dTree = new JTree(_model);
        _noDrag = false;
    }
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setLeafIcon(renderer.getClosedIcon());
    _dTree.setCellRenderer(renderer);
    _dTree.setRootVisible(false);
    _dTree.setShowsRootHandles(true);
    _dTree.setScrollsOnExpand(true);
    //_dTree.setDropMode(DropMode.ON);
    _dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
    _dTree.addTreeSelectionListener((TreeSelectionEvent e) -> {
        updatePanel();
    });
    _dTree.setExpandsSelectedPaths(true);
    _treePane.setViewportView(_dTree);
//        setupPanel();
}
Also used : JTree(javax.swing.JTree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer)

Example 14 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project JMRI by JMRI.

the class NetworkTreePane method initComponents.

@Override
public void initComponents(CanSystemConnectionMemo memo) {
    this.memo = memo;
    memo.getTrafficController().addCanListener(this);
    // add GUI components
    setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
    treePane = new TreePane();
    treePane.setPreferredSize(new Dimension(300, 300));
    treePane.initComponents((MimicNodeStore) memo.get(MimicNodeStore.class), (Connection) memo.get(Connection.class), (NodeID) memo.get(NodeID.class), new ActionLoader(memo.get(OlcbInterface.class)));
    add(treePane);
    treePane.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            JTree tree = (JTree) e.getSource();
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            if (node == null) {
                return;
            }
            if (node.getUserObject() instanceof NodeTreeRep.SelectionKey) {
                ((NodeTreeRep.SelectionKey) node.getUserObject()).select(node);
            }
        }
    });
}
Also used : TreePane(org.openlcb.swing.networktree.TreePane) JTree(javax.swing.JTree) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) NodeTreeRep(org.openlcb.swing.networktree.NodeTreeRep) TreeSelectionListener(javax.swing.event.TreeSelectionListener) Dimension(java.awt.Dimension) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 15 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project intellij-plugins by JetBrains.

the class ChooseBuildConfigurationDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    List<Module> modules = new ArrayList<>(myTreeItems.keySet());
    Collections.sort(modules, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
    for (Module module : modules) {
        DefaultMutableTreeNode moduleNode = new DefaultMutableTreeNode(module, true);
        root.add(moduleNode);
        List<FlexBCConfigurable> bcs = myTreeItems.get(module);
        Collections.sort(bcs, (o1, o2) -> o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName()));
        for (FlexBCConfigurable bc : bcs) {
            DefaultMutableTreeNode bcNode = new DefaultMutableTreeNode(bc, false);
            moduleNode.add(bcNode);
        }
    }
    myTree.setModel(new DefaultTreeModel(root));
    myTree.setRootVisible(false);
    new TreeSpeedSearch(myTree, o -> {
        Object lastPathComponent = o.getLastPathComponent();
        return getText((DefaultMutableTreeNode) lastPathComponent);
    }, true).setComparator(new SpeedSearchComparator(false));
    TreeUIHelper.getInstance().installTreeSpeedSearch(myTree);
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            updateOnSelectionChange();
        }
    });
    myTree.setCellRenderer(new ColoredTreeCellRenderer() {

        @Override
        public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
            Object object = treeNode.getUserObject();
            if (object instanceof Module) {
                Module module = (Module) object;
                setIcon(ModuleType.get(module).getIcon());
                append(module.getName());
            } else if (object instanceof FlexBCConfigurable) {
                FlexBCConfigurable configurable = (FlexBCConfigurable) object;
                setIcon(configurable.getIcon());
                BCUtils.renderBuildConfiguration(configurable.getEditableObject(), null).appendToComponent(this);
            }
        }
    });
    TreeUtil.expandAll(myTree);
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            if (mySelection != null) {
                doOKAction();
                return true;
            }
            return false;
        }
    }.installOn(myTree);
    myTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyTyped(KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                doOKAction();
            }
        }
    });
    updateOnSelectionChange();
    return myContentPane;
}
Also used : FlexModuleType(com.intellij.lang.javascript.flex.FlexModuleType) HashMap(com.intellij.util.containers.HashMap) ContainerUtil(com.intellij.util.containers.ContainerUtil) KeyAdapter(java.awt.event.KeyAdapter) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ArrayList(java.util.ArrayList) BCUtils(com.intellij.lang.javascript.flex.projectStructure.options.BCUtils) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) Map(java.util.Map) Project(com.intellij.openapi.project.Project) Tree(com.intellij.ui.treeStructure.Tree) ModuleType(com.intellij.openapi.module.ModuleType) Module(com.intellij.openapi.module.Module) FlexBuildConfigurationsExtension(com.intellij.lang.javascript.flex.projectStructure.FlexBuildConfigurationsExtension) ModuleStructureConfigurable(com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeUtil(com.intellij.util.ui.tree.TreeUtil) FlexBCConfigurator(com.intellij.lang.javascript.flex.projectStructure.FlexBCConfigurator) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) KeyEvent(java.awt.event.KeyEvent) com.intellij.ui(com.intellij.ui) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Collections(java.util.Collections) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) ArrayList(java.util.ArrayList) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) KeyEvent(java.awt.event.KeyEvent) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Module(com.intellij.openapi.module.Module)

Aggregations

TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)85 TreeSelectionListener (javax.swing.event.TreeSelectionListener)82 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)34 TreePath (javax.swing.tree.TreePath)32 JTree (javax.swing.JTree)27 ActionEvent (java.awt.event.ActionEvent)23 JScrollPane (javax.swing.JScrollPane)23 JPanel (javax.swing.JPanel)22 ActionListener (java.awt.event.ActionListener)20 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)18 MouseEvent (java.awt.event.MouseEvent)15 BorderLayout (java.awt.BorderLayout)14 Dimension (java.awt.Dimension)13 GridBagConstraints (java.awt.GridBagConstraints)12 GridBagLayout (java.awt.GridBagLayout)12 Insets (java.awt.Insets)12 JButton (javax.swing.JButton)11 Tree (com.intellij.ui.treeStructure.Tree)9 KeyAdapter (java.awt.event.KeyAdapter)9 KeyEvent (java.awt.event.KeyEvent)9