Source Code Cross Referenced for AbstractOpenWizardAction.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » ui » 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 » jdt » org.eclipse.jdt.ui.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.jdt.ui.actions;
011:
012:        import org.eclipse.core.runtime.CoreException;
013:
014:        import org.eclipse.core.resources.IWorkspaceRoot;
015:        import org.eclipse.core.resources.ResourcesPlugin;
016:
017:        import org.eclipse.swt.widgets.Shell;
018:
019:        import org.eclipse.jface.action.Action;
020:        import org.eclipse.jface.dialogs.MessageDialog;
021:        import org.eclipse.jface.resource.JFaceResources;
022:        import org.eclipse.jface.viewers.ISelection;
023:        import org.eclipse.jface.viewers.IStructuredSelection;
024:        import org.eclipse.jface.viewers.StructuredSelection;
025:        import org.eclipse.jface.window.Window;
026:        import org.eclipse.jface.wizard.WizardDialog;
027:
028:        import org.eclipse.ui.INewWizard;
029:        import org.eclipse.ui.IWorkbenchWindow;
030:        import org.eclipse.ui.PlatformUI;
031:        import org.eclipse.ui.actions.NewProjectAction;
032:
033:        import org.eclipse.jdt.core.IJavaElement;
034:
035:        import org.eclipse.jdt.internal.ui.JavaPlugin;
036:        import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
037:        import org.eclipse.jdt.internal.ui.util.PixelConverter;
038:        import org.eclipse.jdt.internal.ui.wizards.NewElementWizard;
039:        import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
040:
041:        /**
042:         * <p>Abstract base classed used for the open wizard actions.</p>
043:         * 
044:         * <p>
045:         * Note: This class is for internal use only. Clients should not use this class.
046:         * </p>
047:         * @since 3.2
048:         */
049:        public abstract class AbstractOpenWizardAction extends Action {
050:
051:            private Shell fShell;
052:            private IStructuredSelection fSelection;
053:            private IJavaElement fCreatedElement;
054:
055:            /**
056:             * Creates the action.
057:             */
058:            protected AbstractOpenWizardAction() {
059:                fShell = null;
060:                fSelection = null;
061:                fCreatedElement = null;
062:            }
063:
064:            /* (non-Javadoc)
065:             * @see org.eclipse.jface.action.Action#run()
066:             */
067:            public void run() {
068:                Shell shell = getShell();
069:                if (!doCreateProjectFirstOnEmptyWorkspace(shell)) {
070:                    return;
071:                }
072:                try {
073:                    INewWizard wizard = createWizard();
074:                    wizard.init(PlatformUI.getWorkbench(), getSelection());
075:
076:                    WizardDialog dialog = new WizardDialog(shell, wizard);
077:                    PixelConverter converter = new PixelConverter(
078:                            JFaceResources.getDialogFont());
079:                    dialog.setMinimumPageSize(converter
080:                            .convertWidthInCharsToPixels(70), converter
081:                            .convertHeightInCharsToPixels(20));
082:                    dialog.create();
083:                    int res = dialog.open();
084:                    if (res == Window.OK && wizard instanceof  NewElementWizard) {
085:                        fCreatedElement = ((NewElementWizard) wizard)
086:                                .getCreatedElement();
087:                    }
088:
089:                    notifyResult(res == Window.OK);
090:                } catch (CoreException e) {
091:                    String title = NewWizardMessages.AbstractOpenWizardAction_createerror_title;
092:                    String message = NewWizardMessages.AbstractOpenWizardAction_createerror_message;
093:                    ExceptionHandler.handle(e, shell, title, message);
094:                }
095:            }
096:
097:            /**
098:             * Creates and configures the wizard. This method should only be called once.
099:             * @return returns the created wizard.
100:             * @throws CoreException exception is thrown when the creation was not successful.
101:             */
102:            abstract protected INewWizard createWizard() throws CoreException;
103:
104:            /**
105:             * Returns the configured selection. If no selection has been configured using {@link #setSelection(IStructuredSelection)},
106:             * the currently selected element of the active workbench is returned.
107:             * @return the configured selection
108:             */
109:            protected IStructuredSelection getSelection() {
110:                if (fSelection == null) {
111:                    return evaluateCurrentSelection();
112:                }
113:                return fSelection;
114:            }
115:
116:            private IStructuredSelection evaluateCurrentSelection() {
117:                IWorkbenchWindow window = JavaPlugin.getActiveWorkbenchWindow();
118:                if (window != null) {
119:                    ISelection selection = window.getSelectionService()
120:                            .getSelection();
121:                    if (selection instanceof  IStructuredSelection) {
122:                        return (IStructuredSelection) selection;
123:                    }
124:                }
125:                return StructuredSelection.EMPTY;
126:            }
127:
128:            /**
129:             * Configures the selection to be used as initial selection of the wizard. 
130:             * @param selection the selection to be set or <code>null</code> to use the selection of the active workbench window
131:             */
132:            public void setSelection(IStructuredSelection selection) {
133:                fSelection = selection;
134:            }
135:
136:            /**
137:             * Returns the configured shell. If no shell has been configured using {@link #setShell(Shell)},
138:             * 	the shell of the currently active workbench is returned.
139:             * @return the configured shell
140:             */
141:            protected Shell getShell() {
142:                if (fShell == null) {
143:                    return JavaPlugin.getActiveWorkbenchShell();
144:                }
145:                return fShell;
146:            }
147:
148:            /**
149:             * Configures the shell to be used as parent shell by the wizard.
150:             * @param shell the shell to be set or <code>null</code> to use the shell of the active workbench window
151:             */
152:            public void setShell(Shell shell) {
153:                fShell = shell;
154:            }
155:
156:            /**
157:             * Opens the new project dialog if the workspace is empty. This method is called on {@link #run()}.
158:             * @param shell the shell to use
159:             * @return returns <code>true</code> when a project has been created, or <code>false</code> when the
160:             * new project has been canceled.
161:             */
162:            protected boolean doCreateProjectFirstOnEmptyWorkspace(Shell shell) {
163:                IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace()
164:                        .getRoot();
165:                if (workspaceRoot.getProjects().length == 0) {
166:                    String title = NewWizardMessages.AbstractOpenWizardAction_noproject_title;
167:                    String message = NewWizardMessages.AbstractOpenWizardAction_noproject_message;
168:                    if (MessageDialog.openQuestion(shell, title, message)) {
169:                        new NewProjectAction().run();
170:                        return workspaceRoot.getProjects().length != 0;
171:                    }
172:                    return false;
173:                }
174:                return true;
175:            }
176:
177:            /**
178:             * Returns the created element or <code>null</code> if the wizard has not run or was canceled.
179:             * @return the created element or <code>null</code>
180:             */
181:            public IJavaElement getCreatedElement() {
182:                return fCreatedElement;
183:            }
184:
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.