KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > retouche > navigation > ClassMemberPanelUI


1 /*
2  * ClassMemberPanelUi.java
3  *
4  * Created on November 8, 2006, 4:03 PM
5  */

6
7 package org.netbeans.modules.retouche.navigation;
8
9 import java.awt.BorderLayout JavaDoc;
10 import javax.swing.Action JavaDoc;
11 import javax.swing.KeyStroke JavaDoc;
12 import java.awt.Toolkit JavaDoc;
13 import java.awt.event.KeyEvent JavaDoc;
14 import javax.swing.JLabel JavaDoc;
15 import javax.swing.SwingUtilities JavaDoc;
16 import javax.swing.border.EmptyBorder JavaDoc;
17 import javax.swing.KeyStroke JavaDoc;
18 import javax.swing.event.ChangeEvent JavaDoc;
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 /**
36  * This file is originally from Retouche, the Java Support
37  * infrastructure in NetBeans. I have modified the file as little
38  * as possible to make merging Retouche fixes back as simple as
39  * possible.
40  * <p>
41  *
42  * @author phrebejk
43  */

44 public class ClassMemberPanelUI extends javax.swing.JPanel JavaDoc
45         implements ExplorerManager.Provider, FiltersManager.FilterChangeListener {
46     
47     private ExplorerManager manager = new ExplorerManager();
48     private BeanTreeView elementView;
49     private TapPanel filtersPanel;
50     private JLabel JavaDoc filtersLbl;
51     private Lookup lookup = null; // XXX may need better lookup
52
private ClassMemberFilters filters;
53     
54     private Action JavaDoc[] actions; // General actions for the panel
55

56     /** Creates new form ClassMemberPanelUi */
57     public ClassMemberPanelUI() {
58                       
59         initComponents();
60         
61         // Tree view of the elements
62
elementView = createBeanTreeView();
63         add(elementView, BorderLayout.CENTER);
64                
65         // filters
66
filtersPanel = new TapPanel();
67         filtersLbl = new JLabel JavaDoc(NbBundle.getMessage(ClassMemberPanelUI.class, "LBL_Filter")); //NOI18N
68
filtersLbl.setBorder(new EmptyBorder JavaDoc(0, 5, 5, 0));
69         filtersPanel.add(filtersLbl);
70         filtersPanel.setOrientation(TapPanel.DOWN);
71         // tooltip
72
KeyStroke JavaDoc toggleKey = KeyStroke.getKeyStroke(KeyEvent.VK_T,
73                 Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
74         String JavaDoc 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 JavaDoc[] {
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 JavaDoc
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         // XXX Check for chenge of FileObject
103
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 JavaDoc() {
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             // update
127
//System.out.println("UPDATE ======" + description.fileObject.getName() );
128
SwingUtilities.invokeLater(new Runnable JavaDoc() {
129                 public void run() {
130                     rootNode.updateRecursively( description );
131                 }
132             } );
133         }
134         else {
135             //System.out.println("REFRES =====" + description.fileObject.getName() );
136
// New fileobject => refresh completely
137
SwingUtilities.invokeLater(new Runnable JavaDoc() {
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 JavaDoc[] getActions() {
162         return actions;
163     }
164     
165     public FileObject getFileObject() {
166         return getRootNode().getFileObject();
167     }
168     
169     // FilterChangeListener ----------------------------------------------------
170

171     public void filterStateChanged(ChangeEvent JavaDoc e) {
172         ElementNode root = getRootNode();
173         
174         if ( root != null ) {
175             root.refreshRecursively();
176         }
177     }
178     
179     /** This method is called from within the constructor to
180      * initialize the form.
181      * WARNING: Do NOT modify this code. The content of this method is
182      * always regenerated by the Form Editor.
183      */

184     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
185
private void initComponents() {
186
187         setLayout(new java.awt.BorderLayout JavaDoc());
188     }// </editor-fold>//GEN-END:initComponents
189

190     
191     // Variables declaration - do not modify//GEN-BEGIN:variables
192
// End of variables declaration//GEN-END:variables
193

194     // Private methods ---------------------------------------------------------
195

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 // ActionMap map = getActionMap();
209
// map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(manager));
210
// map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(manager));
211
// map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(manager));
212
// map.put("delete", new DelegatingAction(ActionProvider.COMMAND_DELETE, ExplorerUtils.actionDelete(manager, true)));
213
//
214

215         BeanTreeView btv = new BeanTreeView(); // Add the BeanTreeView
216
// btv.setDragSource (true);
217
// btv.setRootVisible(false);
218
// associateLookup( ExplorerUtils.createLookup(manager, map) );
219
return btv;
220         
221     }
222     
223     
224     // ExplorerManager.Provider imlementation ----------------------------------
225

226     public ExplorerManager getExplorerManager() {
227         return manager;
228     }
229     
230     
231 }
232
Popular Tags