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
|
package org.cristalise.gui.tabs;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.Box;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.cristalise.gui.MainFrame;
import org.cristalise.gui.tabs.execution.ActivityItem;
import org.cristalise.gui.tabs.execution.ActivityViewer;
import org.cristalise.kernel.entity.agent.Job;
import org.cristalise.kernel.entity.proxy.MemberSubscription;
import org.cristalise.kernel.entity.proxy.ProxyObserver;
import org.cristalise.kernel.lifecycle.instance.Workflow;
import org.cristalise.kernel.persistency.ClusterStorage;
import org.cristalise.kernel.utils.Language;
import org.cristalise.kernel.utils.Logger;
public class ExecutionPane extends ItemTabPane implements ProxyObserver<Workflow> {
ArrayList<Job> jobList = null;
Object jobLock = new Object();
ActivityItem emptyAct = new ActivityItem();
JLabel noActs = new JLabel(Language.translate("There are currently no activities that you can execute in this item."));
JPanel view = new JPanel(new GridLayout(1, 1));
ActivityViewer currentActView;
JComboBox activitySelector = new JComboBox();
Box activityBox = Box.createHorizontalBox();
String selAct = null;
ArrayList<ActivityItem> activities;
String autoRun = null;
boolean init = false;
boolean formIsActive = false;
public ExecutionPane() {
super("Execution", "Activity Execution");
super.initPanel();
// add view panel
c = new GridBagConstraints();
c.gridx = 0; c.gridy = 1; c.weightx = 1.0; c.weighty = 2.0;
c.insets = new Insets(5, 5, 5, 5);
c.anchor = GridBagConstraints.CENTER;
c.fill = GridBagConstraints.BOTH;
gridbag.setConstraints(view, c);
add(view);
// create activity selection box
activityBox.add(new JLabel(Language.translate("Select Activity") + ": "));
activityBox.add(Box.createHorizontalStrut(5));
activitySelector.setEditable(false);
activityBox.add(activitySelector);
activitySelector.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent selection) {
if (selection.getStateChange() == ItemEvent.SELECTED) {
selectActivity(selection.getItem());
}
}
});
}
@Override
public void run() {
Thread.currentThread().setName("Execution Pane Builder");
sourceItem.getItem().subscribe(new MemberSubscription<Workflow>(this, ClusterStorage.LIFECYCLE, false));
loadJobList();
init = true;
if (autoRun != null) {
runCommand(autoRun);
autoRun = null;
}
}
private void loadJobList() {
synchronized (jobLock) {
activitySelector.removeAllItems();
view.removeAll();
activities = new ArrayList<ActivityItem>();
try {
jobList = (sourceItem.getItem()).getJobList(MainFrame.userAgent);
activitySelector.addItem(emptyAct);
for (Job thisJob : jobList) {
//Logger.msg(7, "ExecutionPane - loadJobList " + thisJob.hasOutcome() + "|" + thisJob.getSchemaName() + "|" + thisJob.getSchemaVersion() + "|");
ActivityItem newAct = new ActivityItem(thisJob);
if (activities.contains(newAct)) {
int actIndex = activities.indexOf(newAct);
activities.get(actIndex).addJob(thisJob);
} else {
Logger.msg(2, "ExecutionPane - Adding activity " + thisJob.getStepPath());
addActivity(newAct);
}
}
} catch (Exception e) {
Logger.error("Error fetching joblist");
Logger.error(e);
}
switch (activities.size()) {
case 0 :
view.add(noActs);
break;
case 1 :
currentActView = new ActivityViewer(activities.get(0), sourceItem.getItem(), this);
c.fill = GridBagConstraints.BOTH;
gridbag.setConstraints(view, c);
view.add(currentActView);
currentActView.init();
break;
default :
c.fill = GridBagConstraints.HORIZONTAL;
gridbag.setConstraints(view, c);
view.add(activityBox);
}
}
revalidate();
updateUI();
}
@Override
public void reload() {
loadJobList();
}
private void addActivity(ActivityItem newAct) {
if (activities.contains(newAct)) {
Logger.msg(6, "ExecutionPane.addActivity(): Already in " + newAct.getStepPath());
int actIndex = activities.indexOf(newAct);
activitySelector.removeItemAt(actIndex);
activitySelector.insertItemAt(newAct, actIndex);
activities.set(actIndex, newAct);
} else {
Logger.msg(6, "ExecutionPane.addActivity(): New " + newAct.getStepPath());
activities.add(newAct);
activitySelector.addItem(newAct);
}
}
private void selectActivity(Object selObj) {
if (selObj.equals(emptyAct))
return;
view.removeAll();
c.fill = GridBagConstraints.BOTH;
gridbag.setConstraints(view, c);
currentActView = new ActivityViewer((ActivityItem)selObj, sourceItem.getItem(), this);
view.add(currentActView);
revalidate();
updateUI();
currentActView.init();
}
@Override
public void runCommand(String command) {
if (init) {
for (ActivityItem act : activities) {
if (act.name.equals(command)) {
selectActivity(act);
}
}
} else
autoRun = command;
}
/**
* when the workflow changes, reload this pane.
*/
@Override
public void add(Workflow contents) {
if (!formIsActive)
reload();
else { // look to see if this form is now invalid
// get the new joblist
try {
jobList = (sourceItem.getItem()).getJobList(MainFrame.userAgent);
} catch (Exception ex) {
return;
}
// compare to currently editing jobs
ArrayList<?> currentActJobs = currentActView.getActivity().getJobs();
boolean allValid = true;
for (Iterator<?> iter = currentActJobs.iterator(); iter.hasNext() && allValid;) {
Job thisJob = (Job)iter.next();
boolean stillValid = false;
for (Job newJob : jobList) {
if (thisJob.equals(newJob)) {
stillValid = true;
break;
}
}
allValid &= stillValid;
}
if (!allValid) { // not all transitions are now valid
reload(); // refresh the execution pane
}
}
}
/**
* Not pertinent for this one
*/
@Override
public void remove(String id) {
}
@Override
public void control(String control, String msg) {
// TODO Auto-generated method stub
}
}
|