blob: 3d5a29a038892533549914a5c98c60c8a74acb0a (
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
185
186
187
|
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.Aggregation;
import com.c2kernel.collection.Collection;
import com.c2kernel.common.ObjectNotFound;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.entity.proxy.MemberSubscription;
import com.c2kernel.entity.proxy.ProxyObserver;
import com.c2kernel.events.Event;
import com.c2kernel.gui.MainFrame;
import com.c2kernel.lifecycle.instance.predefined.PredefinedStep;
import com.c2kernel.lookup.ItemPath;
import com.c2kernel.persistency.ClusterStorage;
import com.c2kernel.persistency.outcome.Outcome;
import com.c2kernel.process.Gateway;
import com.c2kernel.utils.Language;
import com.c2kernel.utils.Logger;
public class CollectionHistoryWindow extends JFrame {
JTable historyTable;
HistoryTableModel historyModel;
public CollectionHistoryWindow(ItemProxy item, Aggregation 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.setVisible(true);
}
private class HistoryTableModel extends AbstractTableModel implements ProxyObserver<Event> {
ItemProxy item;
ArrayList<Event> collEvents;
ArrayList<Object> collEventData;
Aggregation coll;
public HistoryTableModel(ItemProxy item, Aggregation coll) {
this.item = item;
this.coll = coll;
collEvents = new ArrayList<Event>();
collEventData = new ArrayList<Object>();
item.subscribe(new MemberSubscription<Event>(this, ClusterStorage.HISTORY, true));
}
@Override
public int getColumnCount() {
return 4;
}
@Override
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 "";
}
}
@Override
public int getRowCount() {
return collEvents.size();
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Event ev = 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 {
ItemProxy childItem = Gateway.getProxyManager().getProxy(new ItemPath(((String[])collEventData.get(rowIndex))[2]));
name = childItem.getName();
} catch (ObjectNotFound e) {
name = "Item deleted: "+((String[])collEventData.get(rowIndex))[2];
} catch (Exception e) {
name = "Problem resolving Item key: "+((String[])collEventData.get(rowIndex))[2];
}
return name;
default:
return "";
}
}
public Object getEventData(int row) {
return collEventData.get(row);
}
@Override
public void add(Event thisEv) {
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 (ObjectNotFound ex) { return; }
if (thisEv.getStepName().equals("AssignItemToSlot")) {
if (params[0].equals(coll.getName()))
collEventData.add(params);
else return;
}
else {
Object obj;
try {
obj = Gateway.getMarshaller().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);
}
@Override
public void remove(String id) { }
@Override
public void control(String control, String msg) {
}
}
private class HistoryTableListener extends MouseAdapter {
ItemProxy item;
public HistoryTableListener(ItemProxy item) {
this.item = item;
}
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount()==2) {
int row = historyTable.getSelectedRow();
Object data = historyModel.getEventData(row);
if (data instanceof Aggregation) {
showColl((Aggregation)data);
}
else {
String[] params = (String[])data;
try {
ItemProxy childItem = Gateway.getProxyManager().getProxy(new ItemPath(params[2]));
MainFrame.itemFinder.pushNewKey(childItem.getName());
} catch (Exception ex) { }
}
}
}
public void showColl(Aggregation 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.setVisible(true);
}
}
}
|