1 18 19 package org.apache.jmeter.protocol.jdbc.config.gui; 20 21 import java.awt.BorderLayout ; 22 import java.awt.Dimension ; 23 24 import javax.swing.Box ; 25 import javax.swing.JLabel ; 26 import javax.swing.JPanel ; 27 import javax.swing.JScrollPane ; 28 import javax.swing.JTextArea ; 29 30 import org.apache.jmeter.config.ConfigTestElement; 31 import org.apache.jmeter.config.gui.AbstractConfigGui; 32 import org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler; 33 import org.apache.jmeter.testelement.TestElement; 34 import org.apache.jmeter.util.JMeterUtils; 35 36 39 public class SqlConfigGui extends AbstractConfigGui 40 { 41 private JTextArea sqlField; 42 private boolean displayName; 43 44 public SqlConfigGui() 45 { 46 this(true); 47 } 48 49 public SqlConfigGui(boolean displayName) 50 { 51 this.displayName = displayName; 52 init(); 53 } 54 55 public String getLabelResource() 56 { 57 return "database_sql_query_title"; 58 } 59 60 public void configure(TestElement element) 61 { 62 sqlField.setText(element.getPropertyAsString(JDBCSampler.QUERY)); 63 super.configure(element); 64 } 65 66 public TestElement createTestElement() 67 { 68 ConfigTestElement element = new ConfigTestElement(); 69 modifyTestElement(element); 70 return element; 71 } 72 73 77 public void modifyTestElement(TestElement element) 78 { 79 configureTestElement(element); 80 81 String text = sqlField.getText(); 82 text = text.replace('\n', ' '); 84 element.setProperty(JDBCSampler.QUERY, text); 85 } 86 87 private void init() 88 { 89 setLayout(new BorderLayout (0, 5)); 90 91 if (displayName) 92 { 93 setBorder(makeBorder()); 94 add(makeTitlePanel(), BorderLayout.NORTH); 95 } 96 97 JPanel panel = createSqlPanel(); 98 add(panel, BorderLayout.CENTER); 99 add( 101 Box.createVerticalStrut(panel.getPreferredSize().height), 102 BorderLayout.WEST); 103 } 104 105 private JPanel createSqlPanel() 106 { 107 sqlField = new JTextArea (); 108 sqlField.setRows(4); 109 sqlField.setLineWrap(true); 110 sqlField.setWrapStyleWord(true); 111 112 JLabel label = 113 new JLabel (JMeterUtils.getResString("database_sql_query_string")); 114 label.setLabelFor(sqlField); 115 116 JPanel panel = new JPanel (new BorderLayout ()); 117 panel.add(label, BorderLayout.NORTH); 118 panel.add(new JScrollPane (sqlField), BorderLayout.CENTER); 119 return panel; 120 } 121 122 public Dimension getPreferredSize() 123 { 124 return getMinimumSize(); 125 } 126 } 127 | Popular Tags |