|
What this is
This file is included in the DevDaily.com
"Java Source Code
Warehouse" project. The intent of this project is to help you "Learn
Java by Example" TM.
Other links
The source code
/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is NetBeans. The Initial Developer of the Original
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
* Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.ant.freeform.ui;
import java.awt.Component;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
import javax.swing.JComponent;
import javax.swing.event.ChangeListener;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.modules.ant.freeform.FreeformProjectGenerator;
import org.netbeans.spi.project.support.ant.AntProjectHelper;
import org.netbeans.spi.project.support.ant.PropertyUtils;
import org.openide.ErrorManager;
import org.openide.WizardDescriptor;
import org.openide.filesystems.FileLock;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.NbBundle;
/**
* @author David Konecny
*/
public class NewJ2SEFreeformProjectWizardIterator implements WizardDescriptor.InstantiatingIterator {
// project location panel
public static final String PROP_ANT_SCRIPT = "antScript"; // NOI18N
public static final String PROP_PROJECT_NAME = "projectName"; // NOI18N
// target mappings panel
public static final String PROP_TARGET_MAPPINGS = "targetMappings"; // NOI18N
public static final String PROP_PROJECT_MODEL = "projectModel"; // NOI18N
private static final long serialVersionUID = 1L;
private transient int index;
private transient WizardDescriptor.Panel[] panels;
private transient WizardDescriptor wiz;
public NewJ2SEFreeformProjectWizardIterator() {
}
private WizardDescriptor.Panel[] createPanels () {
return new WizardDescriptor.Panel[] {
new BasicProjectInfoWizardPanel(),
new TargetMappingWizardPanel("j2se"), // NOI18N
new SourceFoldersWizardPanel(),
new ClasspathWizardPanel(),
};
}
private String[] createSteps() {
return new String[] {
NbBundle.getMessage (NewJ2SEFreeformProjectWizardIterator.class, "TXT_NewJ2SEFreeformProjectWizardIterator_NameAndLocation"), // NOI18N
NbBundle.getMessage (NewJ2SEFreeformProjectWizardIterator.class, "TXT_NewJ2SEFreeformProjectWizardIterator_BuildAndRunActions"), // NOI18N
NbBundle.getMessage (NewJ2SEFreeformProjectWizardIterator.class, "TXT_NewJ2SEFreeformProjectWizardIterator_SourcePackageFolders"), // NOI18N
NbBundle.getMessage (NewJ2SEFreeformProjectWizardIterator.class, "TXT_NewJ2SEFreeformProjectWizardIterator_Classpath") // NOI18N
};
}
public Set/**/ instantiate () throws IOException {
ProjectModel pm = (ProjectModel)wiz.getProperty(PROP_PROJECT_MODEL);
File nbProjectFolder = pm.getNBProjectFolder();
String projName = (String)wiz.getProperty(PROP_PROJECT_NAME);
File antScript = (File)wiz.getProperty(PROP_ANT_SCRIPT);
if (antScript.getParentFile().equals(nbProjectFolder) && antScript.getName().equals("build.xml")) { // NOI18N
// default location of build file
antScript = null;
}
List mappings = (List)wiz.getProperty(PROP_TARGET_MAPPINGS);
ProjectModel.instantiateJavaProject(pm, projName, antScript, mappings);
Set resultSet = new HashSet();
resultSet.add(FileUtil.toFileObject(nbProjectFolder));
return resultSet;
}
public void initialize(WizardDescriptor wiz) {
this.wiz = wiz;
index = 0;
panels = createPanels();
// Make sure list of steps is accurate.
String[] steps = createSteps();
for (int i = 0; i < panels.length; i++) {
Component c = panels[i].getComponent();
// if (steps[i] == null) {
// // Default step name to component name of panel.
// // Mainly useful for getting the name of the target
// // chooser to appear in the list of steps.
// steps[i] = c.getName();
// }
assert c instanceof JComponent;
JComponent jc = (JComponent)c;
// Step #.
jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); // NOI18N
// Step name (actually the whole list for reference).
jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
// Name of panel
jc.setName(steps[i]);
// set title
jc.putClientProperty ("NewProjectWizard_Title", NbBundle.getMessage (NewJ2SEFreeformProjectWizardIterator.class, "TXT_NewJ2SEFreeformProjectWizardIterator_NewProjectWizardTitle")); // NOI18N
}
}
public void uninitialize(WizardDescriptor wiz) {
wiz.putProperty(PROP_ANT_SCRIPT, null);
wiz.putProperty(PROP_PROJECT_NAME, null);
wiz.putProperty(PROP_TARGET_MAPPINGS, null);
wiz.putProperty(PROP_PROJECT_MODEL, null);
this.wiz = null;
panels = null;
}
public String name() {
return MessageFormat.format (NbBundle.getMessage (NewJ2SEFreeformProjectWizardIterator.class, "TXT_NewJ2SEFreeformProjectWizardIterator_TitleFormat"), // NOI18N
new Object[] {new Integer (index + 1), new Integer (panels.length) });
}
public boolean hasNext() {
if (current() instanceof SourceFoldersWizardPanel) {
assert current().getComponent() instanceof SourceFoldersPanel;
SourceFoldersPanel sfp = (SourceFoldersPanel)current().getComponent();
if (!sfp.hasSomeSourceFolder()) {
return false;
}
}
return index < panels.length - 1;
}
public boolean hasPrevious() {
return index > 0;
}
public void nextPanel() {
if (!hasNext()) throw new NoSuchElementException();
index++;
}
public void previousPanel() {
if (!hasPrevious()) throw new NoSuchElementException();
index--;
}
public WizardDescriptor.Panel current () {
return panels[index];
}
// If nothing unusual changes in the middle of the wizard, simply:
public final void addChangeListener(ChangeListener l) {}
public final void removeChangeListener(ChangeListener l) {}
}
|