Source Code Cross Referenced for NewJavaProjectWizardPage.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » ui » wizards » 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.wizards 
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.wizards;
011:
012:        import java.lang.reflect.InvocationTargetException;
013:
014:        import org.eclipse.core.filesystem.URIUtil;
015:
016:        import org.eclipse.core.resources.IProject;
017:        import org.eclipse.core.resources.IWorkspaceRoot;
018:
019:        import org.eclipse.core.runtime.Assert;
020:        import org.eclipse.core.runtime.CoreException;
021:        import org.eclipse.core.runtime.IPath;
022:        import org.eclipse.core.runtime.IProgressMonitor;
023:        import org.eclipse.core.runtime.IStatus;
024:        import org.eclipse.core.runtime.NullProgressMonitor;
025:        import org.eclipse.core.runtime.OperationCanceledException;
026:        import org.eclipse.core.runtime.SubProgressMonitor;
027:
028:        import org.eclipse.swt.SWT;
029:        import org.eclipse.swt.layout.GridData;
030:        import org.eclipse.swt.layout.GridLayout;
031:        import org.eclipse.swt.widgets.Composite;
032:        import org.eclipse.swt.widgets.Control;
033:
034:        import org.eclipse.jface.dialogs.Dialog;
035:        import org.eclipse.jface.operation.IRunnableWithProgress;
036:
037:        import org.eclipse.ui.dialogs.WizardNewProjectCreationPage;
038:        import org.eclipse.ui.PlatformUI;
039:
040:        import org.eclipse.jdt.core.IClasspathEntry;
041:        import org.eclipse.jdt.core.IJavaProject;
042:        import org.eclipse.jdt.core.JavaCore;
043:
044:        import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
045:        import org.eclipse.jdt.internal.ui.preferences.NewJavaProjectPreferencePage;
046:        import org.eclipse.jdt.internal.ui.util.BusyIndicatorRunnableContext;
047:        import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener;
048:        import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
049:        import org.eclipse.jdt.internal.ui.wizards.buildpaths.BuildPathsBlock;
050:
051:        /**
052:         * Standard wizard page for creating new Java projects. This page can be used in 
053:         * project creation wizards for projects and will configure the project with the 
054:         * Java nature. This page also allows the user to configure the Java project's 
055:         * output location for class files generated by the Java builder.
056:         * <p>
057:         * Whenever possible clients should use the class  {@link JavaCapabilityConfigurationPage}
058:         * in favor of this class.
059:         * </p>
060:         * <p>
061:         * Clients may instantiate or subclass.
062:         * </p>
063:         * @deprecated Use {@link NewJavaProjectWizardPageTwo} or {@link JavaCapabilityConfigurationPage}.
064:         */
065:        public class NewJavaProjectWizardPage extends NewElementWizardPage {
066:
067:            private static final String PAGE_NAME = "NewJavaProjectWizardPage"; //$NON-NLS-1$
068:
069:            private WizardNewProjectCreationPage fMainPage;
070:
071:            private IPath fOutputLocation;
072:            private IClasspathEntry[] fClasspathEntries;
073:            private BuildPathsBlock fBuildPathsBlock;
074:
075:            private boolean fProjectModified;
076:
077:            /**
078:             * Creates a Java project wizard creation page.
079:             * <p>
080:             * The Java project wizard reads project name and location from the main page.
081:             * </p>
082:             *
083:             * @param root the workspace root
084:             * @param mainpage the main page of the wizard
085:             */
086:            public NewJavaProjectWizardPage(IWorkspaceRoot root,
087:                    WizardNewProjectCreationPage mainpage) {
088:                super (PAGE_NAME);
089:
090:                setTitle(NewWizardMessages.NewJavaProjectWizardPage_title);
091:                setDescription(NewWizardMessages.NewJavaProjectWizardPage_description);
092:
093:                fMainPage = mainpage;
094:                IStatusChangeListener listener = new IStatusChangeListener() {
095:                    public void statusChanged(IStatus status) {
096:                        updateStatus(status);
097:                    }
098:                };
099:
100:                fBuildPathsBlock = new BuildPathsBlock(
101:                        new BusyIndicatorRunnableContext(), listener, 0, false,
102:                        null);
103:
104:                fProjectModified = true;
105:                fOutputLocation = null;
106:                fClasspathEntries = null;
107:            }
108:
109:            /*
110:             * @see org.eclipse.jface.dialogs.DialogPage#dispose()
111:             * @since 3.3
112:             */
113:            public void dispose() {
114:                try {
115:                    super .dispose();
116:                } finally {
117:                    if (fBuildPathsBlock != null) {
118:                        fBuildPathsBlock.dispose();
119:                        fBuildPathsBlock = null;
120:                    }
121:                }
122:            }
123:
124:            /**
125:             * Sets the default output location to be used for the new Java project.
126:             * This is the path of the folder (with the project) into which the Java builder 
127:             * will generate binary class files corresponding to the project's Java source
128:             * files.
129:             * <p>
130:             * The wizard will create this folder if required.
131:             * </p>
132:             * <p>
133:             * The default classpath will be applied when <code>initBuildPaths</code> is
134:             * called. This is done automatically when the page becomes visible and
135:             * the project or the default paths have changed.
136:             * </p>
137:             *
138:             * @param path the folder to be taken as the default output path
139:             */
140:            public void setDefaultOutputFolder(IPath path) {
141:                fOutputLocation = path;
142:                setProjectModified();
143:            }
144:
145:            /**
146:             * Sets the default classpath to be used for the new Java project.
147:             * <p>
148:             * The caller of this method is responsible for creating the classpath entries 
149:             * for the <code>IJavaProject</code> that corresponds to the created project.
150:             * The caller is responsible for creating any new folders that might be mentioned
151:             * on the classpath.
152:             * </p>
153:             * <p>
154:             * The default output location will be applied when <code>initBuildPaths</code> is
155:             * called. This is done automatically when the page becomes visible and
156:             * the project or the default paths have changed.
157:             * </p>
158:             *
159:             * @param entries the default classpath entries
160:             * @param appendDefaultJRE <code>true</code> a variable entry for the
161:             *  default JRE (specified in the preferences) will be added to the classpath.
162:             */
163:            public void setDefaultClassPath(IClasspathEntry[] entries,
164:                    boolean appendDefaultJRE) {
165:                if (entries != null && appendDefaultJRE) {
166:                    IClasspathEntry[] jreEntry = NewJavaProjectPreferencePage
167:                            .getDefaultJRELibrary();
168:                    IClasspathEntry[] newEntries = new IClasspathEntry[entries.length
169:                            + jreEntry.length];
170:                    System.arraycopy(entries, 0, newEntries, 0, entries.length);
171:                    System.arraycopy(jreEntry, 0, newEntries, entries.length,
172:                            jreEntry.length);
173:                    entries = newEntries;
174:                }
175:                fClasspathEntries = entries;
176:                setProjectModified();
177:            }
178:
179:            /**
180:             * Sets the project state to modified. Doing so will initialize the page 
181:             * the next time it becomes visible.
182:             * 
183:             * @since 2.0
184:             */
185:            public void setProjectModified() {
186:                fProjectModified = true;
187:            }
188:
189:            /**
190:             * Returns the project handle. Subclasses should override this 
191:             * method if they don't provide a main page or if they provide 
192:             * their own main page implementation.
193:             * 
194:             * @return the project handle
195:             */
196:            protected IProject getProjectHandle() {
197:                Assert.isNotNull(fMainPage);
198:                return fMainPage.getProjectHandle();
199:            }
200:
201:            /**
202:             * Returns the project location path. Subclasses should override this 
203:             * method if they don't provide a main page or if they provide 
204:             * their own main page implementation.
205:             * 
206:             * @return the project location path
207:             */
208:            protected IPath getLocationPath() {
209:                Assert.isNotNull(fMainPage);
210:                return fMainPage.getLocationPath();
211:            }
212:
213:            /**
214:             * Returns the Java project handle by converting the result of
215:             * <code>getProjectHandle()</code> into a Java project.
216:             *
217:             * @return the Java project handle
218:             * @see #getProjectHandle()
219:             */
220:            public IJavaProject getNewJavaProject() {
221:                return JavaCore.create(getProjectHandle());
222:            }
223:
224:            /* (non-Javadoc)
225:             * @see WizardPage#createControl
226:             */
227:            public void createControl(Composite parent) {
228:                Composite composite = new Composite(parent, SWT.NONE);
229:                composite.setFont(parent.getFont());
230:                composite.setLayout(new GridLayout(1, false));
231:                Control control = fBuildPathsBlock.createControl(composite);
232:                control.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
233:                        true));
234:                Dialog.applyDialogFont(composite);
235:                PlatformUI.getWorkbench().getHelpSystem().setHelp(composite,
236:                        IJavaHelpContextIds.NEW_JAVAPROJECT_WIZARD_PAGE);
237:                setControl(composite);
238:            }
239:
240:            /**
241:             * Forces the initialization of the Java project page. Default classpath or buildpath
242:             * will be used if set. The initialization should only be performed when the project
243:             * or default paths have changed. Toggling back and forward the pages without 
244:             * changes should not re-initialize the page, as changes from the user will be 
245:             * overwritten.
246:             * 
247:             * @since 2.0
248:             */
249:            protected void initBuildPaths() {
250:                fBuildPathsBlock.init(getNewJavaProject(), fOutputLocation,
251:                        fClasspathEntries);
252:            }
253:
254:            /**
255:             * Extend this method to set a user defined default classpath or output location.
256:             * The method <code>initBuildPaths</code> is called when the page becomes 
257:             * visible the first time or the project or the default paths have changed.
258:             * 
259:             * @param visible if <code>true</code> the page becomes visible; otherwise
260:             * it becomes invisible
261:             */
262:            public void setVisible(boolean visible) {
263:                super .setVisible(visible);
264:                if (visible) {
265:                    // evaluate if a initialization is required
266:                    if (fProjectModified || isNewProjectHandle()) {
267:                        // only initialize the project when needed
268:                        initBuildPaths();
269:                        fProjectModified = false;
270:                    }
271:                }
272:            }
273:
274:            private boolean isNewProjectHandle() {
275:                IProject oldProject = fBuildPathsBlock.getJavaProject()
276:                        .getProject();
277:                return !oldProject.equals(getProjectHandle());
278:            }
279:
280:            /**
281:             * Returns the currently configured output location. Note that the returned path 
282:             * might not be valid.
283:             * 
284:             * @return the configured output location
285:             * 
286:             * @since 2.0
287:             */
288:            public IPath getOutputLocation() {
289:                return fBuildPathsBlock.getOutputLocation();
290:            }
291:
292:            /**
293:             * Returns the currently configured classpath. Note that the classpath might
294:             * not be valid.
295:             * 
296:             * @return the configured classpath
297:             * 
298:             * @since 2.0
299:             */
300:            public IClasspathEntry[] getRawClassPath() {
301:                return fBuildPathsBlock.getRawClassPath();
302:            }
303:
304:            /**
305:             * Returns the runnable that will create the Java project. The runnable will create 
306:             * and open the project if needed. The runnable will add the Java nature to the 
307:             * project, and set the project's classpath and output location. 
308:             * <p>
309:             * To create the new java project, execute this runnable
310:             * </p>
311:             *
312:             * @return the runnable
313:             */
314:            public IRunnableWithProgress getRunnable() {
315:                return new IRunnableWithProgress() {
316:                    public void run(IProgressMonitor monitor)
317:                            throws InvocationTargetException,
318:                            InterruptedException {
319:                        if (monitor == null) {
320:                            monitor = new NullProgressMonitor();
321:                        }
322:                        monitor
323:                                .beginTask(
324:                                        NewWizardMessages.NewJavaProjectWizardPage_op_desc,
325:                                        10);
326:                        // initialize if needed
327:                        if (fProjectModified || isNewProjectHandle()) {
328:                            initBuildPaths();
329:                        }
330:
331:                        // create the project
332:                        try {
333:                            IPath locationPath = getLocationPath();
334:                            BuildPathsBlock.createProject(getProjectHandle(),
335:                                    locationPath != null ? URIUtil
336:                                            .toURI(locationPath) : null,
337:                                    new SubProgressMonitor(monitor, 2));
338:                            BuildPathsBlock.addJavaNature(getProjectHandle(),
339:                                    new SubProgressMonitor(monitor, 2));
340:                            fBuildPathsBlock
341:                                    .configureJavaProject(new SubProgressMonitor(
342:                                            monitor, 6));
343:                        } catch (CoreException e) {
344:                            throw new InvocationTargetException(e);
345:                        } catch (OperationCanceledException e) {
346:                            throw new InterruptedException();
347:                        } finally {
348:                            monitor.done();
349:                        }
350:                    }
351:                };
352:            }
353:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.