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
89
90
91
92
93
94
95
|
/**
*
*/
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<FXFile>
{
private SimpleObjectProperty<FXFile> parentDirectoryProperty;
public SimpleObjectProperty<FXFile> getParentDirectoryProperty()
{
return parentDirectoryProperty;
}
/**
* TODO Add constructor comment here
*
* @param parentDirectory
*/
public DirectoryTableView(FXFile parentDirectory)
{
setPlaceholder(new Label("Verzeichnis ist leer."));
this.parentDirectoryProperty = new SimpleObjectProperty<FXFile>(parentDirectory);
// name column with default cell factory
TableColumn<FXFile, String> nameCol = new TableColumn<>("Name");
nameCol.setCellValueFactory(new PropertyValueFactory<FXFile, String>(
"name"));
// length column with custom number cell factory
TableColumn<FXFile, Number> lengthCol = new TableColumn<>("Length");
lengthCol.setCellValueFactory(new PropertyValueFactory<FXFile, Number>(
"length"));
lengthCol.setCellFactory(new NumberTableCellFactory<FXFile>());
// last modified column with custom date cell factory
TableColumn<FXFile, LocalDateTime> lastModifiedCol = new TableColumn<>(
"Last Modified");
lastModifiedCol
.setCellValueFactory(new PropertyValueFactory<FXFile, LocalDateTime>(
"lastModified"));
lastModifiedCol
.setCellFactory(new LocalDateTimeTableCellFactory<FXFile>());
// hidden attribute column with custom checkbox cell factory
TableColumn<FXFile, Boolean> hiddenCol = new TableColumn<>("Hidden");
hiddenCol
.setCellValueFactory(new PropertyValueFactory<FXFile, Boolean>(
"hidden"));
hiddenCol.setCellFactory(new CheckBoxTableCellFactory<FXFile>());
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<FXFile> fxFiles = new ArrayList<>();
for (File file : files)
{
fxFiles.add(new FXFile(file));
}
this.getItems().setAll(FXCollections.observableArrayList(fxFiles));
}
}
|