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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
/*
* StatusPane.java
*
* Created on March 20, 2001, 3:30 PM
*/
package com.c2kernel.gui.tabs;
/**
* @author abranson
* @version
*/
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.entity.proxy.EntityProxyObserver;
import com.c2kernel.events.Event;
import com.c2kernel.events.History;
import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.utils.Language;
import com.c2kernel.utils.Logger;
/**
* Pane to display all work orders that this agent can execute, and activate
* them on request from the user. Subscribes to NodeItem for WorkOrder objects.
* @version $Revision: 1.22 $ $Date: 2005/04/26 06:48:13 $
* @author $Author: abranson $
*/
public class HistoryPane extends EntityTabPane implements ActionListener, EntityProxyObserver {
History history;
HistoryTableModel model;
JTable eventTable;
JButton startButton = new JButton("<<");
JButton prevButton = new JButton("<");
JButton nextButton = new JButton(">");
JButton endButton = new JButton(">>");
public static final int SIZE = 30;
int currentSize = SIZE;
public HistoryPane() {
super("History", "Event History");
initPanel();
// add buttons
Box navBox = Box.createHorizontalBox();
navBox.add(startButton); navBox.add(prevButton);
navBox.add(nextButton); navBox.add(endButton);
// setup buttons
//startButton.setEnabled(false); nextButton.setEnabled(false);
//prevButton.setEnabled(false); endButton.setEnabled(false);
startButton.setActionCommand("start");
startButton.addActionListener(this);
prevButton.setActionCommand("prev");
prevButton.addActionListener(this);
nextButton.setActionCommand("next");
nextButton.addActionListener(this);
endButton.setActionCommand("end");
endButton.addActionListener(this);
getGridBagConstraints();
c.gridx = 0; c.gridy = 1;
c.anchor = GridBagConstraints.NORTHWEST;
c.fill=GridBagConstraints.NONE;
c.weightx=0; c.weighty=0;
gridbag.setConstraints(navBox, c);
add(navBox);
// Create table
eventTable = new JTable();
JScrollPane eventScroll= new JScrollPane(eventTable);
c.weightx = 1.0; c.weighty = 1.0;
c.fill = GridBagConstraints.BOTH; c.gridy++;
gridbag.setConstraints(eventScroll, c);
add(eventScroll);
}
public void reload() {
history.clear();
jumpToEnd();
}
public void run() {
Thread.currentThread().setName("History Pane Builder");
try {
history = (History)sourceEntity.getEntity().getObject(ClusterStorage.HISTORY);
sourceEntity.getEntity().subscribe(this, ClusterStorage.HISTORY, false);
} catch (ObjectNotFoundException e) {
Logger.error(e);
}
model = new HistoryTableModel();
eventTable.setModel(model);
jumpToEnd();
}
public void jumpToEnd() {
int lastEvent = history.getLastId();
int firstEvent = 0; currentSize = SIZE;
if (lastEvent > currentSize) firstEvent = lastEvent - currentSize + 1;
if (lastEvent < currentSize) currentSize = lastEvent + 1;
Logger.msg(5, "HistoryPane.run() - init table start "+firstEvent+" for "+currentSize);
model.setView(firstEvent, currentSize);
}
public void add(C2KLocalObject contents) {
jumpToEnd();
}
public void remove(String id) {
// don't have to deal with this normally
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("end")) {
jumpToEnd();
return;
}
int lastEvent = history.getLastId();
int startEvent = model.getStartId();
if (e.getActionCommand().equals("start")) {
currentSize = SIZE;
startEvent = 0;
}
else if (e.getActionCommand().equals("prev")) {
currentSize = SIZE;
startEvent-=currentSize;
if (startEvent<0) startEvent = 0;
}
else if (e.getActionCommand().equals("next")) {
currentSize = SIZE;
startEvent+=currentSize;
if (startEvent > lastEvent)
startEvent = lastEvent - currentSize +1;
}
else { // unknown action
return;
}
model.setView(startEvent, currentSize);
}
private class HistoryTableModel extends AbstractTableModel {
Event[] event;
Integer[] ids;
int loaded = 0;
int startId = 0;
public HistoryTableModel() {
event = new Event[0];
ids = new Integer[0];
}
public int getStartId() {
return startId;
}
public void setView(int startId, int size) {
event = new Event[size];
ids = new Integer[size];
this.startId = startId;
for (int i=0; i<size; i++) {
event[i] = history.getEvent(startId+i);
ids[i] = new Integer(startId+i);
loaded = i+1;
}
fireTableStructureChanged();
}
/**
* @see javax.swing.table.TableModel#getColumnClass(int)
*/
public Class<?> getColumnClass(int columnIndex) {
switch(columnIndex) {
case 0:
return Integer.class;
default:
return String.class;
}
}
/**
* @see javax.swing.table.TableModel#getColumnCount()
*/
public int getColumnCount() {
return 6;
}
/**
* @see javax.swing.table.TableModel#getColumnName(int)
*/
public String getColumnName(int columnIndex) {
switch(columnIndex) {
case 0: return Language.translate("ID");
case 1: return Language.translate("Activity");
case 2: return Language.translate("Transition");
case 3: return Language.translate("Date");
case 4: return Language.translate("Agent Name");
case 5: return Language.translate("Agent Role");
default: return "";
}
}
/**
* @see javax.swing.table.TableModel#getRowCount()
*/
public int getRowCount() {
return loaded;
}
/**
* @see javax.swing.table.TableModel#getValueAt(int, int)
*/
public Object getValueAt(int rowIndex, int columnIndex) {
if (event.length <= rowIndex || event[rowIndex] == null)
return "";
try {
switch (columnIndex) {
case 0: return ids[rowIndex];
case 1: return event[rowIndex].getStepName();
case 2: return Transitions.getTransitionName(event[rowIndex].getTransition());
case 3: return event[rowIndex].getTimeString();
case 4: return event[rowIndex].getAgentName();
case 5: return event[rowIndex].getAgentRole();
default: return "";
}
} catch (Exception e) {
return null;
}
}
/**
* @see javax.swing.table.TableModel#isCellEditable(int, int)
*/
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
}
}
|