001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.ant.freeform.spi.support;
043:
044: import java.io.File;
045: import java.io.IOException;
046: import java.util.List;
047: import org.netbeans.modules.ant.freeform.FreeformProjectGenerator;
048: import org.netbeans.modules.ant.freeform.spi.TargetDescriptor;
049: import org.netbeans.modules.ant.freeform.ui.BasicProjectInfoWizardPanel;
050: import org.netbeans.modules.ant.freeform.ui.TargetMappingWizardPanel;
051: import org.netbeans.spi.project.support.ant.AntProjectHelper;
052: import org.openide.WizardDescriptor;
053: import org.openide.util.NbCollections;
054:
055: /**
056: * Support for New Project Wizard.
057: * <div class="nonnormative">
058: * <p>
059: * Typical usage of these methods is:
060: * </p>
061: * <ol>
062: * <li>create implementation of {@link org.openide.WizardDescriptor.InstantiatingIterator}
063: * which uses two general panels ({@link #createBasicProjectInfoWizardPanel} and
064: * {@link #createTargetMappingWizardPanel}) plus your own domain specific ones.</li>
065: * <li>in implementation of {@link org.openide.WizardDescriptor.InstantiatingIterator.instantiate}
066: * method call both {@link #instantiateBasicProjectInfoWizardPanel} and
067: * {@link #instantiateTargetMappingWizardPanel} methods to setup project
068: * and update list of target mappings and then use returned AntProjectHelper
069: * to store your domain specific metadata</li>
070: * <li>do not forget to call both {@link #uninitializeBasicProjectInfoWizardPanel} and
071: * {@link #uninitializeTargetMappingWizardPanel} methods in your
072: * {@link org.openide.WizardDescriptor.InstantiatingIterator.uninitialize} to clean up
073: * panels</li>
074: * </ol>
075: * </div>
076: *
077: * @author David Konecny
078: */
079: public class NewFreeformProjectSupport {
080:
081: /** Ant script. Type: java.io.File */
082: public static final String PROP_ANT_SCRIPT = "antScript"; // <java.io.File> NOI18N
083:
084: /** Project name. Type: String */
085: public static final String PROP_PROJECT_NAME = "projectName"; // <String> NOI18N
086:
087: /** Original project base folder. Type: java.io.File */
088: public static final String PROP_PROJECT_LOCATION = "projectLocation"; // <java.io.File> NOI18N
089:
090: /** NetBeans project folder. Type: java.io.File */
091: public static final String PROP_PROJECT_FOLDER = "projectFolder"; // <java.io.File> NOI18N
092:
093: private NewFreeformProjectSupport() {
094: }
095:
096: /**
097: * Returns Basic Project Info panel suitable for new project wizard.
098: * Panel gathers info about original project folder, NB projetc folder,
099: * project name and Ant script.
100: */
101: public static final WizardDescriptor.Panel createBasicProjectInfoWizardPanel() {
102: return new BasicProjectInfoWizardPanel();
103: }
104:
105: /**
106: * Instantiate project according to information gathered in
107: * Basic Project Info panel. The method must to be called
108: * under ProjectManager.writeMutex.
109: */
110: public static final AntProjectHelper instantiateBasicProjectInfoWizardPanel(
111: WizardDescriptor wiz) throws IOException {
112: // XXX assert ProjectManager.mutex().isWriteAccess()
113: File antScript = (File) wiz.getProperty(PROP_ANT_SCRIPT);
114: String projName = (String) wiz.getProperty(PROP_PROJECT_NAME);
115: File projLocation = (File) wiz
116: .getProperty(PROP_PROJECT_LOCATION);
117: File projectFolder = (File) wiz
118: .getProperty(PROP_PROJECT_FOLDER);
119: if (antScript.getParentFile().equals(projectFolder)
120: && antScript.getName().equals("build.xml")) { // NOI18N
121: // default location of build file
122: antScript = null;
123: }
124: return FreeformProjectGenerator.createProject(projLocation,
125: projectFolder, projName, antScript);
126: }
127:
128: /**
129: * Returns Target Mapping panel suitable for new project wizard. The panel
130: * contains mappings of standard IDE actions like clean, build, javadoc,
131: * run and test. Other IDE actions can be added.
132: *
133: * @param targets list of additional targets to be shown in wizard panel. List
134: * of TargetDescriptor instances. Order is relevant.
135: */
136: public static final WizardDescriptor.Panel createTargetMappingWizardPanel(
137: List<TargetDescriptor> targets) {
138: return new TargetMappingWizardPanel(targets);
139: }
140:
141: /**
142: * Update project with information gathered in Target Mapping panel.
143: * The method must to be called under ProjectManager.writeMutex.
144: */
145: public static final void instantiateTargetMappingWizardPanel(
146: AntProjectHelper helper, WizardDescriptor wiz) {
147: List<FreeformProjectGenerator.TargetMapping> mappings = NbCollections
148: .checkedListByCopy(
149: (List) wiz
150: .getProperty(TargetMappingWizardPanel.PROP_TARGET_MAPPINGS),
151: FreeformProjectGenerator.TargetMapping.class,
152: true);
153:
154: FreeformProjectGenerator.putTargetMappings(helper, mappings);
155: FreeformProjectGenerator.putContextMenuAction(helper, mappings);
156: }
157:
158: /**
159: * Uninitialize Basic Project Info panel after wizard was instantiated.
160: */
161: public static void uninitializeBasicProjectInfoWizardPanel(
162: WizardDescriptor wiz) {
163: wiz
164: .putProperty(NewFreeformProjectSupport.PROP_ANT_SCRIPT,
165: null);
166: wiz.putProperty(NewFreeformProjectSupport.PROP_PROJECT_NAME,
167: null);
168: wiz.putProperty(
169: NewFreeformProjectSupport.PROP_PROJECT_LOCATION, null);
170: wiz.putProperty(NewFreeformProjectSupport.PROP_PROJECT_FOLDER,
171: null);
172: }
173:
174: /**
175: * Uninitialize Target Mapping panel after wizard was instantiated.
176: */
177: public static void uninitializeTargetMappingWizardPanel(
178: WizardDescriptor wiz) {
179: wiz.putProperty(TargetMappingWizardPanel.PROP_TARGET_MAPPINGS,
180: null);
181: }
182:
183: }
|