KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CustomResourceWizard.java
22  *
23  */

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

49 public class CustomResourceWizard extends AbstractResourceWizard{
50     
51     private static final String JavaDoc DATAFILE = "org/netbeans/modules/j2ee/sun/ws7/serverresources/wizards/CustomWizard.xml"; //NOI18N
52
private Wizard wizardInfo;
53     private ResourceConfigHelper helper;
54     
55     private transient WizardDescriptor wizard;
56     //private transient WizardDescriptor.Panel[] panels;
57
private transient String JavaDoc[] steps;
58    // private transient int index;
59

60     private static Project project;
61     
62    
63     public static CustomResourceWizard create(){
64         return new CustomResourceWizard();
65     }
66     public void initialize(WizardDescriptor wizard){
67         wizardInfo = getWizardInfo(DATAFILE);
68         this.helper = new ResourceConfigHelperHolder().getCustomResourceHelper();
69         
70         this.wizard = wizard;
71         wizard.putProperty("NewFileWizard_Title",
72                            NbBundle.getMessage(CustomResourceWizard.class, "Templates/SunWS70Resources/Custom_Resource")); //NOI18N
73
index = 0;
74                 
75         project = Templates.getProject(wizard);
76         
77         panels = createPanels();
78         // Make sure list of steps is accurate.
79
steps = createSteps();
80         
81         try{
82             FileObject pkgLocation = project.getProjectDirectory();
83             if (pkgLocation != null) {
84                 this.helper.getData().setTargetFileObject(pkgLocation);
85             }
86         }catch (Exception JavaDoc ex){
87            //Unable to get project location
88
ex.printStackTrace();
89         }
90         
91         for (int i = 0; i < panels.length; i++) {
92             Component JavaDoc c = panels[i].getComponent();
93             if (c instanceof JComponent JavaDoc) { // assume Swing components
94
JComponent JavaDoc jc = (JComponent JavaDoc)c;
95                 // Step #.
96
jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(i)); // NOI18N
97
// Step name (actually the whole list for reference).
98
jc.putClientProperty("WizardPanel_contentData", steps); // NOI18N
99
}
100         }
101     }
102     public Set JavaDoc instantiate(){
103         try{
104             WS70ResourceUtils.saveCustomResourceDatatoXml(this.helper.getData());
105         }catch (Exception JavaDoc ex){
106             System.out.println("Error in instantiate of CustomResourceWizard");
107         }
108         return java.util.Collections.EMPTY_SET;
109     }
110     public void uninitialize(WizardDescriptor wizard){
111         
112     }
113     private Wizard getWizardInfo(){
114         try{
115             InputStream JavaDoc in = this.getClass().getClassLoader().getResourceAsStream(DATAFILE);
116             this.wizardInfo = Wizard.createGraph(in);
117         }catch(Exception JavaDoc ex){
118             ex.printStackTrace();
119         }
120         return this.wizardInfo;
121     }
122         
123  
124     public String JavaDoc name(){
125         return NbBundle.getMessage(CustomResourceWizard.class, "Templates/SunWS70Resources/Custom_Resource"); //NOI18N
126
}
127    private WizardDescriptor.Panel[] createPanels() {
128         return new WizardDescriptor.Panel[] {
129             new CommonGeneralFinishPanel(helper, wizardInfo, new String JavaDoc[] {"general"}), //NOI18N
130
new CommonPropertyPanel(helper, wizardInfo)
131         };
132     }
133     
134     private String JavaDoc[] createSteps() {
135         return new String JavaDoc[] {
136             WS70WizardConstants.__FirstStepChoose,
137             NbBundle.getMessage(CustomResourceWizard.class, "TITLE_GeneralAttributes_CUSTOM"), //NOI18N
138
NbBundle.getMessage(CustomResourceWizard.class, "TITLE_UserProps_CUSTOM") //NOI18N
139
};
140     }
141 }
142
Popular Tags