1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package cz.zcu.mre.sparkle.gui.dialogs.query;
21
22 import cz.zcu.mre.sparkle.SparklePreferences;
23 import cz.zcu.mre.sparkle.gui.tools.AbstractDialogController;
24 import cz.zcu.mre.sparkle.gui.tools.FormControllerFactory;
25 import cz.zcu.mre.sparkle.tools.Definitions;
26 import javafx.event.ActionEvent;
27 import javafx.fxml.FXML;
28 import javafx.scene.control.ComboBox;
29 import javafx.scene.control.Label;
30 import javafx.scene.control.TextField;
31 import javafx.stage.Window;
32 import java.io.IOException;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import java.util.prefs.Preferences;
36
37
38
39
40
41
42
43 public class PathDepthDialog
44 extends AbstractDialogController {
45
46 private static final Logger LOG = LoggerFactory.getLogger(PathDepthDialog.class);
47
48 @FXML
49 private ComboBox<String> langComboBox;
50 @FXML
51 private Label messageLabel;
52 @FXML
53 private TextField messageTextField;
54
55 private boolean changeTextFieldToDefaultValue = true;
56
57 @FXML
58 private void confirmButtonOnClick(final ActionEvent event) {
59 this.changeTextFieldToDefaultValue = false;
60 close();
61 }
62
63 @Override
64 protected final void onDialogInitialized() {
65 final Preferences prefs = SparklePreferences.getUserInstance();
66 initLangComboBox(prefs);
67 }
68
69 @FXML
70 private void cancelButtonOnClick(final ActionEvent event) {
71 close();
72 }
73
74 private void setMessage(String message) {
75 this.messageLabel.setText(message);
76 }
77
78 private void setTextFieldValue(String value) {
79 this.messageTextField.setText(value);
80 }
81
82 public static final PathDepthDialog open(final Window owner, final String title,
83 final String textFieldValue) {
84
85 try {
86 final PathDepthDialog dlg = FormControllerFactory.load(owner, PathDepthDialog.class);
87 dlg.setTitle(title);
88
89 dlg.setTextFieldValue(textFieldValue);
90 dlg.showAndWait();
91 return dlg;
92
93 } catch (final IOException e) {
94 LOG.error("Exception: ", e);
95 }
96 return null;
97 }
98
99 @Override
100 protected boolean onCloseRequest() {
101 if (this.changeTextFieldToDefaultValue) {
102 this.setTextFieldValue(Definitions.BLANK_NODE_PREFIX);
103 }
104
105 final Preferences prefs = SparklePreferences.getUserInstance();
106 Object lang = langComboBox.getSelectionModel().getSelectedItem();
107 prefs.put(SparklePreferences.LANG_LITERALS_PREFS, lang != null ? (String) lang
108 : Definitions.EMPTY_STRING);
109
110 return true;
111 }
112
113 public String getResult() {
114 return this.messageTextField.getText();
115 }
116
117
118
119
120
121
122 private void initLangComboBox(Preferences prefs) {
123 final String lang = prefs.get(SparklePreferences.LANG_LITERALS_PREFS, Definitions.EMPTY_STRING);
124 if (langComboBox.getItems().indexOf(lang) < 0) {
125 langComboBox.getItems().add(lang);
126 }
127 langComboBox.getSelectionModel().select(lang);
128 langComboBox.focusTraversableProperty().set(false);
129 }
130
131 public String getPreferredLanguage() {
132 return langComboBox.getEditor().getText();
133 }
134 }