Skip to content
Snippets Groups Projects
Commit 9a1e752e authored by Harry Linrui XU's avatar Harry Linrui XU
Browse files

Added event filter to okBtn. Brings up error message if no budget is selected

parent 618d4c45
No related branches found
No related tags found
1 merge request!43Merging frontend-testing into master
......@@ -6,6 +6,8 @@ import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.input.MouseButton;
import javafx.stage.Stage;
......@@ -16,6 +18,12 @@ import no.ntnu.idatt1002.demo.data.Budget.FileHandlingSelectedBudget;
public class SelectBudgetController {
@FXML
Button okBtn;
@FXML
private Label errorMsg;
@FXML
private ListView<String> budgetListView;
......@@ -25,6 +33,14 @@ public class SelectBudgetController {
@FXML
public void initialize() throws IOException {
okBtn.addEventFilter(
ActionEvent.ACTION, event -> {
if (budgetListView.getSelectionModel().getSelectedItem() == null) {
errorMsg.setOpacity(1);
event.consume();
}
});
try {
if (FileHandlingBudgetArchive.isBudgetRegisterEmpty()) {
budgetRegister = new BudgetRegister();
......@@ -59,7 +75,7 @@ public class SelectBudgetController {
@FXML
public void exitWindow(ActionEvent event) throws IOException {
FileHandlingSelectedBudget.updateSelectedBudget("");
FileHandlingSelectedBudget.clearSelectedBudget();
final Node source = (Node) event.getSource();
((Stage) source.getScene().getWindow()).close();
}
......
......@@ -10,7 +10,7 @@
<DialogPane prefHeight="300.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="no.ntnu.idatt1002.demo.controller.SelectBudgetController">
<content>
<VBox alignment="CENTER" prefWidth="362.0">
<VBox alignment="CENTER" prefWidth="362.0" spacing="5.0">
<children>
<Label text="Select budget project">
<font>
......@@ -18,15 +18,20 @@
</font>
</Label>
<ListView fx:id="budgetListView" prefHeight="200.0" prefWidth="200.0" />
<Label fx:id="errorMsg" opacity="0.0" text="Please select a budget" textFill="#e60707">
<font>
<Font name="Lucida Console" size="14.0" />
</font>
</Label>
<HBox alignment="CENTER" prefHeight="100.0" prefWidth="200.0" spacing="5.0">
<children>
<Button mnemonicParsing="false" onAction="#exitWindow" prefWidth="70.0" text="Cancel" />
<Button mnemonicParsing="false" onAction="#selectBudget" prefWidth="70.0" text="OK" />
<Button fx:id="okBtn" mnemonicParsing="false" onAction="#selectBudget" prefWidth="70.0" text="OK" />
</children>
</HBox>
<Label text="Click on an entry to select it">
<font>
<Font size="14.0" />
<Font name="Lucida Console" size="14.0" />
</font>
</Label>
</children>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment