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.lifecycle.instance.gui.view;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import com.c2kernel.entity.agent.Job;
import com.c2kernel.entity.proxy.ItemProxy;
import com.c2kernel.graph.model.Vertex;
import com.c2kernel.graph.view.SelectedVertexPanel;
import com.c2kernel.gui.MainFrame;
import com.c2kernel.gui.tabs.EntityTabPane;
import com.c2kernel.gui.tabs.execution.Executor;
import com.c2kernel.lifecycle.instance.Activity;
import com.c2kernel.lifecycle.instance.stateMachine.StateMachine;
import com.c2kernel.lifecycle.instance.stateMachine.States;
import com.c2kernel.lifecycle.instance.stateMachine.Transitions;
import com.c2kernel.utils.Logger;
/**************************************************************************
*
* $Revision: 1.8 $
* $Date: 2005/09/07 13:46:31 $
*
* Copyright (C) 2003 CERN - European Organization for Nuclear Research
* All rights reserved.
**************************************************************************/
public class TransitionPanel extends SelectedVertexPanel implements ActionListener {
protected Activity mCurrentAct;
protected GridBagLayout gridbag;
protected GridBagConstraints c;
protected Box transBox;
protected JComboBox executors;
protected JComboBox states = new JComboBox(States.states);
protected JCheckBox active = new JCheckBox();
protected JLabel status = new JLabel();
protected ItemProxy mItem;
public TransitionPanel() {
super();
gridbag = new GridBagLayout();
setLayout(gridbag);
c = new GridBagConstraints();
c.gridx=0; c.gridy=0;
c.weightx=1; c.weighty=0;
c.fill=GridBagConstraints.HORIZONTAL;
JLabel title = new JLabel("Available Transitions");
title.setFont(EntityTabPane.titleFont);
gridbag.setConstraints(title, c);
add(title);
c.gridy++;
gridbag.setConstraints(status, c);
add(status);
c.gridy++;
transBox = Box.createHorizontalBox();
gridbag.setConstraints(transBox, c);
add(transBox);
c.weightx=0; c.gridx++;
executors = MainFrame.getExecutionPlugins();
if (executors.getItemCount() > 1) {
gridbag.setConstraints(executors, c);
add(executors);
}
if (MainFrame.isAdmin) {
c.gridx=0; c.gridy++;
title = new JLabel("State Hacking");
title.setFont(EntityTabPane.titleFont);
gridbag.setConstraints(title, c);
add(title);
Box hackBox = Box.createHorizontalBox();
hackBox.add(states);
hackBox.add(Box.createHorizontalGlue());
hackBox.add(new JLabel("Active:"));
hackBox.add(active);
c.gridy++;
gridbag.setConstraints(hackBox, c);
add(hackBox);
states.addActionListener(this);
active.addActionListener(this);
}
clear();
}
/**
*
*/
public void select(Vertex vert) {
clear();
if (!(vert instanceof Activity)) return;
mCurrentAct = (Activity)vert;
states.setSelectedIndex(mCurrentAct.getCurrentState());
states.setEnabled(true);
active.setSelected(mCurrentAct.active);
active.setEnabled(true);
Logger.msg("Retrieving possible transitions for activity "+mCurrentAct.getName());
int[] transitions = mCurrentAct.getMachine().possibleTransition();
if (transitions.length == 0) {
status.setText("None");
return;
}
for (int i = 0; i < transitions.length; i++) {
String trans= Transitions.getTransitionName(transitions[i]);
if (!(transitions[i]==Transitions.DONE) && !(transitions[i]==Transitions.COMPLETE)) {
String buttonLabel = trans.substring(0,1).toUpperCase()+trans.substring(1);
JButton thisTrans = new JButton(buttonLabel);
thisTrans.setActionCommand("Trans:"+String.valueOf(transitions[i]));
thisTrans.addActionListener(this);
transBox.add(thisTrans);
transBox.add(Box.createHorizontalGlue());
}
status.setText(transitions.length+" transitions possible.");
}
revalidate();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == active && mCurrentAct != null) {
mCurrentAct.active = active.isSelected();
return;
}
if (e.getSource() == states && mCurrentAct != null) {
mCurrentAct.getMachine().state = states.getSelectedIndex();
return;
}
if (!e.getActionCommand().startsWith("Trans:")) return;
int transition = Integer.parseInt(e.getActionCommand().substring(6));
Logger.msg("Requesting transition "+transition);
Job thisJob = new Job(mItem.getSystemKey(),
mCurrentAct.getPath(),
transition,
new StateMachine(mCurrentAct).simulate(transition),
mCurrentAct.getCurrentState(),
mCurrentAct.getName(),
mCurrentAct.getProperties(),
mCurrentAct.getType(),
MainFrame.userAgent.getName());
try {
Executor selectedExecutor = (Executor)executors.getSelectedItem();
selectedExecutor.execute(thisJob, status);
} catch (Exception ex) {
String className = ex.getClass().getName();
className = className.substring(className.lastIndexOf('.')+1);
Logger.error(ex);
JOptionPane.showMessageDialog(null, ex.getMessage(), className, JOptionPane.ERROR_MESSAGE);
}
}
public void clear() {
mCurrentAct = null;
transBox.removeAll();
status.setText("No activity selected");
states.setSelectedIndex(0);
states.setEnabled(false);
active.setSelected(false);
active.setEnabled(false);
revalidate();
}
/**
* @param item The mItem to set.
*/
public void setItem(ItemProxy item) {
mItem = item;
}
}
|