@@ -0,0 +1,3557 @@
+/*%0A * To change this template, choose Tools %7C Templates%0A * and open the template in the editor.%0A */%0Apackage jui;%0A%0Aimport java.awt.event.ActionEvent;%0Aimport java.awt.event.ActionListener;%0Aimport javax.swing.*;%0Aimport java.awt.*;%0Aimport java.awt.event.*;%0Aimport javax.swing.JPopupMenu;%0Aimport javax.swing.tree.DefaultMutableTreeNode;%0Aimport javax.swing.tree.DefaultTreeModel;%0Aimport javax.swing.tree.TreeNode;%0Aimport javax.swing.JTree;%0Aimport javax.swing.tree.TreePath;%0A%0A/**%0A *%0A * @author lin%0A */%0Apublic class JvxDialogHelper %7B%0A    private JTree dialogTree = null;%0A    DefaultMutableTreeNode rightClickedNode = null;%0A    %0A    %0A    public JvxDialogHelper() %7B%0A        super();%0A    %7D%0A    public JPopupMenu createPopup() %7B%0A        final DialogMenuAction menuAction = new DialogMenuAction(dialogTree, rightClickedNode);%0A        %0A        JPopupMenu popup = new JPopupMenu();%0A        JMenuItem addMenuItem = new JMenuItem(%22Add%22);%0A        JMenuItem delMenuItem = new JMenuItem(%22Delete%22);%0A        JMenuItem editMenuItem = new JMenuItem(%22Edit%22);%0A        %0A        addMenuItem.addActionListener(menuAction);%0A        delMenuItem.addActionListener(menuAction);%0A        editMenuItem.addActionListener(menuAction);%0A        %0A        popup.add(addMenuItem);%0A        popup.add(delMenuItem);%0A        popup.add(editMenuItem);%0A        %0A        return popup;%0A    %7D%0A    public void dialogTreeRClicked(java.awt.event.MouseEvent evt) %7B%0A        if( evt.isPopupTrigger() ) %7B%0A            int x = evt.getX();%0A            int y = evt.getY();%0A            JTree tree = (JTree)evt.getSource();%0A            dialogTree = tree;%0A            TreePath path = tree.getPathForLocation(x, y);%0A            if (path == null) return;%0A            %0A            rightClickedNode =%0A                            (DefaultMutableTreeNode)path.getLastPathComponent();%0A%0A            TreePath%5B%5D selectionPaths = tree.getSelectionPaths();%0A            //check if node was selected%0A            boolean isSelected = false;%0A            if (selectionPaths != null) %7B%0A                for (TreePath selectionPath : selectionPaths) %7B%0A                    if (selectionPath.equals(path)) %7B%0A                        isSelected = true;%0A                    %7D%0A                %7D%0A            %7D%0A            //if clicked node was not selected, select it%0A            if(!isSelected)%7B%0A                tree.setSelectionPath(path);%0A            %7D%0A            //if(rightClickedNode.isLeaf())%7B%0A                JPopupMenu popup = createPopup();%0A                popup.show(tree, x, y);%0A           // %7D%0A        %7D%0A    %7D%0A%7D%0A%0Aclass DialogMenuAction implements ActionListener %7B%0A%0A    private JTree dialogTree = null;%0A    DefaultMutableTreeNode rightClickedNode = null;%0A    %0A    DialogMenuAction(JTree tree, DefaultMutableTreeNode rNode) %7B%0A        dialogTree = tree;%0A        rightClickedNode = rNode;%0A    %7D%0A    %0A    public void actionPerformed(ActionEvent ae) %7B%0A        DefaultTreeModel model = (DefaultTreeModel)dialogTree.getModel();%0A        String action = ((JMenuItem)ae.getSource()).getText();%0A        System.out.println(%22Menu: %22 + action);%0A        if(action.equals(%22Add%22)) %7B%0A            rightClickedNode.add(new DefaultMutableTreeNode(%22another_child%22));%0A        %7D%0A        else if(action.equals(%22Delete%22)) %7B%0A            rightClickedNode.removeAllChildren();%0A            model.removeNodeFromParent(rightClickedNode);%0A            rightClickedNode = null;%0A        %7D%0A        else if(action.equals(%22Edit%22)) %7B%0A            dialogTree.startEditingAtPath(dialogTree.getSelectionPath());%0A        %7D%0A        %0A        model.reload(rightClickedNode);%0A    %7D%0A    %0A%7D

version 2 - dialog add/edit/del