KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > examples > WebSampleProjectIterator


1 /*
2  * Main.java
3  *
4  * Created on April 6, 2004, 3:39 PM
5  */

6
7 package org.netbeans.modules.web.examples;
8
9 import java.io.File JavaDoc;
10 import java.util.HashSet JavaDoc;
11 import java.util.NoSuchElementException JavaDoc;
12 import java.util.Set JavaDoc;
13 import javax.swing.JComponent JavaDoc;
14 import org.openide.WizardDescriptor;
15 import org.openide.filesystems.FileObject;
16 import org.openide.loaders.DataObject;
17 import org.openide.loaders.TemplateWizard;
18 import org.openide.util.NbBundle;
19
20 /**
21  *
22  * @author Martin Grebac
23  */

24 public class WebSampleProjectIterator implements TemplateWizard.Iterator {
25     
26     private static final long serialVersionUID = 4L;
27     
28     int currentIndex;
29     PanelConfigureProject basicPanel;
30     private transient WizardDescriptor wiz;
31
32     static Object JavaDoc create() {
33         return new WebSampleProjectIterator();
34     }
35     
36     public WebSampleProjectIterator () {
37     }
38     
39     public void addChangeListener (javax.swing.event.ChangeListener JavaDoc changeListener) {
40     }
41     
42     public void removeChangeListener (javax.swing.event.ChangeListener JavaDoc changeListener) {
43     }
44     
45     public org.openide.WizardDescriptor.Panel current () {
46         return basicPanel;
47     }
48     
49     public boolean hasNext () {
50         return false;
51     }
52     
53     public boolean hasPrevious () {
54         return false;
55     }
56     
57     public void initialize (org.openide.loaders.TemplateWizard templateWizard) {
58         this.wiz = templateWizard;
59         String JavaDoc name = templateWizard.getTemplate().getNodeDelegate().getDisplayName();
60         if (name != null) {
61             name = name.replaceAll(" ", ""); //NOI18N
62
}
63         templateWizard.putProperty (WizardProperties.NAME, name);
64         basicPanel = new PanelConfigureProject();
65         currentIndex = 0;
66         updateStepsList ();
67     }
68     
69     public void uninitialize (org.openide.loaders.TemplateWizard templateWizard) {
70         basicPanel = null;
71         this.wiz.putProperty(WizardProperties.PROJECT_DIR,null);
72         this.wiz.putProperty(WizardProperties.NAME,null);
73         currentIndex = -1;
74     }
75     
76     public java.util.Set JavaDoc instantiate (org.openide.loaders.TemplateWizard templateWizard) throws java.io.IOException JavaDoc {
77         File JavaDoc projectLocation = (File JavaDoc) wiz.getProperty(WizardProperties.PROJECT_DIR);
78         String JavaDoc name = (String JavaDoc) wiz.getProperty(WizardProperties.NAME);
79                         
80         FileObject prjLoc = null;
81         prjLoc = WebSampleProjectGenerator.createProjectFromTemplate(templateWizard.getTemplate().getPrimaryFile(), projectLocation, name);
82         
83         FileObject webRoot = prjLoc.getFileObject("web"); //NOI18N
84
FileObject index = getIndexFile(webRoot);
85
86         Set JavaDoc hset = new HashSet JavaDoc();
87         hset.add(DataObject.find(prjLoc));
88         hset.add(DataObject.find(index));
89         
90         return hset;
91     }
92     
93     public String JavaDoc name() {
94         return current().getComponent().getName();
95     }
96     
97     public void nextPanel() {
98         throw new NoSuchElementException JavaDoc ();
99     }
100     
101     public void previousPanel() {
102         throw new NoSuchElementException JavaDoc ();
103     }
104     
105     void updateStepsList() {
106         JComponent JavaDoc component = (JComponent JavaDoc) current ().getComponent ();
107         if (component == null) {
108             return;
109         }
110         String JavaDoc[] list;
111         list = new String JavaDoc[] {
112             NbBundle.getMessage(PanelConfigureProject.class, "LBL_NWP1_ProjectTitleName"), // NOI18N
113
};
114         component.putClientProperty ("WizardPanel_contentData", list); // NOI18N
115
component.putClientProperty ("WizardPanel_contentSelectedIndex", new Integer JavaDoc (currentIndex)); // NOI18N
116
}
117     
118     private FileObject getIndexFile(FileObject webRoot) {
119         FileObject file = null;
120         file = webRoot.getFileObject("index", "jsp");
121         if (file == null) {
122             file = webRoot.getFileObject("index", "html");
123         }
124         return file;
125     }
126     
127     
128 }
129
Popular Tags