mirror of
https://github.com/developersu/ns-usbloader.git
synced 2025-05-14 15:15:05 -04:00
v0.2-development intermediate results of UI updates
This commit is contained in:
parent
49bd078bc5
commit
ad23eb0c82
8 changed files with 188 additions and 75 deletions
|
@ -9,12 +9,14 @@ public class NSLRowModel {
|
|||
private String status; // 0 = unknown, 1 = uploaded, 2 = bad file
|
||||
private File nspFile;
|
||||
private String nspFileName;
|
||||
private String nspFileSize;
|
||||
private boolean markForUpload;
|
||||
|
||||
NSLRowModel(File nspFile, boolean checkBoxValue){
|
||||
this.nspFile = nspFile;
|
||||
this.markForUpload = checkBoxValue;
|
||||
this.nspFileName = nspFile.getName();
|
||||
this.nspFileSize = String.format("%.2f", nspFile.length()/1024.0/1024.0);
|
||||
this.status = "";
|
||||
}
|
||||
// Model methods start
|
||||
|
@ -24,6 +26,7 @@ public class NSLRowModel {
|
|||
public String getNspFileName(){
|
||||
return nspFileName;
|
||||
}
|
||||
public String getNspFileSize() { return nspFileSize; }
|
||||
public boolean isMarkForUpload() {
|
||||
return markForUpload;
|
||||
}
|
||||
|
|
|
@ -27,20 +27,25 @@ public class NSTableViewController implements Initializable {
|
|||
private TableView<NSLRowModel> table;
|
||||
private ObservableList<NSLRowModel> rowsObsLst;
|
||||
|
||||
private String protocol;
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
rowsObsLst = FXCollections.observableArrayList();
|
||||
table.setPlaceholder(new Label());
|
||||
|
||||
TableColumn<NSLRowModel, String> statusColumn = new TableColumn<>("Status"); // TODO: Localization
|
||||
TableColumn<NSLRowModel, String> fileNameColumn = new TableColumn<>("File Name"); // TODO: Localization
|
||||
TableColumn<NSLRowModel, Boolean> uploadColumn = new TableColumn<>("Upload?"); // TODO: Localization
|
||||
TableColumn<NSLRowModel, String> statusColumn = new TableColumn<>(resourceBundle.getString("tableStatusLbl"));
|
||||
TableColumn<NSLRowModel, String> fileNameColumn = new TableColumn<>(resourceBundle.getString("tableFileNameLbl"));
|
||||
TableColumn<NSLRowModel, String> fileSizeColumn = new TableColumn<>(resourceBundle.getString("tableSizeLbl"));
|
||||
TableColumn<NSLRowModel, Boolean> uploadColumn = new TableColumn<>(resourceBundle.getString("tableUploadLbl"));
|
||||
statusColumn.setMinWidth(70.0);
|
||||
fileNameColumn.setMinWidth(270.0);
|
||||
fileNameColumn.setMinWidth(250.0);
|
||||
fileSizeColumn.setMinWidth(70.0);
|
||||
uploadColumn.setMinWidth(70.0);
|
||||
|
||||
statusColumn.setCellValueFactory(new PropertyValueFactory<>("status"));
|
||||
fileNameColumn.setCellValueFactory(new PropertyValueFactory<>("nspFileName"));
|
||||
fileSizeColumn.setCellValueFactory(new PropertyValueFactory<>("nspFileSize"));
|
||||
// ><
|
||||
uploadColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<NSLRowModel, Boolean>, ObservableValue<Boolean>>() {
|
||||
@Override
|
||||
|
@ -53,7 +58,7 @@ public class NSTableViewController implements Initializable {
|
|||
@Override
|
||||
public void changed(ObservableValue<? extends Boolean> observableValue, Boolean oldValue, Boolean newValue) {
|
||||
model.setMarkForUpload(newValue);
|
||||
// TODO: add reference to this general class method which will validate protocol and restict selection
|
||||
restrictSelection(model);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -70,19 +75,33 @@ public class NSTableViewController implements Initializable {
|
|||
});
|
||||
|
||||
table.setItems(rowsObsLst);
|
||||
table.getColumns().addAll(statusColumn, fileNameColumn, uploadColumn);
|
||||
|
||||
rowsObsLst.add(new NSLRowModel(new File("/tmp/dump_file"), true));
|
||||
rowsObsLst.add(new NSLRowModel(new File("/home/loper/тяжелые будни.mp4"), false));
|
||||
rowsObsLst.add(new NSLRowModel(new File("/home/loper/стихи.txt"), false));
|
||||
table.getColumns().addAll(statusColumn, fileNameColumn, fileSizeColumn, uploadColumn);
|
||||
/* debug content
|
||||
rowsObsLst.add(new NSLRowModel(new File("/home/loper/стихи_2"), true));
|
||||
rowsObsLst.add(new NSLRowModel(new File("/home/loper/стихи_2"), false));
|
||||
rowsObsLst.add(new NSLRowModel(new File("/home/loper/стихи_1"), false));
|
||||
rowsObsLst.add(new NSLRowModel(new File("/home/loper/стихи_2"), false));
|
||||
rowsObsLst.add(new NSLRowModel(new File("/home/loper/стихи_2"), true));
|
||||
*/
|
||||
}
|
||||
/**
|
||||
* See uploadColumn callback. In case of GoldLeaf we have to restrict selection
|
||||
* */
|
||||
private void restrictSelection(NSLRowModel modelChecked){
|
||||
if (!protocol.equals("TinFoil") && rowsObsLst.size() > 1) { // Tinfoil doesn't need any restrictions. If only one file in list, also useless
|
||||
for (NSLRowModel model: rowsObsLst){
|
||||
if (model != modelChecked)
|
||||
model.setMarkForUpload(false);
|
||||
}table.refresh();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Add files when user selected them
|
||||
* */
|
||||
public void addFiles(List<File> files, String protocol){
|
||||
rowsObsLst.clear();
|
||||
public void setFiles(List<File> files){
|
||||
rowsObsLst.clear(); // TODO: consider table refresh
|
||||
if (files == null) {
|
||||
return;
|
||||
}
|
||||
if (protocol.equals("TinFoil")){
|
||||
for (File nspFile: files){
|
||||
rowsObsLst.add(new NSLRowModel(nspFile, true));
|
||||
|
@ -119,7 +138,7 @@ public class NSTableViewController implements Initializable {
|
|||
/**
|
||||
* Update files in case something is wrong. Requested from UsbCommunications _OR_ PFS
|
||||
* */
|
||||
public void reportFileStatus(String fileName, FileStatus status){
|
||||
public void setFileStatus(String fileName, FileStatus status){
|
||||
for (NSLRowModel model: rowsObsLst){
|
||||
if (model.getNspFileName().equals(fileName)){
|
||||
model.setStatus(status);
|
||||
|
@ -129,10 +148,11 @@ public class NSTableViewController implements Initializable {
|
|||
/**
|
||||
* Called if selected different USB protocol
|
||||
* */
|
||||
public void protocolChangeEvent(String protocol){
|
||||
public void setNewProtocol(String newProtocol){
|
||||
protocol = newProtocol;
|
||||
if (rowsObsLst.isEmpty())
|
||||
return;
|
||||
if (protocol.equals("TinFoil")){
|
||||
if (newProtocol.equals("TinFoil")){
|
||||
for (NSLRowModel model: rowsObsLst)
|
||||
model.setMarkForUpload(true);
|
||||
}
|
||||
|
@ -143,4 +163,5 @@ public class NSTableViewController implements Initializable {
|
|||
}
|
||||
table.refresh();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package nsusbloader;
|
|||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.*;
|
||||
|
@ -13,6 +12,7 @@ import nsusbloader.Controllers.NSTableViewController;
|
|||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
|
@ -20,8 +20,6 @@ public class NSLMainController implements Initializable {
|
|||
|
||||
private ResourceBundle resourceBundle;
|
||||
|
||||
private List<File> nspToUpload;
|
||||
|
||||
@FXML
|
||||
private TextArea logArea;
|
||||
@FXML
|
||||
|
@ -73,7 +71,8 @@ public class NSLMainController implements Initializable {
|
|||
ObservableList<String> choiceProtocolList = FXCollections.observableArrayList("TinFoil", "GoldLeaf");
|
||||
choiceProtocol.setItems(choiceProtocolList);
|
||||
choiceProtocol.getSelectionModel().select(0); // TODO: shared settings
|
||||
choiceProtocol.setOnAction(e->tableFilesListController.protocolChangeEvent(choiceProtocol.getSelectionModel().getSelectedItem()));
|
||||
choiceProtocol.setOnAction(e->tableFilesListController.setNewProtocol(choiceProtocol.getSelectionModel().getSelectedItem())); // Add listener to notify tableView controller
|
||||
tableFilesListController.setNewProtocol(choiceProtocol.getSelectionModel().getSelectedItem()); // Notify tableView controller
|
||||
|
||||
this.previouslyOpenedPath = null;
|
||||
|
||||
|
@ -117,29 +116,29 @@ public class NSLMainController implements Initializable {
|
|||
|
||||
filesList = fileChooser.showOpenMultipleDialog(logArea.getScene().getWindow());
|
||||
if (filesList != null && !filesList.isEmpty()) {
|
||||
setReady(filesList);
|
||||
tableFilesListController.setFiles(filesList);
|
||||
uploadStopBtn.setDisable(false);
|
||||
previouslyOpenedPath = filesList.get(0).getParent();
|
||||
}
|
||||
else
|
||||
setNotReady(resourceBundle.getString("logsNoFolderFileSelected"));
|
||||
}
|
||||
private void setReady(List<File> filesList){
|
||||
logArea.setText(resourceBundle.getString("logsFilesToUploadTitle")+"\n");
|
||||
for (File item: filesList)
|
||||
logArea.appendText(" "+item.getAbsolutePath()+"\n");
|
||||
nspToUpload = filesList;
|
||||
uploadStopBtn.setDisable(false);
|
||||
}
|
||||
private void setNotReady(String whyNotReady){
|
||||
logArea.setText(whyNotReady);
|
||||
nspToUpload = null;
|
||||
uploadStopBtn.setDisable(true);
|
||||
else{
|
||||
tableFilesListController.setFiles(null);
|
||||
uploadStopBtn.setDisable(true);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* It's button listener when no transmission executes
|
||||
* */
|
||||
private void uploadBtnAction(){
|
||||
if (usbThread == null || !usbThread.isAlive()){
|
||||
List<File> nspToUpload;
|
||||
if ((nspToUpload = tableFilesListController.getFiles()) == null) {
|
||||
resourceBundle.getString("logsNoFolderFileSelected");
|
||||
return;
|
||||
}else {
|
||||
logArea.setText(resourceBundle.getString("logsFilesToUploadTitle")+"\n");
|
||||
for (File item: nspToUpload)
|
||||
logArea.appendText(" "+item.getAbsolutePath()+"\n");
|
||||
}
|
||||
UsbCommunications usbCommunications = new UsbCommunications(logArea, progressBar, nspToUpload, choiceProtocol.getSelectionModel().getSelectedItem());
|
||||
usbThread = new Thread(usbCommunications);
|
||||
usbThread.start();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue