Projekt

Obecné

Profil

Stáhnout (16 KB) Statistiky
| Větev: | Tag: | Revize:
1 03a2d08f Michal Horký
import java.io.File;
2 98da6ab0 horkmi
import java.util.Properties;
3 03a2d08f Michal Horký
4 7e0b699a horkmi
import io.Database.DB_Messenger;
5 49fd8648 Michal Horký
import io.FileWorker;
6 03a2d08f Michal Horký
import javafx.application.Application;
7 49fd8648 Michal Horký
import javafx.application.Platform;
8 7e0b699a horkmi
import javafx.collections.FXCollections;
9 98da6ab0 horkmi
import javafx.collections.ObservableList;
10 03a2d08f Michal Horký
import javafx.geometry.Insets;
11
import javafx.geometry.Pos;
12 49fd8648 Michal Horký
import javafx.scene.Node;
13 03a2d08f Michal Horký
import javafx.scene.Parent;
14
import javafx.scene.Scene;
15
import javafx.scene.control.Button;
16 5ae26965 horkmi
import javafx.scene.control.ComboBox;
17 03a2d08f Michal Horký
import javafx.scene.control.Label;
18 49fd8648 Michal Horký
import javafx.scene.control.Menu;
19
import javafx.scene.control.MenuBar;
20
import javafx.scene.control.MenuItem;
21 7e0b699a horkmi
import javafx.scene.control.PasswordField;
22 49fd8648 Michal Horký
import javafx.scene.control.Separator;
23
import javafx.scene.control.SeparatorMenuItem;
24 5ae26965 horkmi
import javafx.scene.control.Tab;
25
import javafx.scene.control.TabPane;
26
import javafx.scene.control.TabPane.TabClosingPolicy;
27 7e0b699a horkmi
import javafx.scene.control.TextField;
28 49fd8648 Michal Horký
import javafx.scene.image.Image;
29
import javafx.scene.image.ImageView;
30
import javafx.scene.input.KeyCode;
31
import javafx.scene.input.KeyCodeCombination;
32
import javafx.scene.input.KeyCombination;
33
import javafx.scene.layout.BorderPane;
34 03a2d08f Michal Horký
import javafx.scene.layout.HBox;
35 49fd8648 Michal Horký
import javafx.scene.layout.Priority;
36 03a2d08f Michal Horký
import javafx.scene.layout.VBox;
37
import javafx.stage.FileChooser;
38
import javafx.stage.Stage;
39
40 49fd8648 Michal Horký
/**
41 967b6b05 horkmi
 * <p>
42
 * Class for creating a GUI. <br>
43
 * <br>
44
 * Note, VM arguments for Java 11: <br>
45
 * --module-path libs\javafx-sdk-11.0.2\lib --add-modules=javafx.controls
46 49fd8648 Michal Horký
 */
47 d2be23a3 horkmi
public class Window extends Application implements IConversionResults {
48 967b6b05 horkmi
49
	/**
50
	 * Main window.
51
	 */
52 03a2d08f Michal Horký
	private Stage stage;
53 967b6b05 horkmi
54
	/**
55
	 * Graphic node of menu item for full screen.
56
	 */
57 49fd8648 Michal Horký
	private Label fullScreen;
58 967b6b05 horkmi
59
	/**
60
	 * Read-only text area with ACE.
61
	 */
62 5ae26965 horkmi
	private Editor editor;
63 967b6b05 horkmi
64
	/**
65
	 * Layout for output file.
66
	 */
67 49fd8648 Michal Horký
	private VBox outputLayout;
68 967b6b05 horkmi
69
	/**
70
	 * Thread for converting input to JSON.
71
	 */
72 49fd8648 Michal Horký
	private Converter converter;
73 967b6b05 horkmi
74
	/**
75
	 * Configuration file.
76
	 */
77 98da6ab0 horkmi
	private Properties properties;
78 967b6b05 horkmi
79 03a2d08f Michal Horký
	@Override
80
	public void init() throws Exception {
81
		super.init();
82 49fd8648 Michal Horký
		converter = new Converter(this);
83
		converter.start();
84 98da6ab0 horkmi
		properties = FileWorker.getConfig();
85 49fd8648 Michal Horký
	}
86 967b6b05 horkmi
87 49fd8648 Michal Horký
	@Override
88
	public void stop() throws Exception {
89
		super.stop();
90
		converter.end();
91
		converter.join();
92 98da6ab0 horkmi
		FileWorker.saveConfig(properties);
93 efc1d63e @havlijan17
		Platform.exit();
94 03a2d08f Michal Horký
	}
95 967b6b05 horkmi
96 03a2d08f Michal Horký
	@Override
97
	public void start(Stage stage) throws Exception {
98
		this.stage = stage;
99 98da6ab0 horkmi
		stage.getIcons().add(new Image(FileWorker.getResource("/logo.png")));
100 49fd8648 Michal Horký
		stage.setTitle("Java Object Universal Deserializer");
101 03a2d08f Michal Horký
		stage.setScene(createScene());
102
		stage.show();
103 967b6b05 horkmi
104 5ae26965 horkmi
		stage.setMinWidth(stage.getWidth());
105
		stage.setMinHeight(stage.getHeight());
106 efc1d63e @havlijan17
107 49fd8648 Michal Horký
		stage.fullScreenProperty().addListener((obs, oldState, newState) -> {
108
			changeFullScreenMenuItem();
109
		});
110 03a2d08f Michal Horký
	}
111 967b6b05 horkmi
112
	/**
113
	 * @return main scene with set CSS.
114
	 */
115 03a2d08f Michal Horký
	private Scene createScene() {
116 49fd8648 Michal Horký
		Scene scene = new Scene(createLayout());
117 98da6ab0 horkmi
		scene.getStylesheets().add(FileWorker.getResource("/main.css"));
118 49fd8648 Michal Horký
		return scene;
119 03a2d08f Michal Horký
	}
120 967b6b05 horkmi
121
	/**
122
	 * @return main layout.
123
	 */
124 03a2d08f Michal Horký
	private Parent createLayout() {
125 49fd8648 Michal Horký
		BorderPane layout = new BorderPane();
126 967b6b05 horkmi
127 49fd8648 Michal Horký
		layout.setTop(createMenu());
128
		layout.setCenter(createBodyLayout());
129 967b6b05 horkmi
130 49fd8648 Michal Horký
		return layout;
131
	}
132 967b6b05 horkmi
133
	/**
134
	 * @return body layout of the window.
135
	 */
136 5ae26965 horkmi
	private Node createBodyLayout() {
137 967b6b05 horkmi
		// Tabs for input file and SQL query.
138 5ae26965 horkmi
		TabPane header = new TabPane();
139 967b6b05 horkmi
		header.setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE);
140
		header.getTabs().add(createInputFileTab());
141
		header.getTabs().add(createQueryTab());
142
143
		// ACE editor.
144
		editor = new Editor();
145
146
		// Last mode and theme of the editor.
147
		String propMode = properties.getProperty(FileWorker.ACE_MODE);
148
		String propTheme = properties.getProperty(FileWorker.ACE_THEME);
149
150
		// Get all ACE modes and themes.
151
		ObservableList<String> aceModes = FXCollections.observableArrayList();
152
		ObservableList<String> aceThemes = FXCollections.observableArrayList();
153
		FileWorker.getAceModesAndThemes(aceModes, aceThemes);
154
155
		// Sets modes combo box.
156
		ComboBox<String> modeBox = new ComboBox<String>();
157
		modeBox.setItems(aceModes);
158
		modeBox.getSelectionModel().select(propMode == null ? Editor.DEFAULT_MODE : propMode);
159
		modeBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
160
			if (modeBox.getValue() != null) {
161
				properties.setProperty(FileWorker.ACE_MODE, modeBox.getValue());
162
				editor.setMode(modeBox.getValue());
163
			}
164
		});
165
166
		// Sets themes combo box.
167
		ComboBox<String> themeBox = new ComboBox<String>();
168
		themeBox.setItems(aceThemes);
169
		themeBox.getSelectionModel().select(propTheme == null ? Editor.DEFAULT_THEME : propTheme);
170
		themeBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
171
			if (themeBox.getValue() != null) {
172
				properties.setProperty(FileWorker.ACE_THEME, themeBox.getValue());
173
				editor.setTheme(themeBox.getValue());
174
			}
175
		});
176
177
		// ACE settings layout.
178
		HBox aceSettings = new HBox();
179
		aceSettings.setPadding(new Insets(0, 10, 0, 0));
180
		aceSettings.setSpacing(10.0);
181
		aceSettings.setAlignment(Pos.CENTER_RIGHT);
182
		aceSettings.getChildren().addAll(new Label("Nastavení editoru (režim / téma):"), modeBox, new Label("/"),
183
				themeBox);
184
185
		// Layout for editor with settings.
186
		VBox editorLayout = new VBox();
187
		editorLayout.setSpacing(5.0);
188
		VBox.setVgrow(editor.getView(), Priority.ALWAYS);
189
		editorLayout.getChildren().addAll(editor.getView(), aceSettings);
190
191
		// Output file label and path.
192 49fd8648 Michal Horký
		Label forOutputFile = new Label("Výstupní soubor:");
193 5ae26965 horkmi
		Label outputFile = new Label("    Ještě nebyl vybrán žádný soubor...");
194
		outputFile.setStyle("-fx-font-style: italic;");
195 967b6b05 horkmi
196
		// Button to save the resulting JSON.
197 5ae26965 horkmi
		Button save = new Button("Uložit");
198
		save.setOnAction(event -> {
199 49fd8648 Michal Horký
			File jsonFile = null;
200 967b6b05 horkmi
201 5ae26965 horkmi
			FileChooser fCh = new FileChooser();
202
			fCh.setInitialDirectory(new File("."));
203
			fCh.getExtensionFilters().add(new FileChooser.ExtensionFilter("JSON Files", "*.json"));
204
			File file = fCh.showSaveDialog(stage);
205
			if (file != null) {
206
				jsonFile = file;
207
				outputFile.setText(file.getAbsolutePath());
208
				outputFile.setStyle("-fx-font-weight: bold;");
209 49fd8648 Michal Horký
			}
210 967b6b05 horkmi
211 5ae26965 horkmi
			if (jsonFile != null) {
212 49fd8648 Michal Horký
				String title = "Uložení JSON";
213
				try {
214 5ae26965 horkmi
					FileWorker.saveJson(jsonFile, editor.getJson());
215 49fd8648 Michal Horký
					Report.info(title, null, "Uložení JSON souboru proběhlo v pořádku.");
216
				} catch (Exception e) {
217
					Report.error(title, null, "Při ukládání JSON souboru nastala chyba.");
218
				}
219 03a2d08f Michal Horký
			}
220
		});
221 967b6b05 horkmi
222 49fd8648 Michal Horký
		HBox bOF = new HBox();
223
		bOF.setAlignment(Pos.CENTER_RIGHT);
224 5ae26965 horkmi
		bOF.getChildren().add(save);
225 967b6b05 horkmi
226
		// Output file layout.
227 49fd8648 Michal Horký
		outputLayout = new VBox();
228 5ae26965 horkmi
		outputLayout.setPadding(new Insets(0, 10, 10, 10));
229 49fd8648 Michal Horký
		outputLayout.setSpacing(5.0);
230
		outputLayout.getChildren().add(forOutputFile);
231
		outputLayout.getChildren().add(outputFile);
232
		outputLayout.getChildren().add(bOF);
233
		setOutputLayoutDisabled(true);
234 967b6b05 horkmi
235
		// Main layout in the body.
236 5ae26965 horkmi
		VBox layout = new VBox();
237
		layout.setSpacing(10.0);
238 ba652858 horkmi
		VBox.setVgrow(editorLayout, Priority.ALWAYS);
239 5ae26965 horkmi
		layout.getChildren().addAll(header, new Separator(), editorLayout, new Separator(), outputLayout);
240 967b6b05 horkmi
241 5ae26965 horkmi
		return layout;
242
	}
243 967b6b05 horkmi
244
	/**
245
	 * @return a tab for connecting to a database.
246
	 */
247 7e0b699a horkmi
	private Tab createQueryTab() {
248 967b6b05 horkmi
		// Get the last inserted texts.
249 98da6ab0 horkmi
		String propType = properties.getProperty(FileWorker.DB_TYPE);
250
		String propUrl = properties.getProperty(FileWorker.DB_URL);
251
		String propUser = properties.getProperty(FileWorker.DB_USER);
252 967b6b05 horkmi
253
		// Help text, database names and driver classes.
254
		String promptTexts[] = new String[] { "jdbc:oracle:thin:@server:port:nazevDB",
255
				"jdbc:sqlserver://server:port;databaseName=nazevDB;", "jdbc:mysql://server:port/nazevDB" };
256 ba652858 horkmi
		String dbTypeTexts[] = new String[] { "ORACLE", "MS-SQL", "MySQL" };
257 967b6b05 horkmi
		String dbDriverClasses[] = new String[] { "oracle.jdbc.driver.OracleDriver",
258
				"com.microsoft.sqlserver.jdbc.SQLServerDriver", "com.mysql.cj.jdbc.Driver" };
259
260
		// DB type, URL.
261 7e0b699a horkmi
		Label rdbmsLabel = new Label("Typ DB");
262
		Label urlLabel = new Label("URL");
263 ba652858 horkmi
		ComboBox<String> rdbms = new ComboBox<String>(FXCollections.observableArrayList(dbTypeTexts));
264 98da6ab0 horkmi
		TextField url = new TextField(propUrl == null ? "" : propUrl);
265 967b6b05 horkmi
266 98da6ab0 horkmi
		if (propType == null) {
267
			rdbms.getSelectionModel().selectFirst();
268
			url.setPromptText(promptTexts[0]);
269
		} else {
270
			rdbms.getSelectionModel().select(propType);
271
			url.setPromptText(promptTexts[rdbms.getItems().indexOf(propType)]);
272
		}
273 7e0b699a horkmi
		rdbms.setOnAction(event -> {
274
			url.setPromptText(promptTexts[rdbms.getSelectionModel().getSelectedIndex()]);
275
		});
276 967b6b05 horkmi
277
		// User and password.
278 7e0b699a horkmi
		Label userLabel = new Label("Uživatel");
279
		Label passwordLabel = new Label("Heslo");
280 98da6ab0 horkmi
		TextField user = new TextField(propUser == null ? "" : propUser);
281 7e0b699a horkmi
		PasswordField password = new PasswordField();
282 967b6b05 horkmi
283
		// Layout for each pair - label and input component.
284 7e0b699a horkmi
		VBox rdbmsLayout = new VBox();
285
		rdbmsLayout.getChildren().addAll(rdbmsLabel, rdbms);
286
		VBox urlLayout = new VBox();
287
		urlLayout.getChildren().addAll(urlLabel, url);
288
		VBox userLayout = new VBox();
289
		userLayout.getChildren().addAll(userLabel, user);
290
		VBox passwordLayout = new VBox();
291
		passwordLayout.getChildren().addAll(passwordLabel, password);
292 967b6b05 horkmi
293
		// Styles settings.
294 7e0b699a horkmi
		rdbmsLabel.setStyle("-fx-font-weight: bold;");
295
		urlLabel.setStyle("-fx-font-weight: bold;");
296
		userLabel.setStyle("-fx-font-weight: bold;");
297
		passwordLabel.setStyle("-fx-font-weight: bold;");
298 967b6b05 horkmi
299 7e0b699a horkmi
		url.setMinWidth(400);
300
		user.setMinWidth(100);
301
		user.setPrefWidth(200);
302
		user.setMaxWidth(300);
303
		password.setMinWidth(100);
304
		password.setPrefWidth(200);
305
		password.setMaxWidth(300);
306 967b6b05 horkmi
307
		// Layout with elements for connecting to the database.
308 7e0b699a horkmi
		HBox connLayout = new HBox();
309 967b6b05 horkmi
		HBox.setHgrow(urlLayout, Priority.ALWAYS);
310 7e0b699a horkmi
		connLayout.setSpacing(10);
311
		connLayout.getChildren().addAll(rdbmsLayout, urlLayout, userLayout, passwordLayout);
312 967b6b05 horkmi
313
		// Elements for query.
314
		Label select = new Label("SELECT"), from = new Label("FROM"), where = new Label("WHERE"),
315
				queryEnd = new Label(";");
316 7e0b699a horkmi
		TextField column = new TextField(), table = new TextField(), cond = new TextField();
317 967b6b05 horkmi
318 7e0b699a horkmi
		select.setStyle("-fx-font-weight: bold;");
319
		from.setStyle("-fx-font-weight: bold;");
320
		where.setStyle("-fx-font-weight: bold;");
321
		queryEnd.setStyle("-fx-font-weight: bold;");
322 967b6b05 horkmi
323 7e0b699a horkmi
		column.setPromptText("sloupec");
324
		table.setPromptText("tabulka");
325
		cond.setPromptText("podminka");
326 967b6b05 horkmi
327 7e0b699a horkmi
		HBox.setHgrow(column, Priority.ALWAYS);
328
		HBox.setHgrow(table, Priority.ALWAYS);
329
		HBox.setHgrow(cond, Priority.ALWAYS);
330 967b6b05 horkmi
331
		// Layout for query.
332 7e0b699a horkmi
		HBox queryLayout = new HBox();
333
		queryLayout.setAlignment(Pos.CENTER);
334
		queryLayout.setSpacing(5.0);
335
		queryLayout.getChildren().addAll(select, column, from, table, where, cond, queryEnd);
336 967b6b05 horkmi
337
		// Button for the execution of the query.
338 7e0b699a horkmi
		Button setQuery = new Button("Spustit");
339
		setQuery.setOnAction(event -> {
340 98da6ab0 horkmi
			String urlStr = url.getText().trim();
341
			String userStr = user.getText().trim();
342
			properties.setProperty(FileWorker.DB_TYPE, rdbms.getValue());
343
			properties.setProperty(FileWorker.DB_URL, urlStr);
344
			properties.setProperty(FileWorker.DB_USER, userStr);
345 967b6b05 horkmi
346 ba652858 horkmi
			String driver = dbDriverClasses[rdbms.getItems().indexOf(rdbms.getValue())];
347 98da6ab0 horkmi
			converter.setInput(null, new DB_Messenger(driver, urlStr, userStr, password.getText().trim(),
348 7e0b699a horkmi
					table.getText().trim(), cond.getText().trim(), column.getText().trim()));
349
		});
350 967b6b05 horkmi
351 7e0b699a horkmi
		HBox bIF = new HBox();
352
		bIF.setAlignment(Pos.CENTER_RIGHT);
353
		bIF.getChildren().add(setQuery);
354 967b6b05 horkmi
355
		// Main layout in the tab.
356 7e0b699a horkmi
		VBox forInput = new VBox();
357
		forInput.setPadding(new Insets(10, 10, 0, 10));
358
		forInput.setSpacing(5.0);
359
		forInput.getChildren().addAll(connLayout, queryLayout, bIF);
360 967b6b05 horkmi
361 7e0b699a horkmi
		return new Tab("SQL", forInput);
362
	}
363 967b6b05 horkmi
364
	/**
365
	 * @return a tab for selecting an input file.
366
	 */
367 5ae26965 horkmi
	private Tab createInputFileTab() {
368 967b6b05 horkmi
		// Input file label and path.
369 5ae26965 horkmi
		Label forInputFile = new Label("Soubor k deserializaci:");
370
		Label inputFile = new Label("    Ještě nebyl vybrán žádný soubor...");
371
		inputFile.setStyle("-fx-font-style: italic;");
372
		inputFile.setPrefWidth(500); // Value to cut the text.
373
		inputFile.setMaxWidth(Double.MAX_VALUE);
374 967b6b05 horkmi
375
		// Button to choose the input file.
376 5ae26965 horkmi
		Button setInputFile = new Button("Vstupní soubor");
377
		setInputFile.setOnAction(event -> {
378
			FileChooser fCh = new FileChooser();
379
			fCh.setInitialDirectory(new File("."));
380 967b6b05 horkmi
			// The input can be a zip file or file without a specific extension -> file
381
			// chooser without extension filters...
382
			// fCh.getExtensionFilters().add(new FileChooser.ExtensionFilter("Binary Files",
383
			// "*.out"));
384
385
			// Set initial folder.
386 a5557143 horkmi
			String inputDir = properties.getProperty(FileWorker.INPUT_DIR);
387
			if (inputDir != null) {
388
				File initDir = new File(inputDir);
389
				if (initDir.exists()) {
390
					fCh.setInitialDirectory(initDir);
391
				}
392
			}
393 967b6b05 horkmi
394
			// Get the selected file.
395 5ae26965 horkmi
			File file = fCh.showOpenDialog(stage);
396
			if (file != null) {
397 a5557143 horkmi
				properties.setProperty(FileWorker.INPUT_DIR, file.getAbsoluteFile().getParent());
398 5ae26965 horkmi
				setOutputLayoutDisabled(true);
399 967b6b05 horkmi
400 5ae26965 horkmi
				inputFile.setText(file.getAbsolutePath());
401
				inputFile.setStyle("-fx-font-weight: bold;");
402 967b6b05 horkmi
403 7e0b699a horkmi
				converter.setInput(file, null);
404 5ae26965 horkmi
			}
405
		});
406 967b6b05 horkmi
407 5ae26965 horkmi
		HBox bIF = new HBox();
408
		bIF.setAlignment(Pos.CENTER_RIGHT);
409
		bIF.getChildren().add(setInputFile);
410 967b6b05 horkmi
411
		// Main layout in the tab.
412 5ae26965 horkmi
		VBox forInput = new VBox();
413
		forInput.setAlignment(Pos.CENTER_LEFT);
414
		forInput.setPadding(new Insets(10, 10, 0, 10));
415
		forInput.setSpacing(5.0);
416
		forInput.getChildren().addAll(forInputFile, inputFile, bIF);
417 967b6b05 horkmi
418 5ae26965 horkmi
		return new Tab("Soubor", forInput);
419 03a2d08f Michal Horký
	}
420 967b6b05 horkmi
421
	/**
422
	 * @return menu bar.
423
	 */
424 49fd8648 Michal Horký
	private Node createMenu() {
425
		Menu menu = new Menu("Aplikace");
426 967b6b05 horkmi
427
		// Full screen (and back).
428
		MenuItem fullScreen = createMenuItem(null, null,
429
				new KeyCodeCombination(KeyCode.F, KeyCombination.CONTROL_DOWN));
430 49fd8648 Michal Horký
		fullScreen.setOnAction(event -> {
431
			stage.setFullScreen(!stage.isFullScreen());
432
		});
433
		this.fullScreen = (Label) fullScreen.getGraphic();
434
		changeFullScreenMenuItem();
435 967b6b05 horkmi
436
		// Close app.
437
		MenuItem close = createMenuItem("Ukončit", FileWorker.getResource("/close.png"),
438
				new KeyCodeCombination(KeyCode.E, KeyCombination.CONTROL_DOWN));
439
		close.setOnAction(event -> {
440 49fd8648 Michal Horký
			Platform.exit();
441
		});
442 967b6b05 horkmi
443
		menu.getItems().addAll(fullScreen, new SeparatorMenuItem(), close);
444
445
		MenuBar bar = new MenuBar();
446
		bar.getMenus().add(menu);
447
		return bar;
448 49fd8648 Michal Horký
	}
449 967b6b05 horkmi
450
	/**
451
	 * Changes the text and icon of the menu item.
452
	 */
453 49fd8648 Michal Horký
	private void changeFullScreenMenuItem() {
454
		fullScreen.setText(stage.isFullScreen() ? "Normální zobrazení" : "Plné zobrazení");
455 967b6b05 horkmi
		fullScreen.setGraphic(new ImageView(
456
				stage.isFullScreen() ? FileWorker.getResource("/normal.png") : FileWorker.getResource("/full.png")));
457 49fd8648 Michal Horký
	}
458 967b6b05 horkmi
459
	/**
460
	 * @param name        menu item text.
461
	 * @param icon        menu item icon.
462
	 * @param keyCodeComb key code combination for the menu item.
463
	 * 
464
	 * @return menu item.
465
	 */
466 49fd8648 Michal Horký
	private MenuItem createMenuItem(String name, String icon, KeyCodeCombination keyCodeComb) {
467 967b6b05 horkmi
		// Menu items are not stylizable. Therefore, a label is used like a graphic
468
		// element of the menu item.
469 49fd8648 Michal Horký
		Label label = new Label(name);
470
		label.setGraphicTextGap(10);
471
		label.getStyleClass().add("menu-graphics");
472
		label.setMinWidth(175);
473
		label.setMaxWidth(175);
474
		if (icon != null)
475
			label.setGraphic(new ImageView(new Image(icon)));
476 967b6b05 horkmi
477 49fd8648 Michal Horký
		MenuItem menuItem = new MenuItem();
478
		menuItem.setGraphic(label);
479
		menuItem.setAccelerator(keyCodeComb);
480 967b6b05 horkmi
		return menuItem;
481 49fd8648 Michal Horký
	}
482 967b6b05 horkmi
483
	/**
484
	 * Used to set the disable property of the layout for the output file.
485
	 * 
486
	 * @param disable whether the layout should be inaccessible.
487
	 */
488 49fd8648 Michal Horký
	private void setOutputLayoutDisabled(boolean disable) {
489 5ae26965 horkmi
		outputLayout.setDisable(disable);
490 a5d16f0a horkmi
	}
491 967b6b05 horkmi
492 49fd8648 Michal Horký
	@Override
493
	public void loadingInputFileError() {
494 967b6b05 horkmi
		Platform.runLater(() -> {
495 49fd8648 Michal Horký
			Report.error("Načítání souboru", null, "Při načítání souboru došlo k chybě.");
496 967b6b05 horkmi
		});
497 49fd8648 Michal Horký
	}
498
499
	@Override
500 c670fa2f @havlijan17
	public void completed(String json, String loaded) {
501 5ae26965 horkmi
		Platform.runLater(() -> {
502 c670fa2f @havlijan17
			String _json = json;
503 967b6b05 horkmi
504 c670fa2f @havlijan17
			boolean showData = json != null;
505 967b6b05 horkmi
506
			if (!showData && loaded != null
507
					&& Report.confirm("Výsledek deserializace", null, "Při deserializaci došlo k chybě. "
508 98da6ab0 horkmi
							+ "Je ale možné, že nejde o serializovaná data. Chcete zobrazit, co bylo načteno?")) {
509 c670fa2f @havlijan17
510
				_json = loaded.trim();
511 5ae26965 horkmi
				showData = true;
512
			}
513 967b6b05 horkmi
514 5ae26965 horkmi
			if (showData) {
515 c670fa2f @havlijan17
				editor.setContent(_json);
516 5ae26965 horkmi
				setOutputLayoutDisabled(false);
517 49fd8648 Michal Horký
			}
518 967b6b05 horkmi
		});
519 03a2d08f Michal Horký
	}
520 967b6b05 horkmi
521 03a2d08f Michal Horký
}