Source Code Cross Referenced for ActionPresentation.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) 2000, 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.Collection;
014:        import java.util.HashMap;
015:        import java.util.HashSet;
016:        import java.util.Iterator;
017:        import java.util.List;
018:
019:        import org.eclipse.core.runtime.CoreException;
020:        import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
021:        import org.eclipse.ui.SubActionBars;
022:        import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2;
023:        import org.eclipse.ui.internal.registry.IActionSet;
024:        import org.eclipse.ui.internal.registry.IActionSetDescriptor;
025:
026:        /**
027:         * Manage the configurable actions for one window.
028:         */
029:        public class ActionPresentation {
030:            private WorkbenchWindow window;
031:
032:            private HashMap mapDescToRec = new HashMap(3);
033:
034:            private HashMap invisibleBars = new HashMap(3);
035:
036:            private class SetRec {
037:                public SetRec(IActionSetDescriptor desc, IActionSet set,
038:                        SubActionBars bars) {
039:                    this .desc = desc;
040:                    this .set = set;
041:                    this .bars = bars;
042:                }
043:
044:                public IActionSetDescriptor desc;
045:
046:                public IActionSet set;
047:
048:                public SubActionBars bars;
049:            }
050:
051:            /**
052:             * ActionPresentation constructor comment.
053:             */
054:            public ActionPresentation(WorkbenchWindow window) {
055:                super ();
056:                this .window = window;
057:            }
058:
059:            /**
060:             * Remove all action sets.
061:             */
062:            public void clearActionSets() {
063:                // Get all of the action sets -- both visible and invisible.
064:                final List oldList = new ArrayList();
065:                oldList.addAll(mapDescToRec.keySet());
066:                oldList.addAll(invisibleBars.keySet());
067:
068:                Iterator iter = oldList.iterator();
069:                while (iter.hasNext()) {
070:                    IActionSetDescriptor desc = (IActionSetDescriptor) iter
071:                            .next();
072:                    removeActionSet(desc);
073:                }
074:            }
075:
076:            /**
077:             * Destroy an action set.
078:             */
079:            public void removeActionSet(IActionSetDescriptor desc) {
080:                SetRec rec = (SetRec) mapDescToRec.remove(desc);
081:                if (rec == null) {
082:                    rec = (SetRec) invisibleBars.remove(desc);
083:                }
084:                if (rec != null) {
085:                    IActionSet set = rec.set;
086:                    SubActionBars bars = rec.bars;
087:                    if (bars != null) {
088:                        bars.dispose();
089:                    }
090:                    if (set != null) {
091:                        set.dispose();
092:                    }
093:                }
094:            }
095:
096:            /**
097:             * Sets the list of visible action set.
098:             */
099:            public void setActionSets(IActionSetDescriptor[] newArray) {
100:                // Convert array to list.
101:                HashSet newList = new HashSet();
102:
103:                for (int i = 0; i < newArray.length; i++) {
104:                    IActionSetDescriptor descriptor = newArray[i];
105:
106:                    newList.add(descriptor);
107:                }
108:                List oldList = new ArrayList(mapDescToRec.keySet());
109:
110:                // Remove obsolete actions.
111:                Iterator iter = oldList.iterator();
112:                while (iter.hasNext()) {
113:                    IActionSetDescriptor desc = (IActionSetDescriptor) iter
114:                            .next();
115:                    if (!newList.contains(desc)) {
116:                        SetRec rec = (SetRec) mapDescToRec.get(desc);
117:                        if (rec != null) {
118:                            mapDescToRec.remove(desc);
119:                            IActionSet set = rec.set;
120:                            SubActionBars bars = rec.bars;
121:                            if (bars != null) {
122:                                SetRec invisibleRec = new SetRec(desc, set,
123:                                        bars);
124:                                invisibleBars.put(desc, invisibleRec);
125:                                bars.deactivate();
126:                            }
127:                        }
128:                    }
129:                }
130:
131:                // Add new actions.
132:                ArrayList sets = new ArrayList();
133:
134:                for (int i = 0; i < newArray.length; i++) {
135:                    IActionSetDescriptor desc = newArray[i];
136:
137:                    if (!mapDescToRec.containsKey(desc)) {
138:                        try {
139:                            SetRec rec;
140:                            // If the action bars and sets have already been created
141:                            // then
142:                            // reuse those action sets
143:                            if (invisibleBars.containsKey(desc)) {
144:                                rec = (SetRec) invisibleBars.get(desc);
145:                                if (rec.bars != null) {
146:                                    rec.bars.activate();
147:                                }
148:                                invisibleBars.remove(desc);
149:                            } else {
150:                                IActionSet set = desc.createActionSet();
151:                                SubActionBars bars = new ActionSetActionBars(
152:                                        window.getActionBars(), window,
153:                                        (IActionBarConfigurer2) window
154:                                                .getWindowConfigurer()
155:                                                .getActionBarConfigurer(), desc
156:                                                .getId());
157:                                rec = new SetRec(desc, set, bars);
158:                                set.init(window, bars);
159:                                sets.add(set);
160:
161:                                // only register against the tracker once - check for
162:                                // other registrations against the provided extension
163:                                Object[] existingRegistrations = window
164:                                        .getExtensionTracker()
165:                                        .getObjects(
166:                                                desc
167:                                                        .getConfigurationElement()
168:                                                        .getDeclaringExtension());
169:                                if (existingRegistrations.length == 0
170:                                        || !containsRegistration(
171:                                                existingRegistrations, desc)) {
172:                                    //register the set with the page tracker
173:                                    //this will be cleaned up by WorkbenchWindow listener
174:                                    window
175:                                            .getExtensionTracker()
176:                                            .registerObject(
177:                                                    desc
178:                                                            .getConfigurationElement()
179:                                                            .getDeclaringExtension(),
180:                                                    desc,
181:                                                    IExtensionTracker.REF_WEAK);
182:                                }
183:                            }
184:                            mapDescToRec.put(desc, rec);
185:                        } catch (CoreException e) {
186:                            WorkbenchPlugin
187:                                    .log(
188:                                            "Unable to create ActionSet: " + desc.getId(), e);//$NON-NLS-1$
189:                        }
190:                    }
191:                }
192:                // We process action sets in two passes for coolbar purposes. First we
193:                // process base contributions
194:                // (i.e., actions that the action set contributes to its toolbar), then
195:                // we process adjunct contributions
196:                // (i.e., actions that the action set contributes to other toolbars).
197:                // This type of processing is
198:                // necessary in order to maintain group order within a coolitem.
199:                PluginActionSetBuilder.processActionSets(sets, window);
200:
201:                iter = sets.iterator();
202:                while (iter.hasNext()) {
203:                    PluginActionSet set = (PluginActionSet) iter.next();
204:                    set.getBars().activate();
205:                }
206:            }
207:
208:            /**
209:             * Return whether the array contains the given action set.
210:             * 
211:             * @param existingRegistrations the array to check
212:             * @param set the set to look for
213:             * @return whether the set is in the array
214:             * @since 3.1
215:             */
216:            private boolean containsRegistration(
217:                    Object[] existingRegistrations, IActionSetDescriptor set) {
218:                for (int i = 0; i < existingRegistrations.length; i++) {
219:                    if (existingRegistrations[i] == set) {
220:                        return true;
221:                    }
222:                }
223:                return false;
224:            }
225:
226:            /**
227:             */
228:            public IActionSet[] getActionSets() {
229:                Collection setRecCollection = mapDescToRec.values();
230:                IActionSet result[] = new IActionSet[setRecCollection.size()];
231:                int i = 0;
232:                for (Iterator iterator = setRecCollection.iterator(); iterator
233:                        .hasNext(); i++) {
234:                    result[i] = ((SetRec) iterator.next()).set;
235:                }
236:                return result;
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.