1
0
Fork 0
mirror of https://gitlab.com/kauron/jstudy synced 2024-12-22 08:23:33 +01:00

Moved and documented DraggableRowFactory

This commit is contained in:
Carlos Galindo 2019-09-13 13:21:29 +02:00
parent a0e3a1fb17
commit 7c46dee784
Signed by: kauron
GPG key ID: 83E68706DEE119A3
2 changed files with 6 additions and 4 deletions

View file

@ -2,6 +2,7 @@ package es.kauron.jstudy.controller;
import es.kauron.jstudy.model.AppPrefs; import es.kauron.jstudy.model.AppPrefs;
import es.kauron.jstudy.model.TestItem; import es.kauron.jstudy.model.TestItem;
import es.kauron.jstudy.util.DraggableRowFactory;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.property.*; import javafx.beans.property.*;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;

View file

@ -1,4 +1,4 @@
package es.kauron.jstudy.controller; package es.kauron.jstudy.util;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.scene.control.TableRow; import javafx.scene.control.TableRow;
@ -11,17 +11,18 @@ import javafx.scene.input.TransferMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
class DraggableRowFactory<S> { // Adapted from https://stackoverflow.com/a/52437193
public class DraggableRowFactory<S> {
private static final DataFormat SERIALIZED_MIME_TYPE = new DataFormat("application/x-java-serialized-object"); private static final DataFormat SERIALIZED_MIME_TYPE = new DataFormat("application/x-java-serialized-object");
private final ObservableList<S> data; private final ObservableList<S> data;
private final List<S> dragging = new ArrayList<>(); private final List<S> dragging = new ArrayList<>();
DraggableRowFactory(ObservableList<S> data) { public DraggableRowFactory(ObservableList<S> data) {
this.data = data; this.data = data;
} }
TableRow<S> generator(TableView<S> table) { public TableRow<S> generator(TableView<S> table) {
TableRow<S> row = new TableRow<>(); TableRow<S> row = new TableRow<>();
row.setOnDragDetected((event) -> { row.setOnDragDetected((event) -> {
if (!row.isEmpty() && table.getItems().size() == data.size()) { if (!row.isEmpty() && table.getItems().size() == data.size()) {