/** * */ package de.fhswf.in.inf.java2.aufgabe05.view; import java.io.File; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import javafx.beans.property.SimpleObjectProperty; import javafx.collections.FXCollections; import javafx.scene.control.Label; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; import de.fhswf.fbin.java2fx.entities.FXFile; import de.fhswf.fbin.java2fx.tables.CheckBoxTableCellFactory; import de.fhswf.fbin.java2fx.tables.LocalDateTimeTableCellFactory; import de.fhswf.fbin.java2fx.tables.NumberTableCellFactory; /** * TODO Add comment here * * @author $Author: $ * @version $Revision: $, $Date: $ UTC */ public class DirectoryTableView extends TableView { private SimpleObjectProperty parentDirectoryProperty; public SimpleObjectProperty getParentDirectoryProperty() { return parentDirectoryProperty; } /** * TODO Add constructor comment here * * @param parentDirectory */ public DirectoryTableView(FXFile parentDirectory) { setPlaceholder(new Label("Verzeichnis ist leer.")); this.parentDirectoryProperty = new SimpleObjectProperty(parentDirectory); // name column with default cell factory TableColumn nameCol = new TableColumn<>("Name"); nameCol.setCellValueFactory(new PropertyValueFactory( "name")); // length column with custom number cell factory TableColumn lengthCol = new TableColumn<>("Length"); lengthCol.setCellValueFactory(new PropertyValueFactory( "length")); lengthCol.setCellFactory(new NumberTableCellFactory()); // last modified column with custom date cell factory TableColumn lastModifiedCol = new TableColumn<>( "Last Modified"); lastModifiedCol .setCellValueFactory(new PropertyValueFactory( "lastModified")); lastModifiedCol .setCellFactory(new LocalDateTimeTableCellFactory()); // hidden attribute column with custom checkbox cell factory TableColumn hiddenCol = new TableColumn<>("Hidden"); hiddenCol .setCellValueFactory(new PropertyValueFactory( "hidden")); hiddenCol.setCellFactory(new CheckBoxTableCellFactory()); this.getColumns() .addAll(nameCol, lengthCol, lastModifiedCol, hiddenCol); this.parentDirectoryProperty .addListener((ov, oldParent, newParent) -> { updateContent(newParent); }); } private void updateContent(FXFile newParent) { File[] files = newParent.getFile().listFiles(f -> (f.isFile())); List fxFiles = new ArrayList<>(); for (File file : files) { fxFiles.add(new FXFile(file)); } this.getItems().setAll(FXCollections.observableArrayList(fxFiles)); } }