-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewLoader.java
More file actions
48 lines (42 loc) · 1.69 KB
/
Copy pathViewLoader.java
File metadata and controls
48 lines (42 loc) · 1.69 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
package openconsignment.common;
import java.io.IOException;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.layout.BorderPane;
import javafx.util.Callback;
import javax.inject.Inject;
import openconsignment.controller.MainController;
import openconsignment.controller.entry.EntryController;
public class ViewLoader {
private final Callback<Class<?>, Object> controllerFactory;
@Inject
public ViewLoader(Callback<Class<?>, Object> controllerFactory) {
this.controllerFactory = controllerFactory;
}
public void loadRoot(String resourcePath, Group root) {
try {
FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(getClass().getResource(resourcePath)));
loader.setControllerFactory(controllerFactory);
Parent parent = loader.load();
root.getChildren().setAll(parent);
} catch (IOException ex) {
Utils.showAlert(ex.toString());
Logger.getLogger(EntryController.class.getName()).log(Level.SEVERE, ex.toString(), ex);
}
}
public void loadCenter(String resourcePath, BorderPane center) {
try {
FXMLLoader loader = new FXMLLoader(Objects.requireNonNull(getClass().getResource(resourcePath)));
loader.setControllerFactory(controllerFactory);
Parent parent = loader.load();
center.setCenter(parent);
} catch (IOException ex) {
Utils.showAlert(ex.toString());
Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, ex.toString(), ex);
}
}
}