2020-03-28 15:24:35 +00:00
|
|
|
package de.wwwu.awolf.view.services;
|
|
|
|
|
|
|
|
import de.wwwu.awolf.presenter.Presenter;
|
|
|
|
import de.wwwu.awolf.presenter.data.DataHandler;
|
2020-04-05 18:53:52 +00:00
|
|
|
import java.io.File;
|
2020-03-28 15:24:35 +00:00
|
|
|
import javafx.concurrent.Service;
|
|
|
|
import javafx.concurrent.Task;
|
|
|
|
|
2020-04-05 17:28:38 +00:00
|
|
|
public class DataService extends Service<Boolean> {
|
|
|
|
|
|
|
|
private File file;
|
2020-03-28 15:24:35 +00:00
|
|
|
private DataHandler.DataType type;
|
2020-04-05 17:28:38 +00:00
|
|
|
private DataHandler.ActionType actionType;
|
2020-03-28 15:24:35 +00:00
|
|
|
private int n;
|
|
|
|
|
2020-04-05 18:53:52 +00:00
|
|
|
public DataService(final DataHandler.ActionType actionType, final DataHandler.DataType type,
|
|
|
|
final int n) {
|
2020-03-28 15:24:35 +00:00
|
|
|
this.type = type;
|
2020-04-05 17:28:38 +00:00
|
|
|
this.actionType = actionType;
|
2020-03-28 15:24:35 +00:00
|
|
|
this.n = n;
|
|
|
|
}
|
|
|
|
|
2020-04-05 17:28:38 +00:00
|
|
|
public DataService(final DataHandler.ActionType actionType, final File file) {
|
|
|
|
this.actionType = actionType;
|
|
|
|
this.file = file;
|
|
|
|
this.type = null;
|
|
|
|
this.n = -1;
|
|
|
|
}
|
|
|
|
|
2020-03-28 15:24:35 +00:00
|
|
|
@Override
|
2020-04-05 17:28:38 +00:00
|
|
|
protected Task<Boolean> createTask() {
|
2020-03-28 15:24:35 +00:00
|
|
|
return new Task<>() {
|
|
|
|
@Override
|
2020-04-05 17:28:38 +00:00
|
|
|
protected Boolean call() throws Exception {
|
|
|
|
switch (actionType) {
|
|
|
|
case EXPORT:
|
|
|
|
Presenter.getInstance().exportDataset(file);
|
|
|
|
break;
|
|
|
|
case IMPORT:
|
|
|
|
Presenter.getInstance().importDataset(file);
|
|
|
|
break;
|
|
|
|
case GENERATE:
|
|
|
|
Presenter.getInstance().generateDataset(n, type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2020-03-28 15:24:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|