gvsig-projects-pool / org.gvsig.vcsgis / trunk / org.gvsig.vcsgis / org.gvsig.vcsgis.swing / org.gvsig.vcsgis.swing.impl / src / main / java / org / gvsig / vcsgis / swing / impl / loggin / VCSGisUserIdentificationRequesterDialog.java @ 3458
History | View | Annotate | Download (3.98 KB)
1 |
/*
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2020 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
18 |
*
|
19 |
* For any additional information, do not hesitate to contact us
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
21 |
*/
|
22 |
|
23 |
package org.gvsig.vcsgis.swing.impl.loggin; |
24 |
|
25 |
import java.awt.Dimension; |
26 |
import java.awt.event.ActionEvent; |
27 |
import javax.swing.SwingUtilities; |
28 |
import org.apache.commons.lang3.StringUtils; |
29 |
import org.apache.commons.lang3.mutable.MutableBoolean; |
30 |
import org.gvsig.tools.ToolsLocator; |
31 |
import org.gvsig.tools.i18n.I18nManager; |
32 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
33 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
34 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
35 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
36 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
37 |
import org.gvsig.vcsgis.lib.VCSGisUserIdentificationRequester; |
38 |
|
39 |
/**
|
40 |
*
|
41 |
* @author gvSIG Team
|
42 |
*/
|
43 |
@SuppressWarnings("UseSpecificCatch") |
44 |
public class VCSGisUserIdentificationRequesterDialog |
45 |
extends VCSGisUserIdentificationRequesterDialogView
|
46 |
implements VCSGisUserIdentificationRequester
|
47 |
|
48 |
{ |
49 |
|
50 |
private String userId; |
51 |
private String password; |
52 |
private boolean translated; |
53 |
|
54 |
public VCSGisUserIdentificationRequesterDialog() {
|
55 |
this.password = null; |
56 |
this.userId = null; |
57 |
// translate();
|
58 |
this.initComponents();
|
59 |
} |
60 |
|
61 |
private void translate() { |
62 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
63 |
swingManager.translate(this.lblUser);
|
64 |
swingManager.translate(this.lblPassword);
|
65 |
swingManager.translate(this.lblDescription, true); |
66 |
} |
67 |
|
68 |
private void initComponents() { |
69 |
this.setPreferredSize(new Dimension(320, 110)); |
70 |
this.translated = false; |
71 |
|
72 |
} |
73 |
|
74 |
|
75 |
@Override
|
76 |
public boolean requestIdentification() { |
77 |
if( !SwingUtilities.isEventDispatchThread() ) { |
78 |
try {
|
79 |
MutableBoolean r = new MutableBoolean();
|
80 |
SwingUtilities.invokeAndWait(() -> {
|
81 |
r.setValue(requestIdentification()); |
82 |
}); |
83 |
return r.booleanValue();
|
84 |
} catch (Exception ex) { |
85 |
return false; |
86 |
} |
87 |
} |
88 |
|
89 |
if(!this.translated){ |
90 |
translate(); |
91 |
this.translated = true; |
92 |
} |
93 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
94 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
95 |
Dialog dialog = windowManager.createDialog(
|
96 |
this,
|
97 |
i18n.getTranslation("_User_login"),
|
98 |
null,
|
99 |
WindowManager_v2.BUTTONS_OK_CANCEL |
100 |
); |
101 |
dialog.addActionListener((ActionEvent e) -> {
|
102 |
if( dialog.getAction()==WindowManager_v2.BUTTON_OK) {
|
103 |
this.userId = StringUtils.defaultIfBlank(this.txtUser.getText(), null); |
104 |
this.password = StringUtils.defaultIfBlank(String.valueOf(this.txtPassword.getPassword()), null); |
105 |
} |
106 |
}); |
107 |
dialog.show(WindowManager.MODE.DIALOG); |
108 |
return dialog.getAction()==WindowManager_v2.BUTTON_OK;
|
109 |
} |
110 |
|
111 |
@Override
|
112 |
public String getUserId() { |
113 |
return this.userId; |
114 |
} |
115 |
|
116 |
@Override
|
117 |
public String getPassword() { |
118 |
return this.password; |
119 |
} |
120 |
|
121 |
} |