blob: ef20a1afa2fe441dcd80bf5d0505fb03b03fee2a (
plain)
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
|
package com.c2kernel.gui.tabs.collection;
import java.awt.HeadlessException;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import com.c2kernel.collection.Collection;
import com.c2kernel.common.ObjectNotFoundException;
import com.c2kernel.entity.C2KLocalObject;
import com.c2kernel.entity.proxy.EntityProxy;
import com.c2kernel.entity.proxy.EntityProxyObserver;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.events.Event;
import com.c2kernel.gui.MainFrame;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.EntityPath;
import com.c2kernel.lookup.InvalidEntityPathException;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.outcome.Outcome;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.CastorXMLUtility;
import com.c2kernel.utils.Language;
import com.c2kernel.utils.Logger;
public class CollectionHistoryWindow extends JFrame {
JTable historyTable;
HistoryTableModel historyModel;
public CollectionHistoryWindow(ItemProxy item, Collection coll) throws HeadlessException {
super("Collection History");
historyModel = new HistoryTableModel(item, coll);
historyTable = new JTable(historyModel);
this.getContentPane().add(new JScrollPane(historyTable));
historyTable.addMouseListener(new HistoryTableListener(item));
this.pack();
super.toFront();
this.validate();
this.show();
}
private class HistoryTableModel extends AbstractTableModel implements EntityProxyObserver {
ItemProxy item;
ArrayList collEvents, collEventData;
Collection coll;
public HistoryTableModel(ItemProxy item, Collection coll) {
this.item = item;
this.coll = coll;
collEvents = new ArrayList();
collEventData = new ArrayList();
item.subscribe(this, ClusterStorage.HISTORY, true);
}
public int getColumnCount() {
// TODO Auto-generated method stub
return 4;
}
public String getColumnName(int columnIndex) {
switch(columnIndex) {
case 0: return Language.translate("Date");
case 1: return Language.translate("Operation");
case 2: return Language.translate("Slot");
case 3: return Language.translate("Child");
default: return "";
}
}
public int getRowCount() {
// TODO Auto-generated method stub
return collEvents.size();
}
public Object getValueAt(int rowIndex, int columnIndex) {
Event ev = (Event)collEvents.get(rowIndex);
switch (columnIndex) {
case 0:
return ev.getTimeString();
case 1:
if (ev.getStepName().equals("AssignItemToSlot"))
return "Item Assigned";
else
return "Collection replaced";
case 2:
if (ev.getStepName().equals("AssignItemToSlot"))
return ((String[])collEventData.get(rowIndex))[1];
return "";
case 3:
if (ev.getStepName().equals("AddC2KObject"))
return "Click to view";
String name;
try {
EntityProxy childItem = Gateway.getProxyManager().getProxy(new EntityPath(Integer.parseInt(((String[])collEventData.get(rowIndex))[2])));
name = childItem.getName();
} catch (NumberFormatException e) {
name = "Invalid entity key: "+((String[])collEventData.get(rowIndex))[2];
} catch (ObjectNotFoundException e) {
name = "Item deleted: "+((String[])collEventData.get(rowIndex))[2];
} catch (InvalidEntityPathException e) {
name = "Invalid entity key: "+((String[])collEventData.get(rowIndex))[2];
}
return name;
default:
return "";
}
}
public Object getEventData(int row) {
return collEventData.get(row);
}
public void add(C2KLocalObject contents) {
if (!(contents instanceof Event)) return;
Event thisEv = (Event)contents;
if (thisEv.getStepName().equals("AssignItemToSlot") || thisEv.getStepName().equals("AddC2KObject")) {
String[] params;
try {
Outcome oc = (Outcome)item.getObject(ClusterStorage.OUTCOME+"/PredefinedStepOutcome/0/"+thisEv.getID());
params = PredefinedStep.getDataList(oc.getData());
} catch (ObjectNotFoundException ex) { return; }
if (thisEv.getStepName().equals("AssignItemToSlot")) {
if (params[0].equals(coll.getName()))
collEventData.add(params);
else return;
}
else {
Object obj;
try {
obj = CastorXMLUtility.unmarshall(params[0]);
} catch (Exception e) {
Logger.error(e);
return;
}
if (obj instanceof Collection)
collEventData.add(obj);
else return;
}
}
else return;
collEvents.add(thisEv);
fireTableRowsInserted(collEvents.size()-1, collEvents.size()-1);
}
public void remove(String id) { }
}
private class HistoryTableListener extends MouseAdapter {
ItemProxy item;
public HistoryTableListener(ItemProxy item) {
this.item = item;
}
public void mouseClicked(MouseEvent e) {
if (e.getClickCount()==2) {
int row = historyTable.getSelectedRow();
Object data = historyModel.getEventData(row);
if (data instanceof Collection) {
showColl((Collection)data);
}
else {
String[] params = (String[])data;
try {
EntityProxy childItem = Gateway.getProxyManager().getProxy(new EntityPath(Integer.parseInt(params[2])));
MainFrame.itemFinder.pushNewKey(childItem.getName());
} catch (Exception ex) { }
}
}
}
public void showColl(Collection coll) {
JFrame newFrame = new JFrame();
AggregationView newView = new AggregationView();
newView.setCollection(coll);
newView.setItem(item);
newFrame.getContentPane().add(newView);
newFrame.pack();
newFrame.toFront();
newFrame.validate();
newFrame.show();
}
}
}
|