1 21 package org.columba.core.gui.scripting; 22 23 import java.util.List ; 24 25 import javax.swing.SwingUtilities ; 26 import javax.swing.table.AbstractTableModel ; 27 28 import org.columba.core.scripting.IScriptsObserver; 29 import org.columba.core.scripting.model.ColumbaScript; 30 31 34 public class ScriptsTableModel 35 extends AbstractTableModel  36 implements IScriptsObserver 37 { 38 39 private static final String  40 RES_NAME_COLUMN = "Script name", 41 RES_AUTHOR_COLUMN = "Author", 42 RES_DESCRIPTION_COLUMN = "Description"; 43 44 private String [] columns = new String [] 45 { 46 RES_NAME_COLUMN, 47 RES_AUTHOR_COLUMN, 48 RES_DESCRIPTION_COLUMN 49 }; 50 51 public static final int 52 NAME_COLUMN = 0, 53 AUTHOR_COLUMN = 1, 54 DESCRIPTION_COLUMN = 2; 55 56 private List scriptList; 57 58 private ScriptManagerDocument document; 59 60 public ScriptsTableModel(ScriptManagerDocument doc) 61 { 62 63 document = doc; 64 document.addObserver(this); 65 66 scriptList = document.getScripts(); 67 } 68 69 public int getColumnCount() 70 { 71 return columns.length; 72 } 73 74 public int getRowCount() 75 { 76 return scriptList.size(); 77 } 78 79 public String getColumnName(int col) 80 { 81 return columns[col]; 82 } 83 84 85 public Class getColumnClass(int columnIndex) 86 { 87 if (columnIndex == 0) return ColumbaScript.class; 88 else return super.getColumnClass(columnIndex); 89 } 90 91 public Object getValueAt(int row, int col) 92 { 93 ColumbaScript script = (ColumbaScript) scriptList.get(row); 94 switch (col) 95 { 96 case NAME_COLUMN: 97 return script; 98 case AUTHOR_COLUMN: 99 return script.getAuthor(); 100 case DESCRIPTION_COLUMN: 101 return script.getDescription(); 102 default: 103 return ""; 104 } 105 106 } 107 108 private void fireTableChangedEv() 109 { 110 SwingUtilities.invokeLater(new Runnable () 111 { 112 public void run() 113 { 114 fireTableDataChanged(); 115 } 116 }); 117 } 118 119 public void scriptsAdded(List scripts) 120 { 121 scriptList.addAll(scripts); 122 fireTableChangedEv(); 123 } 124 125 public void scriptsRemoved(List scripts) 126 { 127 scriptList.removeAll(scripts); 128 fireTableChangedEv(); 129 } 130 131 public void scriptsChanged(List scripts) 132 { 133 fireTableChangedEv(); 134 } 135 136 } 137 | Popular Tags |