Example usage for javax.swing.tree DefaultMutableTreeNode add

List of usage examples for javax.swing.tree DefaultMutableTreeNode add

Introduction

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

Prototype

public void add(MutableTreeNode newChild) 

Source Link

Document

Removes newChild from its parent and makes it a child of this node by adding it to the end of this node's child array.

Usage

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

private void addMetadataNodes(DefaultMutableTreeNode metadataNode, Metadata staticMetadata) {
    for (String group : staticMetadata.getGroups()) {
        Object userObj;/* w ww .ja  v a2 s  . c om*/
        if (staticMetadata.getMetadata(group) != null) {
            ConcurrentHashMap<String, String> map = new ConcurrentHashMap<String, String>();
            map.put(group, StringUtils.join(staticMetadata.getAllMetadata(group), ","));
            userObj = map;
        } else {
            ConcurrentHashMap<String, String> map = new ConcurrentHashMap<String, String>();
            map.put(group, null);
            userObj = map;
        }
        DefaultMutableTreeNode groupNode = new DefaultMutableTreeNode(userObj);
        metadataNode.add(groupNode);
        this.addMetadataNodes(groupNode, staticMetadata.getSubMetadata(group));
    }
}

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

@Override
public void refreshView(ViewState state) {

    Rectangle visibleRect = null;
    if (this.tree != null) {
        visibleRect = this.tree.getVisibleRect();
    }//from  ww  w. j av a2s .c o  m

    DefaultMutableTreeNode root = new DefaultMutableTreeNode("GlobalConfig");

    if (state != null && state.getGlobalConfigGroups() != null) {
        if (globalConfig != null && globalConfig.keySet().equals(state.getGlobalConfigGroups().keySet())
                && globalConfig.values().equals(state.getGlobalConfigGroups().values())) {
            return;
        }

        this.removeAll();

        for (ConfigGroup group : (globalConfig = state.getGlobalConfigGroups()).values()) {
            HashSet<String> keys = new HashSet<String>();
            DefaultMutableTreeNode groupNode = new DefaultMutableTreeNode(new Group(group.getName()));
            root.add(groupNode);
            for (String key : group.getMetadata().getAllKeys()) {
                keys.add(key);
                DefaultMutableTreeNode keyNode = new DefaultMutableTreeNode(new Key(key));
                groupNode.add(keyNode);
                DefaultMutableTreeNode valueNode = new DefaultMutableTreeNode(
                        new Value(StringUtils.join(group.getMetadata().getAllMetadata(key), ",")));
                keyNode.add(valueNode);
            }
            if (group.getExtends() != null) {
                List<String> extendsGroups = new Vector<String>(group.getExtends());
                Collections.reverse(extendsGroups);
                for (String extendsGroup : extendsGroups) {
                    List<String> groupKeys = state.getGlobalConfigGroups().get(extendsGroup).getMetadata()
                            .getAllKeys();
                    groupKeys.removeAll(keys);
                    if (groupKeys.size() > 0) {
                        for (String key : groupKeys) {
                            if (!keys.contains(key)) {
                                keys.add(key);
                                DefaultMutableTreeNode keyNode = new DefaultMutableTreeNode(
                                        new ExtendsKey(extendsGroup, key));
                                groupNode.add(keyNode);
                                DefaultMutableTreeNode valueNode = new DefaultMutableTreeNode(
                                        new ExtendsValue(StringUtils.join(state.getGlobalConfigGroups()
                                                .get(extendsGroup).getMetadata().getAllMetadata(key), ",")));
                                keyNode.add(valueNode);
                            }
                        }
                    }
                }
            }
        }

        tree = new JTree(root);
        tree.setShowsRootHandles(true);
        tree.setRootVisible(false);

        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 Key) {
                    JPanel panel = new JPanel();
                    panel.setLayout(new BorderLayout());
                    JLabel label = new JLabel(node.getUserObject().toString());
                    label.setForeground(Color.darkGray);
                    panel.add(label, BorderLayout.CENTER);
                    panel.setBackground(selected ? Color.lightGray : Color.white);
                    return panel;
                } else if (node.getUserObject() instanceof ExtendsKey) {
                    JPanel panel = new JPanel();
                    panel.setLayout(new BorderLayout());
                    ExtendsKey key = (ExtendsKey) node.getUserObject();
                    JLabel groupLabel = new JLabel("(" + key.getGroup() + ") ");
                    groupLabel.setForeground(Color.black);
                    JLabel keyLabel = new JLabel(key.getValue());
                    keyLabel.setForeground(Color.gray);
                    panel.add(groupLabel, BorderLayout.WEST);
                    panel.add(keyLabel, BorderLayout.CENTER);
                    panel.setBackground(selected ? Color.lightGray : Color.white);
                    return panel;
                } else if (node.getUserObject() instanceof Group) {
                    JPanel panel = new JPanel();
                    panel.setLayout(new BorderLayout());
                    JLabel label = new JLabel(node.getUserObject().toString());
                    label.setForeground(Color.black);
                    label.setBackground(Color.white);
                    panel.add(label, BorderLayout.CENTER);
                    panel.setBackground(selected ? Color.lightGray : Color.white);
                    return panel;
                } else if (node.getUserObject() instanceof Value) {
                    JPanel panel = new JPanel();
                    panel.setLayout(new BorderLayout());
                    panel.setBorder(new EtchedBorder(1));
                    JLabel label = new JLabel(node.getUserObject().toString());
                    label.setForeground(Color.black);
                    panel.add(label, BorderLayout.CENTER);
                    panel.setBackground(selected ? Color.lightGray : Color.white);
                    return panel;
                } else if (node.getUserObject() instanceof ExtendsValue) {
                    JPanel panel = new JPanel();
                    panel.setLayout(new BorderLayout());
                    panel.setBorder(new EtchedBorder(1));
                    JLabel label = new JLabel(node.getUserObject().toString());
                    label.setForeground(Color.gray);
                    panel.add(label, BorderLayout.CENTER);
                    panel.setBackground(selected ? Color.lightGray : Color.white);
                    return panel;
                } else {
                    return new JLabel();
                }
            }

        });
    }

    this.setBorder(new EtchedBorder());
    JLabel panelName = new JLabel("Global-Config Groups");
    panelName.setBorder(new EtchedBorder());
    this.add(panelName, BorderLayout.NORTH);
    JScrollPane scrollPane = new JScrollPane(tree, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

    tabbedPane = new JTabbedPane();
    tabbedPane.addTab("Tree", scrollPane);
    tabbedPane.addTab("Table", new JPanel());

    this.add(tabbedPane, BorderLayout.CENTER);

    if (visibleRect != null) {
        this.tree.scrollRectToVisible(visibleRect);
    }

    this.revalidate();
}

From source file:org.apache.syncope.ide.netbeans.view.ResourceExplorerTopComponent.java

private void folderRightClickAction(final MouseEvent evt, final DefaultMutableTreeNode node) {
    JPopupMenu menu = new JPopupMenu();
    JMenuItem addItem = new JMenuItem("New");
    menu.add(addItem);/*w  w w. j ava2  s  . c o  m*/

    addItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            String name = JOptionPane.showInputDialog("Enter Name");
            boolean added = false;
            if (!"exit".equals(e.getActionCommand())) {

                if (node.getUserObject().equals(PluginConstants.MAIL_TEMPLATES)) {
                    MailTemplateTO mailTemplate = new MailTemplateTO();
                    mailTemplate.setKey(name);
                    added = mailTemplateManagerService.create(mailTemplate);
                    mailTemplateManagerService.setFormat(name, MailTemplateFormat.HTML,
                            IOUtils.toInputStream("//Enter Content here", encodingPattern));
                    mailTemplateManagerService.setFormat(name, MailTemplateFormat.TEXT,
                            IOUtils.toInputStream("//Enter Content here", encodingPattern));
                    try {
                        openMailEditor(name);
                    } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                } else {
                    ReportTemplateTO reportTemplate = new ReportTemplateTO();
                    reportTemplate.setKey(name);
                    added = reportTemplateManagerService.create(reportTemplate);
                    reportTemplateManagerService.setFormat(name, ReportTemplateFormat.FO,
                            IOUtils.toInputStream("//Enter content here", encodingPattern));
                    reportTemplateManagerService.setFormat(name, ReportTemplateFormat.CSV,
                            IOUtils.toInputStream("//Enter content here", encodingPattern));
                    reportTemplateManagerService.setFormat(name, ReportTemplateFormat.HTML,
                            IOUtils.toInputStream("//Enter content here", encodingPattern));
                    try {
                        openReportEditor(name);
                    } catch (IOException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }

                if (added) {
                    node.add(new DefaultMutableTreeNode(name));
                    treeModel.reload(node);
                } else {
                    JOptionPane.showMessageDialog(null, "Error while creating new element", "Error",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    });

    menu.show(evt.getComponent(), evt.getX(), evt.getY());
}

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

private void fillJobTree(final BuildStatusVisitor buildStatusVisitor) {
    final List<Job> jobList = jenkins.getJobs();
    if (jobList.isEmpty()) {
        return;//from   ww w. j ava2s  .  c om
    }

    DefaultTreeModel model = (DefaultTreeModel) jobTree.getModel();
    final DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) model.getRoot();
    rootNode.removeAllChildren();

    for (Job job : jobList) {
        DefaultMutableTreeNode jobNode = new DefaultMutableTreeNode(job);
        rootNode.add(jobNode);
        visit(job, buildStatusVisitor);
    }

    watch();

    setSortedByStatus(sortedByBuildStatus);

    jobTree.setRootVisible(true);
}

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

public static DefaultMutableTreeNode wrapNodes(DefaultMutableTreeNode source, String separator) {
    if (isEmpty(separator)) {
        return source;
    }/* ww  w  . ja v a  2  s  .com*/
    DefaultMutableTreeNode targetRootNode = (DefaultMutableTreeNode) source.clone();
    for (int i = 0; i < source.getChildCount(); i++) {
        DefaultMutableTreeNode originalChildNode = (DefaultMutableTreeNode) source.getChildAt(i);
        NoSqlTreeNode clonedChildNode = (NoSqlTreeNode) originalChildNode.clone();
        RedisKeyValueDescriptor descriptor = (RedisKeyValueDescriptor) clonedChildNode.getDescriptor();
        String[] explodedKey = StringUtils.explode(descriptor.getKey(), separator);
        if (explodedKey.length == 1) {
            addChildren(clonedChildNode, originalChildNode);
            targetRootNode.add(clonedChildNode);
        } else {
            updateTree(targetRootNode, originalChildNode, explodedKey, descriptor);
        }
    }
    return targetRootNode;
}

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

private static void updateTree(DefaultMutableTreeNode parentTargetNode,
        DefaultMutableTreeNode originalChildNode, String[] explodedKey,
        RedisKeyValueDescriptor sourceDescriptor) {
    if (explodedKey.length == 0) {
        addChildren(parentTargetNode, originalChildNode);
        return;/*from w ww  .  j av a2s .  co  m*/
    }
    String keyFragment = explodedKey[0];
    NoSqlTreeNode node = findNodeByKey(parentTargetNode, keyFragment);
    if (node == null) {
        if (explodedKey.length == 1) {
            node = new NoSqlTreeNode(RedisKeyValueDescriptor.createDescriptor(sourceDescriptor.getKeyType(),
                    keyFragment, sourceDescriptor.getValue()));
        } else {
            node = new NoSqlTreeNode(FragmentedKeyNodeDescriptor.createDescriptor(keyFragment));
        }
    }
    updateTree(node, originalChildNode, Arrays.copyOfRange(explodedKey, 1, explodedKey.length),
            sourceDescriptor);

    parentTargetNode.add(node);
}

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

private static void addChildren(DefaultMutableTreeNode parentNode, DefaultMutableTreeNode originalChildNode) {
    Enumeration children = originalChildNode.children();
    while (children.hasMoreElements()) {
        DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement();
        parentNode.add((MutableTreeNode) childNode.clone());
    }/*  w  w  w .  jav  a 2 s .c om*/
}

From source file:org.csml.tommo.sugar.modules.TileTree.java

public DefaultMutableTreeNode createTileTree() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(
            "Tile Numeration: " + getTileNumeration().getName());
    for (String flowCell : flowCellSet) {
        DefaultMutableTreeNode flowCellNode = new DefaultMutableTreeNode("Flow Cell: " + flowCell);
        root.add(flowCellNode);
        SortedSet<Integer> lanes = laneIDsMap.get(flowCell);
        for (Integer lane : lanes) {
            DefaultMutableTreeNode laneNode = new DefaultMutableTreeNode("Lane: " + lane);
            flowCellNode.add(laneNode);//from w  w  w . j a  va 2s .  c o m
            LaneCoordinates lc = new LaneCoordinates(flowCell, lane);
            SortedSet<Integer> tiles = tileIDsMap.get(lc);
            for (Integer tile : tiles) {
                DefaultMutableTreeNode tileNode = new DefaultMutableTreeNode("Tile: " + tile);
                laneNode.add(tileNode);
                TileCoordinates tc = new TileCoordinates(flowCell, lane, tile);
                //               SortedSet<Integer> xSet = xCoordinatesMap.get(tc);
                //               SortedSet<Integer> ySet = yCoordinatesMap.get(tc);
                //               
                //               String xMessage = "X size=" + xSet.size() + ", "; 
                //               String yMessage = "Y size=" + ySet.size() + ", ";
                //               if(!xSet.isEmpty()){
                //                  xMessage += "X range: ";
                //                  xMessage += Collections.min(xSet) + " - " + Collections.max(xSet);
                //               }
                //               if(!ySet.isEmpty()){
                //                  yMessage += "Y range: ";
                //                  yMessage += Collections.min(ySet) + " - " + Collections.max(ySet);
                //               }

                Rectangle range = xyRangeMap.get(tc);

                int maxX = range.x + range.width;
                int maxY = range.y + range.height;

                String xMessage = range != null ? "X range: " + range.x + " - " + maxX : "empty";

                String yMessage = range != null ? "Y range: " + range.y + " - " + maxY : "empty";

                DefaultMutableTreeNode xSummaryNode = new DefaultMutableTreeNode(xMessage);
                tileNode.add(xSummaryNode);
                DefaultMutableTreeNode ySummaryNode = new DefaultMutableTreeNode(yMessage);
                tileNode.add(ySummaryNode);

            }
        }
    }
    return root;
}

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

private void buildChildNodes(DefaultMutableTreeNode parentNode, List<Node> childNodes) {

    DefaultMutableTreeNode treeNode;
    NavigationTreeNode navNode;//from w ww .j a  va2  s. c o m

    for (Node node : childNodes) {
        treeNode = new DefaultMutableTreeNode();
        navNode = new NavigationTreeNode(treeNode);
        navNode.setText(node.getLabel());
        navNode.setNodeId(node.getId());
        navNode.setExpanded(node.isExpanded());
        treeNode.setUserObject(navNode);
        navNode.setLeaf(node.isLeaf());
        parentNode.add(treeNode);

        if (node.getNode() != null && node.getNode().size() > 0) {
            buildChildNodes(treeNode, node.getNode());
        }
    }
}

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));
            }/*from  w  w  w. j a  va2  s  .  c  o m*/
        }

        root.add(node);
    }

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

}