1 19 package org.netbeans.modules.j2ee.websphere6.dd.loaders.ui; 20 21 import java.util.List ; 23 import org.netbeans.modules.j2ee.websphere6.dd.beans.DDXmiConstants; 24 import org.netbeans.modules.j2ee.websphere6.dd.beans.EjbBindingsType; 25 import org.netbeans.modules.j2ee.websphere6.dd.beans.EjbRefBindingsType; 26 import org.netbeans.modules.j2ee.websphere6.dd.beans.ResEnvRefBindingsType; 27 import org.netbeans.modules.j2ee.websphere6.dd.beans.ResRefBindingsType; 28 import org.netbeans.modules.j2ee.websphere6.dd.beans.CommonRef; 29 import org.openide.util.NbBundle; 30 import org.netbeans.modules.schema2beans.*; 31 import org.netbeans.modules.xml.multiview.*; 32 33 public class ReferencesTableModel extends org.netbeans.modules.j2ee.websphere6.dd.loaders.ui.InnerTableModel implements DDXmiConstants { 34 35 private List children; 36 private BaseBean parent; 37 private String hrefType=WEB_APPLICATION; 38 private static final String [] columnNames = { 39 NbBundle.getMessage(ReferencesTableModel.class,"TTL_ReferenceType"), 40 NbBundle.getMessage(ReferencesTableModel.class,"TTL_ReferenceId"), 41 NbBundle.getMessage(ReferencesTableModel.class,"TTL_ReferenceJndiName"), 42 NbBundle.getMessage(ReferencesTableModel.class,"TTL_ReferenceHref") 43 }; 44 45 private static final int [] columnWidths= {200, 160, 180}; 46 47 public ReferencesTableModel(XmlMultiViewDataSynchronizer synchronizer) { 48 super(synchronizer,columnNames,columnWidths); 49 } 50 51 52 53 protected String [] getColumnNames() { 54 return columnNames; 55 } 56 57 protected BaseBean getParent() { 58 return parent; 59 } 60 61 protected List getChildren() { 62 return children; 63 } 64 public void setHrefType(String value) { 65 hrefType=value; 66 } 67 public String getHrefType(String value) { 68 return hrefType; 69 } 70 public int getColumnCount() { 71 return getColumnNames().length; 72 } 73 74 public int getRowCount() { 75 if (children != null) { 76 return (children.size()); 77 } else { 78 return (0); 79 } 80 } 81 82 83 public String getColumnName(int column) { 84 return getColumnNames()[column]; 85 } 86 87 public boolean isCellEditable(int row, int column) { 88 return (false); 89 } 90 91 public int getRowWithValue(int column, Object value) { 92 for(int row = 0; row < getRowCount(); row++) { 93 Object obj = getValueAt(row, column); 94 if (obj.equals(value)) { 95 return (row); 96 } 97 } 98 99 return (-1); 100 } 101 102 103 104 public void setData(BaseBean parent,BaseBean[] children) { 105 this.parent = parent; 106 this.children = new java.util.ArrayList (); 107 if (children==null) return; 108 for(int i=0;i<children.length;i++) 109 this.children.add(children[i]); 110 fireTableDataChanged(); 111 } 112 113 114 public void setValueAt(Object value, int row, int column) { 115 CommonRef ref = (CommonRef)getChildren().get(row); 116 117 if (column == 0) ; else if (column == 1) ref.setXmiId((String )value); 119 else if(column==2) ref.setJndiName((String )value); 120 else if(column==3) ref.setHref((String )value); 121 } 122 123 124 public Object getValueAt(int row, int column) { 125 CommonRef ref = (CommonRef)getChildren().get(row); 126 if (column == 0) return ref.getType(); 127 else if (column == 1) return ref.getXmiId(); 128 else if(column == 2) return ref.getJndiName(); 129 else if(column == 3) return ref.getHref(); 130 return null; 131 } 132 133 public BaseBean addRow(Object [] values) { 134 String type=(String )values[0]; 136 CommonRef ref; 137 if(type.equals(BINDING_REFERENCE_TYPE_RESOURCE)) { 138 ref = new ResRefBindingsType(hrefType); 139 } else if(type.equals(BINDING_REFERENCE_TYPE_RESOURCE_ENV)) { 140 ref = new ResEnvRefBindingsType(hrefType); 141 } else if(type.equals(BINDING_REFERENCE_TYPE_EJB)) { 142 ref = new EjbRefBindingsType(hrefType); 143 } else { 144 return null; 145 } 146 ref.setXmiId((String )values[1]); 147 ref.setJndiName((String )values[2]); 148 ref.setHref((String )values[3]); 149 ((EjbBindingsType)getParent()).addReferenceBinding(ref); 150 getChildren().add(ref); 151 fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1); 152 return ref; 153 155 } 157 158 public int addRow() { 159 return -1; 160 } 161 162 163 public void editRow(int row, Object [] values) { 164 CommonRef ref = (CommonRef)getChildren().get(row); 165 ref.setXmiId((String )values[1]); 166 ref.setJndiName((String )values[2]); 167 ref.setHref((String )values[3]); 168 fireTableRowsUpdated(row,row); 169 } 170 171 public void removeRow(int row) { 172 ((EjbBindingsType)getParent()).removeReferenceBinding((CommonRef)getChildren().get(row)); 173 getChildren().remove(row); 174 fireTableRowsDeleted(row, row); 175 176 } 177 } | Popular Tags |