1 5 package net.sf.panoptes.view.swing.tables; 6 7 import java.util.ArrayList ; 8 9 import javax.swing.table.AbstractTableModel ; 10 11 import net.sf.panoptes.model.node.NodeSupport; 12 13 19 public class ContextTableModel extends AbstractTableModel { 20 21 private ArrayList contextKeys = new ArrayList (); 22 private NodeSupport.Context context = null; 23 24 public ContextTableModel() { 25 } 26 27 public void setContext(NodeSupport.Context context) { 28 this.context = context; 29 contextKeys = new ArrayList (context.keySet()); 30 fireTableDataChanged(); 31 } 32 33 public int getColumnCount() { 34 return 3; 35 } 36 37 public int getRowCount() { 38 return contextKeys.size(); 39 } 40 41 public String getColumnName(int columnIndex) { 42 switch (columnIndex) { 43 case 0 : 44 return "Name"; 45 case 1 : 46 return "Value"; 47 case 2 : 48 return "Class"; 49 default : 50 return "Uknown column"; 51 } 52 53 } 54 55 public Object getValueAt(int rowIndex, int columnIndex) { 56 Object key = contextKeys.get(rowIndex); 57 switch (columnIndex) { 58 case 0 : 59 return key; 60 case 1 : 61 return context.get(key); 62 case 2 : 63 Object value = context.get(key); 64 return value == null ? "" : value.getClass().getName(); 65 default : 66 return "Unknown column"; 67 } 68 } 69 } 70 71 | Popular Tags |