1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 27 import org.netbeans.modules.j2ee.dd.api.common.EjbRef; 28 import org.netbeans.modules.j2ee.dd.api.common.EjbLocalRef; 29 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 30 import org.netbeans.modules.j2ee.dd.api.common.CommonDDBean; 31 import org.openide.util.NbBundle; 32 33 public class EjbRefTableModel extends DDBeanTableModel 34 { 35 private static final String [] columnNames = { 36 NbBundle.getMessage(EjbRefTableModel.class,"TTL_EjbRefName"), 37 NbBundle.getMessage(EjbRefTableModel.class,"TTL_EjbRefType"), 38 NbBundle.getMessage(EjbRefTableModel.class,"TTL_EjbInterfaceType"), 39 NbBundle.getMessage(EjbRefTableModel.class,"TTL_EjbHome"), 40 NbBundle.getMessage(EjbRefTableModel.class,"TTL_EjbInterface"), 41 NbBundle.getMessage(EjbRefTableModel.class,"TTL_EjbLink"), 42 NbBundle.getMessage(EjbRefTableModel.class,"TTL_Description") 43 }; 44 45 protected String [] getColumnNames() { 46 return columnNames; 47 } 48 49 public void setValueAt(Object value, int row, int column) 50 { 51 CommonDDBean ref = getEjbRef(row); 52 if (ref instanceof EjbRef) { 53 EjbRef param = (EjbRef)ref; 54 if (column == 0) param.setEjbRefName((String )value); 55 else if (column == 1) param.setEjbRefType((String )value); 56 else if (column == 3) param.setHome((String )value); 57 else if (column == 4) param.setRemote((String )value); 58 else if (column == 5) param.setEjbLink((String )value); 59 else if (column == 6) param.setDescription((String )value); 60 } else { 61 EjbLocalRef param = (EjbLocalRef)ref; 62 if (column == 0) param.setEjbRefName((String )value); 63 else if (column == 1) param.setEjbRefType((String )value); 64 else if (column == 3) param.setLocalHome((String )value); 65 else if (column == 4) param.setLocal((String )value); 66 else if (column == 5) param.setEjbLink((String )value); 67 else if (column == 6) param.setDescription((String )value); 68 } 69 } 70 71 72 public Object getValueAt(int row, int column) 73 { 74 CommonDDBean ref = getEjbRef(row); 75 if (ref instanceof EjbRef) { 76 EjbRef param = (EjbRef)ref; 77 if (column == 0) return param.getEjbRefName(); 78 else if (column == 1) return param.getEjbRefType(); 79 else if (column == 2) return "Remote"; else if (column == 3) return param.getHome(); 81 else if (column == 4) return param.getRemote(); 82 else if (column == 5) return param.getEjbLink(); 83 else { 84 String desc = param.getDefaultDescription(); 85 return desc==null?null:desc.trim(); 86 } 87 } else { 88 EjbLocalRef param = (EjbLocalRef)ref; 89 if (column == 0) return param.getEjbRefName(); 90 else if (column == 1) return param.getEjbRefType(); 91 else if (column == 2) return "Local"; else if (column == 3) return param.getLocalHome(); 93 else if (column == 4) return param.getLocal(); 94 else if (column == 5) return param.getEjbLink(); 95 else { 96 String desc = param.getDefaultDescription(); 97 return desc==null?null:desc.trim(); 98 } 99 } 100 101 } 102 103 public CommonDDBean addRow(Object [] values) 104 { 105 try { 106 CommonDDBean param=null; 107 WebApp webApp = (WebApp)getParent(); 108 String interfaceType = (String )values[2]; 109 if ("Remote".equals(interfaceType)) { 110 param=webApp.createBean("EjbRef"); ((EjbRef)param).setEjbRefName((String )values[0]); 112 ((EjbRef)param).setEjbRefType((String )values[1]); 113 ((EjbRef)param).setHome((String )values[3]); 114 ((EjbRef)param).setRemote((String )values[4]); 115 String link = (String )values[5]; 116 if (link.length()>0) ((EjbRef)param).setEjbLink(link); 117 String desc = (String )values[6]; 118 if (desc.length()>0) ((EjbRef)param).setDescription(desc); 119 int row = webApp.sizeEjbRef(); 120 webApp.addEjbRef((EjbRef)param); 121 getChildren().add(row,param); 122 fireTableRowsInserted(row, row); 123 } else { 124 param=webApp.createBean("EjbLocalRef"); ((EjbLocalRef)param).setEjbRefName((String )values[0]); 126 ((EjbLocalRef)param).setEjbRefType((String )values[1]); 127 ((EjbLocalRef)param).setLocalHome((String )values[3]); 128 ((EjbLocalRef)param).setLocal((String )values[4]); 129 String link = (String )values[5]; 130 if (link.length()>0) ((EjbLocalRef)param).setEjbLink(link); 131 String desc = (String )values[6]; 132 if (desc.length()>0) ((EjbLocalRef)param).setDescription(desc); 133 webApp.addEjbLocalRef((EjbLocalRef)param); 134 getChildren().add(param); 135 int row = getRowCount() - 1; 136 fireTableRowsInserted(row, row); 137 } 138 return param; 139 } catch (ClassNotFoundException ex) {} 140 return null; 141 } 142 143 public void editRow(int row, Object [] values) 144 { 145 CommonDDBean ref = getEjbRef(row); 147 WebApp webApp = (WebApp)getParent(); 148 String interfaceType = (String )values[2]; 149 if (ref instanceof EjbRef) { 150 EjbRef param = (EjbRef)ref; 151 param.setEjbRefName((String )values[0]); 153 param.setEjbRefType((String )values[1]); 154 param.setHome((String )values[3]); 155 param.setRemote((String )values[4]); 156 String ejbLink = (String )values[5]; 157 param.setEjbLink(ejbLink.length()>0?ejbLink:null); 158 String desc = (String )values[6]; 159 param.setDescription(desc.length()>0?desc:null); 160 fireTableRowsUpdated(row,row); 161 178 } else { 179 EjbLocalRef param = (EjbLocalRef)ref; 180 param.setEjbRefName((String )values[0]); 182 param.setEjbRefType((String )values[1]); 183 param.setLocalHome((String )values[3]); 184 param.setLocal((String )values[4]); 185 String ejbLink = (String )values[5]; 186 param.setEjbLink(ejbLink.length()>0?ejbLink:null); 187 String desc = (String )values[6]; 188 param.setDescription(desc.length()>0?desc:null); 189 fireTableRowsUpdated(row,row); 190 207 } 208 } 210 211 public void removeRow(int row) 212 { 213 WebApp webApp = (WebApp)getParent(); 214 CommonDDBean ref = getEjbRef(row); 215 if (ref instanceof EjbRef) { 216 webApp.removeEjbRef((EjbRef)ref); 217 } else { 218 webApp.removeEjbLocalRef((EjbLocalRef)ref); 219 } 220 getChildren().remove(row); 221 fireTableRowsDeleted(row, row); 222 223 } 224 225 CommonDDBean getEjbRef(int row) { 226 return (CommonDDBean)getChildren().get(row); 227 } 228 } | Popular Tags |