KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > serverresources > wizards > JDBCResourceWizard


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 /*
21  * JDBCResourceWizard.java
22  */

23
24 package org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards;
25
26 import java.awt.Component JavaDoc;
27 import java.util.Set JavaDoc;
28 import javax.swing.JComponent JavaDoc;
29 import java.io.InputStream JavaDoc;
30 import javax.swing.event.ChangeEvent JavaDoc;
31 import javax.swing.event.ChangeListener JavaDoc;
32
33 import org.openide.util.NbBundle;
34 import org.openide.WizardDescriptor;
35 import org.netbeans.api.project.Project;
36 import org.openide.filesystems.FileObject;
37 import org.netbeans.spi.project.ui.templates.support.Templates;
38 import org.openide.WizardDescriptor;
39
40 import org.netbeans.modules.j2ee.sun.sunresources.beans.Wizard;
41 import org.netbeans.modules.j2ee.sun.ws7.serverresources.beans.WS70ResourceUtils;
42
43 /**
44  *
45  * @author Mukesh Garg
46  */

47 public class JDBCResourceWizard extends AbstractResourceWizard{
48     private static final String JavaDoc DATAFILE = "org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/JDBCWizard.xml"; //NOI18N
49
private Wizard wizardInfo;
50     private ResourceConfigHelper helper;
51     
52     private transient WizardDescriptor wizard;
53     private transient String JavaDoc[] steps;
54     private static Project project;
55     
56     public static JDBCResourceWizard create(){
57         return new JDBCResourceWizard();
58     }
59     public void initialize(WizardDescriptor wizard){
60         wizardInfo = getWizardInfo(DATAFILE);
61         this.helper = new ResourceConfigHelperHolder().getJDBCHelper();
62         
63         this.wizard = wizard;
64         wizard.putProperty("NewFileWizard_Title",
65                            NbBundle.getMessage(JDBCResourceWizard.class, "Templates/SunWS70Resources/JDBC_Resource")); //NOI18N
66
index = 0;
67                 
68         project = Templates.getProject(wizard);
69         
70         panels = createPanels();
71         // Make sure list of steps is accurate.
72
steps = createSteps();
73         
74         try{
75             FileObject pkgLocation = project.getProjectDirectory();
76             if (pkgLocation != null) {
77                 this.helper.getData().setTargetFileObject(pkgLocation);
78             }
79         }catch (Exception JavaDoc ex){
80            //Unable to get project location
81
}
82         
83         for (int i = 0; i < panels.length; i++) {
84             Component JavaDoc c = panels[i].getComponent();
85             if (c instanceof JComponent JavaDoc) { // assume Swing components
86
JComponent JavaDoc jc = (JComponent JavaDoc)c;
87                 // Step #.
88
jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(i)); // NOI18N
89
// Step name (actually the whole list for reference).
90
jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
91
}
92         }
93     }
94     public Set JavaDoc instantiate(){
95         try{
96             WS70ResourceUtils.saveJDBCResourceDatatoXml(this.helper.getData());
97         }catch (Exception JavaDoc ex){
98             ex.printStackTrace();
99         }
100         return java.util.Collections.EMPTY_SET;
101         
102     }
103     public void uninitialize(WizardDescriptor wizard){
104         
105     }
106     private Wizard getWizardInfo(){
107         try{
108             InputStream JavaDoc in = this.getClass().getClassLoader().getResourceAsStream(DATAFILE);
109             this.wizardInfo = Wizard.createGraph(in);
110         }catch(Exception JavaDoc ex){
111             ex.printStackTrace();
112         }
113         return this.wizardInfo;
114     }
115         
116  
117     public String JavaDoc name(){
118         return NbBundle.getMessage(JDBCResourceWizard.class, "Templates/SunWS70Resources/JDBC_Resource"); //NOI18N
119
}
120     private WizardDescriptor.Panel[] createPanels() {
121         return new WizardDescriptor.Panel[] {
122             new CommonGeneralFinishPanel(helper, wizardInfo, new String JavaDoc[] {"general", "connection-setting"}), //NOI18N
123
new CommonPropertyPanel(helper, wizardInfo)
124                         
125         };
126     }
127     
128     private String JavaDoc[] createSteps() {
129         return new String JavaDoc[] {
130             WS70WizardConstants.__FirstStepChoose,
131             NbBundle.getMessage(JDBCResourceWizard.class, "TITLE_GeneralAttributes_JDBC"), //NOI18N
132
NbBundle.getMessage(JDBCResourceWizard.class, "TITLE_UserProps_JDBC") //NOI18N
133
};
134     }
135 }
136
Popular Tags