001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: /*
021: * Sun Public License Notice
022: *
023: * The contents of this file are subject to the Sun Public License
024: * Version 1.0 (the "License"). You may not use this file except in
025: * compliance with the License. A copy of the License is available at
026: * http://www.sun.com/
027: *
028: * The Original Code is NetBeans. The Initial Developer of the Original
029: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
030: * Microsystems, Inc. All Rights Reserved.
031: */
032:
033: package org.netbeans.modules.sql.project.ui.wizards;
034:
035: //import org.netbeans.modules.compapp.projects.base.ui.wizards.NewIcanproProjectWizardIterator;
036: import static org.netbeans.modules.sql.project.SQLproConstants.*;
037: import org.netbeans.modules.sql.project.SQLproProjectGenerator;
038: import org.netbeans.spi.project.support.ant.AntProjectHelper;
039: import org.openide.WizardDescriptor;
040: import java.awt.Component;
041: import java.io.File;
042: import java.io.IOException;
043: import java.text.MessageFormat;
044: import java.util.HashSet;
045: import java.util.NoSuchElementException;
046: import java.util.Set;
047: import javax.swing.JComponent;
048: import javax.swing.event.ChangeListener;
049: import org.openide.filesystems.FileObject;
050: import org.openide.filesystems.FileUtil;
051: import org.openide.util.NbBundle;
052:
053: /**
054: * Wizard to create a new Web project.
055: * @author Jesse Glick
056: */
057: public class NewSQLproProjectWizardIterator implements
058: WizardDescriptor.InstantiatingIterator {
059:
060: private static final long serialVersionUID = 1L;
061: private transient int index;
062: private transient WizardDescriptor.Panel[] panels;
063: private transient WizardDescriptor wizardDescriptor;
064:
065: public NewSQLproProjectWizardIterator() {
066: }
067:
068: public Set<Object> instantiate() throws IOException {
069: Set<Object> resultSet = new HashSet<Object>();
070: File dirF = (File) wizardDescriptor.getProperty(PROJECT_DIR);
071: String name = (String) wizardDescriptor.getProperty(NAME);
072: String j2eeLevel = (String) wizardDescriptor
073: .getProperty(J2EE_LEVEL);
074:
075: AntProjectHelper h = SQLproProjectGenerator.createProject(dirF,
076: name, j2eeLevel);
077:
078: FileObject dir = FileUtil.toFileObject(dirF);
079:
080: resultSet.add(dir);
081:
082: return resultSet;
083: }
084:
085: public void initialize(WizardDescriptor wizardDescriptor) {
086: this .wizardDescriptor = wizardDescriptor;
087: index = 0;
088: panels = createPanels();
089: // Make sure list of steps is accurate.
090: String[] steps = createSteps();
091: for (int i = 0; i < panels.length; i++) {
092: Component c = panels[i].getComponent();
093: if (steps[i] == null) {
094: // Default step name to component name of panel.
095: // Mainly useful for getting the name of the target
096: // chooser to appear in the list of steps.
097: steps[i] = c.getName();
098: }
099: if (c instanceof JComponent) { // assume Swing components
100: JComponent jc = (JComponent) c;
101: // Step #.
102: jc.putClientProperty(
103: "WizardPanel_contentSelectedIndex",
104: new Integer(i)); // NOI18N
105: // Step name (actually the whole list for reference).
106: jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
107: }
108: }
109: }
110:
111: public void uninitialize(WizardDescriptor wizardDescriptor) {
112: this .wizardDescriptor.putProperty(PROJECT_DIR, null);
113: this .wizardDescriptor.putProperty(NAME, null);
114: this .wizardDescriptor = null;
115: panels = null;
116: }
117:
118: public WizardDescriptor.Panel current() {
119: return panels[index];
120: }
121:
122: public String name() {
123: return MessageFormat.format(NbBundle.getMessage(
124: NewSQLproProjectWizardIterator.class,
125: "LBL_WizardStepsCount"), //NOI18N
126: new String[] { (new Integer(index + 1)).toString(),
127: (new Integer(panels.length)).toString() });
128: }
129:
130: public boolean hasNext() {
131: return index < panels.length - 1;
132: }
133:
134: public boolean hasPrevious() {
135: return index > 0;
136: }
137:
138: public void nextPanel() {
139: if (!hasNext())
140: throw new NoSuchElementException();
141: index++;
142: }
143:
144: public void previousPanel() {
145: if (!hasPrevious())
146: throw new NoSuchElementException();
147: index--;
148: }
149:
150: public void addChangeListener(ChangeListener l) {
151: }
152:
153: public void removeChangeListener(ChangeListener l) {
154: }
155:
156: private WizardDescriptor.Panel[] createPanels() {
157: return new WizardDescriptor.Panel[] { new PanelConfigureProject(
158: getDefaultName()), };
159: }
160:
161: private String[] createSteps() {
162: return new String[] { NbBundle.getMessage(
163: NewSQLproProjectWizardIterator.class,
164: "LBL_NPW1_ProjectTitleName"), //NOI18N
165: };
166: }
167:
168: protected String getDefaultName() {
169: return NbBundle.getMessage(
170: NewSQLproProjectWizardIterator.class,
171: "LBL_NPW1_DefaultProjectName"); //NOI18N
172: }
173: }
|