KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > examples > J2SESampleProjectIterator


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.examples;
21
22 import java.io.File JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.NoSuchElementException JavaDoc;
25 import javax.swing.JComponent JavaDoc;
26 import org.openide.WizardDescriptor;
27 import org.openide.filesystems.FileObject;
28 import org.openide.loaders.DataObject;
29 import org.openide.loaders.TemplateWizard;
30 import org.openide.util.NbBundle;
31
32 /**
33  * @author Martin Grebac
34  */

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