Revize 98da6ab0
Přidáno uživatelem Michal Horký před asi 4 roky(ů)
project/Deserializer/src/Deserializer.java | ||
---|---|---|
1 | 1 |
import java.io.File; |
2 |
import java.util.Properties; |
|
2 | 3 |
|
3 | 4 |
import io.Database.DB_Messenger; |
4 | 5 |
import io.FileWorker; |
5 | 6 |
import javafx.application.Application; |
6 | 7 |
import javafx.application.Platform; |
7 | 8 |
import javafx.collections.FXCollections; |
9 |
import javafx.collections.ObservableList; |
|
8 | 10 |
import javafx.geometry.Insets; |
9 | 11 |
import javafx.geometry.Pos; |
10 | 12 |
import javafx.scene.Node; |
... | ... | |
47 | 49 |
private VBox outputLayout; |
48 | 50 |
|
49 | 51 |
private Converter converter; |
52 |
private Properties properties; |
|
50 | 53 |
|
51 | 54 |
@Override |
52 | 55 |
public void init() throws Exception { |
53 | 56 |
super.init(); |
54 | 57 |
converter = new Converter(this); |
55 | 58 |
converter.start(); |
59 |
properties = FileWorker.getConfig(); |
|
56 | 60 |
} |
57 | 61 |
|
58 | 62 |
@Override |
... | ... | |
60 | 64 |
super.stop(); |
61 | 65 |
converter.end(); |
62 | 66 |
converter.join(); |
67 |
FileWorker.saveConfig(properties); |
|
63 | 68 |
Platform.exit(); |
64 | 69 |
} |
65 | 70 |
|
66 | 71 |
@Override |
67 | 72 |
public void start(Stage stage) throws Exception { |
68 | 73 |
this.stage = stage; |
69 |
stage.getIcons().add(new Image(getResource("logo.png")));
|
|
74 |
stage.getIcons().add(new Image(FileWorker.getResource("/logo.png")));
|
|
70 | 75 |
stage.setTitle("Java Object Universal Deserializer"); |
71 | 76 |
stage.setScene(createScene()); |
72 | 77 |
stage.show(); |
... | ... | |
82 | 87 |
private Scene createScene() { |
83 | 88 |
createMenu(); |
84 | 89 |
Scene scene = new Scene(createLayout()); |
85 |
scene.getStylesheets().add(getResource("main.css"));
|
|
90 |
scene.getStylesheets().add(FileWorker.getResource("/main.css"));
|
|
86 | 91 |
return scene; |
87 | 92 |
} |
88 | 93 |
|
... | ... | |
104 | 109 |
|
105 | 110 |
editor = new Editor(); |
106 | 111 |
|
112 |
String propMode = properties.getProperty(FileWorker.ACE_MODE); |
|
113 |
String propTheme = properties.getProperty(FileWorker.ACE_THEME); |
|
114 |
|
|
115 |
ObservableList<String> aceModes = FXCollections.observableArrayList(); |
|
116 |
ObservableList<String> aceThemes = FXCollections.observableArrayList(); |
|
117 |
FileWorker.getAceModesAndThemes(aceModes, aceThemes); |
|
118 |
|
|
107 | 119 |
ComboBox<String> modeBox = new ComboBox<String>(); |
108 |
modeBox.setItems(FileWorker.getAceModes());
|
|
109 |
modeBox.getSelectionModel().select(Editor.DEFAULT_MODE);
|
|
120 |
modeBox.setItems(aceModes);
|
|
121 |
modeBox.getSelectionModel().select(propMode == null ? Editor.DEFAULT_MODE : propMode);
|
|
110 | 122 |
modeBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { |
111 |
if (newValue != null && oldValue != newValue) { |
|
123 |
if (modeBox.getValue() != null) { |
|
124 |
properties.setProperty(FileWorker.ACE_MODE, modeBox.getValue()); |
|
112 | 125 |
editor.setMode(modeBox.getValue()); |
113 | 126 |
} |
114 | 127 |
}); |
115 | 128 |
|
116 | 129 |
ComboBox<String> themeBox = new ComboBox<String>(); |
117 |
themeBox.setItems(FileWorker.getAceThemes());
|
|
118 |
themeBox.getSelectionModel().select(Editor.DEFAULT_THEME);
|
|
130 |
themeBox.setItems(aceThemes);
|
|
131 |
themeBox.getSelectionModel().select(propTheme == null ? Editor.DEFAULT_THEME : propTheme);
|
|
119 | 132 |
themeBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { |
120 |
if (newValue != null && oldValue != newValue) { |
|
133 |
if (themeBox.getValue() != null) { |
|
134 |
properties.setProperty(FileWorker.ACE_THEME, themeBox.getValue()); |
|
121 | 135 |
editor.setTheme(themeBox.getValue()); |
122 | 136 |
} |
123 | 137 |
}); |
... | ... | |
184 | 198 |
} |
185 | 199 |
|
186 | 200 |
private Tab createQueryTab() { |
201 |
String propType = properties.getProperty(FileWorker.DB_TYPE); |
|
202 |
String propUrl = properties.getProperty(FileWorker.DB_URL); |
|
203 |
String propUser = properties.getProperty(FileWorker.DB_USER); |
|
204 |
|
|
205 |
|
|
187 | 206 |
String promptTexts[] = new String[] { "jdbc:mysql://server/nazevDB", "jdbc:oracle:thin:@server:port:nazevDB" }; |
188 | 207 |
|
189 | 208 |
Label rdbmsLabel = new Label("Typ DB"); |
190 | 209 |
Label urlLabel = new Label("URL"); |
191 | 210 |
ComboBox<String> rdbms = new ComboBox<String>(FXCollections.observableArrayList(new String[] { "MySQL", "ORACLE" })); |
192 |
TextField url = new TextField(); |
|
193 |
|
|
211 |
TextField url = new TextField(propUrl == null ? "" : propUrl); |
|
212 |
|
|
213 |
if (propType == null) { |
|
214 |
rdbms.getSelectionModel().selectFirst(); |
|
215 |
url.setPromptText(promptTexts[0]); |
|
216 |
} else { |
|
217 |
rdbms.getSelectionModel().select(propType); |
|
218 |
url.setPromptText(promptTexts[rdbms.getItems().indexOf(propType)]); |
|
219 |
} |
|
194 | 220 |
rdbms.setOnAction(event -> { |
195 | 221 |
url.setPromptText(promptTexts[rdbms.getSelectionModel().getSelectedIndex()]); |
196 | 222 |
}); |
197 | 223 |
|
198 |
rdbms.getSelectionModel().selectFirst(); |
|
199 |
url.setPromptText(promptTexts[0]); |
|
224 |
|
|
200 | 225 |
|
201 | 226 |
|
202 | 227 |
Label userLabel = new Label("Uživatel"); |
203 | 228 |
Label passwordLabel = new Label("Heslo"); |
204 |
TextField user = new TextField(); |
|
229 |
TextField user = new TextField(propUser == null ? "" : propUser);
|
|
205 | 230 |
PasswordField password = new PasswordField(); |
206 | 231 |
|
207 | 232 |
VBox rdbmsLayout = new VBox(); |
... | ... | |
256 | 281 |
|
257 | 282 |
Button setQuery = new Button("Spustit"); |
258 | 283 |
setQuery.setOnAction(event -> { |
284 |
String urlStr = url.getText().trim(); |
|
285 |
String userStr = user.getText().trim(); |
|
286 |
properties.setProperty(FileWorker.DB_TYPE, rdbms.getValue()); |
|
287 |
properties.setProperty(FileWorker.DB_URL, urlStr); |
|
288 |
properties.setProperty(FileWorker.DB_USER, userStr); |
|
289 |
|
|
259 | 290 |
String driver = rdbms.getValue().equals("MySQL") ? "com.mysql.cj.jdbc.Driver" : "oracle.jdbc.driver.OracleDriver"; |
260 |
converter.setInput(null, new DB_Messenger(driver, url.getText().trim(), user.getText().trim(), password.getText().trim(),
|
|
291 |
converter.setInput(null, new DB_Messenger(driver, urlStr, userStr, password.getText().trim(),
|
|
261 | 292 |
table.getText().trim(), cond.getText().trim(), column.getText().trim())); |
262 | 293 |
}); |
263 | 294 |
|
... | ... | |
320 | 351 |
this.fullScreen = (Label) fullScreen.getGraphic(); |
321 | 352 |
changeFullScreenMenuItem(); |
322 | 353 |
|
323 |
MenuItem close = createMenuItem("Ukončit", getResource("close.png"), new KeyCodeCombination(KeyCode.E, KeyCombination.CONTROL_DOWN));
|
|
354 |
MenuItem close = createMenuItem("Ukončit", FileWorker.getResource("/close.png"), new KeyCodeCombination(KeyCode.E, KeyCombination.CONTROL_DOWN));
|
|
324 | 355 |
close.setOnAction(event -> { |
325 | 356 |
Platform.exit(); |
326 | 357 |
}); |
... | ... | |
334 | 365 |
|
335 | 366 |
private void changeFullScreenMenuItem() { |
336 | 367 |
fullScreen.setText(stage.isFullScreen() ? "Normální zobrazení" : "Plné zobrazení"); |
337 |
fullScreen.setGraphic(new ImageView(stage.isFullScreen() ? getResource("normal.png") : getResource("full.png")));
|
|
368 |
fullScreen.setGraphic(new ImageView(stage.isFullScreen() ? FileWorker.getResource("/normal.png") : FileWorker.getResource("/full.png")));
|
|
338 | 369 |
} |
339 | 370 |
|
340 | 371 |
private MenuItem createMenuItem(String name, String icon, KeyCodeCombination keyCodeComb) { |
... | ... | |
356 | 387 |
outputLayout.setDisable(disable); |
357 | 388 |
} |
358 | 389 |
|
359 |
private String getResource(String path) { |
|
360 |
return Deserializer.class.getResource(path).toString(); |
|
361 |
} |
|
362 |
|
|
363 | 390 |
@Override |
364 | 391 |
public void loadingInputFileError() { |
365 | 392 |
Platform.runLater(()->{ |
... | ... | |
374 | 401 |
|
375 | 402 |
boolean showData = html != null && html.length() > 0 && json != null && json.length() > 0; |
376 | 403 |
|
377 |
if (!showData && Report.confirm("Výsledek deserializace", null, "Při deserializaci došlo k chybě. Je ale možné, že nejde o serializovaná data. Chcete zobrazit, co bylo načteno?")) { |
|
404 |
if (!showData && loaded != null && loaded.length() > 0 && |
|
405 |
Report.confirm("Výsledek deserializace", null, "Při deserializaci došlo k chybě. " |
|
406 |
+ "Je ale možné, že nejde o serializovaná data. Chcete zobrazit, co bylo načteno?")) { |
|
378 | 407 |
_html = loaded.trim(); |
379 | 408 |
_json = loaded.trim(); |
380 | 409 |
showData = true; |
Také k dispozici: Unified diff
re #7895
Ukládání určitých dat do configu. Konkrétně nastavení editoru a základní konfigurace DB spojení. Vyřešeny problémy při exportu do .jar.