1 9 10 package org.netbeans.modules.retouche.navigation; 11 12 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.Collections ; 16 import javax.swing.ImageIcon ; 17 import javax.swing.JComponent ; 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 37 public final class ClassMemberFilters { 38 39 private ClassMemberPanelUI ui; 40 41 42 private static final String SHOW_NON_PUBLIC = "show_non_public"; 43 private static final String SHOW_STATIC = "show_static"; 44 private static final String SHOW_FIELDS = "show_fields"; 45 private static final String SHOW_INHERITED = "show_inherited"; 46 47 private FiltersManager filters; 48 49 private boolean naturalSort = false; 50 51 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 getComponent() { 64 FiltersManager f = getInstance(); 65 return f.getComponent(); 66 67 } 68 69 public Collection <StructureItem> filter( Collection <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 76 ArrayList <StructureItem> result = new ArrayList <StructureItem>(original.size()); 77 for (StructureItem description : original) { 78 79 if (!non_public && 81 (description.getModifiers().contains(Modifier.PROTECTED) || description.getModifiers().contains(Modifier.PRIVATE))) { 82 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 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 117 118 private static FiltersManager createFilters () { 119 FiltersDescription desc = new FiltersDescription(); 120 121 desc.addFilter(SHOW_FIELDS, 130 NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowFields"), NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowFieldsTip"), true, 133 new ImageIcon (Utilities.loadImage("org/netbeans/modules/retouche/navigation/resources/filterHideFields.gif")), null 135 ); 136 desc.addFilter(SHOW_STATIC, 137 NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowStatic"), NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowStaticTip"), true, 140 new ImageIcon (Utilities.loadImage("org/netbeans/modules/retouche/navigation/resources/filterHideStatic.png")), null 142 ); 143 desc.addFilter(SHOW_NON_PUBLIC, 144 NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowNonPublic"), NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowNonPublicTip"), true, 147 new ImageIcon (Utilities.loadImage("org/netbeans/modules/retouche/navigation/resources/filterHideNonPublic.png")), null 149 ); 150 151 return FiltersDescription.createManager(desc); 152 } 153 154 155 156 } 157 | Popular Tags |