MyLoginDialog.java
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package cn.csbr.app.gui.page;
import cn.csbr.app.auth.LoginService;
import cn.csbr.app.gui.GUIContext;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.util.Pair;
import org.controlsfx.dialog.LoginDialog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.function.Consumer;
@Component
public class MyLoginDialog {
@Autowired
private MainPage mainPage;
@Autowired
private GUIContext context;
@Autowired
private LoginService loginService;
public MyLoginDialog() {
// configureSampleDialog(dlg, "");
// showDialog(dlg);
}
public void show(String message) {
Pair<String, String> userInfo = new Pair("nologin", "");
final LoginDialog dlg = new LoginDialog(null, null);
dlg.getDialogPane().setHeaderText("请录入用户名密码登录耗智能材柜管理系统!");
VBox box = (VBox) dlg.getDialogPane().getContent();
Label lbMessage = (Label) box.getChildren().get(0);
if (!StringUtils.isEmpty(message)) {
lbMessage.setVisible(true);
lbMessage.setManaged(true);
lbMessage.setText(message);
lbMessage.setStyle("-fx-text-fill:red");
}
dlg.initOwner(context.getPrimaryStage());
dlg.showAndWait().ifPresent(new Consumer<Pair<String, String>>() {
@Override
public void accept(Pair<String, String> stringStringPair) {
try {
loginService.call(stringStringPair);
dlg.close();
mainPage.refresh();
context.updateMainContent(mainPage.getContent());
} catch (Exception e) {
e.printStackTrace();
dlg.close();
show(e.getMessage());
}
}
}
);
// configureSampleDialog( String header);
}
}