Source Code Cross Referenced for AggregateWorkingSet.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » 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 workbench » org.eclipse.ui.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 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;
011:
012:        import java.util.ArrayList;
013:        import java.util.Arrays;
014:        import java.util.HashSet;
015:        import java.util.Set;
016:
017:        import org.eclipse.core.runtime.IAdaptable;
018:        import org.eclipse.jface.resource.ImageDescriptor;
019:        import org.eclipse.jface.util.IPropertyChangeListener;
020:        import org.eclipse.jface.util.PropertyChangeEvent;
021:        import org.eclipse.ui.IMemento;
022:        import org.eclipse.ui.IWorkingSet;
023:        import org.eclipse.ui.IWorkingSetManager;
024:        import org.eclipse.ui.internal.util.Util;
025:
026:        /**
027:         * 
028:         * @since 3.2
029:         */
030:        public class AggregateWorkingSet extends AbstractWorkingSet implements 
031:                IPropertyChangeListener {
032:
033:            private IWorkingSet[] components;
034:
035:            /**
036:             * 
037:             * @param name
038:             * @param label
039:             * @param components
040:             */
041:            public AggregateWorkingSet(String name, String label,
042:                    IWorkingSet[] components) {
043:                super (name, label);
044:
045:                IWorkingSet[] componentCopy = new IWorkingSet[components.length];
046:                System.arraycopy(components, 0, componentCopy, 0,
047:                        components.length);
048:                internalSetComponents(componentCopy);
049:                constructElements(false);
050:            }
051:
052:            /**
053:             * 
054:             * @param name
055:             * @param label
056:             * @param memento
057:             */
058:            public AggregateWorkingSet(String name, String label,
059:                    IMemento memento) {
060:                super (name, label);
061:                workingSetMemento = memento;
062:            }
063:
064:            void setComponents(IWorkingSet[] components) {
065:                internalSetComponents(components);
066:                constructElements(true);
067:            }
068:
069:            private void internalSetComponents(IWorkingSet[] components) {
070:                this .components = components;
071:            }
072:
073:            /**
074:             * Takes the elements from all component working sets and sets them to be
075:             * the elements of this working set. Any duplicates are trimmed.
076:             * 
077:             * @param fireEvent whether a working set change event should be fired
078:             */
079:            private void constructElements(boolean fireEvent) {
080:                Set elements = new HashSet();
081:                for (int i = 0; i < components.length; i++) {
082:                    IWorkingSet workingSet = components[i];
083:                    elements.addAll(Arrays.asList(workingSet.getElements()));
084:                }
085:                internalSetElements((IAdaptable[]) elements
086:                        .toArray(new IAdaptable[elements.size()]));
087:                if (fireEvent) {
088:                    fireWorkingSetChanged(
089:                            IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE,
090:                            null);
091:                }
092:            }
093:
094:            public String getId() {
095:                return null;
096:            }
097:
098:            public ImageDescriptor getImageDescriptor() {
099:                return WorkbenchImages
100:                        .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_WORKING_SETS);
101:            }
102:
103:            /**
104:             * A no-op for aggregates - their contents should be derived.
105:             */
106:            public void setElements(IAdaptable[] elements) {
107:            }
108:
109:            public void setId(String id) {
110:
111:            }
112:
113:            /**
114:             * Aggregates are not editable.
115:             */
116:            public boolean isEditable() {
117:                return false;
118:            }
119:
120:            /**
121:             * Aggregates should not generally be visible in the UI.
122:             */
123:            public boolean isVisible() {
124:                return false;
125:            }
126:
127:            public void saveState(IMemento memento) {
128:                if (workingSetMemento != null) {
129:                    // just re-save the previous memento if the working set has
130:                    // not been restored
131:                    memento.putMemento(workingSetMemento);
132:                } else {
133:                    memento.putString(IWorkbenchConstants.TAG_NAME, getName());
134:                    memento
135:                            .putString(IWorkbenchConstants.TAG_LABEL,
136:                                    getLabel());
137:                    memento.putString(AbstractWorkingSet.TAG_AGGREGATE,
138:                            Boolean.TRUE.toString());
139:
140:                    for (int i = 0; i < components.length; i++) {
141:                        IWorkingSet componentSet = components[i];
142:                        memento.createChild(
143:                                IWorkbenchConstants.TAG_WORKING_SET,
144:                                componentSet.getName());
145:                    }
146:                }
147:            }
148:
149:            public void connect(IWorkingSetManager manager) {
150:                manager.addPropertyChangeListener(this );
151:                super .connect(manager);
152:            }
153:
154:            public void disconnect() {
155:                getManager().removePropertyChangeListener(this );
156:                super .disconnect();
157:            }
158:
159:            /**
160:             * Return the component working sets.
161:             * 
162:             * @return the component working sets
163:             */
164:            public IWorkingSet[] getComponents() {
165:                if (components == null) {
166:                    restoreWorkingSet();
167:                    workingSetMemento = null;
168:                }
169:                return components;
170:            }
171:
172:            public void propertyChange(PropertyChangeEvent event) {
173:                String property = event.getProperty();
174:                if (property
175:                        .equals(IWorkingSetManager.CHANGE_WORKING_SET_REMOVE)) {
176:                    for (int i = 0; i < getComponents().length; i++) {
177:                        IWorkingSet set = getComponents()[i];
178:                        if (set.equals(event.getOldValue())) {
179:                            IWorkingSet[] newComponents = new IWorkingSet[components.length - 1];
180:                            Util.arrayCopyWithRemoval(getComponents(),
181:                                    newComponents, i);
182:                            setComponents(newComponents);
183:                        }
184:                    }
185:                } else if (property
186:                        .equals(IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE)) {
187:                    for (int i = 0; i < getComponents().length; i++) {
188:                        IWorkingSet set = getComponents()[i];
189:                        if (set.equals(event.getNewValue())) {
190:                            constructElements(true);
191:                            break;
192:                        }
193:                    }
194:                }
195:            }
196:
197:            void restoreWorkingSet() {
198:                IWorkingSetManager manager = getManager();
199:                if (manager == null) {
200:                    throw new IllegalStateException();
201:                }
202:                IMemento[] workingSetReferences = workingSetMemento
203:                        .getChildren(IWorkbenchConstants.TAG_WORKING_SET);
204:                ArrayList list = new ArrayList(workingSetReferences.length);
205:
206:                for (int i = 0; i < workingSetReferences.length; i++) {
207:                    IMemento setReference = workingSetReferences[i];
208:                    String setId = setReference.getID();
209:                    IWorkingSet set = manager.getWorkingSet(setId);
210:                    if (set != null) {
211:                        list.add(set);
212:                    }
213:                }
214:                internalSetComponents((IWorkingSet[]) list
215:                        .toArray(new IWorkingSet[list.size()]));
216:                constructElements(false);
217:            }
218:
219:            public boolean equals(Object object) {
220:                if (this  == object) {
221:                    return true;
222:                }
223:                if (object instanceof  AggregateWorkingSet) {
224:                    AggregateWorkingSet workingSet = (AggregateWorkingSet) object;
225:
226:                    return Util.equals(workingSet.getName(), getName())
227:                            && Util.equals(workingSet.getComponents(),
228:                                    getComponents());
229:                }
230:                return false;
231:            }
232:
233:            public int hashCode() {
234:                int hashCode = getName().hashCode()
235:                        & getComponents().hashCode();
236:                return hashCode;
237:            }
238:
239:            public boolean isSelfUpdating() {
240:                if (components == null || components.length == 0) {
241:                    return false;
242:                }
243:                for (int i = 0; i < components.length; i++) {
244:                    if (!components[i].isSelfUpdating()) {
245:                        return false;
246:                    }
247:                }
248:                return true;
249:            }
250:
251:            public boolean isAggregateWorkingSet() {
252:                return true;
253:            }
254:
255:            /* (non-Javadoc)
256:             * @see org.eclipse.ui.IWorkingSet#adaptElements(org.eclipse.core.runtime.IAdaptable[])
257:             */
258:            public IAdaptable[] adaptElements(IAdaptable[] objects) {
259:                return new IAdaptable[0];
260:            }
261:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.