source: main/trunk/greenstone3/src/java/org/greenstone/admin/guiext/CommandStep.java@ 21919

Last change on this file since 21919 was 21919, checked in by sjm84, 14 years ago

New code for GAI extension manager

File size: 3.2 KB
Line 
1package org.greenstone.admin.guiext;
2
3import org.w3c.dom.Element;
4import org.w3c.dom.NodeList;
5
6import java.util.ArrayList;
7
8import java.awt.BorderLayout;
9
10import java.awt.event.ActionListener;
11import java.awt.event.ActionEvent;
12
13import javax.swing.JTextArea;
14import javax.swing.JButton;
15import javax.swing.JPanel;
16
17import java.lang.reflect.Constructor;
18import java.lang.reflect.Method;
19
20import java.io.File;
21import java.io.BufferedReader;
22import java.io.InputStreamReader;
23
24import org.greenstone.admin.GAI;
25import org.greenstone.admin.LoggedMessageArea;
26
27public class CommandStep extends Step
28{
29 protected ArrayList _commandsAndCallbacks = new ArrayList();
30 protected LoggedMessageArea _messageArea = new LoggedMessageArea(this.getClass());
31 protected int _threadCount = -1;
32
33 /*
34 Command[] _commands = null;
35 Callback[] _callbacks = null;
36 */
37
38 public CommandStep(Element commandStepElement, SequenceList parent)
39 {
40 super(commandStepElement, parent);
41
42 if(commandStepElement != null){
43 NodeList commandAndCallbackElements = commandStepElement.getElementsByTagName("*");
44
45 for(int i = 0; i < commandAndCallbackElements.getLength(); i++){
46 Element currentChild = (Element)commandAndCallbackElements.item(i);
47 if(currentChild.getTagName().equalsIgnoreCase(ExtXMLHelper.COMMAND)){
48 _commandsAndCallbacks.add(new Command(currentChild, this));
49 }
50 else if (currentChild.getTagName().equalsIgnoreCase(ExtXMLHelper.CALLBACK)){
51 _commandsAndCallbacks.add(new Callback(currentChild, this));
52 }
53 else if (currentChild.getTagName().equalsIgnoreCase(ExtXMLHelper.OS)){
54 }
55 else{
56 System.err.println(currentChild.getTagName() + "A child of this command <" + ExtXMLHelper.STEP + "> is not either a <" + ExtXMLHelper.CALLBACK + "> element or a <" + ExtXMLHelper.COMMAND + "> element");
57 }
58 }
59
60 if(_commandsAndCallbacks.size() == 0){
61 System.err.println("This command step does not have any <" + ExtXMLHelper.COMMAND + "> or <" + ExtXMLHelper.CALLBACK +"> elements");
62 }
63
64 _button.addActionListener(new CommandButtonListener());
65
66 }
67 else{
68 System.err.println("This command <" + ExtXMLHelper.STEP + "> element is null");
69 }
70 }
71
72 public class CommandButtonListener implements ActionListener
73 {
74 public void actionPerformed(ActionEvent e)
75 {
76 ExtensionInformation info = _parent.getParent();
77
78 JPanel panel = new JPanel();
79 panel.setLayout(new BorderLayout());
80 panel.add(_messageArea, BorderLayout.CENTER);
81 info.changeExtPane(panel);
82
83 _button.setEnabled(false);
84 _button.setText("Running...");
85
86 _threadCount = 0;
87 Thread newThread = new Thread((Runnable)_commandsAndCallbacks.get(0));
88 newThread.start();
89 }
90 }
91
92 public JTextArea getMessageArea()
93 {
94 return _messageArea;
95 }
96
97 public void threadError()
98 {
99 _button.setText(_label);
100 _button.setEnabled(true);
101 }
102
103 public void startNextThread()
104 {
105 _threadCount++;
106
107 if(_threadCount < _commandsAndCallbacks.size()){
108 Thread newThread = new Thread((Runnable)_commandsAndCallbacks.get(_threadCount));
109 newThread.start();
110 }
111 else{
112 _button.setText(_label);
113 _button.setEnabled(true);
114 _parent.registerStepCompletion(CommandStep.this);
115 }
116 }
117}
Note: See TracBrowser for help on using the repository browser.