KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > sunresources > wizards > ConnPoolWizard


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  * ConnPoolWizard.java
21  *
22  * Created on September 30, 2003, 10:05 AM
23  */

24
25 package org.netbeans.modules.j2ee.sun.ide.sunresources.wizards;
26
27 /**
28  *
29  * @author nityad
30  */

31
32 import java.awt.Component JavaDoc;
33 import java.util.Set JavaDoc;
34 import javax.swing.JComponent JavaDoc;
35 import java.io.InputStream JavaDoc;
36 import javax.swing.event.ChangeListener JavaDoc;
37
38 import org.openide.util.NbBundle;
39 import org.openide.WizardDescriptor;
40 import org.netbeans.api.project.Project;
41 import org.openide.filesystems.FileObject;
42 import org.netbeans.spi.project.ui.templates.support.Templates;
43
44 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils;
45
46 import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard;
47 import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants;
48 import org.openide.ErrorManager;
49
50 public final class ConnPoolWizard implements WizardDescriptor.InstantiatingIterator, WizardConstants{
51     
52     private static Project project;
53            
54     private static final String JavaDoc DATAFILE = "org/netbeans/modules/j2ee/sun/sunresources/beans/CPWizard.xml"; //NOI18N
55

56     /** An array of all wizard panels */
57     private transient WizardDescriptor.Panel[] panels;
58 // private transient WizardDescriptor wiz;
59
private transient String JavaDoc[] steps;
60     private transient int index;
61     private ResourceConfigHelper helper;
62     private Wizard wizardInfo;
63         
64     /** Creates a new instance of ConnPoolWizard */
65     public static ConnPoolWizard create () {
66         return new ConnPoolWizard ();
67     }
68     
69     private WizardDescriptor.Panel[] createPanels() {
70         return new WizardDescriptor.Panel[] {
71             new CPVendorPanel(this.helper, this.wizardInfo),
72             new CPPropertiesPanelPanel(this.helper, this.wizardInfo),
73             new CommonAttributePanel(this.helper, this.wizardInfo, new String JavaDoc[] {"pool-setting", "pool-setting-2", "pool-setting-3"}), //NOI18N
74
};
75     }
76     
77     private String JavaDoc[] createSteps() {
78         return new String JavaDoc[] {
79             NbBundle.getMessage(ConnPoolWizard.class, __FirstStepChoose),
80             NbBundle.getMessage(ConnPoolWizard.class, "TITLE_ConnPoolWizardPanel_dbConn"), //NOI18N
81
NbBundle.getMessage(ConnPoolWizard.class, "TITLE_ConnPoolWizardPanel_properties"), //NOI18N
82
NbBundle.getMessage(ConnPoolWizard.class, "TITLE_ConnPoolWizardPanel_optionalProps") //NOI18N
83
};
84     }
85     
86     public Set JavaDoc instantiate(){
87         try{
88             ResourceUtils.saveConnPoolDatatoXml(this.helper.getData());
89         }catch (Exception JavaDoc ex){
90                                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
91                                         ex);
92         }
93         return java.util.Collections.EMPTY_SET;
94     }
95     
96     public void initialize(WizardDescriptor wiz){
97         this.wizardInfo = getWizardInfo();
98         this.helper = new ResourceConfigHelperHolder().getConnPoolHelper();
99         
100         //this.wiz = wiz;
101
wiz.putProperty("NewFileWizard_Title", NbBundle.getMessage(ConnPoolWizard.class, "Templates/SunResources/JDBC_Connection_Pool")); //NOI18N
102
index = 0;
103                 
104         project = Templates.getProject(wiz);
105         
106         panels = createPanels();
107         // Make sure list of steps is accurate.
108
steps = createSteps();
109         
110         try{
111             FileObject pkgLocation = project.getProjectDirectory();
112             if (pkgLocation != null) {
113                 this.helper.getData().setTargetFileObject(pkgLocation);
114             }
115         }catch (Exception JavaDoc ex){
116                                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
117                                         ex);
118         }
119         
120         for (int i = 0; i < panels.length; i++) {
121             Component JavaDoc c = panels[i].getComponent();
122             if (c instanceof JComponent JavaDoc) { // assume Swing components
123
JComponent JavaDoc jc = (JComponent JavaDoc)c;
124                 // Step #.
125
jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(i)); // NOI18N
126
// Step name (actually the whole list for reference).
127
jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
128
}
129         }
130     }
131     
132     public void uninitialize(WizardDescriptor wiz){
133         //this.wiz = null;
134
panels = null;
135     }
136     
137     public Wizard getWizardInfo(){
138         try{
139             InputStream JavaDoc in = Wizard.class.getClassLoader().getResourceAsStream(DATAFILE);
140             this.wizardInfo = Wizard.createGraph(in);
141         }catch(Exception JavaDoc ex){
142                                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL,
143                                         ex);
144         }
145         return this.wizardInfo;
146     }
147     
148     public String JavaDoc name(){
149         return NbBundle.getMessage(ConnPoolWizard.class, "Templates/SunResources/JDBC_Connection_Pool"); //NOI18N
150
}
151     
152     public boolean hasNext(){
153         return index < panels.length - 1;
154     }
155     
156     public boolean hasPrevious(){
157         return index > 0;
158     }
159     
160     public synchronized void nextPanel(){
161         if (index + 1 == panels.length) {
162             throw new java.util.NoSuchElementException JavaDoc();
163         }
164         
165         if (index == 0) {
166             ((CPPropertiesPanelPanel) panels[1]).refreshFields();
167         }else if (index == 1){
168             ((CommonAttributePanel) panels[2]).setPropInitialFocus();
169         }
170         index ++;
171     }
172     
173     public synchronized void previousPanel(){
174         if (index == 0) {
175             throw new java.util.NoSuchElementException JavaDoc();
176         }
177         
178         index--;
179     }
180     
181     public WizardDescriptor.Panel current(){
182         return (WizardDescriptor.Panel)panels[index];
183     }
184     
185     public void addChangeListener(ChangeListener JavaDoc l){
186     }
187     
188     public void removeChangeListener(ChangeListener JavaDoc l){
189     }
190
191      
192     public void setResourceConfigHelper(ResourceConfigHelper helper){
193         this.helper = helper;
194     }
195     
196     public ResourceConfigHelper getResourceConfigHelper(){
197         return this.helper;
198     }
199     
200 }
201
Popular Tags