1 19 22 23 package org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards; 24 25 import java.util.Vector ; 26 import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePair; 27 28 import org.openide.DialogDisplayer; 29 import org.openide.NotifyDescriptor; 30 31 35 public class PropertiesTableModel extends javax.swing.table.AbstractTableModel { 36 private static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org.netbeans.modules.j2ee.sun.ws7.serverresources.wizards.Bundle"); private Vector data = null; 38 39 public PropertiesTableModel(ResourceConfigData data) { 40 this.data = data.getProperties(); } 42 43 public int getColumnCount() { 44 return 2; 45 } 46 47 public int getRowCount() { 48 return data.size(); 49 } 50 51 public Object getValueAt(int rowIndex, int columnIndex) { 52 NameValuePair pair = (NameValuePair)data.elementAt(rowIndex); 53 if (columnIndex == 0) 54 return pair.getParamName(); 55 else 56 return pair.getParamValue(); 57 } 58 59 public String getColumnName(int col) { 60 if (0 == col) 61 return bundle.getString("COL_HEADER_NAME"); if (1 == col) 63 return bundle.getString("COL_HEADER_VALUE"); throw new RuntimeException (bundle.getString("COL_HEADER_ERR_ERR_ERR")); } 66 67 public boolean isCellEditable(int row, int col) { 68 return true; 69 } 70 71 public void setValueAt(Object value, int row, int col) { 72 if((row >=0) && (row < data.size())){ 73 NameValuePair property = (NameValuePair)data.elementAt(row); 74 if (col == 0){ 75 if(! isNotUnique((String )value)) 76 property.setParamName((String )value); 77 }else if (col == 1) 78 property.setParamValue((String )value); 79 } 80 fireTableDataChanged(); 81 } 82 83 private boolean isNotUnique(String newVal){ 85 for(int i=0; i<data.size()-1; i++){ 86 NameValuePair pair = (NameValuePair)data.elementAt(i); 87 if(pair.getParamName().equals(newVal)){ 88 NotifyDescriptor d = new NotifyDescriptor.Message(bundle.getString("Err_DuplicateValue"), NotifyDescriptor.INFORMATION_MESSAGE); 89 DialogDisplayer.getDefault().notify(d); 90 return true; 91 } 92 } 93 return false; 94 } 95 96 public void setData(ResourceConfigData data) { 97 this.data = data.getProperties(); 98 fireTableDataChanged(); 99 } 100 101 private boolean changed = false; 102 } 103 | Popular Tags |