1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.selectors; 21 22 import org.openide.explorer.view.BeanTreeView; 23 import org.openide.explorer.ExplorerManager; 24 import org.openide.nodes.Node; 25 import org.openide.nodes.NodeAcceptor; 26 import org.openide.DialogDescriptor; 27 import org.openide.DialogDisplayer; 28 import org.openide.awt.Mnemonics; 29 import org.openide.util.UserCancelException; 30 import org.openide.util.HelpCtx; 31 32 import javax.swing.tree.DefaultTreeCellRenderer ; 33 import javax.swing.*; 34 import java.awt.*; 35 import java.beans.PropertyChangeListener ; 36 import java.beans.PropertyChangeEvent ; 37 38 44 public final class NodeOperation2 extends BeanTreeView implements PropertyChangeListener { 45 46 private final ExplorerManager manager = new ExplorerManager(); 47 48 private DialogDescriptor dd; 49 private boolean hideIcons; 50 private NodeAcceptor acceptor; 51 private HelpCtx helpCtx; 52 53 56 public NodeOperation2() { 57 } 58 59 public Node[] select(String title, String subtitle, String acsd, Node root, String browserAcsn, String browserAcsd, NodeAcceptor acceptor) throws UserCancelException { 60 manager.setRootContext(root); 61 manager.addPropertyChangeListener(this); 62 63 if (hideIcons) { 64 DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer (); 65 renderer.setOpenIcon(null); 66 renderer.setClosedIcon(null); 67 renderer.setLeafIcon(null); 68 tree.setCellRenderer(renderer); 69 } 70 71 setPopupAllowed (false); 72 setDefaultActionAllowed (false); 73 setBorder(UIManager.getBorder("Nb.ScrollPane.border")); 75 JLabel label = new JLabel(); 76 Mnemonics.setLocalizedText(label, subtitle); 77 label.setLabelFor(tree); 78 label.setToolTipText(browserAcsd); 79 getAccessibleContext().setAccessibleDescription(browserAcsd); 80 getAccessibleContext().setAccessibleName(browserAcsn); 81 ExplorerParent pane = new ExplorerParent(this); 82 pane.add(label, BorderLayout.NORTH); 83 pane.setBorder(BorderFactory.createEmptyBorder(12,12,0,12)); 84 85 dd = new DialogDescriptor(pane, title); 86 dd.setModal(true); 87 if (helpCtx != null) { 88 dd.setHelpCtx(helpCtx); 89 } 90 this.acceptor = acceptor; 91 testAccept(); 92 93 Dialog dialog = DialogDisplayer.getDefault().createDialog(dd); 94 dialog.getAccessibleContext().setAccessibleDescription(acsd); 95 dialog.setVisible(true); 96 97 if (dd.getValue() == DialogDescriptor.OK_OPTION) { 98 return manager.getSelectedNodes(); 99 } else { 100 throw new UserCancelException(); 101 } 102 } 103 104 public void setIconsVisible(boolean visible) { 105 hideIcons = visible == false; 106 } 107 108 public void setHelpCtx(HelpCtx help) { 109 helpCtx = help; 110 } 111 112 public void propertyChange (PropertyChangeEvent ev) { 113 if (ev.getPropertyName().equals (ExplorerManager.PROP_SELECTED_NODES)) { 114 testAccept(); 115 } 116 } 117 118 private void testAccept() { 119 dd.setValid(acceptor.acceptNodes (manager.getSelectedNodes())); 120 } 121 122 126 private class ExplorerParent extends JPanel implements ExplorerManager.Provider { 127 public ExplorerParent(Component client) { 128 super(new BorderLayout(6, 6)); 129 add(client, BorderLayout.CENTER); 130 } 131 132 public ExplorerManager getExplorerManager() { 133 return manager; 134 } 135 } 136 } 137 | Popular Tags |