1 14 package org.compiere.db; 15 16 import javax.swing.*; 17 import java.awt.*; 18 import java.awt.event.*; 19 20 import org.compiere.util.Ini; 21 import org.compiere.plaf.*; 22 import org.compiere.swing.*; 23 import java.util.ResourceBundle ; 24 25 32 public class CConnectionDialog extends JDialog implements ActionListener 33 { 34 37 public CConnectionDialog() 38 { 39 this (null); 40 } 42 46 public CConnectionDialog(CConnection cc) 47 { 48 super((Frame)null, true); 49 try 50 { 51 jbInit(); 52 setConnection (cc); 53 } 54 catch(Exception e) 55 { 56 System.err.println("CConnectionDialog"); 57 e.printStackTrace(); 58 } 59 CompierePLAF.showCenterScreen(this); 60 } 62 private static ResourceBundle res = ResourceBundle.getBundle("org.compiere.db.DBRes"); 63 64 public static final String APPS_PORT_HTTP = "80"; 65 public static final String APPS_PORT_JNP = "1099"; 66 67 private CConnection m_cc = null; 68 private CConnection m_ccResult = null; 69 private boolean m_updating = false; 70 private boolean m_saved = false; 71 72 73 private CPanel mainPanel = new CPanel(); 74 private BorderLayout mainLayout = new BorderLayout(); 75 private CPanel centerPanel = new CPanel(); 76 private CPanel southPanel = new CPanel(); 77 private CButton bOK = CompierePLAF.getOKButton(); 78 private CButton bCancel = CompierePLAF.getCancelButton(); 79 private FlowLayout southLayout = new FlowLayout(); 80 private GridBagLayout centerLayout = new GridBagLayout(); 81 private CLabel nameLabel = new CLabel(); 82 private CTextField nameField = new CTextField(); 83 private CLabel hostLabel = new CLabel(); 84 private CTextField hostField = new CTextField(); 85 private CLabel portLabel = new CLabel(); 86 private CTextField portField = new CTextField(); 87 private CLabel sidLabel = new CLabel(); 88 private CTextField sidField = new CTextField(); 89 private CCheckBox cbFirewall = new CCheckBox(); 90 private CLabel fwHostLabel = new CLabel(); 91 private CTextField fwHostField = new CTextField(); 92 private CLabel fwPortLabel = new CLabel(); 93 private CTextField fwPortField = new CTextField(); 94 private CButton bTestDB = new CButton(); 95 private CLabel typeLabel = new CLabel(); 96 private CComboBox typeField = new CComboBox(Database.DB_NAMES); 97 private CCheckBox cbBequeath = new CCheckBox(); 98 private CLabel appsHostLabel = new CLabel(); 99 private CTextField appsHostField = new CTextField(); 100 private CLabel appsPortLabel = new CLabel(); 101 private CTextField appsPortField = new CTextField(); 102 private CButton bTestApps = new CButton(); 103 private CCheckBox cbOverwrite = new CCheckBox(); 104 private CLabel dbUidLabel = new CLabel(); 105 private CTextField dbUidField = new CTextField(); 106 private JPasswordField dbPwdField = new JPasswordField(); 107 private CCheckBox cbRMIoverHTTP = new CCheckBox(); 108 109 110 114 private void jbInit() throws Exception 115 { 116 this.setTitle(res.getString("CConnectionDialog")); 117 CompiereColor.setBackground(this); 118 mainPanel.setLayout(mainLayout); 119 southPanel.setLayout(southLayout); 120 southLayout.setAlignment(FlowLayout.RIGHT); 121 centerPanel.setLayout(centerLayout); 122 nameLabel.setText(res.getString("Name")); 123 nameField.setColumns(30); 124 hostLabel.setText(res.getString("DBHost")); 125 hostField.setColumns(30); 126 portLabel.setText(res.getString("DBPort")); 127 portField.setColumns(10); 128 sidLabel.setText(res.getString("DBName")); 129 cbFirewall.setToolTipText(""); 130 cbFirewall.setText(res.getString("ViaFirewall")); 131 fwHostLabel.setText(res.getString("FWHost")); 132 fwHostField.setColumns(30); 133 fwPortLabel.setText(res.getString("FWPort")); 134 bTestDB.setText(res.getString("TestConnection")); 135 bTestDB.setHorizontalAlignment(JLabel.LEFT); 136 typeLabel.setText(res.getString("Type")); 137 sidField.setColumns(30); 138 fwPortField.setColumns(10); 139 cbBequeath.setText(res.getString("BequeathConnection")); 140 appsHostLabel.setText(res.getString("AppsHost")); 141 appsHostField.setColumns(30); 142 appsPortLabel.setText(res.getString("AppsPort")); 143 appsPortField.setColumns(10); 144 bTestApps.setText(res.getString("TestApps")); 145 bTestApps.setHorizontalAlignment(JLabel.LEFT); 146 cbOverwrite.setText(res.getString("Overwrite")); 147 dbUidLabel.setText(res.getString("DBUidPwd")); 148 dbUidField.setColumns(10); 149 cbRMIoverHTTP.addActionListener(this); 150 cbRMIoverHTTP.setText(res.getString("RMIoverHTTP")); 151 this.getContentPane().add(mainPanel, BorderLayout.CENTER); 152 mainPanel.add(centerPanel, BorderLayout.CENTER); 153 mainPanel.add(southPanel, BorderLayout.SOUTH); 154 southPanel.add(bCancel, null); 155 southPanel.add(bOK, null); 156 centerPanel.add(nameLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 157 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(12, 12, 5, 5), 0, 0)); 158 centerPanel.add(nameField, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0 159 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(12, 0, 5, 12), 0, 0)); 160 centerPanel.add(hostLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0 161 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0)); 162 centerPanel.add(hostField, new GridBagConstraints(1, 6, 2, 1, 0.0, 0.0 163 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 12), 0, 0)); 164 centerPanel.add(portLabel, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0 165 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0)); 166 centerPanel.add(portField, new GridBagConstraints(1, 7, 1, 1, 0.0, 0.0 167 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0)); 168 centerPanel.add(sidLabel, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0 169 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0)); 170 centerPanel.add(sidField, new GridBagConstraints(1, 8, 2, 1, 0.0, 0.0 171 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0)); 172 centerPanel.add(cbFirewall, new GridBagConstraints(1, 10, 2, 1, 0.0, 0.0 173 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 12), 0, 0)); 174 centerPanel.add(fwHostLabel, new GridBagConstraints(0, 11, 1, 1, 0.0, 0.0 175 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0)); 176 centerPanel.add(fwHostField, new GridBagConstraints(1, 11, 2, 1, 0.0, 0.0 177 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0)); 178 centerPanel.add(fwPortLabel, new GridBagConstraints(0, 12, 1, 1, 0.0, 0.0 179 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0)); 180 centerPanel.add(fwPortField, new GridBagConstraints(1, 12, 1, 1, 0.0, 0.0 181 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0)); 182 centerPanel.add(bTestDB, new GridBagConstraints(1, 13, 1, 1, 0.0, 0.0 183 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 12, 0), 0, 0)); 184 centerPanel.add(typeLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0 185 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0)); 186 centerPanel.add(typeField, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0 187 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 0), 0, 0)); 188 centerPanel.add(appsHostLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 189 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 12, 5, 5), 0, 0)); 190 centerPanel.add(appsHostField, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0 191 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 5, 12), 0, 0)); 192 centerPanel.add(appsPortLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 193 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0)); 194 centerPanel.add(appsPortField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 195 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); 196 centerPanel.add(cbBequeath, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0 197 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 12), 0, 0)); 198 centerPanel.add(cbOverwrite, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0 199 ,GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 5, 0, 12), 0, 0)); 200 centerPanel.add(dbUidLabel, new GridBagConstraints(0, 9, 1, 1, 0.0, 0.0 201 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0)); 202 centerPanel.add(dbUidField, new GridBagConstraints(1, 9, 1, 1, 0.0, 0.0 203 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0)); 204 centerPanel.add(dbPwdField, new GridBagConstraints(2, 9, 1, 1, 0.0, 0.0 205 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 5, 5, 12), 0, 0)); 206 centerPanel.add(bTestApps, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0 207 ,GridBagConstraints.SOUTHWEST, GridBagConstraints.HORIZONTAL, new Insets(2, -1, 2, 1), 0, 0)); 208 centerPanel.add(cbRMIoverHTTP, new GridBagConstraints(2, 2, 1, 2, 0.0, 0.0 209 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 12), 0, 0)); 210 nameField.addActionListener(this); 212 appsHostField.addActionListener(this); 213 appsPortField.addActionListener(this); 214 cbOverwrite.addActionListener(this); 215 bTestApps.addActionListener(this); 216 typeField.addActionListener(this); 218 hostField.addActionListener(this); 219 portField.addActionListener(this); 220 sidField.addActionListener(this); 221 cbBequeath.addActionListener(this); 222 cbFirewall.addActionListener(this); 223 fwHostField.addActionListener(this); 224 fwPortField.addActionListener(this); 225 bTestDB.addActionListener(this); 226 bOK.addActionListener(this); 227 bCancel.addActionListener(this); 228 229 if (!Ini.isClient()) 231 { 232 appsHostLabel.setVisible(false); 233 appsHostField.setVisible(false); 234 appsPortLabel.setVisible(false); 235 appsPortField.setVisible(false); 236 bTestApps.setVisible(false); 237 cbRMIoverHTTP.setVisible(false); 238 } 239 else cbBequeath.setVisible(false); 241 } 243 247 private void setBusy (boolean busy) 248 { 249 if (busy) 250 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 251 else 252 this.setCursor(Cursor.getDefaultCursor()); 253 m_updating = busy; 254 } 256 260 public void setConnection (CConnection cc) 261 { 262 m_cc = cc; 263 if (m_cc == null) 264 { 265 m_cc = CConnection.get(); 266 m_cc.setName(); 267 } 268 269 m_ccResult = m_cc; 270 m_cc.setType(m_cc.getType()); updateInfo(); 273 } 275 279 public CConnection getConnection() 280 { 281 return m_ccResult; 282 } 284 288 public void actionPerformed(ActionEvent e) 289 { 290 if (m_updating) 291 return; 292 Object src = e.getSource(); 293 294 if (src == bOK) 295 { 296 m_cc.setName(); 297 m_ccResult = m_cc; 298 dispose(); 299 return; 300 } 301 else if (src == bCancel) 302 { 303 m_cc.setName(); 304 dispose(); 305 return; 306 } 307 else if (src == cbRMIoverHTTP) 308 { 309 if (cbRMIoverHTTP.isSelected()) 310 appsPortField.setText(APPS_PORT_HTTP); 311 else 312 appsPortField.setText(APPS_PORT_JNP); 313 return; 314 } 315 316 317 if (Ini.isClient()) 318 { 319 m_cc.setAppsHost(appsHostField.getText()); 320 m_cc.setAppsPort(appsPortField.getText()); 321 } 322 else 323 m_cc.setAppsHost("localhost"); 324 m_cc.setRMIoverHTTP(cbRMIoverHTTP.isSelected()); 326 m_cc.setDbHost(hostField.getText()); 328 m_cc.setDbPort(portField.getText()); 329 m_cc.setDbName(sidField.getText()); 330 m_cc.setDbUid(dbUidField.getText()); 331 m_cc.setDbPwd(String.valueOf(dbPwdField.getPassword())); 332 m_cc.setBequeath(cbBequeath.isSelected()); 333 m_cc.setViaFirewall(cbFirewall.isSelected()); 334 m_cc.setFwHost(fwHostField.getText()); 335 m_cc.setFwPort(fwPortField.getText()); 336 if (src == bTestApps) 338 cmd_testApps(); 339 340 else if (src == typeField) 342 m_cc.setType(typeField.getSelectedItem().toString()); 343 else if (src == bTestDB) 345 cmd_testDB(); 346 347 if (src == nameField) 349 m_cc.setName(nameField.getText()); 350 351 updateInfo(); 352 } 354 357 private void updateInfo() 358 { 359 m_updating = true; 360 nameField.setText(m_cc.getName()); 361 appsHostField.setText(m_cc.getAppsHost()); 362 appsPortField.setText(String.valueOf(m_cc.getAppsPort())); 363 cbRMIoverHTTP.setSelected(m_cc.isRMIoverHTTP()); 364 bTestApps.setIcon(getStatusIcon(m_cc.isAppsServerOK(false))); 365 367 cbOverwrite.setVisible(m_cc.isAppsServerOK(false)); 368 boolean rw = cbOverwrite.isSelected() || !m_cc.isAppsServerOK(false); 369 typeLabel.setReadWrite(rw); 371 typeField.setReadWrite(rw); 372 typeField.setSelectedItem(m_cc.getType()); 373 hostLabel.setReadWrite(rw); 375 hostField.setReadWrite(rw); 376 hostField.setText(m_cc.getDbHost()); 377 portLabel.setReadWrite(rw); 378 portField.setReadWrite(rw); 379 portField.setText(String.valueOf(m_cc.getDbPort())); 380 sidLabel.setReadWrite(rw); 381 sidField.setReadWrite(rw); 382 sidField.setText(m_cc.getDbName()); 383 dbUidField.setText(m_cc.getDbUid()); 385 dbPwdField.setText(m_cc.getDbPwd()); 386 cbBequeath.setReadWrite(rw); 388 cbBequeath.setEnabled(m_cc.isOracle()); 389 cbBequeath.setSelected(m_cc.isBequeath()); 390 boolean fwEnabled = m_cc.isViaFirewall() && m_cc.isOracle(); 392 cbFirewall.setReadWrite(rw); 393 cbFirewall.setSelected(fwEnabled); 394 cbFirewall.setEnabled(m_cc.isOracle()); 395 fwHostLabel.setReadWrite(fwEnabled && rw); 396 fwHostField.setReadWrite(fwEnabled && rw); 397 fwHostField.setText(m_cc.getFwHost()); 398 fwPortLabel.setReadWrite(fwEnabled && rw); 399 fwPortField.setReadWrite(fwEnabled && rw); 400 fwPortField.setText(String.valueOf(m_cc.getFwPort())); 401 bTestDB.setToolTipText(m_cc.getConnectionURL()); 403 bTestDB.setIcon(getStatusIcon(m_cc.isDatabaseOK())); 404 m_updating = false; 405 } 407 412 private Icon getStatusIcon (boolean ok) 413 { 414 if (ok) 415 return bOK.getIcon(); 416 else 417 return bCancel.getIcon(); 418 } 420 423 private void cmd_testDB() 424 { 425 setBusy (true); 426 Exception e = m_cc.testDatabase(); 427 if (e != null) 428 { 429 JOptionPane.showMessageDialog(this, 430 e, res.getString("ConnectionError") + " - " + m_cc.getConnectionURL(), 432 JOptionPane.ERROR_MESSAGE); 433 } 434 setBusy (false); 435 } 437 440 private void cmd_testApps() 441 { 442 setBusy (true); 443 Exception e = m_cc.testAppsServer(); 444 if (e != null) 445 { 446 JOptionPane.showMessageDialog(this, 447 e.getLocalizedMessage(), 448 res.getString("ServerNotActive") + " - " + m_cc.getAppsHost(), 449 JOptionPane.ERROR_MESSAGE); 450 } 451 setBusy (false); 452 } 454 } | Popular Tags |