KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * ClassMemberFilters.java
3  *
4  * Created on November 9, 2006, 5:40 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.retouche.navigation;
11
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Collection JavaDoc;
15 import java.util.Collections JavaDoc;
16 import javax.swing.ImageIcon JavaDoc;
17 import javax.swing.JComponent JavaDoc;
18 import org.netbeans.api.gsf.ElementKind;
19 import org.netbeans.api.gsf.Modifier;
20 import org.netbeans.api.gsf.StructureItem;
21 import org.netbeans.modules.retouche.navigation.ElementNode.Description;
22 import org.netbeans.modules.retouche.navigation.base.FiltersDescription;
23 import org.netbeans.modules.retouche.navigation.base.FiltersManager;
24 import org.openide.util.NbBundle;
25 import org.openide.util.Utilities;
26
27 /**
28  * This file is originally from Retouche, the Java Support
29  * infrastructure in NetBeans. I have modified the file as little
30  * as possible to make merging Retouche fixes back as simple as
31  * possible.
32  * <p>
33  * Creates filtering for the ClassMemberPanel
34  *
35  * @author phrebejk
36  */

37 public final class ClassMemberFilters {
38     
39     private ClassMemberPanelUI ui;
40     
41     /** constants for defined filters */
42     private static final String JavaDoc SHOW_NON_PUBLIC = "show_non_public";
43     private static final String JavaDoc SHOW_STATIC = "show_static";
44     private static final String JavaDoc SHOW_FIELDS = "show_fields";
45     private static final String JavaDoc SHOW_INHERITED = "show_inherited";
46     
47     private FiltersManager filters;
48     
49     private boolean naturalSort = false;
50     
51     /** Creates a new instance of ClassMemberFilters */
52     ClassMemberFilters( ClassMemberPanelUI ui ) {
53         this.ui = ui;
54     }
55     
56     public FiltersManager getInstance() {
57         if (filters == null) {
58             filters = createFilters();
59         }
60         return filters;
61     }
62     
63     public JComponent JavaDoc getComponent() {
64         FiltersManager f = getInstance();
65         return f.getComponent();
66         
67     }
68     
69     public Collection JavaDoc<StructureItem> filter( Collection JavaDoc<StructureItem> original ) {
70         
71         boolean non_public = filters.isSelected(SHOW_NON_PUBLIC);
72         boolean statik = filters.isSelected(SHOW_STATIC);
73         boolean fields = filters.isSelected(SHOW_FIELDS);
74         // XXX Enable later boolean inherited = filters.isSelected(SHOW_INHERITED);
75

76         ArrayList JavaDoc<StructureItem> result = new ArrayList JavaDoc<StructureItem>(original.size());
77         for (StructureItem description : original) {
78             
79             // I default no access modifier to mean public, unlike the Java version where it means package protected
80
if (!non_public &&
81                    (description.getModifiers().contains(Modifier.PROTECTED) || description.getModifiers().contains(Modifier.PRIVATE))) {
82 // if ( !non_public &&
83
// !description.getModifiers().contains(Modifier.PUBLIC)
84
// /* Fix for #89777 && !description.modifiers.contains(Modifier.PROTECTED) */ ) {
85
continue;
86             }
87             
88             if ( !statik && description.getModifiers().contains(Modifier.STATIC)) {
89                 continue;
90             }
91             
92             if ( !fields && (description.getKind() == ElementKind.FIELD || (description.getKind() == ElementKind.ATTRIBUTE))) {
93                 continue;
94             }
95             
96             // XXX Inherited members
97

98             result.add(description);
99         }
100   
101         Collections.sort( result, isNaturalSort() ? Description.POSITION_COMPARATOR : Description.ALPHA_COMPARATOR );
102         
103         return result;
104     }
105     
106     public boolean isNaturalSort() {
107         return naturalSort;
108     }
109     
110     public void setNaturalSort( boolean naturalSort ) {
111         this.naturalSort = naturalSort;
112         ui.sort();
113     }
114     
115     // Privare methods ---------------------------------------------------------
116

117     /** Creates filter descriptions and filters itself */
118     private static FiltersManager createFilters () {
119         FiltersDescription desc = new FiltersDescription();
120         
121         // XXX to be enabled later
122
// desc.addFilter(SHOW_INHERITED,
123
// NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowInherited"), //NOI18N
124
// NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowInheritedTip"), //NOI18N
125
// false,
126
// new ImageIcon (Utilities.loadImage("org/netbeans/modules/retouche/navigation/resources/filterHideInherited.png")), //NOI18N
127
// null
128
// );
129
desc.addFilter(SHOW_FIELDS,
130                 NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowFields"), //NOI18N
131
NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowFieldsTip"), //NOI18N
132
true,
133                 new ImageIcon JavaDoc (Utilities.loadImage("org/netbeans/modules/retouche/navigation/resources/filterHideFields.gif")), //NOI18N
134
null
135         );
136         desc.addFilter(SHOW_STATIC,
137                 NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowStatic"), //NOI18N
138
NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowStaticTip"), //NOI18N
139
true,
140                 new ImageIcon JavaDoc (Utilities.loadImage("org/netbeans/modules/retouche/navigation/resources/filterHideStatic.png")), //NOI18N
141
null
142         );
143         desc.addFilter(SHOW_NON_PUBLIC,
144                 NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowNonPublic"), //NOI18N
145
NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowNonPublicTip"), //NOI18N
146
true,
147                 new ImageIcon JavaDoc (Utilities.loadImage("org/netbeans/modules/retouche/navigation/resources/filterHideNonPublic.png")), //NOI18N
148
null
149         );
150         
151         return FiltersDescription.createManager(desc);
152     }
153     
154     
155         
156 }
157
Popular Tags