Source Code Cross Referenced for NavigatorFilterService.java in  » IDE-Eclipse » ui » org » eclipse » ui » internal » navigator » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » ui » org.eclipse.ui.internal.navigator 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         ******************************************************************************/package org.eclipse.ui.internal.navigator;
011:
012:        import java.util.ArrayList;
013:        import java.util.Arrays;
014:        import java.util.HashMap;
015:        import java.util.HashSet;
016:        import java.util.Iterator;
017:        import java.util.List;
018:        import java.util.Map;
019:        import java.util.Set;
020:
021:        import org.eclipse.core.runtime.Assert;
022:        import org.eclipse.core.runtime.Preferences;
023:        import org.eclipse.jface.viewers.ViewerFilter;
024:        import org.eclipse.ui.internal.navigator.filters.CommonFilterDescriptor;
025:        import org.eclipse.ui.internal.navigator.filters.CommonFilterDescriptorManager;
026:        import org.eclipse.ui.internal.navigator.filters.SkeletonViewerFilter;
027:        import org.eclipse.ui.navigator.ICommonFilterDescriptor;
028:        import org.eclipse.ui.navigator.INavigatorFilterService;
029:
030:        /**
031:         * @since 3.2
032:         * 
033:         */
034:        public class NavigatorFilterService implements  INavigatorFilterService {
035:
036:            private static final ViewerFilter[] NO_FILTERS = new ViewerFilter[0];
037:
038:            private static final String ACTIVATION_KEY = ".filterActivation"; //$NON-NLS-1$
039:
040:            private static final String DELIM = ":"; //$NON-NLS-1$
041:
042:            private final NavigatorContentService contentService;
043:
044:            /* Map of (ICommonFilterDescriptor, ViewerFilter)-pairs */
045:            private final Map declaredViewerFilters = new HashMap();
046:
047:            /* Set of ViewerFilters enforced from visible/active content extensions */
048:            private final Set enforcedViewerFilters = new HashSet();
049:
050:            /* A set of active filter String ids */
051:            private final Set activeFilters = new HashSet();
052:
053:            /**
054:             * @param aContentService
055:             *            The corresponding content service
056:             */
057:            public NavigatorFilterService(
058:                    NavigatorContentService aContentService) {
059:                contentService = aContentService;
060:                restoreFilterActivation();
061:            }
062:
063:            private synchronized void restoreFilterActivation() {
064:
065:                try {
066:                    Preferences preferences = NavigatorPlugin.getDefault()
067:                            .getPluginPreferences();
068:
069:                    if (preferences
070:                            .contains(getFilterActivationPreferenceKey())) {
071:                        String activatedFiltersPreferenceValue = preferences
072:                                .getString(getFilterActivationPreferenceKey());
073:                        String[] activeFilterIds = activatedFiltersPreferenceValue
074:                                .split(DELIM);
075:                        for (int i = 0; i < activeFilterIds.length; i++) {
076:                            activeFilters.add(activeFilterIds[i]);
077:                        }
078:
079:                    } else {
080:                        ICommonFilterDescriptor[] visibleFilterDescriptors = getVisibleFilterDescriptors();
081:                        for (int i = 0; i < visibleFilterDescriptors.length; i++) {
082:                            if (visibleFilterDescriptors[i].isActiveByDefault()) {
083:                                activeFilters.add(visibleFilterDescriptors[i]
084:                                        .getId());
085:                            }
086:                        }
087:                    }
088:
089:                } catch (RuntimeException e) {
090:                    NavigatorPlugin.logError(0, e.getMessage(), e);
091:                }
092:
093:            }
094:
095:            /*
096:             * (non-Javadoc)
097:             * 
098:             * @see org.eclipse.ui.navigator.INavigatorFilterService#persistFilterActivationState()
099:             */
100:            public void persistFilterActivationState() {
101:
102:                try {
103:                    synchronized (activeFilters) {
104:
105:                        /* by creating a StringBuffer with DELIM, we ensure the string is not empty when persisted.*/
106:                        StringBuffer activatedFiltersPreferenceValue = new StringBuffer(
107:                                DELIM);
108:
109:                        for (Iterator activeItr = activeFilters.iterator(); activeItr
110:                                .hasNext();) {
111:                            activatedFiltersPreferenceValue.append(
112:                                    activeItr.next().toString()).append(DELIM);
113:                        }
114:
115:                        Preferences preferences = NavigatorPlugin.getDefault()
116:                                .getPluginPreferences();
117:
118:                        preferences.setValue(
119:                                getFilterActivationPreferenceKey(),
120:                                activatedFiltersPreferenceValue.toString());
121:                    }
122:
123:                } catch (RuntimeException e) {
124:                    NavigatorPlugin.logError(0, e.getMessage(), e);
125:                }
126:
127:            }
128:
129:            /**
130:             * @return The correct filter activation preference key for the
131:             *         corresponding content service.
132:             */
133:            private String getFilterActivationPreferenceKey() {
134:                return contentService.getViewerId() + ACTIVATION_KEY;
135:            }
136:
137:            /*
138:             * (non-Javadoc)
139:             * 
140:             * @see org.eclipse.ui.navigator.INavigatorFilterService#getVisibleFilters(boolean)
141:             */
142:            public ViewerFilter[] getVisibleFilters(
143:                    boolean toReturnOnlyActiveFilters) {
144:                CommonFilterDescriptor[] descriptors = CommonFilterDescriptorManager
145:                        .getInstance().findVisibleFilters(contentService);
146:
147:                List filters = new ArrayList();
148:
149:                ViewerFilter instance;
150:                for (int i = 0; i < descriptors.length; i++) {
151:                    if (!toReturnOnlyActiveFilters
152:                            || isActive(descriptors[i].getId())) {
153:                        instance = getViewerFilter(descriptors[i]);
154:                        if (instance != null) {
155:                            filters.add(instance);
156:                        }
157:                    }
158:                }
159:
160:                /* return the enforced viewer filters always */
161:                filters.addAll(enforcedViewerFilters);
162:
163:                if (filters.size() == 0) {
164:                    return NO_FILTERS;
165:                }
166:                return (ViewerFilter[]) filters
167:                        .toArray(new ViewerFilter[filters.size()]);
168:            }
169:
170:            /**
171:             * @param descriptor
172:             *            A key into the viewerFilters map.
173:             * @return A non-null ViewerFilter from the extension (or
174:             *         {@link SkeletonViewerFilter#INSTANCE}).
175:             */
176:            public ViewerFilter getViewerFilter(
177:                    ICommonFilterDescriptor descriptor) {
178:                ViewerFilter filter = null;
179:                synchronized (declaredViewerFilters) {
180:                    filter = (ViewerFilter) declaredViewerFilters
181:                            .get(descriptor);
182:                    if (filter == null) {
183:                        declaredViewerFilters.put(descriptor,
184:                                (filter = ((CommonFilterDescriptor) descriptor)
185:                                        .createFilter()));
186:                    }
187:                }
188:                return filter;
189:            }
190:
191:            /*
192:             * (non-Javadoc)
193:             * 
194:             * @see org.eclipse.ui.navigator.INavigatorFilterService#getVisibleFilterIds()
195:             */
196:            public ICommonFilterDescriptor[] getVisibleFilterDescriptors() {
197:                return CommonFilterDescriptorManager.getInstance()
198:                        .findVisibleFilters(contentService);
199:            }
200:
201:            /*
202:             * (non-Javadoc)
203:             * 
204:             * @see org.eclipse.ui.navigator.INavigatorFilterService#isActive(java.lang.String)
205:             */
206:            public boolean isActive(String aFilterId) {
207:                synchronized (activeFilters) {
208:                    return activeFilters.contains(aFilterId);
209:                }
210:            }
211:
212:            /*
213:             * (non-Javadoc)
214:             * 
215:             * @see org.eclipse.ui.navigator.INavigatorFilterService#activateFilters(java.lang.String[])
216:             */
217:            public void setActiveFilterIds(String[] theFilterIds) {
218:                Assert.isNotNull(theFilterIds);
219:                synchronized (activeFilters) {
220:                    activeFilters.clear();
221:                    activeFilters.addAll(Arrays.asList(theFilterIds));
222:                }
223:            }
224:
225:            /**
226:             * Activate the given array without disabling all other filters.
227:             * 
228:             * @param theFilterIds
229:             *            The filter ids to activate.
230:             */
231:            public void addActiveFilterIds(String[] theFilterIds) {
232:                Assert.isNotNull(theFilterIds);
233:                synchronized (activeFilters) {
234:                    activeFilters.addAll(Arrays.asList(theFilterIds));
235:                }
236:            }
237:
238:            /**
239:             * 
240:             * @param aFilterId The id of the filter to activate or deactivate
241:             * @param toMakeActive True to make the filter active, false to make the filter inactive
242:             */
243:            public void setActive(String aFilterId, boolean toMakeActive) {
244:
245:                synchronized (activeFilters) {
246:                    boolean isActive = activeFilters.contains(aFilterId);
247:                    if (isActive ^ toMakeActive) {
248:                        if (toMakeActive)
249:                            activeFilters.remove(aFilterId);
250:                        else
251:                            activeFilters.add(aFilterId);
252:
253:                    }
254:
255:                }
256:            }
257:
258:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.