Created
November 17, 2016 14:01
-
-
Save NielsPilgaard/6d0ffc7df6e1c0622feb4c60a26d4264 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gui; | |
import application.model.Excursion; | |
import javafx.beans.value.ChangeListener; | |
import javafx.geometry.Insets; | |
import javafx.geometry.Pos; | |
import javafx.scene.control.Button; | |
import javafx.scene.control.Label; | |
import javafx.scene.control.ListView; | |
import javafx.scene.control.TextField; | |
import javafx.scene.layout.GridPane; | |
import javafx.scene.layout.HBox; | |
import storage.Storage; | |
public class ExcursionPane extends GridPane { | |
private ListView<Excursion> lvwExcursions; | |
private TextField txfDescription, txfPrice; | |
private Button btnDelete; | |
private Button btnUpdate; | |
private Button btnCreate; | |
private ExcursionWindow dia; | |
public ExcursionPane() { | |
setVgap(10); | |
setHgap(10); | |
Label lblPersons = new Label("Excursions:"); | |
this.add(lblPersons, 0, 0); | |
// list view | |
lvwExcursions = new ListView<Excursion>(); | |
this.add(lvwExcursions, 0, 1, 1, 10); | |
lvwExcursions.getItems().setAll(Storage.getExcursion()); | |
HBox hbxButtons = new HBox(); | |
this.add(hbxButtons, 0, 11, 3, 1); | |
hbxButtons.setPadding(new Insets(10, 0, 0, 0)); | |
hbxButtons.setAlignment(Pos.BASELINE_CENTER); | |
btnCreate = new Button("Create"); | |
hbxButtons.getChildren().add(btnCreate); | |
btnCreate.setOnAction(event -> this.createAction()); | |
btnUpdate = new Button("Update"); | |
btnUpdate.setDisable(true); | |
hbxButtons.getChildren().add(btnUpdate); | |
btnUpdate.setOnAction(event -> this.updateAction()); | |
btnDelete = new Button("Delete"); | |
btnDelete.setDisable(true); | |
hbxButtons.getChildren().add(btnDelete); | |
btnDelete.setOnAction(event -> this.deleteAction()); | |
Label lblDescription = new Label("Description"); | |
this.add(lblDescription, 2, 1); | |
txfDescription = new TextField(); | |
txfDescription.setEditable(false); | |
this.add(txfDescription, 2, 2); | |
Label lblPrice = new Label("Price"); | |
this.add(lblPrice, 2, 3); | |
txfPrice = new TextField(); | |
txfPrice.setEditable(false); | |
this.add(txfPrice, 2, 4); | |
ChangeListener<Excursion> listener = (ov, oldExcursion, newExcursion) -> this.backgroundInformationUpdate(); | |
lvwExcursions.getSelectionModel().selectedItemProperty().addListener(listener); | |
dia = new ExcursionWindow(""); | |
} | |
private void backgroundInformationUpdate() { | |
Excursion e = this.lvwExcursions.getSelectionModel().getSelectedItem(); | |
if (e != null) { | |
btnDelete.setDisable(false); | |
btnUpdate.setDisable(false); | |
txfDescription.setText(e.getDescription()); | |
txfPrice.setText("" + e.getExcursionPrice()); | |
} else { | |
clearTextFields(); | |
btnDelete.setDisable(true); | |
btnUpdate.setDisable(true); | |
} | |
} | |
public void clearTextFields() { | |
txfDescription.clear(); | |
txfPrice.clear(); | |
} | |
public void updateControls() { | |
} | |
private void updateAction() { | |
} | |
private void deleteAction() { | |
} | |
private void createAction() { | |
dia.createExcursion(); | |
dia.showAndWait(); | |
lvwExcursions.getItems().setAll(Storage.getExcursion()); | |
clearTextFields(); | |
} | |
private void okAction() { | |
} | |
private void cancelAction() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment