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