-
Notifications
You must be signed in to change notification settings - Fork 8
/
WatchersController.java
97 lines (78 loc) · 2.77 KB
/
WatchersController.java
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package org.victoria2.tools.vic2sgea.gui;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import org.victoria2.tools.vic2sgea.main.PathKeeper;
import org.victoria2.tools.vic2sgea.watcher.Watcher;
import org.victoria2.tools.vic2sgea.watcher.WatcherManager;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ResourceBundle;
/**
* Created by anth on 12.02.2017.
*/
public class WatchersController extends BaseController implements Initializable {
@FXML
public TableColumn<Watcher, Path> colHistoryFile;
@FXML
public TableColumn<Watcher, Path> colSaveDir;
@FXML
public TableColumn<Watcher, String> colStatus;
@FXML
public TableColumn<Watcher, Void> colActions;
@FXML
TableView<Watcher> tvWatcherList;
@FXML
FilePrompt fpHistoryFile;
@FXML
FilePrompt fpSaveDir;
@FXML
Button btnStart;
private WatcherManager watcherManager = WatcherManager.getInstance();
public void startWatcher() {
Path historyFile = Paths.get(fpHistoryFile.getPath());
Path saveDir = Paths.get(fpSaveDir.getPath());
try {
Watcher watcher = new Watcher(historyFile, saveDir);
watcherManager.add(watcher);
} catch (IOException e) {
e.printStackTrace();
errorAlert(e, "Error while starting watcher");
}
}
@Override
public void initialize(URL location, ResourceBundle resources) {
String savePath = PathKeeper.SAVE_PATH;
fpSaveDir.setPath(Paths.get(savePath).getParent().toString());
colHistoryFile.setCellValueFactory(new PropertyValueFactory<>("historyFile"));
colSaveDir.setCellValueFactory(new PropertyValueFactory<>("saveDir"));
colActions.setCellFactory(column -> new WatcherActionCell());
tvWatcherList.setItems(watcherManager.getWatcherList());
}
static class RemoveWatcherButton extends Button {
private Watcher watcher;
public RemoveWatcherButton(Watcher watcher) {
super("Stop");
this.watcher = watcher;
}
@Override
public void fire() {
super.fire();
WatcherManager.getInstance().remove(watcher);
}
}
static class WatcherActionCell extends TableCell<Watcher, Void> {
@Override
protected void updateItem(Void item, boolean empty) {
super.updateItem(item, empty);
if (!empty) {
Watcher watcher = (Watcher) getTableRow().getItem();
setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
setGraphic(new RemoveWatcherButton(watcher));
}
}
}
}