001: /*
002: * Main.java
003: *
004: * Created on April 6, 2004, 3:39 PM
005: */
006:
007: package org.netbeans.modules.web.examples;
008:
009: import java.io.File;
010: import java.util.HashSet;
011: import java.util.NoSuchElementException;
012: import java.util.Set;
013: import javax.swing.JComponent;
014: import org.openide.WizardDescriptor;
015: import org.openide.filesystems.FileObject;
016: import org.openide.loaders.DataObject;
017: import org.openide.loaders.TemplateWizard;
018: import org.openide.util.NbBundle;
019:
020: /**
021: *
022: * @author Martin Grebac
023: */
024: public class WebSampleProjectIterator implements
025: TemplateWizard.Iterator {
026:
027: private static final long serialVersionUID = 4L;
028:
029: int currentIndex;
030: PanelConfigureProject basicPanel;
031: private transient WizardDescriptor wiz;
032:
033: static Object create() {
034: return new WebSampleProjectIterator();
035: }
036:
037: public WebSampleProjectIterator() {
038: }
039:
040: public void addChangeListener(
041: javax.swing.event.ChangeListener changeListener) {
042: }
043:
044: public void removeChangeListener(
045: javax.swing.event.ChangeListener changeListener) {
046: }
047:
048: public org.openide.WizardDescriptor.Panel current() {
049: return basicPanel;
050: }
051:
052: public boolean hasNext() {
053: return false;
054: }
055:
056: public boolean hasPrevious() {
057: return false;
058: }
059:
060: public void initialize(
061: org.openide.loaders.TemplateWizard templateWizard) {
062: this .wiz = templateWizard;
063: String name = templateWizard.getTemplate().getNodeDelegate()
064: .getDisplayName();
065: if (name != null) {
066: name = name.replaceAll(" ", ""); //NOI18N
067: }
068: templateWizard.putProperty(WizardProperties.NAME, name);
069: basicPanel = new PanelConfigureProject();
070: currentIndex = 0;
071: updateStepsList();
072: }
073:
074: public void uninitialize(
075: org.openide.loaders.TemplateWizard templateWizard) {
076: basicPanel = null;
077: this .wiz.putProperty(WizardProperties.PROJECT_DIR, null);
078: this .wiz.putProperty(WizardProperties.NAME, null);
079: currentIndex = -1;
080: }
081:
082: public java.util.Set instantiate(
083: org.openide.loaders.TemplateWizard templateWizard)
084: throws java.io.IOException {
085: File projectLocation = (File) wiz
086: .getProperty(WizardProperties.PROJECT_DIR);
087: String name = (String) wiz.getProperty(WizardProperties.NAME);
088:
089: FileObject prjLoc = null;
090: prjLoc = WebSampleProjectGenerator.createProjectFromTemplate(
091: templateWizard.getTemplate().getPrimaryFile(),
092: projectLocation, name);
093:
094: FileObject webRoot = prjLoc.getFileObject("web"); //NOI18N
095: FileObject index = getIndexFile(webRoot);
096:
097: Set hset = new HashSet();
098: hset.add(DataObject.find(prjLoc));
099: hset.add(DataObject.find(index));
100:
101: return hset;
102: }
103:
104: public String name() {
105: return current().getComponent().getName();
106: }
107:
108: public void nextPanel() {
109: throw new NoSuchElementException();
110: }
111:
112: public void previousPanel() {
113: throw new NoSuchElementException();
114: }
115:
116: void updateStepsList() {
117: JComponent component = (JComponent) current().getComponent();
118: if (component == null) {
119: return;
120: }
121: String[] list;
122: list = new String[] { NbBundle.getMessage(
123: PanelConfigureProject.class,
124: "LBL_NWP1_ProjectTitleName"), // NOI18N
125: };
126: component.putClientProperty("WizardPanel_contentData", list); // NOI18N
127: component.putClientProperty("WizardPanel_contentSelectedIndex",
128: new Integer(currentIndex)); // NOI18N
129: }
130:
131: private FileObject getIndexFile(FileObject webRoot) {
132: FileObject file = null;
133: file = webRoot.getFileObject("index", "jsp");
134: if (file == null) {
135: file = webRoot.getFileObject("index", "html");
136: }
137: return file;
138: }
139:
140: }
|