View Javadoc
1   package fr.ifremer.tutti.ui.swing.util.auth;
2   
3   /*
4    * #%L
5    * Tutti :: UI
6    * %%
7    * Copyright (C) 2012 - 2014 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the 
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public 
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import fr.ifremer.tutti.ui.swing.TuttiUIContext;
26  import fr.ifremer.tutti.ui.swing.util.AbstractTuttiUIHandler;
27  import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil;
28  import jaxx.runtime.SwingUtil;
29  import jaxx.runtime.validator.swing.SwingValidator;
30  
31  import javax.swing.JComponent;
32  import java.awt.Container;
33  
34  import static org.nuiton.i18n.I18n.t;
35  
36  /**
37   * Created on 1/29/14.
38   *
39   * @author Tony Chemit - chemit@codelutin.com
40   * @since 3.1
41   */
42  public class LoginUIHandler extends AbstractTuttiUIHandler<TuttiUIContext, LoginUI> {
43  
44      protected AuthenticationInfo authenticationInfo;
45  
46      @Override
47      public void onCloseUI() {
48  
49      }
50  
51      @Override
52      public SwingValidator<TuttiUIContext> getValidator() {
53          return null;
54      }
55  
56      @Override
57      protected JComponent getComponentToFocus() {
58          return null;
59      }
60  
61      @Override
62      public void beforeInit(LoginUI ui) {
63          super.beforeInit(ui);
64          ui.setContextValue(TuttiUIUtil.getApplicationContext(ui));
65      }
66  
67      @Override
68      public void afterInit(LoginUI ui) {
69          initUI(ui);
70      }
71  
72      public LoginUI getUi() {
73          return ui;
74      }
75  
76      public void open(String url, AuthenticationInfo authenticationInfo) {
77  
78          ui.getInfoMessage().setText(t("tutti.login.infoMmessage", url));
79          ui.getLoginField().setText(authenticationInfo == null ? null : authenticationInfo.getLogin());
80          ui.getPasswordField().setText(authenticationInfo == null ? null : new String(authenticationInfo.getPassword()));
81          ui.pack();
82  
83          Container parent = ui.getModel().getMainUI();
84          if (parent != null) {
85              SwingUtil.center(parent, ui);
86          }
87          ui.setVisible(true);
88      }
89  
90      protected AuthenticationInfo getAuthenticationInfo() {
91          return authenticationInfo;
92      }
93  
94      public void setAuthenticationInfo(AuthenticationInfo authenticationInfo) {
95          this.authenticationInfo = authenticationInfo;
96      }
97  
98  }