1 18 19 package org.apache.jmeter.assertions.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.assertions.BeanShellAssertion; 31 import org.apache.jmeter.testelement.TestElement; 32 import org.apache.jmeter.util.JMeterUtils; 33 34 37 public class BeanShellAssertionGui extends AbstractAssertionGui 38 { 39 40 private JTextField filename; private JTextField parameters; private JTextArea scriptField; 44 45 public BeanShellAssertionGui() 46 { 47 init(); 48 } 49 50 public void configure(TestElement element) 51 { 52 scriptField.setText(element.getPropertyAsString(BeanShellAssertion.SCRIPT)); 53 filename.setText(element.getPropertyAsString(BeanShellAssertion.FILENAME)); 54 parameters.setText(element.getPropertyAsString(BeanShellAssertion.PARAMETERS)); 55 super.configure(element); 56 } 57 58 public TestElement createTestElement() 59 { 60 BeanShellAssertion sampler = new BeanShellAssertion(); 61 modifyTestElement(sampler); 62 return sampler; 63 } 64 65 69 public void modifyTestElement(TestElement te) 70 { 71 te.clear(); 72 this.configureTestElement(te); 73 te.setProperty(BeanShellAssertion.SCRIPT, scriptField.getText()); 74 te.setProperty(BeanShellAssertion.FILENAME, filename.getText()); 75 te.setProperty(BeanShellAssertion.PARAMETERS, parameters.getText()); 76 } 77 78 public String getLabelResource() 79 { 80 return "bsh_assertion_title"; 81 } 82 83 private JPanel createFilenamePanel() { 85 JLabel label = new JLabel (JMeterUtils.getResString("bsh_script_file")); 86 87 filename = new JTextField (10); 88 filename.setName(BeanShellAssertion.FILENAME); 89 label.setLabelFor(filename); 90 91 JPanel filenamePanel = new JPanel (new BorderLayout (5, 0)); 92 filenamePanel.add(label, BorderLayout.WEST); 93 filenamePanel.add(filename, BorderLayout.CENTER); 94 return filenamePanel; 95 } 96 97 private JPanel createParameterPanel() 98 { 99 JLabel label = new JLabel (JMeterUtils.getResString("bsh_script_parameters")); 100 101 parameters = new JTextField (10); 102 parameters.setName(BeanShellAssertion.PARAMETERS); 103 label.setLabelFor(parameters); 104 105 JPanel parameterPanel = new JPanel (new BorderLayout (5,0)); 106 parameterPanel.add(label,BorderLayout.WEST); 107 parameterPanel.add(parameters, BorderLayout.CENTER); 108 return parameterPanel; 109 } 110 111 private void init() 112 { 113 setLayout(new BorderLayout (0, 5)); 114 setBorder(makeBorder()); 115 116 Box box = Box.createVerticalBox(); 117 box.add(makeTitlePanel()); 118 box.add(createParameterPanel()); 119 box.add(createFilenamePanel()); 120 add(box,BorderLayout.NORTH); 121 122 JPanel panel = createScriptPanel(); 123 add(panel, BorderLayout.CENTER); 124 add( 126 Box.createVerticalStrut(panel.getPreferredSize().height), 127 BorderLayout.WEST); 128 } 129 130 131 private JPanel createScriptPanel() 132 { 133 scriptField = new JTextArea (); 134 scriptField.setRows(4); 135 scriptField.setLineWrap(true); 136 scriptField.setWrapStyleWord(true); 137 138 JLabel label = new JLabel (JMeterUtils.getResString("bsh_assertion_script")); 139 label.setLabelFor(scriptField); 140 141 JPanel panel = new JPanel (new BorderLayout ()); 142 panel.add(label, BorderLayout.NORTH); 143 panel.add(new JScrollPane (scriptField), BorderLayout.CENTER); 144 145 JTextArea explain = new JTextArea ( 146 JMeterUtils.getResString("bsh_assertion_script_variables")); 147 explain.setLineWrap(true); 148 explain.setEditable(false); 149 explain.setBackground(this.getBackground()); 150 panel.add(explain, BorderLayout.SOUTH); 151 152 return panel; 153 } 154 } 155 | Popular Tags |