View Javadoc
1 package com.bonevich.erj.ui.editor; 2 3 import com.bonevich.erj.model.*; 4 import com.bonevich.erj.ErjConstants; 5 6 import javax.swing.table.AbstractTableModel; 7 import java.util.ArrayList; 8 import java.util.Iterator; 9 import java.util.List; 10 11 public final class KeyConstraintTableModel extends AbstractTableModel 12 { 13 ////////////////////////////////////////////////////////// 14 // Constants 15 private static final String[] _COLUMNS = {"Key","Type","Attribute(s)","Cardinality"}; 16 private static final String SPACE_STR = " "; 17 18 ////////////////////////////////////////////////////////// 19 // Attributes 20 private List _keys = new ArrayList(10); 21 22 public Object getValueAt(int row, int col) 23 { 24 //System.err.println("(model) getValueAt called"); 25 KeyConstraint key = (KeyConstraint) _keys.get(row); 26 switch (col) 27 { 28 case 0 : 29 return key.getIdentifier(); 30 case 1 : 31 if (key instanceof PrimaryKey) 32 { 33 return "primary"; 34 } 35 if (key instanceof UniqueKey) 36 { 37 return "alternate"; 38 } 39 return "foreign"; 40 case 2 : 41 StringBuffer attrs = new StringBuffer("[ "); 42 Iterator itr = key.getAttributeIterator(); 43 while (itr.hasNext()) 44 { 45 Attribute attr = (Attribute) itr.next(); 46 attrs.append(attr.getIdentifier()); 47 attrs.append(SPACE_STR); 48 } 49 attrs.append("]"); 50 return attrs.toString(); 51 case 3 : 52 if (key instanceof ForeignKey) 53 { 54 return ((ForeignKey) key).getCardinality().toString(); 55 } 56 return ErjConstants.EMPTY_STR; 57 default: 58 System.err.println("Undefined key call"); 59 return null; 60 } 61 } 62 63 public int getRowCount() 64 { 65 return _keys.size(); 66 } 67 68 public int getColumnCount() 69 { 70 return _COLUMNS.length; 71 } 72 73 public String getColumnName(int col) 74 { 75 return _COLUMNS[col]; 76 } 77 78 public KeyConstraint getRow(int row) 79 { 80 return (KeyConstraint)_keys.get(row); 81 } 82 public void setRow(KeyConstraint key) 83 { 84 _keys.add(key); 85 } 86 87 public void clearRows() 88 { 89 _keys.clear(); 90 } 91 92 } /* end class KeyConstraintTableModel */

This page was automatically generated by Maven