1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 27 import org.netbeans.modules.j2ee.dd.api.common.EnvEntry; 28 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 29 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean; 30 import org.openide.util.NbBundle; 31 32 public class EnvEntryTableModel extends DDBeanTableModel 33 { 34 private static final String [] columnNames = { 35 NbBundle.getMessage(EnvEntryTableModel.class,"TTL_EnvEntryName"), 36 NbBundle.getMessage(EnvEntryTableModel.class,"TTL_EnvEntryType"), 37 NbBundle.getMessage(EnvEntryTableModel.class,"TTL_EnvEntryValue"), 38 NbBundle.getMessage(EnvEntryTableModel.class,"TTL_Description") 39 }; 40 41 protected String [] getColumnNames() { 42 return columnNames; 43 } 44 45 public void setValueAt(Object value, int row, int column) 46 { 47 EnvEntry param = (EnvEntry)getChildren().get(row); 48 49 if (column == 0) param.setEnvEntryName((String )value); 50 else if (column == 1) param.setEnvEntryType((String )value); 51 else if (column == 2) param.setEnvEntryValue((String )value); 52 else param.setDescription((String )value); 53 } 54 55 56 public Object getValueAt(int row, int column) 57 { 58 EnvEntry param = (EnvEntry)getChildren().get(row); 59 60 if (column == 0) return param.getEnvEntryName(); 61 else if (column == 1) return param.getEnvEntryType(); 62 else if (column == 2) return param.getEnvEntryValue(); 63 else { 64 String desc = param.getDefaultDescription(); 65 return desc==null?null:desc.trim(); 66 } 67 } 68 69 public CommonDDBean addRow(Object [] values) 70 { 71 try { 72 WebApp webApp = (WebApp)getParent(); 73 EnvEntry param=(EnvEntry)webApp.createBean("EnvEntry"); param.setEnvEntryName((String )values[0]); 75 param.setEnvEntryType((String )values[1]); 76 String value = (String )values[2]; 77 param.setEnvEntryValue(value.length()>0?value:null); 78 String desc = (String )values[3]; 79 param.setDescription(desc.length()>0?desc:null); 80 webApp.addEnvEntry(param); 81 getChildren().add(param); 82 fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1); 83 return param; 84 } catch (ClassNotFoundException ex) {} 85 return null; 86 } 87 88 public void editRow(int row, Object [] values) 89 { 90 EnvEntry param = (EnvEntry)getChildren().get(row); 91 param.setEnvEntryName((String )values[0]); 92 param.setEnvEntryType((String )values[1]); 93 String value = (String )values[2]; 94 param.setEnvEntryValue(value.length()>0?value:null); 95 String desc = (String )values[3]; 96 param.setDescription(desc.length()>0?desc:null); 97 fireTableRowsUpdated(row,row); 98 } 99 100 public void removeRow(int row) 101 { 102 WebApp webApp = (WebApp)getParent(); 103 webApp.removeEnvEntry((EnvEntry)getChildren().get(row)); 104 getChildren().remove(row); 105 fireTableRowsDeleted(row, row); 106 107 } 108 109 EnvEntry getEnvEntry(int row) { 110 return (EnvEntry)getChildren().get(row); 111 } 112 } | Popular Tags |