1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 27 import org.netbeans.modules.j2ee.dd.api.common.ResourceEnvRef; 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 ResEnvRefTableModel extends DDBeanTableModel 33 { 34 private static final String [] columnNames = { 35 NbBundle.getMessage(ResEnvRefTableModel.class,"TTL_ResRefName"), 36 NbBundle.getMessage(ResEnvRefTableModel.class,"TTL_ResType"), 37 NbBundle.getMessage(ResEnvRefTableModel.class,"TTL_Description") 38 }; 39 40 protected String [] getColumnNames() { 41 return columnNames; 42 } 43 44 public void setValueAt(Object value, int row, int column) 45 { 46 ResourceEnvRef param = getResourceEnvRef(row); 47 48 if (column == 0) param.setResourceEnvRefName((String )value); 49 else if (column == 1) param.setResourceEnvRefType((String )value); 50 else param.setDescription((String )value); 51 } 52 53 54 public Object getValueAt(int row, int column) 55 { 56 ResourceEnvRef param = getResourceEnvRef(row); 57 58 if (column == 0) return param.getResourceEnvRefName(); 59 else if (column == 1) return param.getResourceEnvRefType(); 60 else { 61 String desc = param.getDefaultDescription(); 62 return desc==null?null:desc.trim(); 63 } 64 } 65 66 public CommonDDBean addRow(Object [] values) 67 { 68 try { 69 WebApp webApp = (WebApp)getParent(); 70 ResourceEnvRef param=(ResourceEnvRef)webApp.createBean("ResourceEnvRef"); param.setResourceEnvRefName((String )values[0]); 72 param.setResourceEnvRefType((String )values[1]); 73 String desc = (String )values[2]; 74 param.setDescription(desc.length()>0?desc:null); 75 webApp.addResourceEnvRef(param); 76 getChildren().add(param); 77 fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1); 78 return param; 79 } catch (ClassNotFoundException ex) {} 80 return null; 81 } 82 83 public void editRow(int row, Object [] values) 84 { 85 ResourceEnvRef param = getResourceEnvRef(row); 86 param.setResourceEnvRefName((String )values[0]); 87 param.setResourceEnvRefType((String )values[1]); 88 String desc = (String )values[2]; 89 param.setDescription(desc.length()>0?desc:null); 90 fireTableRowsUpdated(row,row); 91 } 92 93 public void removeRow(int row) 94 { 95 WebApp webApp = (WebApp)getParent(); 96 webApp.removeResourceEnvRef(getResourceEnvRef(row)); 97 getChildren().remove(row); 98 fireTableRowsDeleted(row, row); 99 100 } 101 102 ResourceEnvRef getResourceEnvRef(int row) { 103 return (ResourceEnvRef)getChildren().get(row); 104 } 105 } | Popular Tags |