KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > ALogin


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.apps;
15
16 import java.awt.BorderLayout JavaDoc;
17 import java.awt.Color JavaDoc;
18 import java.awt.Cursor JavaDoc;
19 import java.awt.Dimension JavaDoc;
20 import java.awt.Frame JavaDoc;
21 import java.awt.GridBagConstraints JavaDoc;
22 import java.awt.GridBagLayout JavaDoc;
23 import java.awt.Insets JavaDoc;
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.awt.event.ActionListener JavaDoc;
26 import java.awt.event.WindowEvent JavaDoc;
27 import java.sql.Timestamp JavaDoc;
28 import java.util.Locale JavaDoc;
29 import java.util.Properties JavaDoc;
30 import java.util.ResourceBundle JavaDoc;
31
32 import javax.swing.JDialog JavaDoc;
33 import javax.swing.JOptionPane JavaDoc;
34 import javax.swing.JPanel JavaDoc;
35 import javax.swing.JPasswordField JavaDoc;
36 import javax.swing.JScrollPane JavaDoc;
37 import javax.swing.JTextField JavaDoc;
38 import javax.swing.SwingConstants JavaDoc;
39 import javax.swing.event.ChangeEvent JavaDoc;
40 import javax.swing.event.ChangeListener JavaDoc;
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 /**
56  * Application Login Window
57  *
58  * @author Jorg Janke
59  * @version $Id: ALogin.java,v 1.47 2003/11/06 07:08:28 jjanke Exp $
60  */

61 public final class ALogin extends JDialog JavaDoc
62     implements ActionListener JavaDoc, ChangeListener JavaDoc
63 {
64     /**
65      * Construct the dialog.
66      * Need to call initLogin for dynamic start
67      * @param parent parent
68      */

69     public ALogin(Frame JavaDoc parent)
70     {
71         super (parent, "Login", true); // Modal
72
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
73         m_WindowNo = Env.createWindowNo (null);
74         res = ResourceBundle.getBundle(RESOURCE);
75         //
76
try
77         {
78             jbInit();
79         }
80         catch(Exception JavaDoc e)
81         {
82             System.out.println(e.toString());
83         }
84         // Focus
85
this.setFocusTraversalPolicy(AFocusTraversalPolicy.get());
86         this.getRootPane().setDefaultButton(confirmPanel.getOKButton());
87     } // ALogin
88

89     /**
90      * Set Initial & Ini Parameters
91      * Optional Automatic login
92      * @return true, if connected & parameters set
93      */

94     public boolean initLogin()
95     {
96         m_cc = CConnection.get();
97         hostField.setValue(m_cc);
98         validateConnection ();
99
100         // Application/PWD
101
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         //
107
languageCombo.setSelectedItem(Ini.getProperty(Ini.P_LANGUAGE));
108
109         // Other
110
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         // AutoLogin - assumes that connection is OK
115
if (Ini.getPropertyBool(Ini.P_A_LOGIN))
116         {
117             connectionOK ();
118             defaultsOK ();
119             return m_connectionOK;
120         }
121         return false;
122     } // initLogin
123

124     /**
125      * Window Events - requestFocus
126      * @param e event
127      */

128     protected void processWindowEvent(WindowEvent JavaDoc e)
129     {
130         super.processWindowEvent(e);
131         if (e.getID() == WindowEvent.WINDOW_OPENED)
132         {
133             this.toFront();
134             confirmPanel.getOKButton().requestFocusInWindow();
135         }
136     } // processWindowEvent
137

138     /**
139      * Validate Connection
140      */

141     private void validateConnection()
142     {
143         m_connectionOK = false;
144         Logger.switchLoggingOff();
145         //
146
m_cc.testAppsServer();
147         m_cc.testDatabase();
148         //
149
Logger.switchLoggingOn();
150         hostField.setDisplay();
151     } // validateConnection
152

153     protected static final String JavaDoc RESOURCE = "org.compiere.apps.ALoginRes";
154     private static ResourceBundle JavaDoc res = ResourceBundle.getBundle(RESOURCE);
155
156     private CPanel mainPanel = new CPanel(new BorderLayout JavaDoc());
157     private CTabbedPane loginTabPane = new CTabbedPane();
158     private BorderLayout JavaDoc conTabLayout = new BorderLayout JavaDoc();
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 JavaDoc userTextField = new JTextField JavaDoc();
164     private CLabel passwordLabel = new CLabel();
165     private JPasswordField JavaDoc passwordField = new JPasswordField JavaDoc();
166     private CPanel defaultPanel = new CPanel();
167     private BorderLayout JavaDoc defaultLayout = new BorderLayout JavaDoc();
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 JavaDoc connectionLayout = new GridBagLayout JavaDoc();
185     private GridBagLayout JavaDoc defaultPanelLayout = new GridBagLayout JavaDoc();
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 JavaDoc southLayout = new BorderLayout JavaDoc();
191     private StatusBar statusBar = new StatusBar();
192     private ConfirmPanel confirmPanel = new ConfirmPanel(true);
193     private OnlineHelp onlineHelp = new OnlineHelp(true);
194     private JPanel JavaDoc helpPanel = new JPanel JavaDoc();
195     private JScrollPane JavaDoc helpScollPane = new JScrollPane JavaDoc();
196     private BorderLayout JavaDoc helpLayout = new BorderLayout JavaDoc();
197
198     /** Server Connection */
199     private CConnection m_cc;
200     /** Application User */
201     private String JavaDoc m_user;
202     /** Application Password */
203     private String JavaDoc m_pwd;
204
205     private boolean m_connectionOK = false;
206     private int m_WindowNo;
207     private Properties JavaDoc m_ctx = Env.getCtx();
208     //
209

210     /*************************************************************************/
211
212     /**
213      * Component initialization
214      * @throws Exception
215      */

216     private void jbInit() throws Exception JavaDoc
217     {
218         this.setName("Login");
219         CompiereColor.setBackground(this);
220         titleLabel.setFont(new java.awt.Font JavaDoc("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 JavaDoc("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         // ConnectionTab
258
connectionPanel.setLayout(connectionLayout);
259         //
260
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 JavaDoc(0, 2, 1, 1, 0.0, 0.0
266             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 12, 5, 5), 0, 0));
267         connectionPanel.add(hostField, new GridBagConstraints JavaDoc(1, 2, 3, 1, 1.0, 0.0
268             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 0, 5, 12), 0, 0));
269         userLabel.setHorizontalAlignment(SwingConstants.RIGHT);
270         userLabel.setText("User");
271         connectionPanel.add(userLabel, new GridBagConstraints JavaDoc(0, 3, 1, 1, 0.0, 0.0
272             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 12, 5, 5), 0, 0));
273         userTextField.setText("System"); // default
274
connectionPanel.add(userTextField, new GridBagConstraints JavaDoc(1, 3, 3, 1, 1.0, 0.0
275             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 0, 5, 12), 0, 0));
276         passwordLabel.setHorizontalAlignment(SwingConstants.RIGHT);
277         passwordLabel.setText("Password");
278         connectionPanel.add(passwordLabel, new GridBagConstraints JavaDoc(0, 4, 1, 1, 0.0, 0.0
279             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(0, 12, 5, 5), 0, 0));
280         passwordField.setText("System"); // default
281
connectionPanel.add(passwordField, new GridBagConstraints JavaDoc(1, 4, 3, 1, 1.0, 0.0
282             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(0, 0, 5, 12), 0, 0));
283         languageLabel.setHorizontalAlignment(SwingConstants.RIGHT);
284         languageLabel.setText("Language");
285         connectionPanel.add(languageLabel, new GridBagConstraints JavaDoc(0, 5, 1, 1, 0.0, 0.0
286             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 12, 5, 5), 0, 0));
287         languageCombo.addActionListener(this);
288         connectionPanel.add(languageCombo, new GridBagConstraints JavaDoc(1, 5, 3, 1, 1.0, 0.0
289             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 0, 5, 12), 0, 0));
290         copy0Label.setHorizontalAlignment(SwingConstants.RIGHT);
291         connectionPanel.add(copy0Label, new GridBagConstraints JavaDoc(0, 6, 1, 1, 0.0, 0.0
292             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
293         copy1Label.setText(Compiere.COPYRIGHT);
294         connectionPanel.add(copy1Label, new GridBagConstraints JavaDoc(1, 6, 2, 1, 0.0, 0.0
295             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 12, 12), 0, 0));
296         connectionPanel.add(compileDate, new GridBagConstraints JavaDoc(2, 1, 2, 1, 0.0, 0.0
297             ,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets JavaDoc(2, 0, 0, 12), 0, 0));
298         connectionPanel.add(titleLabel, new GridBagConstraints JavaDoc(0, 0, 2, 2, 0.0, 0.0
299             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets JavaDoc(12, 12, 5, 5), 0, 0));
300         connectionPanel.add(versionLabel, new GridBagConstraints JavaDoc(2, 0, 2, 1, 0.0, 0.0
301             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(12, 5, 0, 12), 0, 0));
302
303         loginTabPane.add(connectionPanel, res.getString("Connection"));
304
305         // DefaultTab
306
defaultPanel.setLayout(defaultPanelLayout);
307         //
308
roleLabel.setText("Role");
309         roleLabel.setHorizontalAlignment(SwingConstants.RIGHT);
310         roleCombo.addActionListener(this);
311         defaultPanel.add(roleLabel, new GridBagConstraints JavaDoc(0, 0, 1, 1, 0.0, 0.0
312             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(12, 12, 5, 5), 0, 0));
313         defaultPanel.add(roleCombo, new GridBagConstraints JavaDoc(1, 0, 1, 1, 1.0, 0.0
314             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(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 JavaDoc(0, 1, 1, 1, 0.0, 0.0
319             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 12, 5, 5), 0, 0));
320         defaultPanel.add(clientCombo, new GridBagConstraints JavaDoc(1, 1, 1, 1, 1.0, 0.0
321             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 0, 5, 12), 0, 0));
322         orgLabel.setText("Organization");
323         orgLabel.setHorizontalAlignment(SwingConstants.RIGHT);
324         defaultPanel.add(orgLabel, new GridBagConstraints JavaDoc(0, 2, 1, 1, 0.0, 0.0
325             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(0, 12, 5, 5), 0, 0));
326         defaultPanel.add(orgCombo, new GridBagConstraints JavaDoc(1, 2, 1, 1, 1.0, 0.0
327             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(0, 0, 5, 12), 0, 0));
328         dateLabel.setText("Date");
329         dateLabel.setHorizontalAlignment(SwingConstants.RIGHT);
330         defaultPanel.add(dateLabel, new GridBagConstraints JavaDoc(0, 4, 1, 1, 0.0, 0.0
331             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 12, 5, 5), 0, 0));
332         defaultPanel.add(dateField, new GridBagConstraints JavaDoc(1, 4, 1, 1, 1.0, 0.0
333             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 0, 5, 12), 0, 0));
334         //
335
warehouseLabel.setText("Warehouse");
336         warehouseLabel.setHorizontalAlignment(SwingConstants.RIGHT);
337         printerLabel.setText("Printer");
338         printerLabel.setHorizontalAlignment(SwingConstants.RIGHT);
339         defaultPanel.add(printerLabel, new GridBagConstraints JavaDoc(0, 5, 1, 1, 0.0, 0.0
340             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(0, 12, 12, 5), 0, 0));
341         defaultPanel.add(printerField, new GridBagConstraints JavaDoc(1, 5, 1, 1, 1.0, 0.0
342             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(0, 0, 12, 12), 0, 0));
343         defaultPanel.add(warehouseLabel, new GridBagConstraints JavaDoc(0, 3, 1, 1, 0.0, 0.0
344             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 12, 5, 5), 0, 0));
345         defaultPanel.add(warehouseCombo, new GridBagConstraints JavaDoc(1, 3, 1, 1, 1.0, 0.0
346             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 0, 5, 12), 0, 0));
347         //
348
loginTabPane.add(defaultPanel, res.getString("Defaults"));
349
350         // Help
351
helpPanel.setLayout(helpLayout);
352         helpPanel.setPreferredSize(new Dimension JavaDoc (100,100));
353         helpPanel.add(helpScollPane, BorderLayout.CENTER);
354         loginTabPane.add(helpPanel, "?");
355         //
356
this.getContentPane().add(mainPanel);
357         mainPanel.add(loginTabPane, BorderLayout.CENTER);
358         mainPanel.setName("loginMainPanel");
359         mainPanel.add(southPanel, BorderLayout.SOUTH);
360         //
361
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     } // jbInit
367

368     /*************************************************************************
369      * Exit action performed
370      */

371     private void appExit()
372     {
373         m_connectionOK = false;
374         dispose();
375     } // appExit_actionPerformed
376

377
378
379     /**
380      * Return true, if logged in
381      * @return true if connected
382      */

383     public boolean isConnected()
384     {
385         return m_connectionOK;
386     } // isConnected
387

388
389     /*************************************************************************/
390
391     /**
392      * Action Event handler
393      * @param e event
394      */

395     public void actionPerformed(ActionEvent JavaDoc e)
396     {
397         if (e.getActionCommand().equals(ConfirmPanel.A_OK))
398         {
399             if (loginTabPane.getSelectedIndex() == 0)
400             {
401             // Runnable pgm = new Runnable() {
402
// public void run()
403
// {
404
connectionOK();
405             // }
406
// };
407
// new Thread(pgm).start();
408
}
409             else
410                 defaultsOK();
411         }
412         else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
413             appExit();
414         //
415
else if (e.getSource() == hostField)
416             validateConnection();
417         else if (e.getSource() == languageCombo)
418             languageComboChanged();
419         //
420
else if (e.getSource() == roleCombo)
421             roleComboChanged();
422         else if (e.getSource() == clientCombo)
423             clientComboChanged();
424     } // actionPerformed
425

426
427     /*************************************************************************/
428
429     /**
430      * Connection OK pressed
431      */

432     private void connectionOK ()
433     {
434         Log.trace(Log.l1_User, "ALogin.connectionOK");
435         //
436
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
437         confirmPanel.getOKButton().setEnabled(false);
438     // setEnabled(false); // causes flickering
439

440         m_connectionOK = tryConnection();
441         //
442
if (m_connectionOK) // switch to default
443
{
444             // Verify Language
445
Env.verifyLanguage (m_ctx, Language.getLanguage());
446             // Set Defaults
447
printerField.setValue(Ini.getProperty(Ini.P_PRINTER));
448             // Change Tab
449
loginTabPane.setSelectedIndex(1);
450         }
451
452     // setEnabled(true);
453
confirmPanel.getOKButton().setEnabled(true);
454         setCursor(Cursor.getDefaultCursor());
455     } // connectionOK
456

457
458     /**
459      * Change of tab <->
460      * @param e event
461      */

462     public void stateChanged(ChangeEvent JavaDoc e)
463     {
464         Log.trace(Log.l3_Util, "ALogin.loginTabPane_stateChanged");
465         if (loginTabPane.getSelectedIndex() == 2) // allow access to help
466
return;
467
468         if (!(String.valueOf(passwordField.getPassword()).equals(m_pwd)
469             && userTextField.getText().equals(m_user)))
470             m_connectionOK = false;
471         //
472
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     } // loginTabPane
481

482
483     /*************************************************************************/
484
485     /**
486      * Defaults OK pressed
487      */

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         // Set Properties
497
Ini.setProperty(Ini.P_CONNECTION, CConnection.get().toStringLong());
498         Ini.setProperty(Ini.P_LANGUAGE, (String JavaDoc)languageCombo.getSelectedItem());
499
500         // Load Properties and save Ini values
501
statusBar.setStatusLine("Loading Preferences");
502         String JavaDoc 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         // Check Apps Server - DB Checked in Menu
509
checkVersion(); // exits if conflict
510

511         // Close - we are done
512
if (m_connectionOK)
513             this.dispose();
514     } // defaultsOK
515

516
517     /*************************************************************************/
518
519     /**
520      * Try to connect.
521      * - Get Connection
522      * - Compare User info
523      * @return true if connected
524      */

525     private boolean tryConnection()
526     {
527         m_user = userTextField.getText();
528         m_pwd = new String JavaDoc (passwordField.getPassword());
529
530         // Establish connection
531
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         // Get Roles
541
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         // Delete existing role items
550
if (roleCombo.getItemCount() > 0)
551             roleCombo.removeAllItems();
552
553         // Initial role
554
KeyNamePair iniValue = null;
555         String JavaDoc iniDefault = Ini.getProperty(Ini.P_ROLE);
556
557         // fill roles
558
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         //
570
statusBar.setStatusLine(txt_LoggedIn);
571         return true;
572     } // tryConnection
573

574
575     /**
576      * Role changed - fill Client List
577      */

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         //
585
KeyNamePair[] clients = DB.loadClients(m_ctx, role);
586         // delete existing client/org items
587
if (clientCombo.getItemCount() > 0)
588             clientCombo.removeAllItems();
589         if (orgCombo.getItemCount() > 0)
590             orgCombo.removeAllItems();
591         // No Clients
592
if (clients == null || clients.length == 0)
593         {
594             statusBar.setStatusLine(txt_RoleError, true);
595             return;
596         }
597         // initial client
598
KeyNamePair iniValue = null;
599         String JavaDoc iniDefault = Ini.getProperty(Ini.P_CLIENT);
600
601         // fill clients
602
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     } // roleComboChanged
613

614
615     /**
616      * Client changed - fill Org & Warehouse List
617      */

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         //
625
KeyNamePair[] orgs = DB.loadOrgs(m_ctx, client);
626         // delete existing cleint items
627
if (orgCombo.getItemCount() > 0)
628             orgCombo.removeAllItems();
629
630         // No Orgs
631
if (orgs == null || orgs.length == 0)
632         {
633             statusBar.setStatusLine(txt_RoleError, true);
634             return;
635         }
636         // initial client
637
KeyNamePair iniValue = null;
638         String JavaDoc iniDefault = Ini.getProperty(Ini.P_ORG);
639
640         // fill orgs
641
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         /**
651          * Set Warehouse
652          */

653         KeyNamePair[] whs = DB.loadWarehouses(m_ctx, client);
654         // Delete existing warehouse items
655
if (warehouseCombo.getItemCount() > 0)
656             warehouseCombo.removeAllItems();
657
658         // fill warehouses
659
if (whs != null)
660         {
661             // initial warehouse
662
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     } // clientComboChanged
674

675     /**
676      * Check Version
677      * @return true if version is OK and
678      * false if version could not be checked or is not the same
679      * @see AEnv#getServerVersion
680      */

681     private boolean checkVersion()
682     {
683         boolean retValue = false;
684         try
685         {
686             String JavaDoc 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 JavaDoc msg = new StringBuffer JavaDoc (">>\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 JavaDoc e)
707         {
708             System.err.println("Contact Server failed - "
709                 + e.getClass().toString() + ": " + e.getMessage());
710         }
711         return retValue;
712     } // checkVersion
713

714
715     /**************************************************************************
716      * Language issues
717      */

718     private String JavaDoc txt_Connected, txt_NotConnected, txt_NoDatabase,
719                     txt_UserPwdError, txt_RoleError, txt_LoggedIn;
720
721     /**
722      * Change Language
723      */

724     private void languageComboChanged ()
725     {
726         String JavaDoc langName = (String JavaDoc)languageCombo.getSelectedItem();
727     // Log.trace(Log.l1_User, "Language: " + langName);
728
Language language = Language.getLanguage(langName);
729         Language.setLanguage(language);
730         Env.setContext(m_ctx, Env.LANG, language.getAD_Language());
731
732         // Locales
733
Locale JavaDoc loc = language.getLocale();
734         Locale.setDefault(loc);
735         this.setLocale(loc);
736         res = ResourceBundle.getBundle(RESOURCE, loc);
737         //
738
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         //
747
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         //
756
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         //
763
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 with new format
769
dateField.setFormat();
770         dateField.setValue(new Timestamp JavaDoc(System.currentTimeMillis()));
771         //
772
if (m_connectionOK)
773             statusBar.setStatusLine(txt_LoggedIn);
774         else
775             statusBar.setStatusLine(txt_NotConnected, true);
776     } // languageCombo_actionPerformed
777

778 } // ALogin
779
Popular Tags