#26 Fix sorting of sizeColumn
change rowmodel.size to long instead of preformatting bytes in model add cellfactory to format strings
This commit is contained in:
parent
8645eac0c7
commit
abb0be6620
2 changed files with 26 additions and 9 deletions
|
@ -9,19 +9,14 @@ public class NSLRowModel {
|
||||||
private String status;
|
private String status;
|
||||||
private File nspFile;
|
private File nspFile;
|
||||||
private String nspFileName;
|
private String nspFileName;
|
||||||
private String nspFileSize;
|
private long nspFileSize;
|
||||||
private boolean markForUpload;
|
private boolean markForUpload;
|
||||||
|
|
||||||
NSLRowModel(File nspFile, boolean checkBoxValue){
|
NSLRowModel(File nspFile, boolean checkBoxValue){
|
||||||
this.nspFile = nspFile;
|
this.nspFile = nspFile;
|
||||||
this.markForUpload = checkBoxValue;
|
this.markForUpload = checkBoxValue;
|
||||||
this.nspFileName = nspFile.getName();
|
this.nspFileName = nspFile.getName();
|
||||||
if (nspFile.length()/1024.0/1024.0/1024.0 > 1)
|
this.nspFileSize = nspFile.length();
|
||||||
this.nspFileSize = String.format("%.2f", nspFile.length()/1024.0/1024.0/1024.0)+" GB";
|
|
||||||
else if (nspFile.length()/1024.0/1024.0 > 1)
|
|
||||||
this.nspFileSize = String.format("%.2f", nspFile.length()/1024.0/1024.0)+" MB";
|
|
||||||
else
|
|
||||||
this.nspFileSize = String.format("%.2f", nspFile.length()/1024.0)+" kB";
|
|
||||||
this.status = "";
|
this.status = "";
|
||||||
}
|
}
|
||||||
// Model methods start
|
// Model methods start
|
||||||
|
@ -31,7 +26,9 @@ public class NSLRowModel {
|
||||||
public String getNspFileName(){
|
public String getNspFileName(){
|
||||||
return nspFileName;
|
return nspFileName;
|
||||||
}
|
}
|
||||||
public String getNspFileSize() { return nspFileSize; }
|
public long getNspFileSize() {
|
||||||
|
return nspFileSize;
|
||||||
|
}
|
||||||
public boolean isMarkForUpload() {
|
public boolean isMarkForUpload() {
|
||||||
return markForUpload;
|
return markForUpload;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class NSTableViewController implements Initializable {
|
||||||
|
|
||||||
TableColumn<NSLRowModel, String> statusColumn = new TableColumn<>(resourceBundle.getString("tab1_table_Lbl_Status"));
|
TableColumn<NSLRowModel, String> statusColumn = new TableColumn<>(resourceBundle.getString("tab1_table_Lbl_Status"));
|
||||||
TableColumn<NSLRowModel, String> fileNameColumn = new TableColumn<>(resourceBundle.getString("tab1_table_Lbl_FileName"));
|
TableColumn<NSLRowModel, String> fileNameColumn = new TableColumn<>(resourceBundle.getString("tab1_table_Lbl_FileName"));
|
||||||
TableColumn<NSLRowModel, String> fileSizeColumn = new TableColumn<>(resourceBundle.getString("tab1_table_Lbl_Size"));
|
TableColumn<NSLRowModel, Long> fileSizeColumn = new TableColumn<>(resourceBundle.getString("tab1_table_Lbl_Size"));
|
||||||
TableColumn<NSLRowModel, Boolean> uploadColumn = new TableColumn<>(resourceBundle.getString("tab1_table_Lbl_Upload"));
|
TableColumn<NSLRowModel, Boolean> uploadColumn = new TableColumn<>(resourceBundle.getString("tab1_table_Lbl_Upload"));
|
||||||
|
|
||||||
statusColumn.setEditable(false);
|
statusColumn.setEditable(false);
|
||||||
|
@ -93,6 +93,16 @@ public class NSTableViewController implements Initializable {
|
||||||
});
|
});
|
||||||
|
|
||||||
uploadColumn.setCellFactory(paramFeatures -> new CheckBoxTableCell<>());
|
uploadColumn.setCellFactory(paramFeatures -> new CheckBoxTableCell<>());
|
||||||
|
fileSizeColumn.setCellFactory(col -> new TableCell<NSLRowModel, Long>() {
|
||||||
|
@Override
|
||||||
|
protected void updateItem(Long length, boolean empty) {
|
||||||
|
if (length == null || empty) {
|
||||||
|
setText("");
|
||||||
|
} else {
|
||||||
|
setText(formatByteSize(length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
table.setRowFactory( // this shit is made to implement context menu. It's such a pain..
|
table.setRowFactory( // this shit is made to implement context menu. It's such a pain..
|
||||||
nslRowModelTableView -> {
|
nslRowModelTableView -> {
|
||||||
final TableRow<NSLRowModel> row = new TableRow<>();
|
final TableRow<NSLRowModel> row = new TableRow<>();
|
||||||
|
@ -209,4 +219,14 @@ public class NSTableViewController implements Initializable {
|
||||||
table.refresh();
|
table.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String formatByteSize(long length) {
|
||||||
|
final String[] unitNames = { "bytes", "KiB", "MiB", "GiB", "TiB"};
|
||||||
|
int i;
|
||||||
|
for (i = 0; length > 1024 && i < unitNames.length - 1; i++) {
|
||||||
|
length = length / 1024;
|
||||||
|
}
|
||||||
|
return String.format("%,d %s", length, unitNames[i]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue