1 18 19 package org.apache.jmeter.protocol.java.control.gui; 20 21 import java.awt.BorderLayout ; 22 23 import javax.swing.Box ; 24 import javax.swing.JLabel ; 25 import javax.swing.JPanel ; 26 import javax.swing.JScrollPane ; 27 import javax.swing.JTextArea ; 28 import javax.swing.JTextField ; 29 30 import org.apache.jmeter.protocol.java.sampler.BeanShellSampler; 31 import org.apache.jmeter.samplers.gui.AbstractSamplerGui; 32 import org.apache.jmeter.testelement.TestElement; 33 import org.apache.jmeter.util.JMeterUtils; 34 35 38 public class BeanShellSamplerGui extends AbstractSamplerGui 39 { 40 41 private JTextField filename; private JTextField parameters; private JTextArea scriptField; 45 46 public BeanShellSamplerGui() 47 { 48 init(); 49 } 50 51 public void configure(TestElement element) 52 { 53 scriptField.setText(element.getPropertyAsString(BeanShellSampler.SCRIPT)); 54 filename.setText(element.getPropertyAsString(BeanShellSampler.FILENAME)); 55 parameters.setText(element.getPropertyAsString(BeanShellSampler.PARAMETERS)); 56 super.configure(element); 57 } 58 59 public TestElement createTestElement() 60 { 61 BeanShellSampler sampler = new BeanShellSampler(); 62 modifyTestElement(sampler); 63 return sampler; 64 } 65 66 70 public void modifyTestElement(TestElement te) 71 { 72 te.clear(); 73 this.configureTestElement(te); 74 te.setProperty(BeanShellSampler.SCRIPT, scriptField.getText()); 75 te.setProperty(BeanShellSampler.FILENAME, filename.getText()); 76 te.setProperty(BeanShellSampler.PARAMETERS, parameters.getText()); 77 } 78 79 public String getLabelResource() 80 { 81 return "bsh_sampler_title"; 82 } 83 84 85 86 private JPanel createFilenamePanel() { 88 JLabel label = new JLabel (JMeterUtils.getResString("bsh_script_file")); 89 90 filename = new JTextField (10); 91 filename.setName(BeanShellSampler.FILENAME); 92 label.setLabelFor(filename); 93 94 JPanel filenamePanel = new JPanel (new BorderLayout (5, 0)); 95 filenamePanel.add(label, BorderLayout.WEST); 96 filenamePanel.add(filename, BorderLayout.CENTER); 97 return filenamePanel; 98 } 99 100 private JPanel createParameterPanel() 101 { 102 JLabel label = new JLabel (JMeterUtils.getResString("bsh_script_parameters")); 103 104 parameters = new JTextField (10); 105 parameters.setName(BeanShellSampler.PARAMETERS); 106 label.setLabelFor(parameters); 107 108 JPanel parameterPanel = new JPanel (new BorderLayout (5,0)); 109 parameterPanel.add(label,BorderLayout.WEST); 110 parameterPanel.add(parameters, BorderLayout.CENTER); 111 return parameterPanel; 112 } 113 114 private void init() 115 { 116 setLayout(new BorderLayout (0, 5)); 117 setBorder(makeBorder()); 118 119 Box box = Box.createVerticalBox(); 120 box.add(makeTitlePanel()); 121 box.add(createParameterPanel()); 122 box.add(createFilenamePanel()); 123 add(box,BorderLayout.NORTH); 124 125 JPanel panel = createScriptPanel(); 126 add(panel, BorderLayout.CENTER); 127 add( 129 Box.createVerticalStrut(panel.getPreferredSize().height), 130 BorderLayout.WEST); 131 } 132 133 134 private JPanel createScriptPanel() 135 { 136 scriptField = new JTextArea (); 137 scriptField.setRows(4); 138 scriptField.setLineWrap(true); 139 scriptField.setWrapStyleWord(true); 140 141 JLabel label = new JLabel (JMeterUtils.getResString("bsh_script")); 142 label.setLabelFor(scriptField); 143 144 JPanel panel = new JPanel (new BorderLayout ()); 145 panel.add(label, BorderLayout.NORTH); 146 panel.add(new JScrollPane (scriptField), BorderLayout.CENTER); 147 return panel; 148 } 149 } 150 | Popular Tags |