1 23 24 package org.objectweb.fractal.gui.dialog.model; 25 26 import org.objectweb.fractal.gui.model.Component; 27 28 import javax.swing.table.AbstractTableModel ; 29 30 35 36 public class AttributeTableModel extends AbstractTableModel { 37 38 41 42 private Component model; 43 44 49 50 void setComponentModel (final Component model) { 51 this.model = model; 52 fireTableDataChanged(); 53 } 54 55 61 62 void attributeChanged (final String attributeName, final String oldValue) { 63 fireTableDataChanged(); 64 } 65 66 70 public int getRowCount () { 71 if (model == null) { 72 return 0; 73 } 74 return model.getAttributeNames().size(); 75 } 76 77 public int getColumnCount () { 78 return 2; 79 } 80 81 public String getColumnName (final int column) { 82 return column == 0 ? "Name" : "Value"; 83 } 84 85 public boolean isCellEditable (final int rowIndex, final int columnIndex) { 86 return true; 87 } 88 89 public Object getValueAt (final int rowIndex, final int columnIndex) { 90 Object key = model.getAttributeNames().get(rowIndex); 91 if (columnIndex == 0) { 92 return key; 93 } else { 94 return model.getAttribute((String )key); 95 } 96 } 97 98 public void setValueAt ( 99 final Object aValue, 100 final int rowIndex, 101 final int columnIndex) 102 { 103 String key = (String )model.getAttributeNames().get(rowIndex); 104 if (columnIndex == 0) { 105 String value = model.getAttribute(key); 106 model.setAttribute(key, null); 107 model.setAttribute((String )aValue, value); 108 } else { 109 model.setAttribute(key, (String )aValue); 110 } 111 } 112 } 113 | Popular Tags |