1 14 package org.compiere.apps; 15 16 import java.awt.BorderLayout ; 17 import java.awt.Color ; 18 import java.awt.Cursor ; 19 import java.awt.Dimension ; 20 import java.awt.Frame ; 21 import java.awt.GridBagConstraints ; 22 import java.awt.GridBagLayout ; 23 import java.awt.Insets ; 24 import java.awt.event.ActionEvent ; 25 import java.awt.event.ActionListener ; 26 import java.awt.event.WindowEvent ; 27 import java.sql.Timestamp ; 28 import java.util.Locale ; 29 import java.util.Properties ; 30 import java.util.ResourceBundle ; 31 32 import javax.swing.JDialog ; 33 import javax.swing.JOptionPane ; 34 import javax.swing.JPanel ; 35 import javax.swing.JPasswordField ; 36 import javax.swing.JScrollPane ; 37 import javax.swing.JTextField ; 38 import javax.swing.SwingConstants ; 39 import javax.swing.event.ChangeEvent ; 40 import javax.swing.event.ChangeListener ; 41 42 import org.compiere.Compiere; 43 import org.compiere.db.CConnection; 44 import org.compiere.db.CConnectionEditor; 45 import org.compiere.grid.ed.VComboBox; 46 import org.compiere.grid.ed.VDate; 47 import org.compiere.plaf.CompiereColor; 48 import org.compiere.plaf.CompierePLAF; 49 import org.compiere.print.CPrinter; 50 import org.compiere.swing.CLabel; 51 import org.compiere.swing.CPanel; 52 import org.compiere.swing.CTabbedPane; 53 import org.compiere.util.*; 54 55 61 public final class ALogin extends JDialog 62 implements ActionListener , ChangeListener 63 { 64 69 public ALogin(Frame parent) 70 { 71 super (parent, "Login", true); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 73 m_WindowNo = Env.createWindowNo (null); 74 res = ResourceBundle.getBundle(RESOURCE); 75 try 77 { 78 jbInit(); 79 } 80 catch(Exception e) 81 { 82 System.out.println(e.toString()); 83 } 84 this.setFocusTraversalPolicy(AFocusTraversalPolicy.get()); 86 this.getRootPane().setDefaultButton(confirmPanel.getOKButton()); 87 } 89 94 public boolean initLogin() 95 { 96 m_cc = CConnection.get(); 97 hostField.setValue(m_cc); 98 validateConnection (); 99 100 userTextField.setText(Ini.getProperty(Ini.P_UID)); 102 if (Ini.getPropertyBool(Ini.P_STORE_PWD)) 103 passwordField.setText(Ini.getProperty(Ini.P_PWD)); 104 else 105 passwordField.setText(""); 106 languageCombo.setSelectedItem(Ini.getProperty(Ini.P_LANGUAGE)); 108 109 Env.setAutoCommit(m_ctx, Ini.getPropertyBool(Ini.P_A_COMMIT)); 111 Env.setContext(m_ctx, "#ShowAcct", Ini.getProperty(Ini.P_SHOW_ACCT)); 112 Env.setContext(m_ctx, "#ShowTrl", Ini.getProperty(Ini.P_SHOW_TRL)); 113 114 if (Ini.getPropertyBool(Ini.P_A_LOGIN)) 116 { 117 connectionOK (); 118 defaultsOK (); 119 return m_connectionOK; 120 } 121 return false; 122 } 124 128 protected void processWindowEvent(WindowEvent e) 129 { 130 super.processWindowEvent(e); 131 if (e.getID() == WindowEvent.WINDOW_OPENED) 132 { 133 this.toFront(); 134 confirmPanel.getOKButton().requestFocusInWindow(); 135 } 136 } 138 141 private void validateConnection() 142 { 143 m_connectionOK = false; 144 Logger.switchLoggingOff(); 145 m_cc.testAppsServer(); 147 m_cc.testDatabase(); 148 Logger.switchLoggingOn(); 150 hostField.setDisplay(); 151 } 153 protected static final String RESOURCE = "org.compiere.apps.ALoginRes"; 154 private static ResourceBundle res = ResourceBundle.getBundle(RESOURCE); 155 156 private CPanel mainPanel = new CPanel(new BorderLayout ()); 157 private CTabbedPane loginTabPane = new CTabbedPane(); 158 private BorderLayout conTabLayout = new BorderLayout (); 159 private CPanel connectionPanel = new CPanel(); 160 private CLabel hostLabel = new CLabel(); 161 private CConnectionEditor hostField = new CConnectionEditor(); 162 private CLabel userLabel = new CLabel(); 163 private JTextField userTextField = new JTextField (); 164 private CLabel passwordLabel = new CLabel(); 165 private JPasswordField passwordField = new JPasswordField (); 166 private CPanel defaultPanel = new CPanel(); 167 private BorderLayout defaultLayout = new BorderLayout (); 168 private CLabel clientLabel = new CLabel(); 169 private CLabel orgLabel = new CLabel(); 170 private CLabel dateLabel = new CLabel(); 171 private VDate dateField = new VDate(DisplayType.Date); 172 private VComboBox orgCombo = new VComboBox(); 173 private VComboBox clientCombo = new VComboBox(); 174 private CLabel warehouseLabel = new CLabel(); 175 private VComboBox warehouseCombo = new VComboBox(); 176 private CLabel printerLabel = new CLabel(); 177 private CPrinter printerField = new CPrinter(); 178 private CLabel roleLabel = new CLabel(); 179 private VComboBox roleCombo = new VComboBox(); 180 private CLabel copy0Label = new CLabel(); 181 private CLabel titleLabel = new CLabel(); 182 private CLabel versionLabel = new CLabel(); 183 private CLabel copy1Label = new CLabel(); 184 private GridBagLayout connectionLayout = new GridBagLayout (); 185 private GridBagLayout defaultPanelLayout = new GridBagLayout (); 186 private CLabel languageLabel = new CLabel(); 187 private VComboBox languageCombo = new VComboBox(Language.getNames()); 188 private CLabel compileDate = new CLabel(); 189 private CPanel southPanel = new CPanel(); 190 private BorderLayout southLayout = new BorderLayout (); 191 private StatusBar statusBar = new StatusBar(); 192 private ConfirmPanel confirmPanel = new ConfirmPanel(true); 193 private OnlineHelp onlineHelp = new OnlineHelp(true); 194 private JPanel helpPanel = new JPanel (); 195 private JScrollPane helpScollPane = new JScrollPane (); 196 private BorderLayout helpLayout = new BorderLayout (); 197 198 199 private CConnection m_cc; 200 201 private String m_user; 202 203 private String m_pwd; 204 205 private boolean m_connectionOK = false; 206 private int m_WindowNo; 207 private Properties m_ctx = Env.getCtx(); 208 210 211 212 216 private void jbInit() throws Exception 217 { 218 this.setName("Login"); 219 CompiereColor.setBackground(this); 220 titleLabel.setFont(new java.awt.Font ("Serif", 2, 10)); 221 titleLabel.setForeground(Color.blue); 222 titleLabel.setRequestFocusEnabled(false); 223 titleLabel.setToolTipText(Compiere.getURL()); 224 titleLabel.setHorizontalTextPosition(SwingConstants.CENTER); 225 titleLabel.setIcon(Compiere.getImageIconLogo()); 226 titleLabel.setText(Compiere.getSubtitle()); 227 titleLabel.setVerticalTextPosition(SwingConstants.BOTTOM); 228 versionLabel.setRequestFocusEnabled(false); 229 versionLabel.setHorizontalAlignment(SwingConstants.RIGHT); 230 versionLabel.setHorizontalTextPosition(SwingConstants.RIGHT); 231 hostLabel.setRequestFocusEnabled(false); 232 hostLabel.setLabelFor(hostField); 233 hostField.addActionListener(this); 234 userLabel.setRequestFocusEnabled(false); 235 userLabel.setLabelFor(userTextField); 236 passwordLabel.setRequestFocusEnabled(false); 237 passwordLabel.setLabelFor(passwordField); 238 languageLabel.setLabelFor(languageCombo); 239 copy0Label.setFont(new java.awt.Font ("Serif", 2, 10)); 240 copy0Label.setForeground(Color.blue); 241 copy0Label.setRequestFocusEnabled(false); 242 copy1Label.setRequestFocusEnabled(false); 243 roleLabel.setRequestFocusEnabled(false); 244 roleLabel.setLabelFor(roleCombo); 245 clientLabel.setRequestFocusEnabled(false); 246 orgLabel.setRequestFocusEnabled(false); 247 dateLabel.setRequestFocusEnabled(false); 248 warehouseLabel.setRequestFocusEnabled(false); 249 printerLabel.setRequestFocusEnabled(false); 250 compileDate.setHorizontalAlignment(SwingConstants.RIGHT); 251 compileDate.setHorizontalTextPosition(SwingConstants.RIGHT); 252 compileDate.setText(Compiere.DATE_VERSION); 253 compileDate.setToolTipText(Compiere.getImplementationVendor()); 254 southPanel.setLayout(southLayout); 255 loginTabPane.addChangeListener(this); 256 257 connectionPanel.setLayout(connectionLayout); 259 titleLabel.setHorizontalAlignment(SwingConstants.CENTER); 261 versionLabel.setText(Compiere.MAIN_VERSION); 262 versionLabel.setToolTipText(Compiere.getImplementationVersion()); 263 hostLabel.setHorizontalAlignment(SwingConstants.RIGHT); 264 hostLabel.setText("Host"); 265 connectionPanel.add(hostLabel, new GridBagConstraints (0, 2, 1, 1, 0.0, 0.0 266 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (5, 12, 5, 5), 0, 0)); 267 connectionPanel.add(hostField, new GridBagConstraints (1, 2, 3, 1, 1.0, 0.0 268 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets (5, 0, 5, 12), 0, 0)); 269 userLabel.setHorizontalAlignment(SwingConstants.RIGHT); 270 userLabel.setText("User"); 271 connectionPanel.add(userLabel, new GridBagConstraints (0, 3, 1, 1, 0.0, 0.0 272 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (5, 12, 5, 5), 0, 0)); 273 userTextField.setText("System"); connectionPanel.add(userTextField, new GridBagConstraints (1, 3, 3, 1, 1.0, 0.0 275 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets (5, 0, 5, 12), 0, 0)); 276 passwordLabel.setHorizontalAlignment(SwingConstants.RIGHT); 277 passwordLabel.setText("Password"); 278 connectionPanel.add(passwordLabel, new GridBagConstraints (0, 4, 1, 1, 0.0, 0.0 279 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (0, 12, 5, 5), 0, 0)); 280 passwordField.setText("System"); connectionPanel.add(passwordField, new GridBagConstraints (1, 4, 3, 1, 1.0, 0.0 282 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets (0, 0, 5, 12), 0, 0)); 283 languageLabel.setHorizontalAlignment(SwingConstants.RIGHT); 284 languageLabel.setText("Language"); 285 connectionPanel.add(languageLabel, new GridBagConstraints (0, 5, 1, 1, 0.0, 0.0 286 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (5, 12, 5, 5), 0, 0)); 287 languageCombo.addActionListener(this); 288 connectionPanel.add(languageCombo, new GridBagConstraints (1, 5, 3, 1, 1.0, 0.0 289 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets (5, 0, 5, 12), 0, 0)); 290 copy0Label.setHorizontalAlignment(SwingConstants.RIGHT); 291 connectionPanel.add(copy0Label, new GridBagConstraints (0, 6, 1, 1, 0.0, 0.0 292 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (5, 5, 5, 5), 0, 0)); 293 copy1Label.setText(Compiere.COPYRIGHT); 294 connectionPanel.add(copy1Label, new GridBagConstraints (1, 6, 2, 1, 0.0, 0.0 295 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets (5, 5, 12, 12), 0, 0)); 296 connectionPanel.add(compileDate, new GridBagConstraints (2, 1, 2, 1, 0.0, 0.0 297 ,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets (2, 0, 0, 12), 0, 0)); 298 connectionPanel.add(titleLabel, new GridBagConstraints (0, 0, 2, 2, 0.0, 0.0 299 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets (12, 12, 5, 5), 0, 0)); 300 connectionPanel.add(versionLabel, new GridBagConstraints (2, 0, 2, 1, 0.0, 0.0 301 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (12, 5, 0, 12), 0, 0)); 302 303 loginTabPane.add(connectionPanel, res.getString("Connection")); 304 305 defaultPanel.setLayout(defaultPanelLayout); 307 roleLabel.setText("Role"); 309 roleLabel.setHorizontalAlignment(SwingConstants.RIGHT); 310 roleCombo.addActionListener(this); 311 defaultPanel.add(roleLabel, new GridBagConstraints (0, 0, 1, 1, 0.0, 0.0 312 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (12, 12, 5, 5), 0, 0)); 313 defaultPanel.add(roleCombo, new GridBagConstraints (1, 0, 1, 1, 1.0, 0.0 314 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets (12, 0, 5, 12), 0, 0)); 315 clientLabel.setText("Client"); 316 clientLabel.setHorizontalAlignment(SwingConstants.RIGHT); 317 clientCombo.addActionListener(this); 318 defaultPanel.add(clientLabel, new GridBagConstraints (0, 1, 1, 1, 0.0, 0.0 319 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (5, 12, 5, 5), 0, 0)); 320 defaultPanel.add(clientCombo, new GridBagConstraints (1, 1, 1, 1, 1.0, 0.0 321 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets (5, 0, 5, 12), 0, 0)); 322 orgLabel.setText("Organization"); 323 orgLabel.setHorizontalAlignment(SwingConstants.RIGHT); 324 defaultPanel.add(orgLabel, new GridBagConstraints (0, 2, 1, 1, 0.0, 0.0 325 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (0, 12, 5, 5), 0, 0)); 326 defaultPanel.add(orgCombo, new GridBagConstraints (1, 2, 1, 1, 1.0, 0.0 327 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets (0, 0, 5, 12), 0, 0)); 328 dateLabel.setText("Date"); 329 dateLabel.setHorizontalAlignment(SwingConstants.RIGHT); 330 defaultPanel.add(dateLabel, new GridBagConstraints (0, 4, 1, 1, 0.0, 0.0 331 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (5, 12, 5, 5), 0, 0)); 332 defaultPanel.add(dateField, new GridBagConstraints (1, 4, 1, 1, 1.0, 0.0 333 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets (5, 0, 5, 12), 0, 0)); 334 warehouseLabel.setText("Warehouse"); 336 warehouseLabel.setHorizontalAlignment(SwingConstants.RIGHT); 337 printerLabel.setText("Printer"); 338 printerLabel.setHorizontalAlignment(SwingConstants.RIGHT); 339 defaultPanel.add(printerLabel, new GridBagConstraints (0, 5, 1, 1, 0.0, 0.0 340 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (0, 12, 12, 5), 0, 0)); 341 defaultPanel.add(printerField, new GridBagConstraints (1, 5, 1, 1, 1.0, 0.0 342 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets (0, 0, 12, 12), 0, 0)); 343 defaultPanel.add(warehouseLabel, new GridBagConstraints (0, 3, 1, 1, 0.0, 0.0 344 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets (5, 12, 5, 5), 0, 0)); 345 defaultPanel.add(warehouseCombo, new GridBagConstraints (1, 3, 1, 1, 1.0, 0.0 346 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets (5, 0, 5, 12), 0, 0)); 347 loginTabPane.add(defaultPanel, res.getString("Defaults")); 349 350 helpPanel.setLayout(helpLayout); 352 helpPanel.setPreferredSize(new Dimension (100,100)); 353 helpPanel.add(helpScollPane, BorderLayout.CENTER); 354 loginTabPane.add(helpPanel, "?"); 355 this.getContentPane().add(mainPanel); 357 mainPanel.add(loginTabPane, BorderLayout.CENTER); 358 mainPanel.setName("loginMainPanel"); 359 mainPanel.add(southPanel, BorderLayout.SOUTH); 360 southPanel.add(confirmPanel, BorderLayout.NORTH); 362 southPanel.add(statusBar, BorderLayout.SOUTH); 363 helpScollPane.getViewport().add(onlineHelp, null); 364 confirmPanel.addActionListener(this); 365 statusBar.setStatusDB(null); 366 } 368 371 private void appExit() 372 { 373 m_connectionOK = false; 374 dispose(); 375 } 377 378 379 383 public boolean isConnected() 384 { 385 return m_connectionOK; 386 } 388 389 390 391 395 public void actionPerformed(ActionEvent e) 396 { 397 if (e.getActionCommand().equals(ConfirmPanel.A_OK)) 398 { 399 if (loginTabPane.getSelectedIndex() == 0) 400 { 401 connectionOK(); 405 } 409 else 410 defaultsOK(); 411 } 412 else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) 413 appExit(); 414 else if (e.getSource() == hostField) 416 validateConnection(); 417 else if (e.getSource() == languageCombo) 418 languageComboChanged(); 419 else if (e.getSource() == roleCombo) 421 roleComboChanged(); 422 else if (e.getSource() == clientCombo) 423 clientComboChanged(); 424 } 426 427 428 429 432 private void connectionOK () 433 { 434 Log.trace(Log.l1_User, "ALogin.connectionOK"); 435 setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 437 confirmPanel.getOKButton().setEnabled(false); 438 440 m_connectionOK = tryConnection(); 441 if (m_connectionOK) { 444 Env.verifyLanguage (m_ctx, Language.getLanguage()); 446 printerField.setValue(Ini.getProperty(Ini.P_PRINTER)); 448 loginTabPane.setSelectedIndex(1); 450 } 451 452 confirmPanel.getOKButton().setEnabled(true); 454 setCursor(Cursor.getDefaultCursor()); 455 } 457 458 462 public void stateChanged(ChangeEvent e) 463 { 464 Log.trace(Log.l3_Util, "ALogin.loginTabPane_stateChanged"); 465 if (loginTabPane.getSelectedIndex() == 2) return; 467 468 if (!(String.valueOf(passwordField.getPassword()).equals(m_pwd) 469 && userTextField.getText().equals(m_user))) 470 m_connectionOK = false; 471 if (m_connectionOK) 473 statusBar.setStatusLine(txt_LoggedIn); 474 else 475 { 476 statusBar.setStatusLine(txt_NotConnected, true); 477 loginTabPane.setSelectedIndex(0); 478 } 479 confirmPanel.getOKButton().requestFocus(); 480 } 482 483 484 485 488 private void defaultsOK () 489 { 490 Log.trace(Log.l1_User, "ALogin.defaultOK"); 491 492 KeyNamePair org = (KeyNamePair)orgCombo.getSelectedItem(); 493 if (org == null) 494 return; 495 496 Ini.setProperty(Ini.P_CONNECTION, CConnection.get().toStringLong()); 498 Ini.setProperty(Ini.P_LANGUAGE, (String )languageCombo.getSelectedItem()); 499 500 statusBar.setStatusLine("Loading Preferences"); 502 String msg = DB.loadPreferences(m_ctx, org, 503 (KeyNamePair)warehouseCombo.getSelectedItem(), 504 dateField.getTimestamp(), printerField.getDisplay()); 505 if (msg.length() > 0) 506 ADialog.info(m_WindowNo, this, msg); 507 508 checkVersion(); 511 if (m_connectionOK) 513 this.dispose(); 514 } 516 517 518 519 525 private boolean tryConnection() 526 { 527 m_user = userTextField.getText(); 528 m_pwd = new String (passwordField.getPassword()); 529 530 DB.closeTarget(); 532 DB.setDBTarget(CConnection.get()); 533 if (!DB.isConnected()) 534 { 535 statusBar.setStatusLine(txt_NoDatabase, true); 536 hostField.setBackground(CompierePLAF.getFieldBackground_Error()); 537 return false; 538 } 539 540 KeyNamePair[] roles = DB.login(m_ctx, m_user, m_pwd); 542 if (roles == null || roles.length == 0) 543 { 544 statusBar.setStatusLine(txt_UserPwdError, true); 545 userTextField.setBackground(CompierePLAF.getFieldBackground_Error()); 546 passwordField.setBackground(CompierePLAF.getFieldBackground_Error()); 547 return false; 548 } 549 if (roleCombo.getItemCount() > 0) 551 roleCombo.removeAllItems(); 552 553 KeyNamePair iniValue = null; 555 String iniDefault = Ini.getProperty(Ini.P_ROLE); 556 557 for (int i = 0; i < roles.length; i++) 559 { 560 roleCombo.addItem(roles[i]); 561 if (roles[i].getName().equals(iniDefault)) 562 iniValue = roles[i]; 563 } 564 if (iniValue != null) 565 roleCombo.setSelectedItem(iniValue); 566 567 userTextField.setBackground(CompierePLAF.getFieldBackground_Normal()); 568 passwordField.setBackground(CompierePLAF.getFieldBackground_Normal()); 569 statusBar.setStatusLine(txt_LoggedIn); 571 return true; 572 } 574 575 578 private void roleComboChanged () 579 { 580 Log.trace(Log.l3_Util, "ALogin.roleComboChanged"); 581 KeyNamePair role = (KeyNamePair)roleCombo.getSelectedItem(); 582 if (role == null) 583 return; 584 KeyNamePair[] clients = DB.loadClients(m_ctx, role); 586 if (clientCombo.getItemCount() > 0) 588 clientCombo.removeAllItems(); 589 if (orgCombo.getItemCount() > 0) 590 orgCombo.removeAllItems(); 591 if (clients == null || clients.length == 0) 593 { 594 statusBar.setStatusLine(txt_RoleError, true); 595 return; 596 } 597 KeyNamePair iniValue = null; 599 String iniDefault = Ini.getProperty(Ini.P_CLIENT); 600 601 for (int i = 0; i < clients.length; i++) 603 { 604 clientCombo.addItem(clients[i]); 605 if (clients[i].getName().equals(iniDefault)) 606 iniValue = clients[i]; 607 } 608 if (iniValue != null) 609 clientCombo.setSelectedItem(iniValue); 610 else 611 clientCombo.setSelectedIndex(0); 612 } 614 615 618 private void clientComboChanged() 619 { 620 Log.trace(Log.l3_Util, "ALogin.clientComboChanged"); 621 KeyNamePair client = (KeyNamePair)clientCombo.getSelectedItem(); 622 if (client == null) 623 return; 624 KeyNamePair[] orgs = DB.loadOrgs(m_ctx, client); 626 if (orgCombo.getItemCount() > 0) 628 orgCombo.removeAllItems(); 629 630 if (orgs == null || orgs.length == 0) 632 { 633 statusBar.setStatusLine(txt_RoleError, true); 634 return; 635 } 636 KeyNamePair iniValue = null; 638 String iniDefault = Ini.getProperty(Ini.P_ORG); 639 640 for (int i = 0; i < orgs.length; i++) 642 { 643 orgCombo.addItem(orgs[i]); 644 if (orgs[i].getName().equals(iniDefault)) 645 iniValue = orgs[i]; 646 } 647 if (iniValue != null) 648 orgCombo.setSelectedItem(iniValue); 649 650 653 KeyNamePair[] whs = DB.loadWarehouses(m_ctx, client); 654 if (warehouseCombo.getItemCount() > 0) 656 warehouseCombo.removeAllItems(); 657 658 if (whs != null) 660 { 661 iniValue = null; 663 iniDefault = Ini.getProperty(Ini.P_WAREHOUSE); 664 for (int i = 0; i < whs.length; i++) 665 { 666 warehouseCombo.addItem(whs[i]); 667 if (whs[i].getName().equals(iniDefault)) 668 iniValue = whs[i]; 669 } 670 if (iniValue != null) 671 warehouseCombo.setSelectedItem(iniValue); 672 } 673 } 675 681 private boolean checkVersion() 682 { 683 boolean retValue = false; 684 try 685 { 686 String version = AEnv.getServerVersion(); 687 if (Compiere.DATE_VERSION.equals(version)) 688 { 689 Log.trace(Log.l4_Data, "ALogin.checkVersion", "Server = Client - " + version); 690 retValue = true; 691 } 692 else if (version != null) 693 { 694 StringBuffer msg = new StringBuffer (">>\n"); 695 msg.append(res.getString("VersionConflict")).append("\n") 696 .append(res.getString("VersionInfo")).append("\n"); 697 msg.append(version == null ? "null" : version).append(" <> ") 698 .append(Compiere.DATE_VERSION).append("\n"); 699 msg.append(res.getString("PleaseUpgrade")).append("\n<<"); 700 JOptionPane.showMessageDialog(null, msg.toString(), 701 Compiere.getName() + " - " + res.getString("VersionConflict"), 702 JOptionPane.ERROR_MESSAGE); 703 AEnv.exit(1); 704 } 705 } 706 catch (Exception e) 707 { 708 System.err.println("Contact Server failed - " 709 + e.getClass().toString() + ": " + e.getMessage()); 710 } 711 return retValue; 712 } 714 715 718 private String txt_Connected, txt_NotConnected, txt_NoDatabase, 719 txt_UserPwdError, txt_RoleError, txt_LoggedIn; 720 721 724 private void languageComboChanged () 725 { 726 String langName = (String )languageCombo.getSelectedItem(); 727 Language language = Language.getLanguage(langName); 729 Language.setLanguage(language); 730 Env.setContext(m_ctx, Env.LANG, language.getAD_Language()); 731 732 Locale loc = language.getLocale(); 734 Locale.setDefault(loc); 735 this.setLocale(loc); 736 res = ResourceBundle.getBundle(RESOURCE, loc); 737 this.setTitle(res.getString("Login")); 739 hostLabel.setText(res.getString("Host")); 740 userLabel.setText(res.getString("User")); 741 userLabel.setToolTipText(res.getString("EnterUser")); 742 passwordLabel.setText(res.getString("Password")); 743 passwordLabel.setToolTipText(res.getString("EnterPassword")); 744 languageLabel.setText(res.getString("Language")); 745 languageLabel.setToolTipText(res.getString("SelectLanguage")); 746 roleLabel.setText(res.getString("Role")); 748 clientLabel.setText(res.getString("Client")); 749 orgLabel.setText(res.getString("Organization")); 750 dateLabel.setText(res.getString("Date")); 751 warehouseLabel.setText(res.getString("Warehouse")); 752 printerLabel.setText(res.getString("Printer")); 753 defaultPanel.setToolTipText(res.getString("Defaults")); 754 connectionPanel.setToolTipText(res.getString("Connection")); 755 txt_Connected = res.getString("Connected"); 757 txt_NotConnected = res.getString("NotConnected"); 758 txt_NoDatabase = res.getString("DatabaseNotFound"); 759 txt_UserPwdError = res.getString("UserPwdError"); 760 txt_RoleError = res.getString("RoleNotFound"); 761 txt_LoggedIn = res.getString("Authorized"); 762 loginTabPane.setTitleAt(0, res.getString("Connection")); 764 loginTabPane.setTitleAt(1, res.getString("Defaults")); 765 confirmPanel.getOKButton().setToolTipText(res.getString("Ok")); 766 confirmPanel.getCancelButton().setToolTipText(res.getString("Cancel")); 767 768 dateField.setFormat(); 770 dateField.setValue(new Timestamp (System.currentTimeMillis())); 771 if (m_connectionOK) 773 statusBar.setStatusLine(txt_LoggedIn); 774 else 775 statusBar.setStatusLine(txt_NotConnected, true); 776 } 778 } | Popular Tags |