KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > gui > AddDomainDialog


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * AddDomainDialog.java
26  *
27  * Created on September 29, 2003, 3:57 PM
28  */

29
30 package com.sun.enterprise.tools.upgrade.gui;
31
32 /**
33  *
34  * @author prakash
35  */

36 import java.util.*;
37 import com.sun.enterprise.tools.upgrade.gui.util.*;
38 import java.util.logging.*;
39 import com.sun.enterprise.util.i18n.StringManager;
40 import com.sun.enterprise.tools.upgrade.logging.*;
41 import javax.swing.*;
42 import java.awt.Insets JavaDoc;
43 import java.awt.GridBagConstraints JavaDoc;
44 import com.sun.enterprise.tools.upgrade.common.DomainInfo;
45 import com.sun.enterprise.tools.upgrade.common.CommonInfoModel;
46 import com.sun.enterprise.tools.upgrade.common.UpgradeConstants;
47
48 public class AddDomainDialog extends javax.swing.JDialog JavaDoc {
49     
50     private javax.swing.JComboBox JavaDoc domainsComboBox;
51     private javax.swing.JComboBox JavaDoc instancesComboBox; // used during migrations from 7.x
52
private javax.swing.JPasswordField JavaDoc targetKeyDBPwdField;
53     private javax.swing.JPasswordField JavaDoc sourceCertPwdField;
54     private javax.swing.JPasswordField JavaDoc targetCertAuthPwdField;
55     
56     public final static int JKStoJKS = 1;
57     public final static int NSStoNSS = 2;
58     public final static int NSStoJKS = 3;
59     public final static int JKStoNSS = 4;
60     private int currentSourceToVersion;
61     
62     private StringManager stringManager = StringManager.getManager("com.sun.enterprise.tools.upgrade.gui");
63     private Logger logger = com.sun.enterprise.tools.upgrade.common.CommonInfoModel.getDefaultLogger();
64     
65     private java.util.List JavaDoc domainList;
66     private java.util.List JavaDoc instanceList;
67     private Hashtable domainMap;
68     private CommonInfoModel commonInfo;
69     
70     private Vector dialogListeners = new Vector();
71     public void addDialogListener(DialogListener listener){
72         this.dialogListeners.addElement(listener);
73     }
74     public void removeDialogListener(DialogListener listener){
75         this.dialogListeners.removeElement(listener);
76     }
77     
78     /** Creates new form AddDomainDialog */
79     public AddDomainDialog(java.awt.Frame JavaDoc parent, boolean modal, CommonInfoModel commonInfo, int currentStoT) {
80         super(parent, modal);
81         this.setTitle(stringManager.getString("upgrade.gui.adddomainpanel.dialogTitle"));
82         this.domainList = commonInfo.getDomainList();
83         this.domainMap = commonInfo.getDomainMapping();
84         this.instanceList = new ArrayList();
85         this.currentSourceToVersion = currentStoT;
86         this.commonInfo = commonInfo;
87         initComponents();
88     }
89     
90     /** This method is called from within the constructor to
91      * initialize the form.
92      * WARNING: Do NOT modify this code. The content of this method is
93      * always regenerated by the Form Editor.
94      */

95     private void initComponents() {
96         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
97         
98         javax.swing.JLabel JavaDoc domainNameLabel = new javax.swing.JLabel JavaDoc();
99         domainsComboBox = new javax.swing.JComboBox JavaDoc();
100         instancesComboBox = new javax.swing.JComboBox JavaDoc();
101         javax.swing.JPanel JavaDoc passwordPanel = null;
102         getContentPane().setLayout(new java.awt.GridBagLayout JavaDoc());
103         
104         addWindowListener(new java.awt.event.WindowAdapter JavaDoc() {
105             public void windowClosing(java.awt.event.WindowEvent JavaDoc evt) {
106                 cancelButtonActionPerformed();
107             }
108         });
109         
110         domainsComboBox.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(domainList.toArray()));
111         domainsComboBox.addItemListener(new java.awt.event.ItemListener JavaDoc() {
112             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
113                 domainsComboBoxItemStateChanged();
114             }
115         });
116
117         this.addComponetWithConstraints(domainsComboBox,getContentPane(), 0, 1, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(0, 10, 10, 60), 1.0,0.0);
118         if(commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X)) {
119             domainNameLabel.setText(stringManager.getString("upgrade.gui.adddomainpanel.instanceBoxLabel"));
120             DomainInfo dInfo = (DomainInfo)domainMap.get((String JavaDoc)domainsComboBox.getSelectedItem());
121             instanceList = dInfo.getInstanceNames();
122             instanceList.remove("admin-server");
123             instancesComboBox.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(instanceList.toArray()));
124             instancesComboBox.addItemListener(new java.awt.event.ItemListener JavaDoc() {
125                 public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
126                     instancesComboBoxItemStateChanged();
127                 }
128             });
129             this.addComponetWithConstraints(instancesComboBox,getContentPane(), 0, 2, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(0, 10, 10, 60), 1.0,0.0);
130         } else {
131             domainNameLabel.setText(stringManager.getString("upgrade.gui.adddomainpanel.listBoxLabel"));
132         }
133         this.addComponetWithConstraints(domainNameLabel,getContentPane(), 0, 0, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(10,10,5,60), 1.0,0.0);
134         if((this.currentSourceToVersion == this.NSStoJKS) || (this.currentSourceToVersion == this.JKStoNSS)){
135             passwordPanel = this.getPasswordPanelWith3Fields();
136         }else{
137             passwordPanel = this.getPasswordPanelWith2Fields();
138         }
139         this.addComponetWithConstraints(passwordPanel,getContentPane(), 0, 3, 1,1, GridBagConstraints.BOTH, new Insets JavaDoc(5, 10, 10, 60), 1.0,1.0);
140         
141         this.addComponetWithConstraints(getButtonsPanel(),getContentPane(), 0, 4, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(0,0,0,0), 1.0,0.0);
142         
143         this.setSize(400, 350);
144     }
145     private void addComponetWithConstraints(JComponent compo, java.awt.Container JavaDoc parent, int gx, int gy, int gw, int gh, int fill,java.awt.Insets JavaDoc in,
146             double wx, double wy){
147         java.awt.GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
148         gridBagConstraints.gridx = gx; gridBagConstraints.gridy = gy;
149         gridBagConstraints.gridwidth = gw; gridBagConstraints.gridheight = gh;
150         gridBagConstraints.fill = fill;
151         gridBagConstraints.insets = in;
152         gridBagConstraints.weightx = wx;
153         gridBagConstraints.weighty = wy;
154         parent.add(compo, gridBagConstraints);
155     }
156     private JPanel getPasswordPanelWith3Fields(){
157         javax.swing.JPanel JavaDoc passwordPanel = new javax.swing.JPanel JavaDoc();
158         javax.swing.JLabel JavaDoc sourceCertPwdLabel = new javax.swing.JLabel JavaDoc();
159         sourceCertPwdField = new javax.swing.JPasswordField JavaDoc();
160         javax.swing.JLabel JavaDoc targetKeyDBPwdLabel = new javax.swing.JLabel JavaDoc();
161         targetKeyDBPwdField = new javax.swing.JPasswordField JavaDoc();
162         targetCertAuthPwdField = new javax.swing.JPasswordField JavaDoc();
163         javax.swing.JLabel JavaDoc targetCertAuthPwdLabel = new javax.swing.JLabel JavaDoc();
164         
165         passwordPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
166         passwordPanel.setBorder(new javax.swing.border.TitledBorder JavaDoc(stringManager.getString("upgrade.gui.adddomainpanel.certTitleBorder")));
167         
168         String JavaDoc[] labelAndToolTipStrings = new String JavaDoc[6];
169         if(this.currentSourceToVersion == this.NSStoJKS){
170             labelAndToolTipStrings[0] = stringManager.getString("upgrade.gui.adddomainpanel.NSStoJKS.sourceCertLabelTooltip");
171             labelAndToolTipStrings[1] = stringManager.getString("upgrade.gui.adddomainpanel.NSStoJKS.targetKeyDBTooltip");
172             labelAndToolTipStrings[2] = stringManager.getString("upgrade.gui.adddomainpanel.NSStoJKS.targetCATooltip");
173             labelAndToolTipStrings[3] = stringManager.getString("upgrade.gui.adddomainpanel.NSStoJKS.sourceCertLabel");
174             labelAndToolTipStrings[4] = stringManager.getString("upgrade.gui.adddomainpanel.NSStoJKS.targetKeyDBLabel");
175             labelAndToolTipStrings[5] = stringManager.getString("upgrade.gui.adddomainpanel.NSStoJKS.targetCALabel");
176         }else{
177             labelAndToolTipStrings[0] = stringManager.getString("upgrade.gui.adddomainpanel.JKStoNSS.sourceCertLabelTooltip");
178             labelAndToolTipStrings[1] = stringManager.getString("upgrade.gui.adddomainpanel.JKStoNSS.targetKeyDBTooltip");
179             labelAndToolTipStrings[2] = stringManager.getString("upgrade.gui.adddomainpanel.JKStoNSS.targetCATooltip");
180             labelAndToolTipStrings[3] = stringManager.getString("upgrade.gui.adddomainpanel.JKStoNSS.sourceCertLabel");
181             labelAndToolTipStrings[4] = stringManager.getString("upgrade.gui.adddomainpanel.JKStoNSS.targetKeyDBLabel");
182             labelAndToolTipStrings[5] = stringManager.getString("upgrade.gui.adddomainpanel.JKStoNSS.targetCALabel");
183         }
184         sourceCertPwdLabel.setText(labelAndToolTipStrings[3]);
185         sourceCertPwdLabel.setToolTipText(labelAndToolTipStrings[0]);
186         this.addComponetWithConstraints(sourceCertPwdLabel,passwordPanel, 0, 0, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 10, 5, 10), 1.0,0.0);
187         
188         sourceCertPwdField.setToolTipText(labelAndToolTipStrings[0]);
189         this.addComponetWithConstraints(sourceCertPwdField,passwordPanel, 0, 1, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(0, 10, 7, 10), 1.0,0.0);
190         
191         targetKeyDBPwdLabel.setText(labelAndToolTipStrings[4]);
192         targetKeyDBPwdLabel.setToolTipText(labelAndToolTipStrings[1]);
193         this.addComponetWithConstraints(targetKeyDBPwdLabel,passwordPanel, 0, 2, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 10, 5, 10), 1.0,0.0);
194         
195         targetKeyDBPwdField.setToolTipText(labelAndToolTipStrings[1]);
196         this.addComponetWithConstraints(targetKeyDBPwdField,passwordPanel, 0, 3, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(0, 10, 7, 10), 1.0,0.0);
197         
198         targetCertAuthPwdLabel.setText(labelAndToolTipStrings[5]);
199         targetCertAuthPwdLabel.setToolTipText(labelAndToolTipStrings[2]);
200         this.addComponetWithConstraints(targetCertAuthPwdLabel,passwordPanel, 0, 4, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 10, 5, 10), 1.0,0.0);
201         
202         targetCertAuthPwdField.setToolTipText(labelAndToolTipStrings[2]);
203         this.addComponetWithConstraints(targetCertAuthPwdField,passwordPanel, 0, 5, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(0, 10, 7, 10), 1.0,0.0);
204         
205         return passwordPanel;
206     }
207     private JPanel getPasswordPanelWith2Fields(){
208         javax.swing.JPanel JavaDoc passwordPanel = new javax.swing.JPanel JavaDoc();
209         javax.swing.JLabel JavaDoc sourceCertPwdLabel = new javax.swing.JLabel JavaDoc();
210         sourceCertPwdField = new javax.swing.JPasswordField JavaDoc();
211         javax.swing.JLabel JavaDoc targetKeyDBPwdLabel = new javax.swing.JLabel JavaDoc();
212         targetKeyDBPwdField = new javax.swing.JPasswordField JavaDoc();
213         
214         passwordPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
215         passwordPanel.setBorder(new javax.swing.border.TitledBorder JavaDoc(stringManager.getString("upgrade.gui.adddomainpanel.certTitleBorder")));
216         
217         String JavaDoc[] labelAndToolTipStrings = new String JavaDoc[4];
218         if(this.currentSourceToVersion == this.JKStoJKS){
219             labelAndToolTipStrings[0] = stringManager.getString("upgrade.gui.adddomainpanel.JKStoJKS.sourceCertLabelTooltip");
220             labelAndToolTipStrings[1] = stringManager.getString("upgrade.gui.adddomainpanel.JKStoJKS.targetKeyDBTooltip");
221             labelAndToolTipStrings[2] = stringManager.getString("upgrade.gui.adddomainpanel.JKStoJKS.sourceCertLabel");
222             labelAndToolTipStrings[3] = stringManager.getString("upgrade.gui.adddomainpanel.JKStoJKS.targetKeyDBLabel");
223         }else{
224             labelAndToolTipStrings[0] = stringManager.getString("upgrade.gui.adddomainpanel.NSStoNSS.sourceCertLabelTooltip");
225             labelAndToolTipStrings[1] = stringManager.getString("upgrade.gui.adddomainpanel.NSStoNSS.targetKeyDBTooltip");
226             labelAndToolTipStrings[2] = stringManager.getString("upgrade.gui.adddomainpanel.NSStoNSS.sourceCertLabel");
227             labelAndToolTipStrings[3] = stringManager.getString("upgrade.gui.adddomainpanel.NSStoNSS.targetKeyDBLabel");
228         }
229         sourceCertPwdLabel.setText(labelAndToolTipStrings[2]);
230         sourceCertPwdLabel.setToolTipText(labelAndToolTipStrings[0]);
231         this.addComponetWithConstraints(sourceCertPwdLabel,passwordPanel, 0, 0, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 10, 5, 10), 1.0,0.0);
232         
233         sourceCertPwdField.setToolTipText(labelAndToolTipStrings[0]);
234         this.addComponetWithConstraints(sourceCertPwdField,passwordPanel, 0, 1, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(0, 10, 7, 10), 1.0,0.0);
235         
236         targetKeyDBPwdLabel.setText(labelAndToolTipStrings[3]);
237         targetKeyDBPwdLabel.setToolTipText(labelAndToolTipStrings[1]);
238         this.addComponetWithConstraints(targetKeyDBPwdLabel,passwordPanel, 0, 2, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 10, 5, 10), 1.0,0.0);
239         
240         targetKeyDBPwdField.setToolTipText(labelAndToolTipStrings[1]);
241         this.addComponetWithConstraints(targetKeyDBPwdField,passwordPanel, 0, 3, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(0, 10, 7, 10), 1.0,0.0);
242         
243         return passwordPanel;
244     }
245     
246     private javax.swing.JPanel JavaDoc getButtonsPanel(){
247         javax.swing.JPanel JavaDoc buttonsPanel = new javax.swing.JPanel JavaDoc();
248         javax.swing.JButton JavaDoc okButton = new javax.swing.JButton JavaDoc();
249         javax.swing.JButton JavaDoc cancelButton = new javax.swing.JButton JavaDoc();
250         javax.swing.JButton JavaDoc helpButton = new javax.swing.JButton JavaDoc();
251         buttonsPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
252         
253         okButton.setText(stringManager.getString("upgrade.gui.adddomainpanel.okButtonText"));
254         okButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
255             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
256                 okButtonActionPerformed();
257             }
258         });
259         this.addComponetWithConstraints(okButton, buttonsPanel, 1, 0, 1,1, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 10, 10), 0.0,0.0);
260         
261         cancelButton.setText(stringManager.getString("upgrade.gui.adddomainpanel.cancelButtonText"));
262         cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
263             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
264                 cancelButtonActionPerformed();
265             }
266         });
267         this.addComponetWithConstraints(cancelButton, buttonsPanel, 2, 0, 1,1, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 10, 10), 0.0,0.0);
268         
269         helpButton.setText(stringManager.getString("upgrade.gui.adddomainpanel.helpButtonText"));
270         helpButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
271             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
272                 helpButtonActionPerformed();
273             }
274         });
275         this.addComponetWithConstraints(helpButton, buttonsPanel, 3, 0, 1,1, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 10, 10), 0.0,0.0);
276         this.addComponetWithConstraints(new JPanel(), buttonsPanel, 0, 0, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 5, 10, 10), 1.0,0.0);
277         if(Utils.getHelpBroker() != null)
278             Utils.getHelpBroker().enableHelpOnButton(helpButton, "ADD_DOMAIN_DIALOG", null);
279         return buttonsPanel;
280     }
281     
282     private void helpButtonActionPerformed() {
283         DialogEvent de = new DialogEvent(this, DialogEvent.HELP_ACTION);
284         for(int i=0 ; i<this.dialogListeners.size(); i++){
285             ((DialogListener)dialogListeners.elementAt(i)).dialogProcessed(de);
286         }
287     }
288     
289     private void cancelButtonActionPerformed() {
290         DialogEvent de = new DialogEvent(this, DialogEvent.CANCEL_ACTION);
291         for(int i=0 ; i<this.dialogListeners.size(); i++){
292             ((DialogListener)dialogListeners.elementAt(i)).dialogProcessed(de);
293         }
294     }
295     
296     private void okButtonActionPerformed() {
297         DialogEvent de = new DialogEvent(this, DialogEvent.FINISH_ACTION);
298         Vector data = new Vector();
299         de.setObject(data);
300         data.add(new Integer JavaDoc(this.currentSourceToVersion));
301         data.add(domainsComboBox.getSelectedItem());
302         if(instanceList.isEmpty()) {
303             data.add("server");
304         } else {
305             data.add(instancesComboBox.getSelectedItem());
306         }
307         if((sourceCertPwdField.getPassword() != null) && (!("".equals(new String JavaDoc(sourceCertPwdField.getPassword()).trim())))){
308             data.add(new String JavaDoc(sourceCertPwdField.getPassword()));
309         }
310         if((targetKeyDBPwdField.getPassword() != null) && (!("".equals(new String JavaDoc(targetKeyDBPwdField.getPassword()).trim())))){
311             data.add(new String JavaDoc(targetKeyDBPwdField.getPassword()));
312         }
313         if((this.currentSourceToVersion == this.NSStoJKS) || (this.currentSourceToVersion == this.JKStoNSS)){
314             if((targetCertAuthPwdField.getPassword() != null) && (!("".equals(new String JavaDoc(targetCertAuthPwdField.getPassword()).trim())))){
315                 data.add(new String JavaDoc(targetCertAuthPwdField.getPassword()));
316             }
317         }
318         for(int i=0 ; i<this.dialogListeners.size(); i++){
319             ((DialogListener)dialogListeners.elementAt(i)).dialogProcessed(de);
320         }
321     }
322     
323     private void domainsComboBoxItemStateChanged() {
324         // Add your handling code here:
325
DomainInfo dInfo = (DomainInfo)domainMap.get((String JavaDoc)domainsComboBox.getSelectedItem());
326         instanceList = dInfo.getInstanceNames();
327         if(commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X)){
328             instanceList.remove("admin-server");
329         }
330         instancesComboBox.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(instanceList.toArray()));
331     }
332     
333     private void instancesComboBoxItemStateChanged() {
334         // Add your handling code here:
335
}
336     
337     public static void main(String JavaDoc args[]) {
338         //new AddDomainDialog(new javax.swing.JFrame(), true).show();
339
}
340     public void clearFields(){
341         sourceCertPwdField.setText("");
342         targetKeyDBPwdField.setText("");
343         if(targetCertAuthPwdField != null)
344             targetCertAuthPwdField.setText("");
345     }
346 }
347
Popular Tags