package com.megatim.fdxconvert.views;
|
|
import com.megatim.fdxconvert.model.TypeFichierJson;
|
import com.megatim.fdxconvert.viewmodel.JsonStructureTableViewModel;
|
import javafx.beans.property.SimpleStringProperty;
|
import javafx.event.ActionEvent;
|
import javafx.fxml.FXML;
|
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.Initializable;
|
import javafx.scene.Parent;
|
import javafx.scene.Scene;
|
import javafx.scene.control.*;
|
import javafx.scene.input.MouseEvent;
|
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.VBox;
|
import javafx.stage.Modality;
|
import javafx.stage.Stage;
|
import javafx.stage.StageStyle;
|
|
import java.io.IOException;
|
import java.net.URL;
|
import java.util.Arrays;
|
import java.util.ResourceBundle;
|
import java.util.logging.Level;
|
import java.util.logging.Logger;
|
|
public class JsonStructureTableViewController implements Initializable {
|
|
@FXML
|
private BorderPane searchPane;
|
|
@FXML
|
private Button btnSearch;
|
|
@FXML
|
private Button btnReset;
|
|
@FXML
|
private CheckBox advancedCheckBox;
|
|
@FXML
|
private VBox normalSearchContainer;
|
|
@FXML
|
private VBox advancedSearchContainer;
|
|
@FXML
|
private HBox buttonContainer;
|
|
@FXML
|
private Button btnAdd;
|
|
@FXML
|
private Button btnEdit;
|
|
@FXML
|
private Button btnDelete;
|
|
@FXML
|
private TableView<TypeFichierJson> elementTable;
|
|
@FXML
|
private Button btnPrevious;
|
|
@FXML
|
private Button btnNext;
|
|
@FXML
|
private Label paginationNumberInfo;
|
|
@FXML
|
private Button btnClose;
|
|
private final JsonStructureTableViewModel viewModel = new JsonStructureTableViewModel();
|
|
@Override
|
public void initialize(URL location, ResourceBundle resources) {
|
|
viewModel.init();
|
|
initTable();
|
|
btnNext.setOnAction(event -> viewModel.nextPage());
|
btnPrevious.setOnAction(event -> viewModel.previousPage());
|
btnAdd.setOnAction(event -> openFormDialog(null));
|
btnEdit.setOnAction(event -> viewModel.loadSelectedItemChildren(selectedItem -> openFormDialog(selectedItem)));
|
btnDelete.setOnAction(event -> viewModel.deleteSelectedItem());
|
|
viewModel.selectedItemProperty().bind(elementTable.getSelectionModel().selectedItemProperty());
|
|
paginationNumberInfo.textProperty().bind(viewModel.getPaginationNumberInfo());
|
btnEdit.disableProperty().bind(elementTable.getSelectionModel().selectedItemProperty().isNull());
|
btnDelete.disableProperty().bind(elementTable.getSelectionModel().selectedItemProperty().isNull());
|
btnNext.disableProperty().bind(viewModel.getLastProperty());
|
btnPrevious.disableProperty().bind(viewModel.getFirstProperty());
|
|
}
|
|
private void initTable() {
|
|
TableColumn<TypeFichierJson, String> codeTypeFichierColumn = new TableColumn("Code type fichier");
|
codeTypeFichierColumn.setCellValueFactory(c -> {
|
return new SimpleStringProperty(c.getValue().getTypeFichier() != null ? c.getValue().getTypeFichier().getCode() : "");
|
});
|
|
TableColumn<TypeFichierJson, String> libelleTypeFichierColumn = new TableColumn("Libellé type fichier");
|
libelleTypeFichierColumn.setCellValueFactory(c -> {
|
return new SimpleStringProperty(c.getValue().getTypeFichier() != null ? c.getValue().getTypeFichier().getLibelle() : "");
|
});
|
|
elementTable.getColumns().addAll(Arrays.asList(codeTypeFichierColumn, libelleTypeFichierColumn));
|
|
this.elementTable.setPlaceholder(new Label("Pas de données"));
|
|
elementTable.setItems(viewModel.getData());
|
}
|
|
@FXML
|
public void close(ActionEvent event) {
|
((Stage) elementTable.getScene().getWindow()).close();
|
}
|
|
@FXML
|
public void maximize(ActionEvent event) {
|
}
|
|
@FXML
|
public void minimize(ActionEvent event) {
|
}
|
|
@FXML
|
public void mouseDraggedTitleBar(MouseEvent event) {
|
}
|
|
@FXML
|
public void mousePressedTitleBar(MouseEvent event) {
|
}
|
|
private void openFormDialog(TypeFichierJson typeFichierJson) {
|
try {
|
JsonStructureFormController jsonStructureFormController = new JsonStructureFormController(typeFichierJson);
|
FXMLLoader loader = new FXMLLoader(JsonStructureFormController.class.getResource("JsonStructureFormView.fxml"));
|
loader.setController(jsonStructureFormController);
|
Parent root = loader.load();
|
setStage(root);
|
|
jsonStructureFormController.resultProperty().addListener((observable, oldValue, newValue) -> {
|
viewModel.reloadData();
|
});
|
|
} catch (IOException ex) {
|
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, ex.getMessage(), ex);
|
}
|
}
|
|
private void setStage(Parent root) {
|
Scene scene = new Scene(root);
|
Stage stage = new Stage();
|
|
stage.setScene(scene);
|
stage.initStyle(StageStyle.UNDECORATED);
|
stage.initModality(Modality.APPLICATION_MODAL);
|
stage.show();
|
}
|
|
}
|