import WebFlow.*; import WebFlow.event.*; import WebFlow.xml.*; import WebFlow.submitJob2.*; import WebFlow.ATD.*; import org.omg.CORBA.*; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.util.*; public class RunAppl extends JInternalFrame { String selectedServer; desktop d; JComboBox cb, acb; Vector hosts; JTabbedPane inputs,outputs; JTabbedPane center; String AD; String application; String ApplHost; JPanel[] inTab, outTab; JTextField[] inTextField, outTextField; JTextArea cmdDisplay, stdoutTA; int cmdDisplayLength=180; String Applications[]; String xmlFile,xmlATDFile; JPanel helpPanel, optionPanel, streamPanel, argPanel, envPanel; JPanel SwPanel, ArPanel, stdoutPanel; ORB orb; String IorURL; WebFlowContext master; org.omg.CORBA.Object oxml,oatd,osj; submitJob2 submit; XmlServer parser; //XmlATD atdParser; boolean batchJob=false; String jobid; public RunAppl(desktop d) { super("Run Application", true, true, true, true); this.d = d; IorURL = d.IORfileURL; this.selectedServer = d.selectedServer; xmlFile = d.AADxml; xmlATDFile = d.AADroot+"ATD.xml"; /* if(Connection.ws==null) { scream! } connect(); */ JPanel bck = new JPanel(); bck.setLayout(new BorderLayout()); getContentPane().add(bck); JPanel upper = new JPanel(); center = new JTabbedPane(); JPanel lower = new JPanel(); /* ----- upper panel ----- */ upper.setLayout(new GridLayout(3,1)); JPanel applPanel = new JPanel(); JPanel hostPanel = new JPanel(); JPanel cmdPanel = new JPanel(); /* applPanel */ applPanel.setLayout(new GridLayout(1,2)); applPanel.add(new JLabel("select application: ")); acb = new JComboBox(); acb.setPreferredSize(new Dimension(200,20)); applicationList(); acb.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { setApplication((String)((JComboBox)e.getSource()).getSelectedItem()); } }); applPanel.add(acb); /* host panel */ hostPanel.setLayout(new GridLayout(1,2)); hostPanel.add(new JLabel("select target host: ")); hosts=new Vector(); cb = new JComboBox(hosts); cb.setPreferredSize(new Dimension(200,20)); cb.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { setApplHost((String)((JComboBox)e.getSource()).getSelectedItem()); } }); hostPanel.add(cb); /* cmdPanel */ cmdDisplay = new JTextArea(); //cmdDisplay = new JTextArea("command line goes here",cmdDisplayLength,5); cmdDisplay.setEditable(false); cmdDisplay.setPreferredSize(new Dimension(cmdDisplayLength*3,20)); cmdPanel.add(cmdDisplay); //cmdPanel.add(new JLabel("command goes here")); upper.add(applPanel); upper.add(hostPanel); upper.add(cmdPanel); /*----- end of upper pannel -----*/ /*------ center panel ------------*/ helpPanel = new JPanel(); helpPanel.add(new JLabel("Help")); optionPanel = new JPanel(); optionPanel.setLayout(new BorderLayout()); optionPanel.add(new JLabel("select switches"),BorderLayout.NORTH); argPanel = new JPanel(); argPanel.setLayout(new BorderLayout()); argPanel.add(new JLabel("set arguments"),BorderLayout.NORTH); JPanel inPanel = new JPanel(); JPanel outPanel = new JPanel(); streamPanel = new JPanel(); streamPanel.add(new JLabel("redirect streams")); envPanel = new JPanel(); envPanel.add(new JLabel("set environmental variables")); stdoutPanel = new JPanel(); stdoutPanel.setLayout(new BorderLayout()); stdoutPanel.add(new JLabel("standard output"),BorderLayout.NORTH); stdoutTA = new JTextArea(30,6); stdoutTA.setFont(new Font("Courier",Font.PLAIN,12)); JScrollPane scroller = new JScrollPane(stdoutTA,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); stdoutPanel.add(scroller,BorderLayout.CENTER); /* inPanel */ inputs = new JTabbedPane(); inPanel.add(inputs); /* outPanel */ outputs = new JTabbedPane(); outPanel.add(outputs); center.addTab("Help",helpPanel); center.addTab("options",optionPanel); center.addTab("arguments",argPanel); center.addTab("inputFiles",inPanel); center.addTab("outputFiles",outPanel); center.addTab("streams",streamPanel); center.addTab("environment",envPanel); center.addTab("stdout",stdoutPanel); /* ----- end of center panel ------*/ /* ------ lower panel -------------*/ JButton runB = new JButton("submit job"); runB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { submitJob(); } }); lower.add(runB); /* ------ end of lower panel--------*/ bck.add(upper, BorderLayout.NORTH); bck.add(center, BorderLayout.CENTER); bck.add(lower, BorderLayout.SOUTH); } public void submitJob() { String runCommand=""; if(parser.instantiateParser(xmlFile)) { System.out.println("submit job"); /* command line */ System.out.println("CommandLine="); runCommand=cmdDisplay.getText(); System.out.println(runCommand); parser.addRunCommand(application,ApplHost,runCommand); /* input files */ System.out.println("input files"); int n=inputs.getTabCount(); if(n<1) { System.out.println("no input files defined"); } else { System.out.println(n+" file(s) defined"); JTextField jtf=null; String inFile=""; for(int j=0; j-1) batchJob=true; else batchJob=false; jobid="0"; if(ApplHost.equals(d.RootHost)) { submit.submitLocally(runCommand); } else { submit.submitRsh(ApplHost,"pse",runCommand); } System.out.println("run locally completed"); String OLine=""; stdoutTA.setText(OLine); int curLine=0; System.out.println("start reading..."); while(!OLine.equals("theEnd")) { OLine=submit.getOLine(curLine); if(OLine.equals("wait")) { System.out.println("waiting..."); waitFor(10); } else { //System.out.println(curLine+" "+OLine); stdoutTA.append(OLine+"\n"); if(batchJob) { //extract job id int id1=OLine.indexOf("<"); int id2=OLine.indexOf(">"); if(id1>-1) { if(id2>-1) { jobid=OLine.substring(id1+1,id2); id1=jobid.indexOf("."); jobid=jobid.substring(0,id1); System.out.println("JobId is "+jobid); } } } submit.setLineRead(curLine); curLine++; if(curLine==20) curLine=0; } } if(batchJob) { BatchJobStatus bjs = new BatchJobStatus(jobid,ApplHost,"pse",d,submit); Thread bjsThread = new Thread(bjs); bjsThread.start(); } } public void applicationList() { System.out.println("try to instantiate parser with "+xmlFile); if(parser.instantiateParser(xmlFile)) { Applications=parser.getApplications(); } for(int i=0; i-1) thisSpace=""; if(nextToken.indexOf("space")>-1) thisSpace=" "; if(nextToken.indexOf("equals")>-1) thisSpace="="; } else { if(nextToken.startsWith("[v")) { thisValue = nextToken.substring(2,l-1); v=true; } else { if(nextToken.startsWith("[t")) { if(nextToken.equals("[tliteral]")) literal=true; else literal=false; } else { thisSwitch = nextToken; } } } } } } } } //while if(msfixed) { cmdLine += " "+thisSwitch; if(v) { cmdLine += thisSpace+thisValue; if(!literal){ System.out.println("msfixed: addTab"); JPanel swInFile = new JPanel(); swInFile.setLayout(new GridLayout(2,1)); thisSwitch +=thisSpace+thisValue; swInFile.add(new JLabel("switch: "+thisSwitch)); JTextField swInFileTF = new JTextField(30); swInFile.add(swInFileTF); swInFile.setPreferredSize(new Dimension(500,50)); inputs.addTab(thisSwitch,swInFile); } } } else { if(v) { thisSwitch += thisSpace+thisValue; if(!literal){ JCheckBox cb = new JCheckBox(thisSwitch); cb.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ev) { JCheckBox src=(JCheckBox)ev.getSource(); String what=src.getText(); checkBoxChange1(ev.getStateChange(),what); } }); SwPanel.add(cb); } } else { JCheckBox cb = new JCheckBox(thisSwitch); cb.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ev) { JCheckBox src=(JCheckBox)ev.getSource(); String what=src.getText(); checkBoxChange(ev.getStateChange(),what); } }); SwPanel.add(cb); } } } //for optionPanel.add(SwPanel,BorderLayout.CENTER); } if(!NameValue[0].equals("null")) { for(int i=0; icmdDisplayLength) { cmdDisplay.append("\n"+cmdLine.substring(0,cmdDisplayLength)); cmdLine = cmdLine.substring(cmdDisplayLength); } cmdDisplay.append("\n"+cmdLine); } */ } getInputs(); } public void updateHosts(){ String[] hostList = null; hosts.removeAllElements(); inputs.removeAll(); outputs.removeAll(); if(parser.instantiateParser(xmlFile)) { hostList = parser.getInstalledHosts(application); } try { for(int i=0; i0)) { int nfiles = inputfiles.length/2; inTab = new JPanel[nfiles]; inTextField = new JTextField[nfiles]; for(int i=0; i<(inputfiles.length); i=i+2) { int k = i/2; inTab[k] = new JPanel(); inTab[k].setLayout(new GridLayout(2,1)); inTab[k].add(new JLabel(inputfiles[i]+inputfiles[i+1])); inTextField[k]= new JTextField(30); inTab[k].add(inTextField[k]); inTab[k].setPreferredSize(new Dimension(500,50)); inputs.addTab("input file "+k,inTab[k]); } } if((outputfiles != null) && (outputfiles.length>0)) { int nfiles = outputfiles.length/2; outTab = new JPanel[nfiles]; outTextField = new JTextField[nfiles]; for(int i=0; i<(outputfiles.length); i=i+2) { int k = i/2; outTab[k] = new JPanel(); outTab[k].setLayout(new GridLayout(2,1)); outTab[k].add(new JLabel(outputfiles[i]+outputfiles[i+1])); outTextField[k]= new JTextField(30); outTab[k].add(outTextField[k]); outTab[k].setPreferredSize(new Dimension(500,50)); outputs.addTab("output file "+i,outTab[k]); } } } } public synchronized void waitFor(long howLong){ try { wait(howLong); } catch (Exception e) { System.out.println(e);} } public void checkBoxChange(int i, String what) { if(i==ItemEvent.DESELECTED) { String copy = cmdDisplay.getText(); int idx = copy.indexOf(what); String newText = copy.substring(0,idx-1); newText += copy.substring(idx+what.length()); cmdDisplay.setText(newText); } if(i==ItemEvent.SELECTED) { cmdDisplay.append(" "+what); } } public void checkBoxChange1(int i, String what) { if(i==ItemEvent.DESELECTED) { String copy = cmdDisplay.getText(); int idx = copy.indexOf(what); String newText = copy.substring(0,idx-1); newText += copy.substring(idx+what.length()); cmdDisplay.setText(newText); int k = inputs.indexOfTab(what); inputs.removeTabAt(k); } if(i==ItemEvent.SELECTED) { cmdDisplay.append(" "+what); JPanel swInFile = new JPanel(); swInFile.setLayout(new GridLayout(2,1)); swInFile.add(new JLabel(what)); JTextField swInFileTF = new JTextField(30); swInFile.add(swInFileTF); swInFile.setPreferredSize(new Dimension(500,50)); inputs.addTab(what,swInFile); } } }