1 23 24 29 30 package com.sun.enterprise.tools.upgrade.gui; 31 32 36 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.common.*; 41 import com.sun.enterprise.tools.upgrade.logging.*; 42 import javax.swing.*; 43 import java.util.*; 44 import java.awt.Insets ; 45 import java.awt.GridBagConstraints ; 46 47 public class DomainPathSelectionDialog extends javax.swing.JDialog { 48 49 private StringManager stringManager = StringManager.getManager("com.sun.enterprise.tools.upgrade.gui"); 50 private DomainPathTableModel domainPathTableModel= null; 51 private JTable domainPathTable = null; 52 private JScrollPane domainPathTableScrollPane = null; 53 private JPanel domainPathsPanel = null; 54 private JPanel addRemoveButtonsPanel = null; 55 private JButton addDomainPathButton = null; 56 private JButton removeDomainPathButton = null; 57 58 private JFileChooser fileChooser = null; 59 60 public static final int OK_ACTION = 2; 61 public static final int CANCEL_ACTION = 1; 62 public static final int HELP_ACTION = 3; 63 public int USER_ACTION = 1; 64 65 private java.util.Vector dialogListeners = new java.util.Vector (); 66 67 68 public DomainPathSelectionDialog() { 69 this.setTitle(stringManager.getString("upgrade.gui.domainPanel.dialogTitle")); 70 this.initComponents(); 71 super.setModal(true); 72 } 73 74 private void initComponents(){ 75 this.getContentPane().setLayout(new java.awt.GridBagLayout ()); 76 javax.swing.JSeparator separatorPanel = new javax.swing.JSeparator (); 77 78 this.addComponetWithConstraints(getDomainPathsPanel(), this.getContentPane(), 0, 0,1,1, GridBagConstraints.BOTH, new Insets (10, 0, 0, 5), 1.0,1.0); 79 this.addComponetWithConstraints(separatorPanel, this.getContentPane(), 0, 1,1,1, GridBagConstraints.HORIZONTAL, new Insets (5, 5, 0, 5), 1.0,0.0); 80 this.addComponetWithConstraints(getButtonsPanel(), this.getContentPane(), 0, 2,1,1, GridBagConstraints.HORIZONTAL, new Insets (5, 0, 0, 0), 1.0,0.0); 81 getDomainPathTableScrollPane().setViewportView(getDomainPathTable()); 82 83 getDomainPathTable().setModel(this.getDomainPathTableModel()); 84 getDomainPathTable().createDefaultColumnsFromModel(); 85 86 this.setSize(500, 350); 87 } 88 private javax.swing.JPanel getDomainPathsPanel() { 89 if (domainPathsPanel == null) { 90 domainPathsPanel = new javax.swing.JPanel (); 91 domainPathsPanel.setName("domainPathsPanel"); 92 domainPathsPanel.setLayout(new java.awt.GridBagLayout ()); 93 94 JLabel tableTitleLabel = new JLabel(); 95 tableTitleLabel.setText(stringManager.getString("upgrade.gui.domainPanel.tableTitleName")); 96 this.addComponetWithConstraints(tableTitleLabel, domainPathsPanel, 0, 0,3,1, GridBagConstraints.NONE, new Insets (10, 10, 5, 0), 0.0,0.0); 97 this.addComponetWithConstraints(getDomainPathTableScrollPane(), domainPathsPanel, 0, 1,2,1, GridBagConstraints.BOTH, new Insets (5, 10, 5, 0), 1.0,1.0); 98 this.addComponetWithConstraints(getaddRemoveButtonsPanel(), domainPathsPanel, 2, 1,1,1, GridBagConstraints.VERTICAL, new Insets (5, 0, 5, 0), 0.0,1.0); 99 } 100 return domainPathsPanel; 101 } 102 private javax.swing.JTable getDomainPathTable() { 103 if (domainPathTable == null) { 104 domainPathTable = new javax.swing.JTable (); 105 domainPathTable.setName("domainPathTable"); 106 getDomainPathTableScrollPane().setColumnHeaderView(domainPathTable.getTableHeader()); 107 getDomainPathTableScrollPane().getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE); 108 domainPathTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); 109 domainPathTable.setAutoCreateColumnsFromModel(true); 110 domainPathTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); 111 domainPathTable.setAutoCreateColumnsFromModel(true); 112 113 ListSelectionModel rowSM = domainPathTable.getSelectionModel(); 114 rowSM.addListSelectionListener(new javax.swing.event.ListSelectionListener () { 115 public void valueChanged(javax.swing.event.ListSelectionEvent e) { 116 if (e.getValueIsAdjusting()) return; 118 119 ListSelectionModel lsm = (ListSelectionModel)e.getSource(); 120 enableDisableRemoveButton(domainPathTable,getremoveDomainPathButton()); 121 } 122 }); 123 final DefaultCellEditor editor = (DefaultCellEditor)domainPathTable.getDefaultEditor(String .class); 124 editor.getComponent().addKeyListener(new java.awt.event.KeyAdapter (){ 125 public void keyReleased(java.awt.event.KeyEvent ke){ 126 try{ 127 getDomainPathTableModel().setValueAt(((JTextField)editor.getComponent()).getText().trim(),domainPathTable.getEditingRow(),0); 128 }catch(Exception e){ 129 } 130 } 131 132 }); 133 134 } 135 return domainPathTable; 136 } 137 private javax.swing.JScrollPane getDomainPathTableScrollPane() { 138 if (domainPathTableScrollPane == null) { 139 domainPathTableScrollPane = new javax.swing.JScrollPane (); 140 domainPathTableScrollPane.setName("getDomainPathTable"); 141 domainPathTableScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 142 domainPathTableScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 143 domainPathTableScrollPane.setMaximumSize(new java.awt.Dimension (21, 20)); 144 domainPathTableScrollPane.setPreferredSize(new java.awt.Dimension (21, 20)); 145 domainPathTableScrollPane.setMinimumSize(new java.awt.Dimension (21, 20)); 146 domainPathTableScrollPane.setViewportView(getDomainPathTable()); 147 } 148 return domainPathTableScrollPane; 149 } 150 private javax.swing.JPanel getaddRemoveButtonsPanel() { 151 if (addRemoveButtonsPanel == null) { 152 addRemoveButtonsPanel = new javax.swing.JPanel (); 153 addRemoveButtonsPanel.setName("addRemoveButtonsPanel"); 154 addRemoveButtonsPanel.setLayout(new java.awt.GridBagLayout ()); 155 156 this.addComponetWithConstraints(getaddDomainPathButton(), addRemoveButtonsPanel, 0, 0,1,1, GridBagConstraints.NONE, new Insets (10, 5, 5, 5), 0.0,0.0); 157 this.addComponetWithConstraints(getremoveDomainPathButton(), addRemoveButtonsPanel, 0, 1,1,1, GridBagConstraints.NONE, new Insets (5, 5, 5, 5), 0.0,0.0); 158 } 159 return addRemoveButtonsPanel; 160 } 161 private javax.swing.JButton getaddDomainPathButton() { 162 if (addDomainPathButton == null) { 163 addDomainPathButton = new javax.swing.JButton (); 164 addDomainPathButton.setName("addDomainPathButton"); 165 addDomainPathButton.setText(stringManager.getString("upgrade.gui.domainPanel.addButtonText")); 166 addDomainPathButton.addActionListener(new java.awt.event.ActionListener (){ 167 public void actionPerformed(java.awt.event.ActionEvent e) { 168 addDomainPathAction(); 169 } 170 }); 171 } 172 return addDomainPathButton; 173 } 174 private javax.swing.JButton getremoveDomainPathButton() { 175 if (removeDomainPathButton == null) { 176 removeDomainPathButton = new javax.swing.JButton (); 177 removeDomainPathButton.setName("removeDomainPathButton"); 178 removeDomainPathButton.setText(stringManager.getString("upgrade.gui.domainPanel.deleteButtonText")); 179 removeDomainPathButton.addActionListener(new java.awt.event.ActionListener (){ 180 public void actionPerformed(java.awt.event.ActionEvent e) { 181 removeDomainPathAction(); 182 } 183 }); 184 } 185 return removeDomainPathButton; 186 } 187 private javax.swing.JPanel getButtonsPanel(){ 188 javax.swing.JPanel buttonsPanel = new javax.swing.JPanel (); 189 javax.swing.JButton okButton = new javax.swing.JButton (); 190 javax.swing.JButton cancelButton = new javax.swing.JButton (); 191 javax.swing.JButton helpButton = new javax.swing.JButton (); 192 buttonsPanel.setLayout(new java.awt.GridBagLayout ()); 193 194 okButton.setText(stringManager.getString("upgrade.gui.adddomainpanel.okButtonText")); 195 okButton.addActionListener(new java.awt.event.ActionListener () { 196 public void actionPerformed(java.awt.event.ActionEvent evt) { 197 okButtonActionPerformed(); 198 } 199 }); 200 this.addComponetWithConstraints(okButton, buttonsPanel, 1, 0, 1,1, GridBagConstraints.NONE, new Insets (5, 5, 10, 10), 0.0,0.0); 201 202 cancelButton.setText(stringManager.getString("upgrade.gui.adddomainpanel.cancelButtonText")); 203 cancelButton.addActionListener(new java.awt.event.ActionListener () { 204 public void actionPerformed(java.awt.event.ActionEvent evt) { 205 cancelButtonActionPerformed(); 206 } 207 }); 208 this.addComponetWithConstraints(cancelButton, buttonsPanel, 2, 0, 1,1, GridBagConstraints.NONE, new Insets (5, 5, 10, 10), 0.0,0.0); 209 210 helpButton.setText(stringManager.getString("upgrade.gui.adddomainpanel.helpButtonText")); 211 helpButton.addActionListener(new java.awt.event.ActionListener () { 212 public void actionPerformed(java.awt.event.ActionEvent evt) { 213 helpButtonActionPerformed(); 214 } 215 }); 216 this.addComponetWithConstraints(helpButton, buttonsPanel, 3, 0, 1,1, GridBagConstraints.NONE, new Insets (5, 5, 10, 10), 0.0,0.0); 217 this.addComponetWithConstraints(new JPanel(), buttonsPanel, 0, 0, 1,1, GridBagConstraints.HORIZONTAL, new Insets (5, 5, 10, 10), 1.0,0.0); 218 if(Utils.getHelpBroker() != null) 219 Utils.getHelpBroker().enableHelpOnButton(helpButton, "ADD_DOMAIN_DIALOG", null); 220 return buttonsPanel; 221 } 222 private void addComponetWithConstraints(JComponent compo, java.awt.Container parent, int gx, int gy, int gw, int gh, int fill,java.awt.Insets in, 223 double wx, double wy){ 224 java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints (); 225 gridBagConstraints.gridx = gx; gridBagConstraints.gridy = gy; 226 gridBagConstraints.gridwidth = gw; gridBagConstraints.gridheight = gh; 227 gridBagConstraints.fill = fill; 228 gridBagConstraints.insets = in; 229 gridBagConstraints.weightx = wx; 230 gridBagConstraints.weighty = wy; 231 parent.add(compo, gridBagConstraints); 232 } 233 private void helpButtonActionPerformed() { 234 this.USER_ACTION = HELP_ACTION; 235 240 } 241 242 private void cancelButtonActionPerformed() { 243 this.USER_ACTION = CANCEL_ACTION; 244 this.dispose(); 245 249 } 250 251 private void okButtonActionPerformed() { 252 this.USER_ACTION = OK_ACTION; 253 this.dispose(); 254 } 255 public DomainPathTableModel getDomainPathTableModel(){ 256 if(this.domainPathTableModel == null){ 257 domainPathTableModel = new DomainPathTableModel(this); 258 } 259 return domainPathTableModel; 260 } 261 public void addDomainPathAction() { 262 int returnedValue = getfileChooser().showOpenDialog(this); 263 if(returnedValue == javax.swing.JFileChooser.APPROVE_OPTION){ 264 getDomainPathTableModel().addDomainPath(String.valueOf(getfileChooser().getSelectedFile())); 265 } 266 } 267 private javax.swing.JFileChooser getfileChooser() { 268 if (fileChooser == null) { 269 fileChooser = new javax.swing.JFileChooser (); 270 fileChooser.setName("fileChooser"); 271 fileChooser.setBounds(668, 49, 500, 300); 272 fileChooser.setDialogTitle(stringManager.getString("upgrade.gui.certpanel.chooseFile")); 273 fileChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY); 274 } 275 return fileChooser; 276 } 277 public void removeDomainPathAction() { 278 279 int rows[] = getDomainPathTable().getSelectedRows(); 280 String [] rowPropNames = new String [rows.length]; 281 int option = 282 javax.swing.JOptionPane.showConfirmDialog( 283 this, 284 stringManager.getString("upgrade.gui.domainPanel.removeConfirmMsg"), 285 stringManager.getString("upgrade.gui.domainPanel.removeConfirmTitle"), 286 javax.swing.JOptionPane.YES_NO_OPTION, 287 javax.swing.JOptionPane.QUESTION_MESSAGE); 288 if (option == javax.swing.JOptionPane.NO_OPTION) { 289 return; 290 } 291 292 for (int i = 0; i < rows.length; i++) { 293 rowPropNames[i] = 294 (String )getDomainPathTableModel().getDomainPath(rows[i]); 295 } 296 for (int i = 0; i < rows.length; i++) { 297 getDomainPathTableModel().removeDomainPath(rowPropNames[i]); 298 } 299 getDomainPathTable().clearSelection(); 301 enableDisableRemoveButton(getDomainPathTable(), getremoveDomainPathButton()); 302 } 303 304 class DomainPathTableModel extends javax.swing.table.AbstractTableModel { 305 private Vector domainPaths = new Vector(0); 306 private String columnNames[] = null; 307 private DomainPathSelectionDialog domainPathSelectionDialog; 308 309 private StringManager stringManager = StringManager.getManager("com.sun.enterprise.tools.upgrade.gui"); 310 public DomainPathTableModel(DomainPathSelectionDialog cdp) { 311 super(); 312 this.domainPathSelectionDialog = cdp; 313 columnNames = new String []{stringManager.getString("upgrade.gui.domainPanel.tableColumnName")}; 314 } 315 public int getColumnCount() { 316 return columnNames.length; 317 } 318 public java.lang.String getColumnName(int column) { 319 return columnNames[column]; 320 } 321 public int getRowCount() { 322 return domainPaths.size(); 323 } 324 public boolean isCellEditable(int row, int col) { 325 if (col == 0) { 328 return true; 329 } else { 330 return false; 331 } 332 } 333 public void setValueAt(Object value, int row, int col) { 334 335 if ( value instanceof String ) { 336 if(row < domainPaths.size()) 337 domainPaths.setElementAt(value,row); 338 } 339 } 340 public Class getColumnClass(int c) { 341 return getValueAt(0, c).getClass(); 342 } 343 public Object getValueAt(int row, int col) { 344 String rowEle = (String ) domainPaths.elementAt(row); 345 String ret = ""; 346 switch (col) { 347 case 0: 348 ret = rowEle; 350 break; 351 352 } 353 return ret; 354 355 } 356 public Vector getDomainPaths(){ 357 return this.domainPaths; 358 } 359 public void setDomainPaths(Vector v){ 360 this.domainPaths=v; 361 } 362 public void addDomainPath(String ele){ 363 if(ele != null){ 364 if(getDomainPath(ele) == null) 365 this.domainPaths.addElement(ele); 366 } 367 fireTableDataChanged(); 368 domainPathSelectionDialog.processDialogEvent(); 369 } 370 public void removeDomainPath(String ele){ 371 if(ele != null){ 372 this.domainPaths.removeElement(ele); 373 } 374 fireTableDataChanged(); 375 domainPathSelectionDialog.processDialogEvent(); 376 } 377 public String getDomainPath(int rowNo){ 378 if(rowNo < domainPaths.size()){ 379 return (String )domainPaths.elementAt(rowNo); 380 } 381 else return null; 382 } 383 public String getDomainPath(String propName){ 384 String ele1 = null; 385 boolean found = false; 386 if(propName != null){ 387 for(int i=0; i<domainPaths.size(); i++){ 388 ele1 = (String )domainPaths.elementAt(i); 389 if(propName.equals(ele1)){ 390 found = true; 391 break; 392 } 393 } 394 } 395 if(found) 396 return ele1; 397 else 398 return null; 399 } 400 401 } 402 public void enableDisableRemoveButton(JTable table,JButton removeButton) { 403 if (table.getSelectionModel().isSelectionEmpty()) { 404 removeButton.setEnabled(false); 405 406 } else { 407 if (table.getSelectedRowCount() > 1) { 408 } else { 410 removeButton.setEnabled(true); 411 } 412 } 413 } 414 public void addDialogListener(DialogListener listener){ 415 this.dialogListeners.addElement(listener); 416 } 417 public void removeDialogListener(DialogListener listener){ 418 this.dialogListeners.removeElement(listener); 419 } 420 private void processDialogEvent(){ 421 DialogEvent de = new DialogEvent(this, DialogEvent.CHANGE_ACTION); 422 for(int i=0 ; i<this.dialogListeners.size(); i++){ 423 ((DialogListener)dialogListeners.elementAt(i)).dialogProcessed(de); 424 } 425 } 426 427 } 428 | Popular Tags |