Source Code Cross Referenced for NewWizardShortcutAction.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » actions » 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.actions 
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.actions;
011:
012:        import org.eclipse.core.runtime.CoreException;
013:        import org.eclipse.jface.action.Action;
014:        import org.eclipse.jface.dialogs.ErrorDialog;
015:        import org.eclipse.jface.viewers.ISelection;
016:        import org.eclipse.jface.viewers.IStructuredSelection;
017:        import org.eclipse.jface.viewers.StructuredSelection;
018:        import org.eclipse.jface.wizard.WizardDialog;
019:        import org.eclipse.swt.graphics.Point;
020:        import org.eclipse.swt.widgets.Shell;
021:        import org.eclipse.ui.IEditorInput;
022:        import org.eclipse.ui.IEditorPart;
023:        import org.eclipse.ui.INewWizard;
024:        import org.eclipse.ui.IPluginContribution;
025:        import org.eclipse.ui.IWorkbenchPart;
026:        import org.eclipse.ui.IWorkbenchWindow;
027:        import org.eclipse.ui.actions.ActionFactory;
028:        import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
029:        import org.eclipse.ui.internal.LegacyResourceSupport;
030:        import org.eclipse.ui.internal.WorkbenchMessages;
031:        import org.eclipse.ui.internal.util.Util;
032:        import org.eclipse.ui.wizards.IWizardDescriptor;
033:
034:        /**
035:         * Opens a specific new wizard. 
036:         */
037:        public class NewWizardShortcutAction extends Action implements 
038:                IPluginContribution {
039:            private IWizardDescriptor wizardElement;
040:
041:            /**
042:             * The wizard dialog width
043:             */
044:            private static final int SIZING_WIZARD_WIDTH = 500;
045:
046:            /**
047:             * The wizard dialog height
048:             */
049:            private static final int SIZING_WIZARD_HEIGHT = 500;
050:
051:            private IWorkbenchWindow window;
052:
053:            /**
054:             * Create an instance of this class.
055:             *
056:             * @param window the workbench window in which this action will appear
057:             * @param wizardDesc a wizard element
058:             */
059:            public NewWizardShortcutAction(IWorkbenchWindow window,
060:                    IWizardDescriptor wizardDesc) {
061:                super (wizardDesc.getLabel());
062:                setToolTipText(wizardDesc.getDescription());
063:                setImageDescriptor(wizardDesc.getImageDescriptor());
064:                setId(ActionFactory.NEW.getId());
065:                wizardElement = wizardDesc;
066:                this .window = window;
067:            }
068:
069:            /**
070:             * Get the wizard descriptor for this action.
071:             * 
072:             * @return the wizard descriptor 
073:             */
074:            public IWizardDescriptor getWizardDescriptor() {
075:                return wizardElement;
076:            }
077:
078:            /* (non-Javadoc)
079:             * @see org.eclipse.jface.action.IAction#run()
080:             */
081:            public void run() {
082:                // create instance of target wizard
083:
084:                INewWizard wizard;
085:                try {
086:                    wizard = (INewWizard) wizardElement.createWizard();
087:                } catch (CoreException e) {
088:                    ErrorDialog
089:                            .openError(
090:                                    window.getShell(),
091:                                    WorkbenchMessages.NewWizardShortcutAction_errorTitle,
092:                                    WorkbenchMessages.NewWizardShortcutAction_errorMessage,
093:                                    e.getStatus());
094:                    return;
095:                }
096:
097:                ISelection selection = window.getSelectionService()
098:                        .getSelection();
099:                IStructuredSelection selectionToPass = StructuredSelection.EMPTY;
100:                if (selection instanceof  IStructuredSelection) {
101:                    selectionToPass = wizardElement
102:                            .adaptedSelection((IStructuredSelection) selection);
103:                } else {
104:                    // Build the selection from the IFile of the editor
105:                    IWorkbenchPart part = window.getPartService()
106:                            .getActivePart();
107:                    if (part instanceof  IEditorPart) {
108:                        IEditorInput input = ((IEditorPart) part)
109:                                .getEditorInput();
110:                        Class fileClass = LegacyResourceSupport.getFileClass();
111:                        if (input != null && fileClass != null) {
112:                            Object file = Util.getAdapter(input, fileClass);
113:                            if (file != null) {
114:                                selectionToPass = new StructuredSelection(file);
115:                            }
116:                        }
117:                    }
118:                }
119:
120:                // even tho we MAY finish early without showing a dialog, prep the
121:                // wizard with a dialog and such in case it's logic requires it
122:                // - yes, it wastes a dialog but they are plentiful...
123:                wizard.init(window.getWorkbench(), selectionToPass);
124:
125:                Shell parent = window.getShell();
126:                WizardDialog dialog = new WizardDialog(parent, wizard);
127:                dialog.create();
128:                Point defaultSize = dialog.getShell().getSize();
129:                dialog.getShell().setSize(
130:                        Math.max(SIZING_WIZARD_WIDTH, defaultSize.x),
131:                        Math.max(SIZING_WIZARD_HEIGHT, defaultSize.y));
132:                window.getWorkbench().getHelpSystem().setHelp(
133:                        dialog.getShell(),
134:                        IWorkbenchHelpContextIds.NEW_WIZARD_SHORTCUT);
135:
136:                // if the wizard can finish early and doesn't have any pages, just finish it.
137:                if (wizardElement.canFinishEarly() && !wizardElement.hasPages()) {
138:                    wizard.performFinish();
139:                    dialog.close();
140:                } else {
141:                    dialog.open();
142:                }
143:            }
144:
145:            /* (non-Javadoc)
146:             * @see org.eclipse.ui.IPluginContribution#getLocalId()
147:             */
148:            public String getLocalId() {
149:                IPluginContribution contribution = getPluginContribution();
150:                if (contribution != null) {
151:                    return contribution.getLocalId();
152:                }
153:                return wizardElement.getId();
154:            }
155:
156:            /* (non-Javadoc)
157:             * @see org.eclipse.ui.IPluginContribution#getPluginId()
158:             */
159:            public String getPluginId() {
160:                IPluginContribution contribution = getPluginContribution();
161:                if (contribution != null) {
162:                    return contribution.getPluginId();
163:                }
164:                return null;
165:            }
166:
167:            /**
168:             * Return the plugin contribution associated with the wizard.
169:             * 
170:             * @return the contribution or <code>null</code>
171:             * @since 3.1
172:             */
173:            private IPluginContribution getPluginContribution() {
174:                return (IPluginContribution) Util.getAdapter(wizardElement,
175:                        IPluginContribution.class);
176:            }
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.