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.java.freeform.spi.support;
043:
044: import java.io.IOException;
045: import org.netbeans.modules.java.freeform.ui.ClasspathWizardPanel;
046: import org.netbeans.modules.java.freeform.ui.NewJ2SEFreeformProjectWizardIterator;
047: import org.netbeans.modules.java.freeform.ui.OutputWizardPanel;
048: import org.netbeans.modules.java.freeform.ui.ProjectModel;
049: import org.netbeans.modules.java.freeform.ui.SourceFoldersPanel;
050: import org.netbeans.modules.java.freeform.ui.SourceFoldersWizardPanel;
051: import org.netbeans.spi.project.support.ant.AntProjectHelper;
052: import org.openide.WizardDescriptor;
053:
054: /**
055: * Support for Java New Project Wizard. These methods are typically used by the
056: * freeform project extension which want to instantiate also Java development
057: * support in project.
058: * <div class="nonnormative">
059: * <p>
060: * Typical usage of these methods is:
061: * </p>
062: * <ol>
063: * <li>create implementation of {@link org.openide.WizardDescriptor.InstantiatingIterator}
064: * with your wizard panels and add panels created by {@link #createJavaPanels}
065: * method</li>
066: * <li>in implementation of {@link org.openide.WizardDescriptor.Iterator.hasNext}
067: * method call also {@link #enableNextButton}</li>
068: * <li>in implementation of {@link org.openide.WizardDescriptor.InstantiatingIterator.instantiate}
069: * method call in addition also {@link #instantiateJavaPanels}</li>
070: * <li>do not forget to call {@link #uninitializeJavaPanels} in your
071: * {@link org.openide.WizardDescriptor.InstantiatingIterator.uninitialize}
072: * to clean up Java panels</li>
073: * </ol>
074: * </div>
075: *
076: * @author David Konecny
077: */
078: public class NewJavaFreeformProjectSupport {
079:
080: /** List of initial source folders. Type: List of String pair: [source path, its display name]*/
081: public static final String PROP_EXTRA_JAVA_SOURCE_FOLDERS = "sourceFolders"; // <List<String,String>> NOI18N
082:
083: private NewJavaFreeformProjectSupport() {
084: }
085:
086: /**
087: * Returns array of standard Java panels suitable for new project wizard.
088: * Panel gathers info about Java source folders and their classpath.
089: */
090: public static WizardDescriptor.Panel[] createJavaPanels() {
091: return new WizardDescriptor.Panel[] {
092: new SourceFoldersWizardPanel(),
093: new ClasspathWizardPanel(), new OutputWizardPanel() };
094: }
095:
096: /**
097: * There is special logic in Java panels that Sources panel should enable
098: * Next button only when at least one source folder was specified. Wizard
099: * iterator which is using panels created by createJavaPanels() method
100: * should always call this method in hasNext() method.
101: */
102: public static boolean enableNextButton(WizardDescriptor.Panel panel) {
103: if (panel instanceof SourceFoldersWizardPanel) {
104: SourceFoldersPanel sfp = (SourceFoldersPanel) panel
105: .getComponent();
106: if (!sfp.hasSomeSourceFolder()) {
107: return false;
108: }
109: }
110: return true;
111: }
112:
113: /**
114: * Update project with information gathered in Java panels, that is
115: * add Java support to project. The method must to be called under
116: * ProjectManager.writeMutex.
117: */
118: public static void instantiateJavaPanels(AntProjectHelper helper,
119: WizardDescriptor wiz) throws IOException {
120: ProjectModel pm = (ProjectModel) wiz
121: .getProperty(NewJ2SEFreeformProjectWizardIterator.PROP_PROJECT_MODEL);
122: ProjectModel.instantiateJavaProject(helper, pm);
123: }
124:
125: /**
126: * Uninitialize Java panels after wizard was instantiated.
127: */
128: public static void uninitializeJavaPanels(WizardDescriptor wiz) {
129: wiz
130: .putProperty(
131: NewJavaFreeformProjectSupport.PROP_EXTRA_JAVA_SOURCE_FOLDERS,
132: null);
133: wiz
134: .putProperty(
135: NewJ2SEFreeformProjectWizardIterator.PROP_PROJECT_MODEL,
136: null);
137: }
138:
139: }
|