Search in sources :

Example 71 with TreeNode

use of javax.swing.tree.TreeNode in project sldeditor by robward-scisys.

the class FileSystemExtension method initialise.

/**
 * Initialise.
 *
 * @param parent the parent
 * @param toolMgr the tool manager
 */
@Override
public void initialise(LoadSLDInterface parent, ToolSelectionInterface toolMgr) {
    this.toolMgr = toolMgr;
    this.parentObj = parent;
    if (toolMgr != null) {
        toolMgr.addRecursiveListener(this);
    }
    // Add extensions
    extensionList = FileSystemExtensionFactory.getFileExtensionList(toolMgr);
    extensionPanel = new JPanel();
    extensionPanel.setLayout(new BorderLayout());
    extensionPanel.setPreferredSize(new Dimension(450, 400));
    JPanel toolPanel = null;
    if (toolMgr != null) {
        toolPanel = toolMgr.getPanel();
    }
    if (toolPanel != null) {
        extensionPanel.add(toolPanel, BorderLayout.NORTH);
    }
    tree = new FSTree();
    tree.setRootVisible(true);
    DefaultMutableTreeNode rootNode;
    try {
        rootNode = new DefaultMutableTreeNode(ROOT_NODE);
        model = new DefaultTreeModel(rootNode);
        FileSystemNodeManager.create(tree, model);
        for (FileSystemInterface extension : extensionList) {
            extension.populate(tree, model, rootNode);
        }
    } catch (SecurityException e1) {
        ConsoleManager.getInstance().exception(this, e1);
    }
    tree.setModel(model);
    tree.setDragEnabled(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                int row = tree.getClosestRowForLocation(e.getX(), e.getY());
                tree.setSelectionRow(row);
                Object selectedItem = tree.getLastSelectedPathComponent();
                Thread t1 = new Thread(new Runnable() {

                    public void run() {
                        JPopupMenu popupMenu = new JPopupMenu();
                        for (FileSystemInterface extension : extensionList) {
                            extension.rightMouseButton(popupMenu, selectedItem, e);
                        }
                        if ((popupMenu.getComponentCount() > 0) && (e != null)) {
                            popupMenu.show(e.getComponent(), e.getX(), e.getY());
                        }
                    }
                });
                t1.start();
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }
    });
    // Listen for Tree Selection Events
    tree.addTreeExpansionListener(new TreeExpansionListener() {

        /*
             * (non-Javadoc)
             * 
             * @see javax.swing.event.TreeExpansionListener#treeExpanded(javax.swing.event.TreeExpansionEvent)
             */
        public void treeExpanded(TreeExpansionEvent evt) {
            TreePath path = evt.getPath();
            Object selectedItem = path.getLastPathComponent();
            for (FileSystemInterface extension : extensionList) {
                if (extension.treeExpanded(selectedItem)) {
                    ((DefaultTreeModel) tree.getModel()).nodeStructureChanged((TreeNode) selectedItem);
                }
            }
        }

        /*
             * (non-Javadoc)
             * 
             * @see javax.swing.event.TreeExpansionListener#treeCollapsed(javax.swing.event.TreeExpansionEvent)
             */
        public void treeCollapsed(TreeExpansionEvent evt) {
        // Nothing to do
        }
    });
    // Tree selection listener
    tree.setTreeSelection(this);
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS));
    panel.add(new JScrollPane(tree));
    extensionPanel.add(panel, BorderLayout.CENTER);
    logger.debug("FileSystem initialise finished");
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) TreeExpansionListener(javax.swing.event.TreeExpansionListener) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) FSTree(com.sldeditor.datasource.extension.filesystem.node.FSTree) BoxLayout(javax.swing.BoxLayout) Dimension(java.awt.Dimension) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) JPopupMenu(javax.swing.JPopupMenu) FileSystemInterface(com.sldeditor.common.filesystem.FileSystemInterface) MouseListener(java.awt.event.MouseListener) BorderLayout(java.awt.BorderLayout) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent)

Example 72 with TreeNode

use of javax.swing.tree.TreeNode in project sldeditor by robward-scisys.

the class FileSystemInput method deleteNodes.

/*
     * (non-Javadoc)
     * 
     * @see
     * com.sldeditor.extension.input.FileSystemInterface#deleteNodes(com.sldeditor.extension.input.
     * NodeInterface, java.util.List)
     */
@Override
public void deleteNodes(NodeInterface nodeToTransfer, List<SLDDataInterface> sldDataList) {
    if (sldDataList == null) {
        return;
    }
    if (nodeToTransfer instanceof FileTreeNode) {
        for (SLDDataInterface sldData : sldDataList) {
            String sldFilename = sldData.getSLDFile().getAbsolutePath();
            File file = new File(sldFilename);
            file.delete();
        }
        DefaultMutableTreeNode destinationNode = (DefaultMutableTreeNode) nodeToTransfer;
        TreeNode parent = destinationNode.getParent();
        destinationNode.removeFromParent();
        if (treeModel != null) {
            treeModel.reload(parent);
        }
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SLDDataInterface(com.sldeditor.common.SLDDataInterface) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) TreeNode(javax.swing.tree.TreeNode) File(java.io.File) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)

Example 73 with TreeNode

use of javax.swing.tree.TreeNode in project sldeditor by robward-scisys.

the class GeoServerLayerUpdateTool method extractWorkspaceLayers.

private void extractWorkspaceLayers(GeoServerWorkspaceNode workspaceNode) {
    for (int layerIndex = 0; layerIndex < workspaceNode.getChildCount(); layerIndex++) {
        TreeNode childTreeNode = workspaceNode.getChildAt(layerIndex);
        if (childTreeNode instanceof GeoServerLayerNode) {
            GeoServerLayerNode layerNode = (GeoServerLayerNode) childTreeNode;
            GeoServerLayer layer = layerNode.getLayer();
            layerList.add(layer);
        }
    }
}
Also used : GeoServerLayer(com.sldeditor.common.data.GeoServerLayer) TreeNode(javax.swing.tree.TreeNode) GeoServerLayerNode(com.sldeditor.datasource.extension.filesystem.node.geoserver.GeoServerLayerNode)

Example 74 with TreeNode

use of javax.swing.tree.TreeNode in project Spark by igniterealtime.

the class BroadcastDialog method hideOfflineUsers.

private void hideOfflineUsers() {
    int i;
    if (OfflineUsers.isSelected()) {
        final ContactList contactList = SparkManager.getWorkspace().getContactList();
        i = 0;
        for (CheckNode node : nodes) {
            if (contactList.getContactItemByDisplayName(node.toString()).getPresence().getType() == Presence.Type.unavailable) {
                if (node.getParent() != null) {
                    TreeNode parent = node.getParent();
                    TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(parent);
                    ((DefaultTreeModel) checkTree.getTree().getModel()).removeNodeFromParent(node);
                    checkTree.getTree().setSelectionPath(new TreePath(path));
                    NodesGroups.add(new ArrayList<>());
                    NodesGroups.get(i).add(parent);
                    NodesGroups.get(i).add(node);
                    i++;
                }
            }
        }
        for (int x = 0; x < groupNodes.size(); x++) {
            if (groupNodes.get(x).toString().equals(Res.getString("group.offline"))) {
                OfflineGroup = x;
                TreeNode parent = groupNodes.get(x).getParent();
                TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(parent);
                ((DefaultTreeModel) checkTree.getTree().getModel()).removeNodeFromParent(groupNodes.get(x));
                checkTree.getTree().setSelectionPath(new TreePath(path));
            }
        }
    } else {
        i = 0;
        DefaultMutableTreeNode child = groupNodes.get(OfflineGroup);
        ((DefaultTreeModel) checkTree.getTree().getModel()).insertNodeInto(child, rosterNode, rosterNode.getChildCount());
        TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(rosterNode);
        checkTree.getTree().expandPath(new TreePath(path));
        checkTree.expandTree();
        for (CheckNode node : nodes) {
            if (node.getParent() == null) {
                child = (CheckNode) NodesGroups.get(i).get(1);
                ((DefaultTreeModel) checkTree.getTree().getModel()).insertNodeInto(child, ((CheckNode) NodesGroups.get(i).get(0)), ((CheckNode) NodesGroups.get(i).get(0)).getChildCount());
                path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(node);
                checkTree.getTree().expandPath(new TreePath(path));
                checkTree.expandTree();
                i++;
            }
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ContactList(org.jivesoftware.spark.ui.ContactList) CheckNode(org.jivesoftware.spark.component.CheckNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 75 with TreeNode

use of javax.swing.tree.TreeNode in project MtgDesktopCompanion by nicho92.

the class JDeckChooserDialog method expandAll.

private void expandAll(TreePath parent) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (Enumeration e = node.children(); e.hasMoreElements(); ) {
            TreeNode n = (TreeNode) e.nextElement();
            TreePath path = parent.pathByAddingChild(n);
            expandAll(path);
        }
    }
    tree.expandPath(parent);
}
Also used : Enumeration(java.util.Enumeration) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Aggregations

TreeNode (javax.swing.tree.TreeNode)313 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)146 TreePath (javax.swing.tree.TreePath)125 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)31 Enumeration (java.util.Enumeration)30 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)28 MPart (gov.sandia.n2a.eqset.MPart)27 ArrayList (java.util.ArrayList)27 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)25 JTree (javax.swing.JTree)23 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)23 Nullable (org.jetbrains.annotations.Nullable)23 MutableTreeNode (javax.swing.tree.MutableTreeNode)19 CannotRedoException (javax.swing.undo.CannotRedoException)18 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)16 CannotUndoException (javax.swing.undo.CannotUndoException)14 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)12 MouseEvent (java.awt.event.MouseEvent)11 NotNull (org.jetbrains.annotations.NotNull)11 PanelEquations (gov.sandia.n2a.ui.eq.PanelEquations)10