Source Code Cross Referenced for EditorMenuManager.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.HashSet;
014:        import java.util.Iterator;
015:
016:        import org.eclipse.jface.action.ActionContributionItem;
017:        import org.eclipse.jface.action.IAction;
018:        import org.eclipse.jface.action.IContributionItem;
019:        import org.eclipse.jface.action.IContributionManagerOverrides;
020:        import org.eclipse.jface.action.IMenuManager;
021:        import org.eclipse.jface.action.MenuManager;
022:        import org.eclipse.jface.action.SubMenuManager;
023:        import org.eclipse.ui.actions.RetargetAction;
024:
025:        /**
026:         * An <code>EditorMenuManager</code> is used to sort the contributions
027:         * made by an editor so that they always appear after the action sets.  
028:         */
029:        public class EditorMenuManager extends SubMenuManager {
030:            private ArrayList wrappers;
031:
032:            private boolean enabledAllowed = true;
033:
034:            private class Overrides implements  IContributionManagerOverrides {
035:                /**
036:                 * Indicates that the items of this manager are allowed to enable;
037:                 * <code>true</code> by default.
038:                 */
039:                public void updateEnabledAllowed() {
040:                    // update the items in the map
041:                    IContributionItem[] items = EditorMenuManager.super 
042:                            .getItems();
043:                    for (int i = 0; i < items.length; i++) {
044:                        IContributionItem item = items[i];
045:                        item.update(IContributionManagerOverrides.P_ENABLED);
046:                    }
047:                    // update the wrapped menus
048:                    if (wrappers != null) {
049:                        for (int i = 0; i < wrappers.size(); i++) {
050:                            EditorMenuManager manager = (EditorMenuManager) wrappers
051:                                    .get(i);
052:                            manager.setEnabledAllowed(enabledAllowed);
053:                        }
054:                    }
055:                }
056:
057:                public Boolean getEnabled(IContributionItem item) {
058:                    if (((item instanceof  ActionContributionItem) && (((ActionContributionItem) item)
059:                            .getAction() instanceof  RetargetAction))
060:                            || enabledAllowed) {
061:                        return null;
062:                    } else {
063:                        return Boolean.FALSE;
064:                    }
065:                }
066:
067:                public Integer getAccelerator(IContributionItem item) {
068:                    if (getEnabled(item) == null) {
069:                        return getParentMenuManager().getOverrides()
070:                                .getAccelerator(item);
071:                    } else {
072:                        // no acclerator if the item is disabled
073:                        return new Integer(0);
074:                    }
075:                }
076:
077:                public String getAcceleratorText(IContributionItem item) {
078:                    return getParentMenuManager().getOverrides()
079:                            .getAcceleratorText(item);
080:                }
081:
082:                public String getText(IContributionItem item) {
083:                    return getParentMenuManager().getOverrides().getText(item);
084:                }
085:            }
086:
087:            private Overrides overrides = new Overrides();
088:
089:            /**
090:             * Constructs a new editor manager.
091:             */
092:            public EditorMenuManager(IMenuManager mgr) {
093:                super (mgr);
094:            }
095:
096:            /* (non-Javadoc)
097:             * Method declared on IContributionManager.
098:             */
099:            public IContributionItem[] getItems() {
100:                return getParentMenuManager().getItems();
101:            }
102:
103:            /* (non-Javadoc)
104:             * Method declared on IContributionManager.
105:             */
106:            public IContributionManagerOverrides getOverrides() {
107:                return overrides;
108:            }
109:
110:            /* (non-Javadoc)
111:             * Method declared on IContributionManager.
112:             * Inserts the new item after any action set contributions which may
113:             * exist within the toolbar to ensure a consistent order for actions.
114:             */
115:            public void insertAfter(String id, IContributionItem item) {
116:                IContributionItem refItem = PluginActionSetBuilder
117:                        .findInsertionPoint(id, null, getParentMenuManager(),
118:                                false);
119:                if (refItem != null) {
120:                    super .insertAfter(refItem.getId(), item);
121:                } else {
122:                    WorkbenchPlugin
123:                            .log("Reference item " + id + " not found for action " + item.getId()); //$NON-NLS-1$ //$NON-NLS-2$
124:                }
125:            }
126:
127:            /* (non-Javadoc)
128:             * Method declared on IContributionManager.
129:             * Inserts the new item after any action set contributions which may
130:             * exist within the toolbar to ensure a consistent order for actions.
131:             */
132:            public void prependToGroup(String groupName, IContributionItem item) {
133:                insertAfter(groupName, item);
134:            }
135:
136:            /**
137:             * Sets the visibility of the manager. If the visibility is <code>true</code>
138:             * then each item within the manager appears within the parent manager.
139:             * Otherwise, the items are not visible.
140:             * <p>
141:             * If force visibility is <code>true</code>, or grayed out if force visibility is <code>false</code>
142:             * <p>
143:             * This is a workaround for the layout flashing when editors contribute
144:             * large amounts of items.</p>
145:             *
146:             * @param visible the new visibility
147:             * @param forceVisibility whether to change the visibility or just the
148:             * 		enablement state.
149:             */
150:            public void setVisible(boolean visible, boolean forceVisibility) {
151:                if (visible) {
152:                    if (forceVisibility) {
153:                        // Make the items visible 
154:                        if (!enabledAllowed) {
155:                            setEnabledAllowed(true);
156:                        }
157:                    } else {
158:                        if (enabledAllowed) {
159:                            setEnabledAllowed(false);
160:                        }
161:                    }
162:                    if (!isVisible()) {
163:                        setVisible(true);
164:                    }
165:                } else {
166:                    if (forceVisibility) {
167:                        // Remove the editor menu items
168:                        setVisible(false);
169:                    } else {
170:                        // Disable the editor menu items.
171:                        setEnabledAllowed(false);
172:                    }
173:                }
174:            }
175:
176:            /**
177:             * Sets the enablement ability of all the items contributed by the editor.
178:             *
179:             * @param enabledAllowed <code>true</code> if the items may enable
180:             * @since 2.0
181:             */
182:            public void setEnabledAllowed(boolean enabledAllowed) {
183:                if (this .enabledAllowed == enabledAllowed) {
184:                    return;
185:                }
186:                this .enabledAllowed = enabledAllowed;
187:                overrides.updateEnabledAllowed();
188:            }
189:
190:            /* (non-Javadoc)
191:             * Method declared on SubMenuManager.
192:             */
193:            protected SubMenuManager wrapMenu(IMenuManager menu) {
194:                if (wrappers == null) {
195:                    wrappers = new ArrayList();
196:                }
197:                EditorMenuManager manager = new EditorMenuManager(menu);
198:                wrappers.add(manager);
199:                return manager;
200:            }
201:
202:            protected IAction[] getAllContributedActions() {
203:                HashSet set = new HashSet();
204:                getAllContributedActions(set);
205:                return (IAction[]) set.toArray(new IAction[set.size()]);
206:            }
207:
208:            protected void getAllContributedActions(HashSet set) {
209:                IContributionItem[] items = super .getItems();
210:                for (int i = 0; i < items.length; i++) {
211:                    getAllContributedActions(set, items[i]);
212:                }
213:                if (wrappers == null) {
214:                    return;
215:                }
216:                for (Iterator iter = wrappers.iterator(); iter.hasNext();) {
217:                    EditorMenuManager element = (EditorMenuManager) iter.next();
218:                    element.getAllContributedActions(set);
219:                }
220:            }
221:
222:            protected void getAllContributedActions(HashSet set,
223:                    IContributionItem item) {
224:                if (item instanceof  MenuManager) {
225:                    IContributionItem subItems[] = ((MenuManager) item)
226:                            .getItems();
227:                    for (int j = 0; j < subItems.length; j++) {
228:                        getAllContributedActions(set, subItems[j]);
229:                    }
230:                } else if (item instanceof  ActionContributionItem) {
231:                    set.add(((ActionContributionItem) item).getAction());
232:                }
233:            }
234:
235:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.