Source Code Cross Referenced for ViewerActionBuilder.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 org.eclipse.core.runtime.Assert;
013:        import org.eclipse.core.runtime.IConfigurationElement;
014:        import org.eclipse.jface.action.IMenuManager;
015:        import org.eclipse.jface.action.IToolBarManager;
016:        import org.eclipse.jface.viewers.ISelection;
017:        import org.eclipse.jface.viewers.ISelectionChangedListener;
018:        import org.eclipse.jface.viewers.ISelectionProvider;
019:        import org.eclipse.jface.viewers.IStructuredSelection;
020:        import org.eclipse.jface.viewers.SelectionChangedEvent;
021:        import org.eclipse.ui.IEditorPart;
022:        import org.eclipse.ui.IViewPart;
023:        import org.eclipse.ui.IWorkbenchPart;
024:        import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
025:
026:        /**
027:         * This class reads the registry for extensions that plug into
028:         * 'popupMenus' extension point and deals only with the 'viewerContribution'
029:         * elements.
030:         */
031:        public class ViewerActionBuilder extends PluginActionBuilder {
032:
033:            private ISelectionProvider provider;
034:
035:            private IWorkbenchPart part;
036:
037:            /**
038:             * Basic contstructor
039:             */
040:            public ViewerActionBuilder() {
041:            }
042:
043:            /* (non-Javadoc)
044:             * Method declared on PluginActionBuilder.
045:             */
046:            protected ActionDescriptor createActionDescriptor(
047:                    IConfigurationElement element) {
048:                if (part instanceof  IViewPart) {
049:                    return new ActionDescriptor(element,
050:                            ActionDescriptor.T_VIEW, part);
051:                }
052:                return new ActionDescriptor(element, ActionDescriptor.T_EDITOR,
053:                        part);
054:            }
055:
056:            /* (non-Javadoc)
057:             * Method declared on PluginActionBuilder.
058:             */
059:            protected BasicContribution createContribution() {
060:                return new ViewerContribution(provider);
061:            }
062:
063:            /**
064:             * Dispose of the action builder
065:             */
066:            public void dispose() {
067:                if (cache != null) {
068:                    for (int i = 0; i < cache.size(); i++) {
069:                        ((BasicContribution) cache.get(i)).dispose();
070:                    }
071:                    cache = null;
072:                }
073:            }
074:
075:            /* (non-Javadoc)
076:             * Method declared on PluginActionBuilder.
077:             */
078:            protected boolean readElement(IConfigurationElement element) {
079:                String tag = element.getName();
080:
081:                // Found visibility sub-element
082:                if (currentContribution != null
083:                        && tag
084:                                .equals(IWorkbenchRegistryConstants.TAG_VISIBILITY)) {
085:                    ((ViewerContribution) currentContribution)
086:                            .setVisibilityTest(element);
087:                    return true;
088:                }
089:
090:                return super .readElement(element);
091:            }
092:
093:            /**
094:             * Reads the contributions for a viewer menu.
095:             * This method is typically used in conjunction with <code>contribute</code> to read
096:             * and then insert actions for a particular viewer menu.
097:             *
098:             * @param id the menu id
099:             * @param prov the selection provider for the control containing the menu
100:             * @param part the part containing the menu.
101:             * @return <code>true</code> if 1 or more items were read.  
102:             */
103:            public boolean readViewerContributions(String id,
104:                    ISelectionProvider prov, IWorkbenchPart part) {
105:                Assert.isTrue(part instanceof  IViewPart
106:                        || part instanceof  IEditorPart);
107:                provider = prov;
108:                this .part = part;
109:                readContributions(id,
110:                        IWorkbenchRegistryConstants.TAG_VIEWER_CONTRIBUTION,
111:                        IWorkbenchRegistryConstants.PL_POPUP_MENU);
112:                return (cache != null);
113:            }
114:
115:            /**
116:             * Helper class to collect the menus and actions defined within a
117:             * contribution element.
118:             */
119:            private static class ViewerContribution extends BasicContribution
120:                    implements  ISelectionChangedListener {
121:                private ISelectionProvider selProvider;
122:
123:                private ActionExpression visibilityTest;
124:
125:                /**
126:                 * Create a new ViewerContribution.
127:                 * 
128:                 * @param selProvider the selection provider
129:                 */
130:                public ViewerContribution(ISelectionProvider selProvider) {
131:                    super ();
132:                    this .selProvider = selProvider;
133:                    if (selProvider != null) {
134:                        selProvider.addSelectionChangedListener(this );
135:                    }
136:                }
137:
138:                /**
139:                 * Set the visibility test.
140:                 * 
141:                 * @param element the element
142:                 */
143:                public void setVisibilityTest(IConfigurationElement element) {
144:                    visibilityTest = new ActionExpression(element);
145:                }
146:
147:                /* (non-Javadoc)
148:                 * Method declared on BasicContribution.
149:                 */
150:                public void contribute(IMenuManager menu,
151:                        boolean menuAppendIfMissing, IToolBarManager toolbar,
152:                        boolean toolAppendIfMissing) {
153:                    boolean visible = true;
154:
155:                    if (visibilityTest != null) {
156:                        ISelection selection = selProvider.getSelection();
157:                        if (selection instanceof  IStructuredSelection) {
158:                            visible = visibilityTest
159:                                    .isEnabledFor((IStructuredSelection) selection);
160:                        } else {
161:                            visible = visibilityTest.isEnabledFor(selection);
162:                        }
163:                    }
164:
165:                    if (visible) {
166:                        super .contribute(menu, menuAppendIfMissing, toolbar,
167:                                toolAppendIfMissing);
168:                    }
169:                }
170:
171:                /* (non-Javadoc)
172:                 * @see org.eclipse.ui.internal.PluginActionBuilder.BasicContribution#dispose()
173:                 */
174:                public void dispose() {
175:                    if (selProvider != null) {
176:                        selProvider.removeSelectionChangedListener(this );
177:                    }
178:                    disposeActions();
179:                    super .dispose();
180:                }
181:
182:                /**
183:                 * Rather than hooking up each action as a selection listener,
184:                 * the contribution itself is added, and propagates
185:                 * the selection changed notification to all actions.
186:                 * This simplifies cleanup, in addition to potentially reducing the number of listeners.
187:                 * 
188:                 * @see ISelectionChangedListener
189:                 * @since 3.1
190:                 */
191:                public void selectionChanged(SelectionChangedEvent event) {
192:                    if (actions != null) {
193:                        if (actions != null) {
194:                            for (int i = 0; i < actions.size(); i++) {
195:                                PluginAction proxy = ((ActionDescriptor) actions
196:                                        .get(i)).getAction();
197:                                proxy.selectionChanged(event);
198:                            }
199:                        }
200:                    }
201:                }
202:            }
203:
204:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.