Example usage for javax.swing.tree DefaultMutableTreeNode getUserObject

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

Introduction

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

Prototype

public Object getUserObject() 

Source Link

Document

Returns this node's user object.

Usage

From source file:org.apache.jmeter.visualizers.ViewResultsFullVisualizer.java

/** {@inheritDoc} */
@Override/*www  .ja va 2 s.  co  m*/
public void valueChanged(TreeSelectionEvent e) {
    lastSelectionEvent = e;
    DefaultMutableTreeNode node = null;
    synchronized (this) {
        node = (DefaultMutableTreeNode) jTree.getLastSelectedPathComponent();
    }

    if (node != null) {
        // to restore last tab used
        if (rightSide.getTabCount() > selectedTab) {
            resultsRender.setLastSelectedTab(rightSide.getSelectedIndex());
        }
        Object userObject = node.getUserObject();
        resultsRender.setSamplerResult(userObject);
        resultsRender.setupTabPane(); // Processes Assertions
        // display a SampleResult
        if (userObject instanceof SampleResult) {
            SampleResult sampleResult = (SampleResult) userObject;
            if (isTextDataType(sampleResult)) {
                resultsRender.renderResult(sampleResult);
            } else {
                byte[] responseBytes = sampleResult.getResponseData();
                if (responseBytes != null) {
                    resultsRender.renderImage(sampleResult);
                }
            }
        }
    }
}

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

public TreePath getTreePath(DefaultMutableTreeNode node, ModelGraph graph) {
    if (node.getUserObject().equals(graph)) {
        return new TreePath(node.getPath());
    } else {//from   w  w  w  . j  av  a2  s  .  co  m
        for (int i = 0; i < node.getChildCount(); i++) {
            // System.out.println("i: " + ((DefaultMutableTreeNode)
            // node.getChildAt(i)).getUserObject());
            TreePath treePath = this.getTreePath((DefaultMutableTreeNode) node.getChildAt(i), graph);
            if (treePath != null) {
                return treePath;
            }
        }
        return null;
    }
}

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

private TreePath getTreePath(TreePath currentPath, ViewState state) {
    String lookingForPath = state.getCurrentMetGroup();
    Stack<DefaultMutableTreeNode> stack = new Stack<DefaultMutableTreeNode>();
    DefaultMutableTreeNode baseNode = (DefaultMutableTreeNode) currentPath.getLastPathComponent();
    for (int i = 0; i < baseNode.getChildCount(); i++) {
        stack.push((DefaultMutableTreeNode) baseNode.getChildAt(i));
    }/* ww w.j a v a  2  s. co m*/
    while (!stack.empty()) {
        DefaultMutableTreeNode node = stack.pop();
        if (node.getUserObject().equals("static-metadata")) {
            for (int i = 0; i < node.getChildCount(); i++) {
                stack.push((DefaultMutableTreeNode) node.getChildAt(i));
            }
        } else if (node.getUserObject() instanceof ConcurrentHashMap) {
            String key = (String) ((ConcurrentHashMap<String, String>) node.getUserObject()).keySet().iterator()
                    .next();
            if (lookingForPath.equals(key)) {
                return new TreePath(node.getPath());
            } else if (lookingForPath.startsWith(key + "/")) {
                lookingForPath = lookingForPath.substring(lookingForPath.indexOf("/") + 1);
                stack.clear();
                for (int i = 0; i < node.getChildCount(); i++) {
                    stack.add((DefaultMutableTreeNode) node.getChildAt(i));
                }
            }
        }
    }
    return currentPath;
}

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 ww  w.  j  a va 2 s.  com*/

    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.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultTreeView.java

private PopupMenu createPopupMenu(final ViewState state) {
    final String ACTIONS_POP_MENU_NAME = "Actions";
    final String VIEW_CONDITION_MAP = "View...";
    PopupMenu actionsMenu = new PopupMenu(ACTIONS_POP_MENU_NAME);
    actionsMenu.add(new MenuItem(VIEW_CONDITION_MAP));
    actionsMenu.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals(VIEW_CONDITION_MAP)) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getSelectionPath()
                        .getLastPathComponent();
                ModelGraph graphToFocus = null;
                if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_PRECONDITIONS))
                        || Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_POSTCONDITIONS))) {
                    // if (node.getUserObject() instanceof String &&
                    // (node.getUserObject().equals("pre-conditions") ||
                    // node.getUserObject().equals("post-conditions"))) {
                    ModelGraph graph = state.getSelected();
                    if (Boolean.parseBoolean(state.getFirstPropertyValue(EXPAND_PRECONDITIONS))) {
                        graphToFocus = graph.getPreConditions();
                    } else {
                        graphToFocus = graph.getPostConditions();
                    }/*from w ww.jav a 2s.c o m*/
                } else if (node.getUserObject() instanceof ModelGraph) {
                    graphToFocus = (ModelGraph) node.getUserObject();
                }
                DefaultTreeView.this
                        .notifyListeners(new ViewChange.NEW_VIEW(graphToFocus, DefaultTreeView.this));
            }
        }

    });

    final String ORDER_SUB_POP_MENU_NAME = "Order";
    final String TO_FRONT_ITEM_NAME = "Move To Front";
    final String TO_BACK_ITEM_NAME = "Move To Back";
    final String FORWARD_ITEM_NAME = "Move Forward";
    final String BACKWARDS_ITEM_NAME = "Move Backwards";
    actionsMenu.add(orderSubMenu = new PopupMenu(ORDER_SUB_POP_MENU_NAME));
    orderSubMenu.add(new MenuItem(TO_FRONT_ITEM_NAME));
    orderSubMenu.add(new MenuItem(TO_BACK_ITEM_NAME));
    orderSubMenu.add(new MenuItem(FORWARD_ITEM_NAME));
    orderSubMenu.add(new MenuItem(BACKWARDS_ITEM_NAME));
    orderSubMenu.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            ModelGraph graph = state.getSelected();
            ModelGraph parent = graph.getParent();
            if (e.getActionCommand().equals(TO_FRONT_ITEM_NAME)) {
                if (parent.getChildren().remove(graph)) {
                    parent.getChildren().add(0, graph);
                }
            } else if (e.getActionCommand().equals(TO_BACK_ITEM_NAME)) {
                if (parent.getChildren().remove(graph)) {
                    parent.getChildren().add(graph);
                }
            } else if (e.getActionCommand().equals(FORWARD_ITEM_NAME)) {
                int index = parent.getChildren().indexOf(graph);
                if (index != -1) {
                    parent.getChildren().remove(index);
                    parent.getChildren().add(Math.max(0, index + 1), graph);
                }
            } else if (e.getActionCommand().equals(BACKWARDS_ITEM_NAME)) {
                int index = parent.getChildren().indexOf(graph);
                if (index != -1) {
                    parent.getChildren().remove(index);
                    parent.getChildren().add(Math.max(0, index - 1), graph);
                }
            }
            DefaultTreeView.this.notifyListeners();
            DefaultTreeView.this.refreshView(state);
        }

    });
    return actionsMenu;
}

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();
    }/*w  w w  .j ava 2s  .  co  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 resourceExplorerTreeMouseClicked(final java.awt.event.MouseEvent evt) {
    if (evt.getButton() == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) resourceExplorerTree
                .getLastSelectedPathComponent();
        DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) selectedNode.getParent();
        String parentNodeName = parentNode == null ? null : String.valueOf(parentNode.getUserObject());
        if (selectedNode.isLeaf() && StringUtils.isNotBlank(parentNodeName)) {
            String leafNodeName = (String) selectedNode.getUserObject();
            try {
                if (PluginConstants.MAIL_TEMPLATES.equals(parentNodeName)) {
                    openMailEditor(leafNodeName);
                } else if (PluginConstants.REPORT_XSLTS.equals(parentNodeName)) {
                    openReportEditor(leafNodeName);
                }//  w ww .java 2 s  . c  o  m
            } catch (IOException e) {
                Exceptions.printStackTrace(e);
            }
        }
    } else if (evt.getButton() == MouseEvent.BUTTON3 && evt.getClickCount() == 1) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) resourceExplorerTree
                .getLastSelectedPathComponent();
        String selectedNodeName = (String) selectedNode.getUserObject();
        if (selectedNode.isLeaf() && !PluginConstants.ROOT_NAME.equals(selectedNodeName)
                && !PluginConstants.MAIL_TEMPLATES.equals(selectedNodeName)
                && !PluginConstants.REPORT_XSLTS.equals(selectedNodeName)) {
            leafRightClickAction(evt, selectedNode);
        } else if (PluginConstants.MAIL_TEMPLATES.equals(selectedNodeName)) {
            folderRightClickAction(evt, mailTemplates);
        } else if (PluginConstants.REPORT_XSLTS.equals(selectedNodeName)) {
            folderRightClickAction(evt, reportXslts);
        } else if (PluginConstants.ROOT_NAME.equals(selectedNodeName)) {
            rootRightClickAction(evt);
        }
    }
}

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);//from w ww .j a  v  a 2s  . 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.apache.syncope.ide.netbeans.view.ResourceExplorerTopComponent.java

private void leafRightClickAction(final MouseEvent evt, final DefaultMutableTreeNode node) {
    JPopupMenu menu = new JPopupMenu();
    JMenuItem deleteItem = new JMenuItem("Delete");
    menu.add(deleteItem);/*  ww w.j a  v a 2s. com*/

    deleteItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            int result = JOptionPane.showConfirmDialog(null, "Are you sure to delete the item?");
            if (result == JOptionPane.OK_OPTION) {
                DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
                boolean deleted;
                if (parent.getUserObject().equals(PluginConstants.MAIL_TEMPLATES)) {
                    deleted = mailTemplateManagerService.delete((String) node.getUserObject());
                } else {
                    deleted = reportTemplateManagerService.delete((String) node.getUserObject());
                }
                if (deleted) {
                    node.removeFromParent();
                    treeModel.reload(parent);
                } else {
                    JOptionPane.showMessageDialog(null, "Error while deleting new element", "Error",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    });

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

From source file:org.carewebframework.help.javahelp.HelpView.java

/**
 * Retrieves the help topic associated with the given node. Note that this also maintains a map
 * of topic id --> topic mappings in the parent help set.
 * //from ww  w.  j  a  va 2 s .  c o m
 * @param node Tree node.
 * @return A help topic instance.
 */
protected HelpTopic getTopic(TreeNode node) {
    try {
        DefaultMutableTreeNode nd = (DefaultMutableTreeNode) node;
        TreeItem item = (TreeItem) nd.getUserObject();
        ID id = item.getID();
        HelpTopic topic = new HelpTopic(id == null ? null : id.getURL(), item.getName(),
                item.getHelpSet().getTitle());

        if (id != null && view.getHelpSet().getKeyData("topics", id.id) == null) {
            view.getHelpSet().setKeyData("topics", id.id, topic);
        }

        return topic;
    } catch (MalformedURLException e) {
        return null;
    }
}