1 6 7 package org.netbeans.modules.retouche.navigation; 8 9 import java.awt.BorderLayout ; 10 import javax.swing.Action ; 11 import javax.swing.KeyStroke ; 12 import java.awt.Toolkit ; 13 import java.awt.event.KeyEvent ; 14 import javax.swing.JLabel ; 15 import javax.swing.SwingUtilities ; 16 import javax.swing.border.EmptyBorder ; 17 import javax.swing.KeyStroke ; 18 import javax.swing.event.ChangeEvent ; 19 import org.netbeans.api.gsf.StructureItem; 20 import org.netbeans.modules.retouche.navigation.ClassMemberFilters; 21 import org.netbeans.modules.retouche.navigation.ElementNode; 22 import org.netbeans.modules.retouche.navigation.actions.FilterSubmenuAction; 23 import org.netbeans.modules.retouche.navigation.actions.SortActionSupport.SortByNameAction; 24 import org.netbeans.modules.retouche.navigation.actions.SortActionSupport.SortBySourceAction; 25 import org.netbeans.modules.retouche.navigation.base.FiltersManager; 26 import org.openide.nodes.Node; 27 import org.openide.util.NbBundle; 28 import org.openide.util.Utilities; 29 import org.netbeans.modules.retouche.navigation.base.TapPanel; 30 import org.openide.explorer.ExplorerManager; 31 import org.openide.explorer.view.BeanTreeView; 32 import org.openide.filesystems.FileObject; 33 import org.openide.util.Lookup; 34 35 44 public class ClassMemberPanelUI extends javax.swing.JPanel 45 implements ExplorerManager.Provider, FiltersManager.FilterChangeListener { 46 47 private ExplorerManager manager = new ExplorerManager(); 48 private BeanTreeView elementView; 49 private TapPanel filtersPanel; 50 private JLabel filtersLbl; 51 private Lookup lookup = null; private ClassMemberFilters filters; 53 54 private Action [] actions; 56 57 public ClassMemberPanelUI() { 58 59 initComponents(); 60 61 elementView = createBeanTreeView(); 63 add(elementView, BorderLayout.CENTER); 64 65 filtersPanel = new TapPanel(); 67 filtersLbl = new JLabel (NbBundle.getMessage(ClassMemberPanelUI.class, "LBL_Filter")); filtersLbl.setBorder(new EmptyBorder (0, 5, 5, 0)); 69 filtersPanel.add(filtersLbl); 70 filtersPanel.setOrientation(TapPanel.DOWN); 71 KeyStroke toggleKey = KeyStroke.getKeyStroke(KeyEvent.VK_T, 73 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); 74 String keyText = Utilities.keyToString(toggleKey); 75 filtersPanel.setToolTipText(NbBundle.getMessage(ClassMemberPanelUI.class, "TIP_TapPanel", keyText)); 76 77 filters = new ClassMemberFilters( this ); 78 filters.getInstance().hookChangeListener(this); 79 filtersPanel.add(filters.getComponent()); 80 81 actions = new Action [] { 82 new SortByNameAction( filters ), 83 new SortBySourceAction( filters ), 84 null, 85 new FilterSubmenuAction(filters.getInstance()) 86 }; 87 88 add(filtersPanel, BorderLayout.SOUTH); 89 90 manager.setRootContext(ElementNode.getWaitNode()); 91 92 } 93 94 @Override 95 public boolean requestFocusInWindow() { 96 boolean result = super.requestFocusInWindow(); 97 elementView.requestFocusInWindow(); 98 return result; 99 } 100 101 public org.openide.util.Lookup getLookup() { 102 return lookup; 104 } 105 106 public org.netbeans.modules.retouche.navigation.ElementScanningTask getTask() { 107 108 return new ElementScanningTask(this); 109 110 } 111 112 113 public void showWaitNode() { 114 SwingUtilities.invokeLater(new Runnable () { 115 public void run() { 116 elementView.setRootVisible(true); 117 manager.setRootContext(ElementNode.getWaitNode()); 118 } 119 }); 120 } 121 122 public void refresh( final StructureItem description, final FileObject fileObject) { 123 final ElementNode rootNode = getRootNode(); 124 125 if ( rootNode != null && rootNode.getFileObject().equals( fileObject) ) { 126 SwingUtilities.invokeLater(new Runnable () { 129 public void run() { 130 rootNode.updateRecursively( description ); 131 } 132 } ); 133 } 134 else { 135 SwingUtilities.invokeLater(new Runnable () { 138 139 public void run() { 140 elementView.setRootVisible(false); 141 manager.setRootContext(new ElementNode( description, ClassMemberPanelUI.this, fileObject ) ); 142 elementView.expandAll(); 143 } 144 } ); 145 146 } 147 } 148 149 public void sort() { 150 getRootNode().refreshRecursively(); 151 } 152 153 public ClassMemberFilters getFilters() { 154 return filters; 155 } 156 157 public void expandNode( Node n ) { 158 elementView.expandNode(n); 159 } 160 161 public Action [] getActions() { 162 return actions; 163 } 164 165 public FileObject getFileObject() { 166 return getRootNode().getFileObject(); 167 } 168 169 171 public void filterStateChanged(ChangeEvent e) { 172 ElementNode root = getRootNode(); 173 174 if ( root != null ) { 175 root.refreshRecursively(); 176 } 177 } 178 179 184 private void initComponents() { 186 187 setLayout(new java.awt.BorderLayout ()); 188 } 190 191 194 196 private ElementNode getRootNode() { 197 198 Node n = manager.getRootContext(); 199 if ( n instanceof ElementNode ) { 200 return (ElementNode)n; 201 } 202 else { 203 return null; 204 } 205 } 206 207 private BeanTreeView createBeanTreeView() { 208 215 BeanTreeView btv = new BeanTreeView(); return btv; 220 221 } 222 223 224 226 public ExplorerManager getExplorerManager() { 227 return manager; 228 } 229 230 231 } 232 | Popular Tags |