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