forked from bigolol/JoanaKeyGui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddSourceDialogController.java
88 lines (76 loc) · 2.87 KB
/
AddSourceDialogController.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package joanakeygui;
import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ComboBox;
import javafx.stage.Stage;
import joanakeygui.joanahandler.JoanaInstance;
/**
* FXML Controller class
*
* @author holger
*/
public class AddSourceDialogController implements Initializable {
@FXML
private ComboBox<String> selectMethodCB;
@FXML
private ComboBox<String> selectionCB;
@FXML
public void onOk() {
stage.close();
}
private Stage stage;
private JoanaInstance joanaInstance;
private String[] addingMethods = {"programPart", "callsToMethod"};
public void setJoanaInstance(JoanaInstance joanaInstance) {
this.joanaInstance = joanaInstance;
}
public void setStage(Stage stage) {
this.stage = stage;
}
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
selectMethodCB.getItems().addAll(addingMethods);
selectMethodCB.valueProperty().addListener((observable) -> {
selectionCB.getItems().clear();
String selected = selectMethodCB.getSelectionModel().getSelectedItem();
if (selected.equals("programPart")) {
selectionCB.getItems().addAll(joanaInstance.getAllProgramPartsString());
} else if (selected.equals("callsToMethod")) {
selectionCB.getItems().addAll(joanaInstance.getAllMethodsString());
}
});
}
public Optional<SinkOrSource> showForSink() {
stage.showAndWait();
String selectMethodStr = selectMethodCB.getSelectionModel().getSelectedItem();
String selectionStr = selectionCB.getSelectionModel().getSelectedItem();
if (selectMethodStr.equals("programPart")) {
return Optional.of(SinkOrSource.createProgramPart(selectionStr, "low"));
} else if (selectMethodStr.equals("callsToMethod")) {
return Optional.of(SinkOrSource.createMethod(selectionStr, "low"));
}
return Optional.empty();
}
public Optional<SinkOrSource> showForSrc() {
stage.showAndWait();
String selectMethodStr = selectMethodCB.getSelectionModel().getSelectedItem();
String selectionStr = selectionCB.getSelectionModel().getSelectedItem();
if (selectMethodStr.equals("programPart")) {
return Optional.of(SinkOrSource.createProgramPart(selectionStr, "high"));
} else if (selectMethodStr.equals("callsToMethod")) {
return Optional.of(SinkOrSource.createMethod(selectionStr, "high"));
}
return Optional.empty();
}
}