1 23 24 29 30 package com.sun.enterprise.tools.upgrade.gui; 31 32 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 ; 43 import java.awt.GridBagConstraints ; 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 { 49 50 private javax.swing.JComboBox domainsComboBox; 51 private javax.swing.JComboBox instancesComboBox; private javax.swing.JPasswordField targetKeyDBPwdField; 53 private javax.swing.JPasswordField sourceCertPwdField; 54 private javax.swing.JPasswordField 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 domainList; 66 private java.util.List 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 79 public AddDomainDialog(java.awt.Frame 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 95 private void initComponents() { 96 java.awt.GridBagConstraints gridBagConstraints; 97 98 javax.swing.JLabel domainNameLabel = new javax.swing.JLabel (); 99 domainsComboBox = new javax.swing.JComboBox (); 100 instancesComboBox = new javax.swing.JComboBox (); 101 javax.swing.JPanel passwordPanel = null; 102 getContentPane().setLayout(new java.awt.GridBagLayout ()); 103 104 addWindowListener(new java.awt.event.WindowAdapter () { 105 public void windowClosing(java.awt.event.WindowEvent evt) { 106 cancelButtonActionPerformed(); 107 } 108 }); 109 110 domainsComboBox.setModel(new javax.swing.DefaultComboBoxModel (domainList.toArray())); 111 domainsComboBox.addItemListener(new java.awt.event.ItemListener () { 112 public void itemStateChanged(java.awt.event.ItemEvent evt) { 113 domainsComboBoxItemStateChanged(); 114 } 115 }); 116 117 this.addComponetWithConstraints(domainsComboBox,getContentPane(), 0, 1, 1,1, GridBagConstraints.HORIZONTAL, new Insets (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 )domainsComboBox.getSelectedItem()); 121 instanceList = dInfo.getInstanceNames(); 122 instanceList.remove("admin-server"); 123 instancesComboBox.setModel(new javax.swing.DefaultComboBoxModel (instanceList.toArray())); 124 instancesComboBox.addItemListener(new java.awt.event.ItemListener () { 125 public void itemStateChanged(java.awt.event.ItemEvent evt) { 126 instancesComboBoxItemStateChanged(); 127 } 128 }); 129 this.addComponetWithConstraints(instancesComboBox,getContentPane(), 0, 2, 1,1, GridBagConstraints.HORIZONTAL, new Insets (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 (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 (5, 10, 10, 60), 1.0,1.0); 140 141 this.addComponetWithConstraints(getButtonsPanel(),getContentPane(), 0, 4, 1,1, GridBagConstraints.HORIZONTAL, new Insets (0,0,0,0), 1.0,0.0); 142 143 this.setSize(400, 350); 144 } 145 private void addComponetWithConstraints(JComponent compo, java.awt.Container parent, int gx, int gy, int gw, int gh, int fill,java.awt.Insets in, 146 double wx, double wy){ 147 java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints (); 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 passwordPanel = new javax.swing.JPanel (); 158 javax.swing.JLabel sourceCertPwdLabel = new javax.swing.JLabel (); 159 sourceCertPwdField = new javax.swing.JPasswordField (); 160 javax.swing.JLabel targetKeyDBPwdLabel = new javax.swing.JLabel (); 161 targetKeyDBPwdField = new javax.swing.JPasswordField (); 162 targetCertAuthPwdField = new javax.swing.JPasswordField (); 163 javax.swing.JLabel targetCertAuthPwdLabel = new javax.swing.JLabel (); 164 165 passwordPanel.setLayout(new java.awt.GridBagLayout ()); 166 passwordPanel.setBorder(new javax.swing.border.TitledBorder (stringManager.getString("upgrade.gui.adddomainpanel.certTitleBorder"))); 167 168 String [] labelAndToolTipStrings = new String [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 (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 (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 (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 (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 (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 (0, 10, 7, 10), 1.0,0.0); 204 205 return passwordPanel; 206 } 207 private JPanel getPasswordPanelWith2Fields(){ 208 javax.swing.JPanel passwordPanel = new javax.swing.JPanel (); 209 javax.swing.JLabel sourceCertPwdLabel = new javax.swing.JLabel (); 210 sourceCertPwdField = new javax.swing.JPasswordField (); 211 javax.swing.JLabel targetKeyDBPwdLabel = new javax.swing.JLabel (); 212 targetKeyDBPwdField = new javax.swing.JPasswordField (); 213 214 passwordPanel.setLayout(new java.awt.GridBagLayout ()); 215 passwordPanel.setBorder(new javax.swing.border.TitledBorder (stringManager.getString("upgrade.gui.adddomainpanel.certTitleBorder"))); 216 217 String [] labelAndToolTipStrings = new String [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 (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 (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 (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 (0, 10, 7, 10), 1.0,0.0); 242 243 return passwordPanel; 244 } 245 246 private javax.swing.JPanel getButtonsPanel(){ 247 javax.swing.JPanel buttonsPanel = new javax.swing.JPanel (); 248 javax.swing.JButton okButton = new javax.swing.JButton (); 249 javax.swing.JButton cancelButton = new javax.swing.JButton (); 250 javax.swing.JButton helpButton = new javax.swing.JButton (); 251 buttonsPanel.setLayout(new java.awt.GridBagLayout ()); 252 253 okButton.setText(stringManager.getString("upgrade.gui.adddomainpanel.okButtonText")); 254 okButton.addActionListener(new java.awt.event.ActionListener () { 255 public void actionPerformed(java.awt.event.ActionEvent evt) { 256 okButtonActionPerformed(); 257 } 258 }); 259 this.addComponetWithConstraints(okButton, buttonsPanel, 1, 0, 1,1, GridBagConstraints.NONE, new Insets (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 () { 263 public void actionPerformed(java.awt.event.ActionEvent evt) { 264 cancelButtonActionPerformed(); 265 } 266 }); 267 this.addComponetWithConstraints(cancelButton, buttonsPanel, 2, 0, 1,1, GridBagConstraints.NONE, new Insets (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 () { 271 public void actionPerformed(java.awt.event.ActionEvent evt) { 272 helpButtonActionPerformed(); 273 } 274 }); 275 this.addComponetWithConstraints(helpButton, buttonsPanel, 3, 0, 1,1, GridBagConstraints.NONE, new Insets (5, 5, 10, 10), 0.0,0.0); 276 this.addComponetWithConstraints(new JPanel(), buttonsPanel, 0, 0, 1,1, GridBagConstraints.HORIZONTAL, new Insets (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 (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 (sourceCertPwdField.getPassword()).trim())))){ 308 data.add(new String (sourceCertPwdField.getPassword())); 309 } 310 if((targetKeyDBPwdField.getPassword() != null) && (!("".equals(new String (targetKeyDBPwdField.getPassword()).trim())))){ 311 data.add(new String (targetKeyDBPwdField.getPassword())); 312 } 313 if((this.currentSourceToVersion == this.NSStoJKS) || (this.currentSourceToVersion == this.JKStoNSS)){ 314 if((targetCertAuthPwdField.getPassword() != null) && (!("".equals(new String (targetCertAuthPwdField.getPassword()).trim())))){ 315 data.add(new String (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 DomainInfo dInfo = (DomainInfo)domainMap.get((String )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 (instanceList.toArray())); 331 } 332 333 private void instancesComboBoxItemStateChanged() { 334 } 336 337 public static void main(String args[]) { 338 } 340 public void clearFields(){ 341 sourceCertPwdField.setText(""); 342 targetKeyDBPwdField.setText(""); 343 if(targetCertAuthPwdField != null) 344 targetCertAuthPwdField.setText(""); 345 } 346 } 347 | Popular Tags |