Context menu added to the TableView for items. Now it's possible to remove items from the table.

master
Dmitry Isaenko 2019-03-15 04:09:04 +03:00
parent dc5ba1425b
commit c5f62ed84a
5 changed files with 59 additions and 7 deletions

View File

@ -191,6 +191,12 @@ public class NSLMainController implements Initializable {
uploadStopBtn.getStyleClass().add("buttonUp");
}
}
/**
* Crunch. Now you see that I'm not a programmer.. This function called from NSTableViewController
* */
public void disableUploadStopBtn(){
uploadStopBtn.setDisable(true);
}
/**
* Drag-n-drop support (dragOver consumer)
* */

View File

@ -1,19 +1,21 @@
package nsusbloader.Controllers;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.*;
import javafx.scene.control.cell.CheckBoxTableCell;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.util.Callback;
import nsusbloader.MediatorControl;
import nsusbloader.NSLDataTypes.EFileStatus;
import java.io.File;
@ -32,6 +34,7 @@ public class NSTableViewController implements Initializable {
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
rowsObsLst = FXCollections.observableArrayList();
table.setPlaceholder(new Label());
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
@ -87,7 +90,45 @@ public class NSTableViewController implements Initializable {
return cell;
}
});
table.setRowFactory( // this shit is made to implement context menu. It's such a pain..
new Callback<TableView<NSLRowModel>, TableRow<NSLRowModel>>() {
@Override
public TableRow<NSLRowModel> call(TableView<NSLRowModel> nslRowModelTableView) {
final TableRow<NSLRowModel> row = new TableRow<>();
ContextMenu contextMenu = new ContextMenu();
MenuItem deleteMenuItem = new MenuItem(resourceBundle.getString("contextMenuBtnDelete"));
deleteMenuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
rowsObsLst.remove(row.getItem());
if (rowsObsLst.isEmpty())
MediatorControl.getInstance().getContoller().disableUploadStopBtn();
table.refresh();
}
});
MenuItem deleteAllMenuItem = new MenuItem(resourceBundle.getString("contextMenuBtnDeleteAll"));
deleteAllMenuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
rowsObsLst.clear();
MediatorControl.getInstance().getContoller().disableUploadStopBtn();
table.refresh();
}
});
contextMenu.getItems().addAll(deleteMenuItem, deleteAllMenuItem);
row.setContextMenu(contextMenu);
row.contextMenuProperty().bind(
Bindings.when(
Bindings.isNotNull(
row.itemProperty()))
.then(MediatorControl.getInstance().getTransferActive()?(ContextMenu)null:contextMenu)
.otherwise((ContextMenu) null)
);
return row;
}
}
);
table.setItems(rowsObsLst);
table.getColumns().addAll(statusColumn, fileNameColumn, fileSizeColumn, uploadColumn);
}
@ -108,9 +149,8 @@ public class NSTableViewController implements Initializable {
* */
public void setFiles(List<File> files){
rowsObsLst.clear(); // TODO: consider table refresh
if (files == null) {
if (files == null)
return;
}
if (protocol.equals("TinFoil")){
for (File nspFile: files){
rowsObsLst.add(new NSLRowModel(nspFile, true));

View File

@ -19,3 +19,5 @@ tableStatusLbl=Status
tableFileNameLbl=File name
tableSizeLbl=Size
tableUploadLbl=Upload?
contextMenuBtnDelete=Remove
contextMenuBtnDeleteAll=Remove all

View File

@ -20,4 +20,6 @@ tableUploadLbl=\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044C?
tableSizeLbl=\u0420\u0430\u0437\u043C\u0435\u0440
tableFileNameLbl=\u0418\u043C\u044F \u0444\u0430\u0439\u043B\u0430
tableStatusLbl=\u0421\u043E\u0441\u0442\u043E\u044F\u043D\u0438\u0435
contextMenuBtnDelete=\u0423\u0434\u0430\u043B\u0438\u0442\u044C
contextMenuBtnDeleteAll=\u0423\u0434\u0430\u043B\u0438\u0442\u044C \u0432\u0441\u0451

View File

@ -18,4 +18,6 @@ windowBodyConfirmWrongPFS0=\u0412\u0438\u0431\u0440\u0430\u043D\u0438\u0439 \u04
tableStatusLbl=\u0421\u0442\u0430\u043D
tableFileNameLbl=\u0406\u043C'\u044F \u0444\u0430\u0439\u043B\u0443
tableSizeLbl=\u0420\u043E\u0437\u043C\u0456\u0440
tableUploadLbl=\u0417\u0430\u0432\u0430\u043D\u0442\u0430\u0436.?
tableUploadLbl=\u0417\u0430\u0432\u0430\u043D\u0442\u0430\u0436.?
contextMenuBtnDelete=\u0412\u0438\u0434\u0430\u043B\u0438\u0442\u0438
contextMenuBtnDeleteAll=\u0412\u0438\u0434\u0430\u043B\u0438\u0442\u0438 \u0432\u0441\u0435