Source Code Cross Referenced for UpdateActiveFiltersOperation.java in  » IDE-Eclipse » ui » org » eclipse » ui » internal » navigator » filters » 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.filters 
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.filters;
011:
012:        import java.util.Arrays;
013:
014:        import org.eclipse.core.commands.operations.AbstractOperation;
015:        import org.eclipse.core.runtime.Assert;
016:        import org.eclipse.core.runtime.IAdaptable;
017:        import org.eclipse.core.runtime.IProgressMonitor;
018:        import org.eclipse.core.runtime.IStatus;
019:        import org.eclipse.core.runtime.Status;
020:        import org.eclipse.jface.viewers.StructuredSelection;
021:        import org.eclipse.jface.viewers.ViewerFilter;
022:        import org.eclipse.ui.internal.navigator.CommonNavigatorMessages;
023:        import org.eclipse.ui.internal.navigator.NavigatorFilterService;
024:        import org.eclipse.ui.navigator.CommonViewer;
025:        import org.eclipse.ui.navigator.ICommonFilterDescriptor;
026:        import org.eclipse.ui.navigator.INavigatorContentService;
027:        import org.eclipse.ui.navigator.INavigatorFilterService;
028:
029:        /**
030:         * Ensures that a given set of filters is <i>active</i> and the complement of
031:         * that set of filters are not <i>active</i>.
032:         * 
033:         * <p>
034:         * This operation is smart enough not to force any change if each id in each set
035:         * is already in its desired state (<i>active</i> or <i>inactive</i>).
036:         * </p>
037:         * 
038:         * @since 3.2
039:         * 
040:         */
041:        public class UpdateActiveFiltersOperation extends AbstractOperation {
042:
043:            private String[] filterIdsToActivate;
044:
045:            private final CommonViewer commonViewer;
046:
047:            private final INavigatorContentService contentService;
048:
049:            private boolean disableTheComplement;
050:
051:            /**
052:             * Create an operation to activate extensions and refresh the viewer.
053:             * 
054:             * 
055:             * @param aCommonViewer
056:             *            The CommonViewer instance to update
057:             * @param theActiveFilterIds
058:             *            An array of ids that correspond to the filters that should be
059:             *            in the <i>active</i> state after this operation executes. The
060:             *            complement of this set will likewise be in the <i>inactive</i>
061:             *            state after this operation executes.
062:             *            @param toDisableTheComplement True indicates that all filters not in the set should be made inactive.
063:             */
064:            public UpdateActiveFiltersOperation(CommonViewer aCommonViewer,
065:                    String[] theActiveFilterIds, boolean toDisableTheComplement) {
066:                super (
067:                        CommonNavigatorMessages.UpdateFiltersOperation_Update_CommonViewer_Filter_);
068:                Assert.isNotNull(theActiveFilterIds);
069:
070:                commonViewer = aCommonViewer;
071:                contentService = commonViewer.getNavigatorContentService();
072:                filterIdsToActivate = theActiveFilterIds;
073:                disableTheComplement = toDisableTheComplement;
074:
075:            }
076:
077:            /*
078:             * (non-Javadoc)
079:             * 
080:             * @see org.eclipse.core.commands.operations.AbstractOperation#execute(org.eclipse.core.runtime.IProgressMonitor,
081:             *      org.eclipse.core.runtime.IAdaptable)
082:             */
083:            public IStatus execute(IProgressMonitor monitor, IAdaptable info) {
084:
085:                boolean updateFilterActivation = false;
086:
087:                // we sort the array in order to use Array.binarySearch();
088:                Arrays.sort(filterIdsToActivate);
089:
090:                try {
091:                    commonViewer.getControl().setRedraw(false);
092:
093:                    INavigatorFilterService filterService = contentService
094:                            .getFilterService();
095:
096:                    if (disableTheComplement) {
097:
098:                        ICommonFilterDescriptor[] visibleFilterDescriptors = filterService
099:                                .getVisibleFilterDescriptors();
100:
101:                        int indexofFilterIdToBeActivated;
102:
103:                        /* is there a delta? */
104:                        for (int i = 0; i < visibleFilterDescriptors.length
105:                                && !updateFilterActivation; i++) {
106:                            indexofFilterIdToBeActivated = Arrays.binarySearch(
107:                                    filterIdsToActivate,
108:                                    visibleFilterDescriptors[i].getId());
109:
110:                            /*
111:                             * Either we have a filter that should be active that isn't
112:                             * XOR a filter that shouldn't be active that is currently
113:                             */
114:                            if (indexofFilterIdToBeActivated >= 0
115:                                    ^ filterService
116:                                            .isActive(visibleFilterDescriptors[i]
117:                                                    .getId())) {
118:                                updateFilterActivation = true;
119:                            }
120:                        }
121:
122:                        /* If so, update */
123:                        if (updateFilterActivation) {
124:
125:                            filterService
126:                                    .setActiveFilterIds(filterIdsToActivate);
127:                            filterService.persistFilterActivationState();
128:
129:                            commonViewer.resetFilters();
130:
131:                            ViewerFilter[] visibleFilters = filterService
132:                                    .getVisibleFilters(true);
133:                            for (int i = 0; i < visibleFilters.length; i++) {
134:                                commonViewer.addFilter(visibleFilters[i]);
135:                            }
136:
137:                            // the action providers may no longer be enabled, so we
138:                            // reset the selection.
139:                            commonViewer
140:                                    .setSelection(StructuredSelection.EMPTY);
141:                        }
142:                    } else {
143:                        NavigatorFilterService internalFilterService = (NavigatorFilterService) filterService;
144:
145:                        internalFilterService
146:                                .addActiveFilterIds(filterIdsToActivate);
147:
148:                        ICommonFilterDescriptor[] visibleDescriptors = filterService
149:                                .getVisibleFilterDescriptors();
150:                        for (int i = 0; i < visibleDescriptors.length; i++) {
151:                            if (Arrays.binarySearch(filterIdsToActivate,
152:                                    visibleDescriptors[i].getId()) >= 0) {
153:                                commonViewer
154:                                        .addFilter(internalFilterService
155:                                                .getViewerFilter(visibleDescriptors[i]));
156:                            }
157:                        }
158:
159:                        // the action providers may no longer be enabled, so we
160:                        // reset the selection.
161:                        commonViewer.setSelection(StructuredSelection.EMPTY);
162:                    }
163:
164:                } finally {
165:                    commonViewer.getControl().setRedraw(true);
166:                }
167:                return Status.OK_STATUS;
168:            }
169:
170:            /*
171:             * (non-Javadoc)
172:             * 
173:             * @see org.eclipse.core.commands.operations.AbstractOperation#redo(org.eclipse.core.runtime.IProgressMonitor,
174:             *      org.eclipse.core.runtime.IAdaptable)
175:             */
176:            public IStatus redo(IProgressMonitor monitor, IAdaptable info) {
177:                return null;
178:            }
179:
180:            /*
181:             * (non-Javadoc)
182:             * 
183:             * @see org.eclipse.core.commands.operations.AbstractOperation#undo(org.eclipse.core.runtime.IProgressMonitor,
184:             *      org.eclipse.core.runtime.IAdaptable)
185:             */
186:            public IStatus undo(IProgressMonitor monitor, IAdaptable info) {
187:                return null;
188:            }
189:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.