1 18 19 package org.apache.jmeter.protocol.jdbc.config.gui; 20 import java.awt.BorderLayout ; 21 22 import javax.swing.BorderFactory ; 23 import javax.swing.JLabel ; 24 import javax.swing.JPanel ; 25 import javax.swing.JTextField ; 26 27 import org.apache.jmeter.config.ConfigTestElement; 28 import org.apache.jmeter.config.gui.AbstractConfigGui; 29 import org.apache.jmeter.config.gui.LoginConfigGui; 30 import org.apache.jmeter.gui.util.VerticalPanel; 31 import org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler; 32 import org.apache.jmeter.testelement.TestElement; 33 import org.apache.jmeter.util.JMeterUtils; 34 35 38 public class DbConfigGui extends AbstractConfigGui 39 { 40 private static String URL = "url"; 41 private static String DRIVER = "driver"; 42 private JTextField urlField = new JTextField (20); 43 private JTextField driverField = new JTextField (20); 44 45 private boolean displayName; 46 private LoginConfigGui loginGui; 47 48 public DbConfigGui() 49 { 50 this(true); 51 } 52 53 public DbConfigGui(boolean displayName) 54 { 55 this.displayName = displayName; 56 init(); 57 } 58 59 public String getLabelResource() 60 { 61 return "database_login_title"; 62 } 63 64 public TestElement createTestElement() 65 { 66 ConfigTestElement element = new ConfigTestElement(); 67 modifyTestElement(element); 68 return element; 69 } 70 71 75 public void modifyTestElement(TestElement element) 76 { 77 element.clear(); 78 configureTestElement(element); 79 element.setProperty(JDBCSampler.URL, urlField.getText()); 80 element.setProperty(JDBCSampler.DRIVER, driverField.getText()); 81 element.addTestElement(loginGui.createTestElement()); 82 } 83 84 public void configure(TestElement element) 85 { 86 super.configure(element); 87 urlField.setText(element.getPropertyAsString(JDBCSampler.URL)); 88 driverField.setText(element.getPropertyAsString(JDBCSampler.DRIVER)); 89 loginGui.configure(element); 90 } 91 92 private void init() 93 { 94 setLayout(new BorderLayout (0, 5)); 95 96 if (displayName) 97 { 98 setBorder(makeBorder()); 99 100 add(makeTitlePanel(), BorderLayout.NORTH); 101 } 102 103 VerticalPanel mainPanel = new VerticalPanel(); 104 105 VerticalPanel urlJDBCPanel = new VerticalPanel(); 107 urlJDBCPanel.setBorder( 108 BorderFactory.createTitledBorder( 109 JMeterUtils.getResString("database_url_jdbc_props"))); 110 111 urlJDBCPanel.add(getUrlPanel()); 112 urlJDBCPanel.add(getDriverPanel()); 113 114 mainPanel.add(urlJDBCPanel); 115 116 JPanel loginPanel = new JPanel (new BorderLayout ()); 118 loginPanel.setBorder( 119 BorderFactory.createTitledBorder( 120 JMeterUtils.getResString("login_config"))); 121 122 loginGui = new LoginConfigGui(false); 123 loginPanel.add(loginGui, BorderLayout.NORTH); 124 125 mainPanel.add(loginPanel); 126 127 add(mainPanel, BorderLayout.CENTER); 128 } 129 130 private JPanel getDriverPanel() 131 { 132 JPanel panel = new JPanel (new BorderLayout (5, 0)); 133 JLabel label = 134 new JLabel (JMeterUtils.getResString("database_driver_class")); 135 label.setLabelFor(driverField); 136 driverField.setName(DRIVER); 137 panel.add(label, BorderLayout.WEST); 138 panel.add(driverField, BorderLayout.CENTER); 139 return panel; 140 } 141 142 private JPanel getUrlPanel() 143 { 144 JPanel panel = new JPanel (new BorderLayout (5, 0)); 145 JLabel label = new JLabel (JMeterUtils.getResString("database_url")); 146 label.setLabelFor(urlField); 147 urlField.setName(URL); 148 panel.add(label, BorderLayout.WEST); 149 panel.add(urlField, BorderLayout.CENTER); 150 return panel; 151 } 152 } 153 | Popular Tags |