[21919] | 1 | package org.greenstone.admin.guiext;
|
---|
| 2 |
|
---|
| 3 | import org.w3c.dom.Element;
|
---|
| 4 | import org.w3c.dom.NodeList;
|
---|
| 5 |
|
---|
| 6 | import java.util.ArrayList;
|
---|
| 7 |
|
---|
| 8 | import java.awt.BorderLayout;
|
---|
| 9 |
|
---|
| 10 | import java.awt.event.ActionListener;
|
---|
| 11 | import java.awt.event.ActionEvent;
|
---|
| 12 |
|
---|
| 13 | import javax.swing.JTextArea;
|
---|
| 14 | import javax.swing.JButton;
|
---|
| 15 | import javax.swing.JPanel;
|
---|
| 16 |
|
---|
| 17 | import java.lang.reflect.Constructor;
|
---|
| 18 | import java.lang.reflect.Method;
|
---|
| 19 |
|
---|
| 20 | import java.io.File;
|
---|
| 21 | import java.io.BufferedReader;
|
---|
| 22 | import java.io.InputStreamReader;
|
---|
| 23 |
|
---|
| 24 | import org.greenstone.admin.GAI;
|
---|
| 25 | import org.greenstone.admin.LoggedMessageArea;
|
---|
| 26 |
|
---|
| 27 | public 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 | } |
---|