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


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2007 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.menus;
011:
012:        import org.eclipse.core.runtime.CoreException;
013:        import org.eclipse.core.runtime.IConfigurationElement;
014:        import org.eclipse.core.runtime.IStatus;
015:        import org.eclipse.core.runtime.Status;
016:        import org.eclipse.swt.widgets.Composite;
017:        import org.eclipse.swt.widgets.CoolBar;
018:        import org.eclipse.swt.widgets.Menu;
019:        import org.eclipse.swt.widgets.ToolBar;
020:        import org.eclipse.ui.IWorkbenchWindow;
021:        import org.eclipse.ui.internal.WorkbenchPlugin;
022:        import org.eclipse.ui.menus.AbstractWorkbenchTrimWidget;
023:        import org.eclipse.ui.menus.IWorkbenchWidget;
024:
025:        /**
026:         * <p>
027:         * A proxy for a widget that has been defined in XML. This delays the class
028:         * loading until the widget is really asked to fill a menu collection. Asking
029:         * the widget for anything will instantiate the class.
030:         * </p>
031:         * 
032:         * @since 3.2
033:         */
034:        final class WidgetProxy implements  IWorkbenchWidget {
035:
036:            /**
037:             * Used to determine whether the load has been tried to 
038:             * prevent multiple retries at a failed load.
039:             */
040:            private boolean firstLoad = true;
041:
042:            /**
043:             * The configuration element from which the widget can be created. This
044:             * value will exist until the element is converted into a real class -- at
045:             * which point this value will be set to <code>null</code>.
046:             */
047:            private IConfigurationElement configurationElement;
048:
049:            /**
050:             * The real widget. This value is <code>null</code> until the proxy is
051:             * forced to load the real widget. At this point, the configuration element
052:             * is converted, nulled out, and this widget gains a reference.
053:             */
054:            private IWorkbenchWidget widget = null;
055:
056:            /**
057:             * The name of the configuration element attribute which contains the
058:             * information necessary to instantiate the real widget.
059:             */
060:            private final String widgetAttributeName;
061:
062:            /**
063:             * Constructs a new instance of <code>WidgetProxy</code> with all the
064:             * information it needs to try to load the class at a later point in time.
065:             * 
066:             * @param configurationElement
067:             *            The configuration element from which the real class can be
068:             *            loaded at run-time; must not be <code>null</code>.
069:             * @param widgetAttributeName
070:             *            The name of the attibute or element containing the widget
071:             *            executable extension; must not be <code>null</code>.
072:             */
073:            public WidgetProxy(
074:                    final IConfigurationElement configurationElement,
075:                    final String widgetAttributeName) {
076:                if (configurationElement == null) {
077:                    throw new NullPointerException(
078:                            "The configuration element backing a widget proxy cannot be null"); //$NON-NLS-1$
079:                }
080:
081:                if (widgetAttributeName == null) {
082:                    throw new NullPointerException(
083:                            "The attribute containing the widget class must be known"); //$NON-NLS-1$
084:                }
085:
086:                this .configurationElement = configurationElement;
087:                this .widgetAttributeName = widgetAttributeName;
088:            }
089:
090:            public final void dispose() {
091:                if (loadWidget()) {
092:                    widget.dispose();
093:                }
094:            }
095:
096:            public final void fill(final Composite parent) {
097:                if (loadWidget()) {
098:                    widget.fill(parent);
099:                }
100:            }
101:
102:            public final void fill(final CoolBar parent, final int index) {
103:                if (loadWidget()) {
104:                    widget.fill(parent, index);
105:                }
106:            }
107:
108:            public final void fill(final Menu parent, final int index) {
109:                if (loadWidget()) {
110:                    widget.fill(parent, index);
111:                }
112:            }
113:
114:            public final void fill(final ToolBar parent, final int index) {
115:                if (loadWidget()) {
116:                    widget.fill(parent, index);
117:                }
118:            }
119:
120:            /* (non-Javadoc)
121:             * @see org.eclipse.ui.menus.IWorkbenchWidget#init(org.eclipse.ui.IWorkbenchWindow)
122:             */
123:            public void init(IWorkbenchWindow workbenchWindow) {
124:                if (loadWidget()) {
125:                    widget.init(workbenchWindow);
126:                }
127:            }
128:
129:            /**
130:             * Convenience method that allows the trim layout manager to
131:             * inform widgets if they have changed locations. If the IWidget
132:             * implementation does not support the method then we default
133:             * to using the simpler <code>fill(final Composite parent)</code>.
134:             * 
135:             * @param parent The composite to create the controls in
136:             * @param oldSide The side the trim was previously displayed on
137:             * @param newSide The new side that the trim will be displayed on
138:             */
139:            public final void fill(Composite parent, int oldSide, int newSide) {
140:                if (loadWidget()) {
141:                    if (isMoveableTrimWidget()) {
142:                        ((AbstractWorkbenchTrimWidget) widget).fill(parent,
143:                                oldSide, newSide);
144:                    } else {
145:                        widget.fill(parent);
146:                    }
147:                }
148:            }
149:
150:            /**
151:             * Loads the widget, if possible. If the widget is loaded, then the member
152:             * variables are updated accordingly.
153:             * 
154:             * @return <code>true</code> if the widget is now non-null;
155:             *         <code>false</code> otherwise.
156:             */
157:            private final boolean loadWidget() {
158:                if (firstLoad) {
159:                    // Load the handler.
160:                    try {
161:                        widget = (IWorkbenchWidget) configurationElement
162:                                .createExecutableExtension(widgetAttributeName);
163:                        configurationElement = null;
164:                    } catch (final ClassCastException e) {
165:                        final String message = "The proxied widget was the wrong class"; //$NON-NLS-1$
166:                        final IStatus status = new Status(IStatus.ERROR,
167:                                WorkbenchPlugin.PI_WORKBENCH, 0, message, e);
168:                        WorkbenchPlugin.log(message, status);
169:
170:                    } catch (final CoreException e) {
171:                        final String message = "The proxied widget for '" + configurationElement.getAttribute(widgetAttributeName) //$NON-NLS-1$
172:                                + "' could not be loaded"; //$NON-NLS-1$
173:                        IStatus status = new Status(IStatus.ERROR,
174:                                WorkbenchPlugin.PI_WORKBENCH, 0, message, e);
175:                        WorkbenchPlugin.log(message, status);
176:                    }
177:                }
178:
179:                // We're througth the first load
180:                firstLoad = false;
181:
182:                // the load only succeeded if there's a widget..
183:                return widget != null;
184:            }
185:
186:            /**
187:             * Determine if the widget knows how to respond to changes in the
188:             * workbench 'side' that it is being displayed on.
189:             * 
190:             * @return <code>true</code> iff the <code>IWidget</code> implementation
191:             * is actually based on <code>AbstractTrimWidget</code> 
192:             */
193:            private final boolean isMoveableTrimWidget() {
194:                if (loadWidget()) {
195:                    return widget instanceof  AbstractWorkbenchTrimWidget;
196:                }
197:
198:                return false;
199:            }
200:
201:            public final String toString() {
202:                if (widget == null) {
203:                    return configurationElement
204:                            .getAttribute(widgetAttributeName);
205:                }
206:
207:                return widget.toString();
208:            }
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.