diff options
Diffstat (limited to 'source/com/c2kernel/gui/tabs/ExecutionPane.java')
| -rwxr-xr-x | source/com/c2kernel/gui/tabs/ExecutionPane.java | 198 |
1 files changed, 198 insertions, 0 deletions
diff --git a/source/com/c2kernel/gui/tabs/ExecutionPane.java b/source/com/c2kernel/gui/tabs/ExecutionPane.java new file mode 100755 index 0000000..de07319 --- /dev/null +++ b/source/com/c2kernel/gui/tabs/ExecutionPane.java @@ -0,0 +1,198 @@ +package com.c2kernel.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 com.c2kernel.entity.C2KLocalObject;
+import com.c2kernel.entity.agent.Job;
+import com.c2kernel.entity.proxy.EntityProxyObserver;
+import com.c2kernel.entity.proxy.ItemProxy;
+import com.c2kernel.gui.MainFrame;
+import com.c2kernel.gui.tabs.execution.ActivityItem;
+import com.c2kernel.gui.tabs.execution.ActivityViewer;
+import com.c2kernel.persistency.ClusterStorage;
+import com.c2kernel.utils.Language;
+import com.c2kernel.utils.Logger;
+
+public class ExecutionPane extends EntityTabPane implements EntityProxyObserver {
+
+ ArrayList jobList = null;
+ Object jobLock = new Object();
+ String[] emptyAct = { "--" };
+ 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(emptyAct);
+ Box activityBox = Box.createHorizontalBox();
+ String selAct = null;
+ ArrayList 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() {
+ public void itemStateChanged(ItemEvent selection) {
+ if (selection.getStateChange() == ItemEvent.SELECTED) {
+ selectActivity(selection.getItem());
+ }
+ }
+ });
+ }
+ public void run() {
+ Thread.currentThread().setName("Execution Pane Builder");
+ sourceEntity.getEntity().subscribe(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();
+ try {
+ jobList = ((ItemProxy)sourceEntity.getEntity()).getJobList(MainFrame.userAgent);
+ activitySelector.addItem("--");
+ for (Iterator e = jobList.iterator(); e.hasNext();) {
+ Job thisJob = (Job)e.next();
+ Logger.msg(7, "ExecutionPane - loadJobList " + thisJob.isOutcomeUsed() + "|" + thisJob.getSchemaType() + "|" + thisJob.getSchemaVersion() + "|");
+ ActivityItem newAct = new ActivityItem(thisJob);
+ if (activities.contains(newAct)) {
+ int actIndex = activities.indexOf(newAct);
+ ((ActivityItem)activities.get(actIndex)).addJob(thisJob);
+ } else {
+ Logger.msg(2, "ExecutionPane - Adding activity " + thisJob.getStepPath());
+ addActivity(newAct);
+ }
+ }
+ } catch (Exception e) {
+ activitySelector.addItem("Error fetching JobList");
+ Logger.debug("Error fetching joblist");
+ Logger.error(e);
+ }
+
+ switch (activities.size()) {
+ case 0 :
+ view.add(noActs);
+ break;
+ case 1 :
+ currentActView = new ActivityViewer((ActivityItem)activities.get(0), (ItemProxy)sourceEntity.getEntity(), 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();
+ }
+ 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 instanceof ActivityItem))
+ return;
+ view.removeAll();
+ c.fill = GridBagConstraints.BOTH;
+ gridbag.setConstraints(view, c);
+ currentActView = new ActivityViewer((ActivityItem)selObj, (ItemProxy)sourceEntity.getEntity(), this);
+ view.add(currentActView);
+ revalidate();
+ updateUI();
+ currentActView.init();
+ }
+ public void runCommand(String command) {
+ if (init) {
+ for (Iterator iter = activities.iterator(); iter.hasNext();) {
+ ActivityItem act = (ActivityItem)iter.next();
+ if (act.name.equals(command)) {
+ selectActivity(act);
+ }
+ }
+ } else
+ autoRun = command;
+ }
+ /**
+ * when the workflow changes, reload this pane.
+ */
+ public void add(C2KLocalObject contents) {
+ if (!formIsActive)
+ reload();
+ else { // look to see if this form is now invalid
+ // get the new joblist
+ try {
+ jobList = ((ItemProxy)sourceEntity.getEntity()).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 (Iterator iter2 = jobList.iterator(); iter2.hasNext();) {
+ Job newJob = (Job)iter2.next();
+ 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
+ */
+ public void remove(String id) {
+ }
+}
|
