Merge pull request #35 from wolfposd/master
#26 Fix sorting of sizeColumn
This commit is contained in:
commit
6f5d02a864
2 changed files with 26 additions and 9 deletions
|
@ -9,19 +9,14 @@ public class NSLRowModel {
|
|||
private String status;
|
||||
private File nspFile;
|
||||
private String nspFileName;
|
||||
private String nspFileSize;
|
||||
private long nspFileSize;
|
||||
private boolean markForUpload;
|
||||
|
||||
NSLRowModel(File nspFile, boolean checkBoxValue){
|
||||
this.nspFile = nspFile;
|
||||
this.markForUpload = checkBoxValue;
|
||||
this.nspFileName = nspFile.getName();
|
||||
if (nspFile.length()/1024.0/1024.0/1024.0 > 1)
|
||||
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.nspFileSize = nspFile.length();
|
||||
this.status = "";
|
||||
}
|
||||
// Model methods start
|
||||
|
@ -31,7 +26,9 @@ public class NSLRowModel {
|
|||
public String getNspFileName(){
|
||||
return nspFileName;
|
||||
}
|
||||
public String getNspFileSize() { return nspFileSize; }
|
||||
public long getNspFileSize() {
|
||||
return nspFileSize;
|
||||
}
|
||||
public boolean isMarkForUpload() {
|
||||
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> 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"));
|
||||
|
||||
statusColumn.setEditable(false);
|
||||
|
@ -93,6 +93,16 @@ public class NSTableViewController implements Initializable {
|
|||
});
|
||||
|
||||
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..
|
||||
nslRowModelTableView -> {
|
||||
final TableRow<NSLRowModel> row = new TableRow<>();
|
||||
|
@ -209,4 +219,14 @@ public class NSTableViewController implements Initializable {
|
|||
table.refresh();
|
||||
}
|
||||
|
||||
|
||||
private String formatByteSize(double 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("%,.2f %s", length, unitNames[i]);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue