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 45 public class ClusterDetailsPanel extends javax.swing.JPanel { 46 47 private StringManager stringManager = StringManager.getManager("com.sun.enterprise.tools.upgrade.gui"); 48 private ClusterFilesTableModel clusterFilesTableModel= null; 49 private JTable clusterFilesTable = null; 50 private JScrollPane clusterFilesTableScrollPane = null; 51 private JPanel clusterFilesPanel = null; 52 private JPanel addRemoveEditHomeInterfacePanel = null; 53 private JButton addClusterFileButton = null; 54 private JButton removeClusterFileButton = null; 55 56 private JFileChooser fileChooser = null; 57 58 private java.util.Vector dialogListeners = new java.util.Vector (); 59 60 61 public ClusterDetailsPanel() { 62 this.initComponents(); 63 } 64 private void initComponents(){ 65 this.setLayout(new java.awt.GridBagLayout ()); 66 67 java.awt.GridBagConstraints constraints = new java.awt.GridBagConstraints (); 68 constraints.gridx = 0; constraints.gridy = 0; 69 constraints.gridwidth = 1; 70 constraints.fill = java.awt.GridBagConstraints.BOTH; 71 constraints.weightx = 1.0; 72 constraints.weighty = 1.0; 73 constraints.insets = new java.awt.Insets (0, 0, 0, 0); 74 this.add(getClusterFilesPanel(), constraints); 75 76 getClusterFilesTableScrollPane().setViewportView(getClusterFilesTable()); 77 78 getClusterFilesTable().setModel(this.getClusterFilesTableModel()); 79 getClusterFilesTable().createDefaultColumnsFromModel(); 80 81 } 82 private javax.swing.JPanel getClusterFilesPanel() { 83 if (clusterFilesPanel == null) { 84 clusterFilesPanel = new javax.swing.JPanel (); 85 clusterFilesPanel.setName("clusterFilesPanel"); 86 clusterFilesPanel.setLayout(new java.awt.GridBagLayout ()); 87 88 JLabel tableTitleLabel = new JLabel(); 89 tableTitleLabel.setText(stringManager.getString("upgrade.gui.clusterPanel.tableTitleName")); 90 java.awt.GridBagConstraints labelConstraints = new java.awt.GridBagConstraints (); 91 labelConstraints.gridx = 0; labelConstraints.gridy = 0; 92 labelConstraints.gridwidth = 3; 93 labelConstraints.fill = java.awt.GridBagConstraints.NONE; 94 labelConstraints.insets = new java.awt.Insets (10, 10, 5, 0); 95 clusterFilesPanel.add(tableTitleLabel, labelConstraints); 96 97 java.awt.GridBagConstraints constraintsClusterScrollPane1 = new java.awt.GridBagConstraints (); 98 constraintsClusterScrollPane1.gridx = 0; constraintsClusterScrollPane1.gridy = 1; 99 constraintsClusterScrollPane1.gridwidth = 2; 100 constraintsClusterScrollPane1.fill = java.awt.GridBagConstraints.BOTH; 101 constraintsClusterScrollPane1.weightx = 1.0; 102 constraintsClusterScrollPane1.weighty = 1.0; 103 constraintsClusterScrollPane1.insets = new java.awt.Insets (5, 10, 5, 0); 104 clusterFilesPanel.add(getClusterFilesTableScrollPane(), constraintsClusterScrollPane1); 105 106 java.awt.GridBagConstraints constraintsaddRemoveEditHomeInterfacePanel1 = new java.awt.GridBagConstraints (); 107 constraintsaddRemoveEditHomeInterfacePanel1.gridx = 2; constraintsaddRemoveEditHomeInterfacePanel1.gridy = 1; 108 constraintsaddRemoveEditHomeInterfacePanel1.fill = java.awt.GridBagConstraints.VERTICAL; 109 constraintsaddRemoveEditHomeInterfacePanel1.weighty = 1.0; 110 constraintsaddRemoveEditHomeInterfacePanel1.insets = new java.awt.Insets (5, 0, 5, 0); 111 clusterFilesPanel.add(getaddRemoveEditHomeInterfacePanel(), constraintsaddRemoveEditHomeInterfacePanel1); 112 } 113 return clusterFilesPanel; 114 } 115 private javax.swing.JTable getClusterFilesTable() { 116 if (clusterFilesTable == null) { 117 clusterFilesTable = new javax.swing.JTable (); 118 clusterFilesTable.setName("clusterFilesTable"); 119 getClusterFilesTableScrollPane().setColumnHeaderView(clusterFilesTable.getTableHeader()); 120 getClusterFilesTableScrollPane().getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE); 121 clusterFilesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); 122 clusterFilesTable.setAutoCreateColumnsFromModel(true); 123 clusterFilesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); 124 clusterFilesTable.setAutoCreateColumnsFromModel(true); 125 126 ListSelectionModel rowSM = clusterFilesTable.getSelectionModel(); 127 rowSM.addListSelectionListener(new javax.swing.event.ListSelectionListener () { 128 public void valueChanged(javax.swing.event.ListSelectionEvent e) { 129 if (e.getValueIsAdjusting()) return; 131 132 ListSelectionModel lsm = (ListSelectionModel)e.getSource(); 133 enableDisableRemoveButton(clusterFilesTable,getremoveClusterFileButton()); 134 } 135 }); 136 final DefaultCellEditor editor = (DefaultCellEditor)clusterFilesTable.getDefaultEditor(String .class); 137 editor.getComponent().addKeyListener(new java.awt.event.KeyAdapter (){ 138 public void keyReleased(java.awt.event.KeyEvent ke){ 139 try{ 140 getClusterFilesTableModel().setValueAt(((JTextField)editor.getComponent()).getText().trim(),clusterFilesTable.getEditingRow(),0); 141 }catch(Exception e){ 142 } 143 } 144 145 }); 146 147 } 148 return clusterFilesTable; 149 } 150 private javax.swing.JScrollPane getClusterFilesTableScrollPane() { 151 if (clusterFilesTableScrollPane == null) { 152 clusterFilesTableScrollPane = new javax.swing.JScrollPane (); 153 clusterFilesTableScrollPane.setName("getClusterFilesTable"); 154 clusterFilesTableScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 155 clusterFilesTableScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 156 clusterFilesTableScrollPane.setMaximumSize(new java.awt.Dimension (21, 20)); 157 clusterFilesTableScrollPane.setPreferredSize(new java.awt.Dimension (21, 20)); 158 clusterFilesTableScrollPane.setMinimumSize(new java.awt.Dimension (21, 20)); 159 clusterFilesTableScrollPane.setViewportView(getClusterFilesTable()); 160 } 161 return clusterFilesTableScrollPane; 162 } 163 private javax.swing.JPanel getaddRemoveEditHomeInterfacePanel() { 164 if (addRemoveEditHomeInterfacePanel == null) { 165 addRemoveEditHomeInterfacePanel = new javax.swing.JPanel (); 166 addRemoveEditHomeInterfacePanel.setName("addRemoveEditHomeInterfacePanel"); 167 addRemoveEditHomeInterfacePanel.setLayout(new java.awt.GridBagLayout ()); 168 169 java.awt.GridBagConstraints constraintsaddClusterFileButton = new java.awt.GridBagConstraints (); 170 constraintsaddClusterFileButton.gridx = 0; constraintsaddClusterFileButton.gridy = 0; 171 constraintsaddClusterFileButton.insets = new java.awt.Insets (10, 5, 5, 5); 172 addRemoveEditHomeInterfacePanel.add(getaddClusterFileButton(), constraintsaddClusterFileButton); 173 174 java.awt.GridBagConstraints constraintsremoveClusterFileButton = new java.awt.GridBagConstraints (); 175 constraintsremoveClusterFileButton.gridx = 0; constraintsremoveClusterFileButton.gridy = 1; 176 constraintsremoveClusterFileButton.insets = new java.awt.Insets (5, 5, 5, 5); 177 addRemoveEditHomeInterfacePanel.add(getremoveClusterFileButton(), constraintsremoveClusterFileButton); 178 } 179 return addRemoveEditHomeInterfacePanel; 180 } 181 private javax.swing.JButton getaddClusterFileButton() { 182 if (addClusterFileButton == null) { 183 addClusterFileButton = new javax.swing.JButton (); 184 addClusterFileButton.setName("addClusterFileButton"); 185 addClusterFileButton.setText(stringManager.getString("upgrade.gui.clusterPanel.addButtonText")); 186 addClusterFileButton.addActionListener(new java.awt.event.ActionListener (){ 187 public void actionPerformed(java.awt.event.ActionEvent e) { 188 addClusterFileAction(); 189 } 190 }); 191 } 192 return addClusterFileButton; 193 } 194 private javax.swing.JButton getremoveClusterFileButton() { 195 if (removeClusterFileButton == null) { 196 removeClusterFileButton = new javax.swing.JButton (); 197 removeClusterFileButton.setName("removeClusterFileButton"); 198 removeClusterFileButton.setText(stringManager.getString("upgrade.gui.clusterPanel.deleteButtonText")); 199 removeClusterFileButton.addActionListener(new java.awt.event.ActionListener (){ 200 public void actionPerformed(java.awt.event.ActionEvent e) { 201 removeClusterFileAction(); 202 } 203 }); 204 } 205 return removeClusterFileButton; 206 } 207 public ClusterFilesTableModel getClusterFilesTableModel(){ 208 if(this.clusterFilesTableModel == null){ 209 clusterFilesTableModel = new ClusterFilesTableModel(this); 210 } 211 return clusterFilesTableModel; 212 } 213 public void addClusterFileAction() { 214 int returnedValue = getfileChooser().showOpenDialog(this); 215 if(returnedValue == javax.swing.JFileChooser.APPROVE_OPTION){ 216 getClusterFilesTableModel().addClusterFile(String.valueOf(getfileChooser().getSelectedFile())); 217 } 218 } 219 private javax.swing.JFileChooser getfileChooser() { 220 if (fileChooser == null) { 221 fileChooser = new javax.swing.JFileChooser (); 222 fileChooser.setName("fileChooser"); 223 fileChooser.setBounds(668, 49, 500, 300); 224 fileChooser.setDialogTitle(stringManager.getString("upgrade.gui.certpanel.chooseFile")); 225 } 226 return fileChooser; 227 } 228 public void removeClusterFileAction() { 229 230 int rows[] = getClusterFilesTable().getSelectedRows(); 231 String [] rowPropNames = new String [rows.length]; 232 int option = 233 javax.swing.JOptionPane.showConfirmDialog( 234 this, 235 stringManager.getString("upgrade.gui.clusterPanel.removeConfirmMsg"), 236 stringManager.getString("upgrade.gui.clusterPanel.removeConfirmTitle"), 237 javax.swing.JOptionPane.YES_NO_OPTION, 238 javax.swing.JOptionPane.QUESTION_MESSAGE); 239 if (option == javax.swing.JOptionPane.NO_OPTION) { 240 return; 241 } 242 243 for (int i = 0; i < rows.length; i++) { 244 rowPropNames[i] = 245 (String )getClusterFilesTableModel().getClusterFile(rows[i]); 246 } 247 for (int i = 0; i < rows.length; i++) { 248 getClusterFilesTableModel().removeClusterFile(rowPropNames[i]); 249 } 250 getClusterFilesTable().clearSelection(); 252 enableDisableRemoveButton(getClusterFilesTable(), getremoveClusterFileButton()); 253 } 254 255 class ClusterFilesTableModel extends javax.swing.table.AbstractTableModel { 256 private Vector clusterFiles = new Vector(0); 257 private String columnNames[] = null; 258 private ClusterDetailsPanel clusterDetailsPanel; 259 260 private StringManager stringManager = StringManager.getManager("com.sun.enterprise.tools.upgrade.gui"); 261 public ClusterFilesTableModel(ClusterDetailsPanel cdp) { 262 super(); 263 this.clusterDetailsPanel = cdp; 264 columnNames = new String []{stringManager.getString("upgrade.gui.clusterPanel.tableColumnName")}; 265 } 266 public int getColumnCount() { 267 return columnNames.length; 268 } 269 public java.lang.String getColumnName(int column) { 270 return columnNames[column]; 271 } 272 public int getRowCount() { 273 return clusterFiles.size(); 274 } 275 public boolean isCellEditable(int row, int col) { 276 if (col == 0) { 279 return true; 280 } else { 281 return false; 282 } 283 } 284 public void setValueAt(Object value, int row, int col) { 285 286 if ( value instanceof String ) { 287 if(row < clusterFiles.size()) 288 clusterFiles.setElementAt(value,row); 289 } 290 } 291 public Class getColumnClass(int c) { 292 return getValueAt(0, c).getClass(); 293 } 294 public Object getValueAt(int row, int col) { 295 String rowEle = (String ) clusterFiles.elementAt(row); 297 String ret = ""; 298 switch (col) { 299 case 0: 300 ret = rowEle; 302 break; 303 304 } 305 return ret; 306 307 } 308 public Vector getClusterFiles(){ 309 return this.clusterFiles; 310 } 311 public void setClusterFiles(Vector v){ 312 this.clusterFiles=v; 313 } 314 public void addClusterFile(String ele){ 315 if(ele != null){ 316 if(getClusterFile(ele) == null) 317 this.clusterFiles.addElement(ele); 318 } 319 fireTableDataChanged(); 320 clusterDetailsPanel.processDialogEvent(); 321 } 322 public void removeClusterFile(String ele){ 323 if(ele != null){ 324 this.clusterFiles.removeElement(ele); 325 } 326 fireTableDataChanged(); 327 clusterDetailsPanel.processDialogEvent(); 328 } 329 public String getClusterFile(int rowNo){ 330 if(rowNo < clusterFiles.size()){ 331 return (String )clusterFiles.elementAt(rowNo); 332 } 333 else return null; 334 } 335 public String getClusterFile(String propName){ 336 String ele1 = null; 337 boolean found = false; 338 if(propName != null){ 339 for(int i=0; i<clusterFiles.size(); i++){ 340 ele1 = (String )clusterFiles.elementAt(i); 341 if(propName.equals(ele1)){ 342 found = true; 343 break; 344 } 345 } 346 } 347 if(found) 348 return ele1; 349 else 350 return null; 351 } 352 353 } 354 public void enableDisableRemoveButton(JTable table,JButton removeButton) { 355 if (table.getSelectionModel().isSelectionEmpty()) { 356 removeButton.setEnabled(false); 359 360 } else { 361 if (table.getSelectedRowCount() > 1) { 363 } else { 365 removeButton.setEnabled(true); 366 } 368 369 } 371 } 372 public void addDialogListener(DialogListener listener){ 373 this.dialogListeners.addElement(listener); 374 } 375 public void removeDialogListener(DialogListener listener){ 376 this.dialogListeners.removeElement(listener); 377 } 378 private void processDialogEvent(){ 379 DialogEvent de = new DialogEvent(this, DialogEvent.CHANGE_ACTION); 380 for(int i=0 ; i<this.dialogListeners.size(); i++){ 381 ((DialogListener)dialogListeners.elementAt(i)).dialogProcessed(de); 382 } 383 } 384 385 } 386 | Popular Tags |