1 23 24 package org.objectweb.fractal.gui.dialog.model; 25 26 import org.objectweb.fractal.gui.model.Component; 27 import org.objectweb.fractal.gui.model.Interface; 28 29 import javax.swing.table.AbstractTableModel ; 30 31 36 37 public class InterfaceTableModel extends AbstractTableModel { 38 39 42 43 private boolean isClient; 44 45 48 49 private Component model; 50 51 56 57 InterfaceTableModel (final boolean isClient) { 58 this.isClient = isClient; 59 } 60 61 66 67 void setComponentModel (final Component model) { 68 this.model = model; 69 fireTableDataChanged(); 70 } 71 72 77 78 void interfaceChanged (final Interface i) { 79 final int index; 80 if (isClient) { 81 index = i.getOwner().getClientInterfaces().indexOf(i); 82 } else { 83 index = i.getOwner().getServerInterfaces().indexOf(i); 84 } 85 if (index != -1) { 86 fireTableRowsUpdated(index, index); 87 } 88 } 89 90 97 98 void interfaceAdded (final Interface i, final int index) { 99 fireTableRowsInserted(index, index); 100 } 101 102 109 110 void interfaceRemoved (final Interface i, final int index) { 111 fireTableRowsDeleted(index, index); 112 } 113 114 118 public int getRowCount () { 119 if (model == null) { 120 return 0; 121 } 122 if (isClient) { 123 return model.getClientInterfaces().size(); 124 } else { 125 return model.getServerInterfaces().size(); 126 } 127 } 128 129 public int getColumnCount () { 130 return 4; 131 } 132 133 public String getColumnName (final int column) { 134 switch (column) { 135 case 0: 136 return "Name"; 137 case 1: 138 return "Signature"; 139 case 2: 140 return "Contingency"; 141 default: 142 return "Cardinality"; 143 } 144 } 145 146 public boolean isCellEditable (final int rowIndex, final int columnIndex) { 147 Interface i; 148 if (isClient) { 149 i = (Interface)model.getClientInterfaces().get(rowIndex); 150 } else { 151 i = (Interface)model.getServerInterfaces().get(rowIndex); 152 } 153 return i.getMasterCollectionInterface() == null; 154 } 155 156 public Object getValueAt (final int rowIndex, final int columnIndex) { 157 Interface i; 158 if (isClient) { 159 i = (Interface)model.getClientInterfaces().get(rowIndex); 160 } else { 161 i = (Interface)model.getServerInterfaces().get(rowIndex); 162 } 163 switch (columnIndex) { 164 case 0: 165 return i.getName(); 166 case 1: 167 return i.getSignature(); 168 case 2: 169 return i.isOptional() ? "optional" : "mandatory"; 170 case 3: 171 return i.isCollection() ? "collection" : "single"; 172 default: 173 return i; 174 } 175 } 176 177 public void setValueAt ( 178 final Object aValue, 179 final int rowIndex, 180 final int columnIndex) 181 { 182 Interface i; 183 if (isClient) { 184 i = (Interface)model.getClientInterfaces().get(rowIndex); 185 } else { 186 i = (Interface)model.getServerInterfaces().get(rowIndex); 187 } 188 switch (columnIndex) { 189 case 0: 190 i.setName((String )aValue); 191 break; 192 case 1: 193 i.setSignature((String )aValue); 194 break; 195 case 2: 196 i.setIsOptional(aValue.equals("optional")); break; 198 default: 199 i.setIsCollection(aValue.equals("collection")); 200 } 201 } 202 } 203 | Popular Tags |