Source Code Cross Referenced for WorkbenchWizardElement.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » dialogs » 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.dialogs 
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.dialogs;
011:
012:        import org.eclipse.core.runtime.CoreException;
013:        import org.eclipse.core.runtime.IAdaptable;
014:        import org.eclipse.core.runtime.IConfigurationElement;
015:        import org.eclipse.core.runtime.Platform;
016:        import org.eclipse.jface.resource.ImageDescriptor;
017:        import org.eclipse.jface.viewers.IStructuredSelection;
018:        import org.eclipse.jface.viewers.StructuredSelection;
019:        import org.eclipse.ui.IPluginContribution;
020:        import org.eclipse.ui.IWorkbenchWizard;
021:        import org.eclipse.ui.PlatformUI;
022:        import org.eclipse.ui.SelectionEnabler;
023:        import org.eclipse.ui.internal.ISelectionConversionService;
024:        import org.eclipse.ui.internal.WorkbenchPlugin;
025:        import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
026:        import org.eclipse.ui.internal.registry.RegistryReader;
027:        import org.eclipse.ui.model.IWorkbenchAdapter;
028:        import org.eclipse.ui.model.IWorkbenchAdapter2;
029:        import org.eclipse.ui.model.WorkbenchAdapter;
030:        import org.eclipse.ui.plugin.AbstractUIPlugin;
031:        import org.eclipse.ui.wizards.IWizardCategory;
032:        import org.eclipse.ui.wizards.IWizardDescriptor;
033:
034:        /**
035:         * Instances represent registered wizards.
036:         */
037:        public class WorkbenchWizardElement extends WorkbenchAdapter implements 
038:                IAdaptable, IPluginContribution, IWizardDescriptor {
039:            private String id;
040:
041:            private ImageDescriptor imageDescriptor;
042:
043:            private SelectionEnabler selectionEnabler;
044:
045:            private IConfigurationElement configurationElement;
046:
047:            private ImageDescriptor descriptionImage;
048:
049:            private WizardCollectionElement parentCategory;
050:
051:            /**
052:             * TODO: DO we need to  make this API?
053:             */
054:            public static final String TAG_PROJECT = "project"; //$NON-NLS-1$
055:
056:            private static final String[] EMPTY_TAGS = new String[0];
057:
058:            private static final String[] PROJECT_TAGS = new String[] { TAG_PROJECT };
059:
060:            /**
061:             * Create a new instance of this class
062:             * 
063:             * @param configurationElement
064:             * @since 3.1
065:             */
066:            public WorkbenchWizardElement(
067:                    IConfigurationElement configurationElement) {
068:                this .configurationElement = configurationElement;
069:                id = configurationElement
070:                        .getAttribute(IWorkbenchRegistryConstants.ATT_ID);
071:            }
072:
073:            /**
074:             * Answer a boolean indicating whether the receiver is able to handle the
075:             * passed selection
076:             * 
077:             * @return boolean
078:             * @param selection
079:             *            IStructuredSelection
080:             */
081:            public boolean canHandleSelection(IStructuredSelection selection) {
082:                return getSelectionEnabler().isEnabledForSelection(selection);
083:            }
084:
085:            /**
086:             * Answer the selection for the reciever based on whether the it can handle
087:             * the selection. If it can return the selection. If it can handle the
088:             * adapted to IResource value of the selection. If it satisfies neither of
089:             * these conditions return an empty IStructuredSelection.
090:             * 
091:             * @return IStructuredSelection
092:             * @param selection
093:             *            IStructuredSelection
094:             */
095:            public IStructuredSelection adaptedSelection(
096:                    IStructuredSelection selection) {
097:                if (canHandleSelection(selection)) {
098:                    return selection;
099:                }
100:
101:                IStructuredSelection adaptedSelection = convertToResources(selection);
102:                if (canHandleSelection(adaptedSelection)) {
103:                    return adaptedSelection;
104:                }
105:
106:                //Couldn't find one that works so just return
107:                return StructuredSelection.EMPTY;
108:            }
109:
110:            /**
111:             * Create an the instance of the object described by the configuration
112:             * element. That is, create the instance of the class the isv supplied in
113:             * the extension point.
114:             * @return the new object
115:             * @throws CoreException 
116:             */
117:            public Object createExecutableExtension() throws CoreException {
118:                return WorkbenchPlugin.createExtension(configurationElement,
119:                        IWorkbenchRegistryConstants.ATT_CLASS);
120:            }
121:
122:            /**
123:             * Returns an object which is an instance of the given class associated
124:             * with this object. Returns <code>null</code> if no such object can be
125:             * found.
126:             */
127:            public Object getAdapter(Class adapter) {
128:                if (adapter == IWorkbenchAdapter.class
129:                        || adapter == IWorkbenchAdapter2.class) {
130:                    return this ;
131:                } else if (adapter == IPluginContribution.class) {
132:                    return this ;
133:                } else if (adapter == IConfigurationElement.class) {
134:                    return configurationElement;
135:                }
136:                return Platform.getAdapterManager().getAdapter(this , adapter);
137:            }
138:
139:            /**
140:             * @return IConfigurationElement
141:             */
142:            public IConfigurationElement getConfigurationElement() {
143:                return configurationElement;
144:            }
145:
146:            /**
147:             * Answer the description parameter of this element
148:             * 
149:             * @return java.lang.String
150:             */
151:            public String getDescription() {
152:                return RegistryReader.getDescription(configurationElement);
153:            }
154:
155:            /**
156:             * Answer the icon of this element.
157:             */
158:            public ImageDescriptor getImageDescriptor() {
159:                if (imageDescriptor == null) {
160:                    String iconName = configurationElement
161:                            .getAttribute(IWorkbenchRegistryConstants.ATT_ICON);
162:                    if (iconName == null) {
163:                        return null;
164:                    }
165:                    imageDescriptor = AbstractUIPlugin
166:                            .imageDescriptorFromPlugin(configurationElement
167:                                    .getNamespaceIdentifier(), iconName);
168:                }
169:                return imageDescriptor;
170:            }
171:
172:            /**
173:             * Returns the name of this wizard element.
174:             */
175:            public ImageDescriptor getImageDescriptor(Object element) {
176:                return getImageDescriptor();
177:            }
178:
179:            /**
180:             * Returns the name of this wizard element.
181:             */
182:            public String getLabel(Object element) {
183:                return configurationElement
184:                        .getAttribute(IWorkbenchRegistryConstants.ATT_NAME);
185:            }
186:
187:            /**
188:             * Answer self's action enabler, creating it first iff necessary
189:             */
190:            protected SelectionEnabler getSelectionEnabler() {
191:                if (selectionEnabler == null) {
192:                    selectionEnabler = new SelectionEnabler(
193:                            configurationElement);
194:                }
195:
196:                return selectionEnabler;
197:            }
198:
199:            /**
200:             * Attempt to convert the elements in the passed selection into resources
201:             * by asking each for its IResource property (iff it isn't already a
202:             * resource). If all elements in the initial selection can be converted to
203:             * resources then answer a new selection containing these resources;
204:             * otherwise answer an empty selection.
205:             * 
206:             * @param originalSelection the original selection
207:             * @return the converted selection or an empty selection
208:             */
209:            private IStructuredSelection convertToResources(
210:                    IStructuredSelection originalSelection) {
211:                Object selectionService = PlatformUI.getWorkbench().getService(
212:                        ISelectionConversionService.class);
213:                if (selectionService == null || originalSelection == null) {
214:                    return StructuredSelection.EMPTY;
215:                }
216:                return ((ISelectionConversionService) selectionService)
217:                        .convertToResources(originalSelection);
218:            }
219:
220:            /*
221:             * (non-Javadoc)
222:             * 
223:             * @see org.eclipse.ui.IPluginContribution#getLocalId()
224:             */
225:            public String getLocalId() {
226:                return getId();
227:            }
228:
229:            /* (non-Javadoc)
230:             * @see org.eclipse.ui.IPluginContribution#getPluginId()
231:             */
232:            public String getPluginId() {
233:                return (configurationElement != null) ? configurationElement
234:                        .getNamespaceIdentifier() : null;
235:            }
236:
237:            /* (non-Javadoc)
238:             * @see org.eclipse.ui.wizards.INewWizardDescriptor#getDescriptionImage()
239:             */
240:            public ImageDescriptor getDescriptionImage() {
241:                if (descriptionImage == null) {
242:                    String descImage = configurationElement
243:                            .getAttribute(IWorkbenchRegistryConstants.ATT_DESCRIPTION_IMAGE);
244:                    if (descImage == null) {
245:                        return null;
246:                    }
247:                    descriptionImage = AbstractUIPlugin
248:                            .imageDescriptorFromPlugin(configurationElement
249:                                    .getNamespaceIdentifier(), descImage);
250:                }
251:                return descriptionImage;
252:            }
253:
254:            /* (non-Javadoc)
255:             * @see org.eclipse.ui.wizards.INewWizardDescriptor#getHelpHref()
256:             */
257:            public String getHelpHref() {
258:                return configurationElement
259:                        .getAttribute(IWorkbenchRegistryConstants.ATT_HELP_HREF);
260:            }
261:
262:            /* (non-Javadoc)
263:             * @see org.eclipse.ui.wizards.INewWizardDescriptor#createWizard()
264:             */
265:            public IWorkbenchWizard createWizard() throws CoreException {
266:                return (IWorkbenchWizard) createExecutableExtension();
267:            }
268:
269:            /* (non-Javadoc)
270:             * @see org.eclipse.ui.IWorkbenchPartDescriptor#getId()
271:             */
272:            public String getId() {
273:                return id;
274:            }
275:
276:            /* (non-Javadoc)
277:             * @see org.eclipse.ui.IWorkbenchPartDescriptor#getLabel()
278:             */
279:            public String getLabel() {
280:                return getLabel(this );
281:            }
282:
283:            /* (non-Javadoc)
284:             * @see org.eclipse.ui.wizards.INewWizardDescriptor#getCategory()
285:             */
286:            public IWizardCategory getCategory() {
287:                return (IWizardCategory) getParent(this );
288:            }
289:
290:            /**
291:             * Return the collection.
292:             * 
293:             * @return the collection
294:             * @since 3.1
295:             */
296:            public WizardCollectionElement getCollectionElement() {
297:                return (WizardCollectionElement) getParent(this );
298:            }
299:
300:            /* (non-Javadoc)
301:             * @see org.eclipse.ui.wizards.IWizardDescriptor#getTags()
302:             */
303:            public String[] getTags() {
304:
305:                String flag = configurationElement
306:                        .getAttribute(IWorkbenchRegistryConstants.ATT_PROJECT);
307:                if (Boolean.valueOf(flag).booleanValue()) {
308:                    return PROJECT_TAGS;
309:                }
310:
311:                return EMPTY_TAGS;
312:            }
313:
314:            /* (non-Javadoc)
315:             * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
316:             */
317:            public Object getParent(Object object) {
318:                return parentCategory;
319:            }
320:
321:            /**
322:             * Set the parent category.
323:             * 
324:             * @param parent the parent category
325:             * @since 3.1
326:             */
327:            public void setParent(WizardCollectionElement parent) {
328:                parentCategory = parent;
329:            }
330:
331:            /* (non-Javadoc)
332:             * @see org.eclipse.ui.wizards.IWizardDescriptor#canFinishEarly()
333:             */
334:            public boolean canFinishEarly() {
335:                return Boolean
336:                        .valueOf(
337:                                configurationElement
338:                                        .getAttribute(IWorkbenchRegistryConstants.ATT_CAN_FINISH_EARLY))
339:                        .booleanValue();
340:            }
341:
342:            /* (non-Javadoc)
343:             * @see org.eclipse.ui.wizards.IWizardDescriptor#hasPages()
344:             */
345:            public boolean hasPages() {
346:                String hasPagesString = configurationElement
347:                        .getAttribute(IWorkbenchRegistryConstants.ATT_HAS_PAGES);
348:                // default value is true
349:                if (hasPagesString == null) {
350:                    return true;
351:                }
352:                return Boolean.valueOf(hasPagesString).booleanValue();
353:            }
354:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.