KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ant > freeform > spi > support > NewFreeformProjectSupport


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.ant.freeform.spi.support;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.List JavaDoc;
25 import org.netbeans.modules.ant.freeform.FreeformProjectGenerator;
26 import org.netbeans.modules.ant.freeform.spi.TargetDescriptor;
27 import org.netbeans.modules.ant.freeform.ui.BasicProjectInfoWizardPanel;
28 import org.netbeans.modules.ant.freeform.ui.TargetMappingWizardPanel;
29 import org.netbeans.spi.project.support.ant.AntProjectHelper;
30 import org.openide.WizardDescriptor;
31 import org.openide.util.NbCollections;
32
33 /**
34  * Support for New Project Wizard.
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  * which uses two general panels ({@link #createBasicProjectInfoWizardPanel} and
42  * {@link #createTargetMappingWizardPanel}) plus your own domain specific ones.</li>
43  * <li>in implementation of {@link org.openide.WizardDescriptor.InstantiatingIterator.instantiate}
44  * method call both {@link #instantiateBasicProjectInfoWizardPanel} and
45  * {@link #instantiateTargetMappingWizardPanel} methods to setup project
46  * and update list of target mappings and then use returned AntProjectHelper
47  * to store your domain specific metadata</li>
48  * <li>do not forget to call both {@link #uninitializeBasicProjectInfoWizardPanel} and
49  * {@link #uninitializeTargetMappingWizardPanel} methods in your
50  * {@link org.openide.WizardDescriptor.InstantiatingIterator.uninitialize} to clean up
51  * panels</li>
52  * </ol>
53  * </div>
54  *
55  * @author David Konecny
56  */

57 public class NewFreeformProjectSupport {
58     
59     /** Ant script. Type: java.io.File */
60     public static final String JavaDoc PROP_ANT_SCRIPT = "antScript"; // <java.io.File> NOI18N
61

62     /** Project name. Type: String */
63     public static final String JavaDoc PROP_PROJECT_NAME = "projectName"; // <String> NOI18N
64

65     /** Original project base folder. Type: java.io.File */
66     public static final String JavaDoc PROP_PROJECT_LOCATION = "projectLocation"; // <java.io.File> NOI18N
67

68     /** NetBeans project folder. Type: java.io.File */
69     public static final String JavaDoc PROP_PROJECT_FOLDER = "projectFolder"; // <java.io.File> NOI18N
70

71     private NewFreeformProjectSupport() {}
72    
73     /**
74      * Returns Basic Project Info panel suitable for new project wizard.
75      * Panel gathers info about original project folder, NB projetc folder,
76      * project name and Ant script.
77      */

78     public static final WizardDescriptor.Panel createBasicProjectInfoWizardPanel() {
79         return new BasicProjectInfoWizardPanel();
80     }
81     
82     /**
83      * Instantiate project according to information gathered in
84      * Basic Project Info panel. The method must to be called
85      * under ProjectManager.writeMutex.
86      */

87     public static final AntProjectHelper instantiateBasicProjectInfoWizardPanel(WizardDescriptor wiz) throws IOException JavaDoc {
88         // XXX assert ProjectManager.mutex().isWriteAccess()
89
File JavaDoc antScript = (File JavaDoc)wiz.getProperty(PROP_ANT_SCRIPT);
90         String JavaDoc projName = (String JavaDoc)wiz.getProperty(PROP_PROJECT_NAME);
91         File JavaDoc projLocation = (File JavaDoc)wiz.getProperty(PROP_PROJECT_LOCATION);
92         File JavaDoc projectFolder = (File JavaDoc)wiz.getProperty(PROP_PROJECT_FOLDER);
93         if (antScript.getParentFile().equals(projectFolder) && antScript.getName().equals("build.xml")) { // NOI18N
94
// default location of build file
95
antScript = null;
96         }
97         return FreeformProjectGenerator.createProject(projLocation, projectFolder, projName, antScript);
98     }
99
100     /**
101      * Returns Target Mapping panel suitable for new project wizard. The panel
102      * contains mappings of standard IDE actions like clean, build, javadoc,
103      * run and test. Other IDE actions can be added.
104      *
105      * @param targets list of additional targets to be shown in wizard panel. List
106      * of TargetDescriptor instances. Order is relevant.
107      */

108     public static final WizardDescriptor.Panel createTargetMappingWizardPanel(List JavaDoc<TargetDescriptor> targets) {
109         return new TargetMappingWizardPanel(targets);
110     }
111     
112     /**
113      * Update project with information gathered in Target Mapping panel.
114      * The method must to be called under ProjectManager.writeMutex.
115      */

116     public static final void instantiateTargetMappingWizardPanel(AntProjectHelper helper, WizardDescriptor wiz) {
117         List JavaDoc<FreeformProjectGenerator.TargetMapping> mappings = NbCollections.checkedListByCopy(
118                 (List JavaDoc) wiz.getProperty(TargetMappingWizardPanel.PROP_TARGET_MAPPINGS),
119                 FreeformProjectGenerator.TargetMapping.class, true);
120         
121         FreeformProjectGenerator.putTargetMappings(helper, mappings);
122         FreeformProjectGenerator.putContextMenuAction(helper, mappings);
123     }
124
125     /**
126      * Uninitialize Basic Project Info panel after wizard was instantiated.
127      */

128     public static void uninitializeBasicProjectInfoWizardPanel(WizardDescriptor wiz) {
129         wiz.putProperty(NewFreeformProjectSupport.PROP_ANT_SCRIPT, null);
130         wiz.putProperty(NewFreeformProjectSupport.PROP_PROJECT_NAME, null);
131         wiz.putProperty(NewFreeformProjectSupport.PROP_PROJECT_LOCATION, null);
132         wiz.putProperty(NewFreeformProjectSupport.PROP_PROJECT_FOLDER, null);
133     }
134     
135
136     /**
137      * Uninitialize Target Mapping panel after wizard was instantiated.
138      */

139     public static void uninitializeTargetMappingWizardPanel(WizardDescriptor wiz) {
140         wiz.putProperty(TargetMappingWizardPanel.PROP_TARGET_MAPPINGS, null);
141     }
142     
143 }
144
Popular Tags