KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > freeform > spi > support > NewJavaFreeformProjectSupport


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.freeform.spi.support;
21
22 import java.io.IOException JavaDoc;
23 import org.netbeans.modules.java.freeform.ui.ClasspathWizardPanel;
24 import org.netbeans.modules.java.freeform.ui.NewJ2SEFreeformProjectWizardIterator;
25 import org.netbeans.modules.java.freeform.ui.ProjectModel;
26 import org.netbeans.modules.java.freeform.ui.SourceFoldersPanel;
27 import org.netbeans.modules.java.freeform.ui.SourceFoldersWizardPanel;
28 import org.netbeans.spi.project.support.ant.AntProjectHelper;
29 import org.openide.WizardDescriptor;
30
31 /**
32  * Support for Java New Project Wizard. These methods are typically used by the
33  * freeform project extension which want to instantiate also Java development
34  * support in project.
35  * <div class="nonnormative">
36  * <p>
37  * Typical usage of these methods is:
38  * </p>
39  * <ol>
40  * <li>create implementation of {@link org.openide.WizardDescriptor.InstantiatingIterator}
41  * with your wizard panels and add panels created by {@link #createJavaPanels}
42  * method</li>
43  * <li>in implementation of {@link org.openide.WizardDescriptor.Iterator.hasNext}
44  * method call also {@link #enableNextButton}</li>
45  * <li>in implementation of {@link org.openide.WizardDescriptor.InstantiatingIterator.instantiate}
46  * method call in addition also {@link #instantiateJavaPanels}</li>
47  * <li>do not forget to call {@link #uninitializeJavaPanels} in your
48  * {@link org.openide.WizardDescriptor.InstantiatingIterator.uninitialize}
49  * to clean up Java panels</li>
50  * </ol>
51  * </div>
52  *
53  * @author David Konecny
54  */

55 public class NewJavaFreeformProjectSupport {
56
57     /** List of initial source folders. Type: List of String pair: [source path, its display name]*/
58     public static final String JavaDoc PROP_EXTRA_JAVA_SOURCE_FOLDERS = "sourceFolders"; // <List<String,String>> NOI18N
59

60     private NewJavaFreeformProjectSupport() {
61     }
62     
63     /**
64      * Returns array of standard Java panels suitable for new project wizard.
65      * Panel gathers info about Java source folders and their classpath.
66      */

67     public static WizardDescriptor.Panel[] createJavaPanels() {
68         return new WizardDescriptor.Panel[]{new SourceFoldersWizardPanel(), new ClasspathWizardPanel()};
69     }
70
71     /**
72      * There is special logic in Java panels that Sources panel should enable
73      * Next button only when at least one source folder was specified. Wizard
74      * iterator which is using panels created by createJavaPanels() method
75      * should always call this method in hasNext() method.
76      */

77     public static boolean enableNextButton(WizardDescriptor.Panel panel) {
78         if (panel instanceof SourceFoldersWizardPanel) {
79             SourceFoldersPanel sfp = (SourceFoldersPanel)panel.getComponent();
80             if (!sfp.hasSomeSourceFolder()) {
81                 return false;
82             }
83         }
84         return true;
85     }
86     
87     /**
88      * Update project with information gathered in Java panels, that is
89      * add Java support to project. The method must to be called under
90      * ProjectManager.writeMutex.
91      */

92     public static void instantiateJavaPanels(AntProjectHelper helper, WizardDescriptor wiz) throws IOException JavaDoc {
93         ProjectModel pm = (ProjectModel)wiz.getProperty(NewJ2SEFreeformProjectWizardIterator.PROP_PROJECT_MODEL);
94         ProjectModel.instantiateJavaProject(helper, pm);
95     }
96     
97     /**
98      * Uninitialize Java panels after wizard was instantiated.
99      */

100     public static void uninitializeJavaPanels(WizardDescriptor wiz) {
101         wiz.putProperty(NewJavaFreeformProjectSupport.PROP_EXTRA_JAVA_SOURCE_FOLDERS, null);
102         wiz.putProperty(NewJ2SEFreeformProjectWizardIterator.PROP_PROJECT_MODEL, null);
103     }
104     
105 }
106
Popular Tags