1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 /******************************************************************************
25 * GenTableModel.java
26 *
27 * The underlying model for the Generator Table
28 *****************************************************************************/
29
30 package zeus.generator.code;
31
32 import java.util.*;
33 import javax.swing.table.*;
34 import javax.swing.event.*;
35
36 import zeus.util.*;
37
38
39 public class GenerationTableModel extends AbstractTableModel
40 implements ChangeListener {
41
42 static final int AGENT_FILTER = 1;
43 static final int TASK_FILTER = 2;
44 static final int UTILITY_FILTER = 3;
45
46 protected static final String[] columnNames = {
47 "Name", "Type", "Command Line"
48 };
49
50 protected Vector data = new Vector();
51
52 protected boolean hideAgents = false;
53 protected boolean hideTasks = false;
54 protected boolean hideUtilities = false;
55
56 protected GenerationPlan genplan;
57
58 public GenerationTableModel(GenerationPlan genplan) {
59 this.genplan = genplan;
60 genplan.addChangeListener(this);
61 refresh();
62 }
63
64 public void setFilter(int f) {
65 if (f == AGENT_FILTER) hideAgents = !hideAgents;
66 else if (f == TASK_FILTER) hideTasks = !hideTasks;
67 else if (f == UTILITY_FILTER) hideUtilities = !hideUtilities;
68 refresh();
69 }
70
71 public void removeRows(int[] rows) {
72 for(int i = 0; i < rows.length; i++ ) {
73 String[] entry = (String[])data.elementAt(rows[i]-i);
74 genplan.removeEntry(entry[GenerationInfo.TYPE],
75 entry[GenerationInfo.ID]);
76 }
77 }
78
79 protected synchronized void refresh() {
80 int p_size = data.size();
81 data.removeAllElements();
82 String[][] entry;
83
84 if ( !hideUtilities ) {
85 entry = genplan.summarizeNameservers();
86 for(int i = 0; i < entry.length; i++ )
87 data.addElement(entry[i]);
88
89 entry = genplan.summarizeFacilitators();
90 for(int i = 0; i < entry.length; i++ )
91 data.addElement(entry[i]);
92
93 entry = genplan.summarizeVisualisers();
94 for(int i = 0; i < entry.length; i++ )
95 data.addElement(entry[i]);
96
97 entry = genplan.summarizeDbProxys();
98 for(int i = 0; i < entry.length; i++ )
99 data.addElement(entry[i]);
100 }
101
102 if ( !hideAgents ) {
103 entry = genplan.summarizeSelectedAgents();
104 for(int i = 0; i < entry.length; i++ )
105 data.addElement(entry[i]);
106 }
107
108 if ( !hideTasks ) {
109 entry = genplan.summarizeSelectedTasks();
110 for(int i = 0; i < entry.length; i++ )
111 data.addElement(entry[i]);
112 }
113 if ( p_size > 0 ) fireTableRowsDeleted(0,p_size-1);
114 int c_size = data.size();
115 if ( c_size > 0 ) fireTableRowsInserted(0,c_size-1);
116 }
117
118 public int getColumnCount() { return columnNames.length; }
119 public int getRowCount() { return data.size(); }
120 public boolean isCellEditable(int row, int col) { return false;}
121 public String getColumnName(int col) { return columnNames[col]; }
122
123 public Object getValueAt(int row, int column) {
124 try {
125 String[] entry = (String[])data.elementAt(row);
126 return entry[column];
127 }
128 catch(ArrayIndexOutOfBoundsException e) {
129 return null;
130 }
131 }
132
133 public void setValueAt(Object aValue, int row, int column) {
134 }
135
136 public void stateChanged(ChangeEvent e) {
137
138 refresh();
139 }
140 }