Problem chyba jest w tym, ze jeśli zmienić linie na taką:
rightTableView.itemsProperty().bindBidirectional(worker.valueProperty());
to valueProperty jest read only. Jak to teraz zmienić?
Klasa wygląda tak:
package sample;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
public class CopyFileTask extends Task<ObservableList<FilesForTableView>> {
private File source;
private File destination;
public CopyFileTask(File source, File destination) {
this.source = source;
this.destination = destination;
}
public CopyFileTask(String sourceString, String destinationString) {
this.source = new File(sourceString);
this.destination = new File(destinationString);
}
// The task implementation
@Override
protected ObservableList<FilesForTableView> call()
{
final ObservableList<FilesForTableView> results = Controller.getDirectoryContent(destination);
// Update the title
this.updateTitle("Prime Number Finder Task");
// Sleep for some time
try {
copyFile(source, destination);
System.out.println("file copied");
results.add(new FilesForTableView(destination.getName(), destination.length(), destination.isDirectory()));
} /*catch (InterruptedException e) {
// Check if the task is cancelled
if (this.isCancelled())
{
break;
}
}*/ catch (IOException e) {
e.printStackTrace();
}
return results;
}
@Override
protected void cancelled()
{
super.cancelled();
updateMessage("The task was cancelled.");
}
@Override
protected void failed()
{
super.failed();
updateMessage("The task failed.");
}
@Override
public void succeeded()
{
super.succeeded();
updateMessage("The task finished successfully.");
}
private static void copyFile(File source, File destination) throws IOException {
Files.copy(source.toPath(), destination.toPath());
}
}