allora, sinceramente ho qualche problema / confusione.
partiamo dalla functional interface:
codice:
import jxl.write.WriteException;
import java.io.File;
import java.io.IOException;
import java.util.List;
@FunctionalInterface
public interface DoExport {
public void export(File file, List<Nota> list, String[] header) throws IOException, WriteException;
}
ho aggiunto anche un'altra eccezione visto che uno degli export lo richiede.
poi nel controller:
codice:
@FXML
private void esporta(ActionEvent ev) {
Object obj = ev.getSource();
List<Nota> list = null;
try {
list = db.getAll();
} catch (SQLException ex) {
GenericDialog.showDialog("Errore database: " + ex.getMessage(), Alert.AlertType.WARNING);
}
if (list != null) {
if (obj == miJson) {
doExp(new JsonDb(), "Esporta JSON", new FileChooser.ExtensionFilter("JSON (*.json)", "*.json"), list);
} else if (obj == miXls) {
} else if (obj == miCsv) {
} else if (obj == miXml) {
}
}
}
private <T> void doExp(T obj, String titolo, FileChooser.ExtensionFilter ext, List<Nota> list) {
DirChooser dc = new DirChooser();
Optional<File> file = dc.saveFile(getStage().getOwner(), titolo, ext);
try {
DoExport de = (File f, List<Nota> l, String[] header) -> f.getPath(), ll, str;
de.export(file.get(), list, new String[]{});
} catch (IOException | WriteException ex) {
GenericDialog.showDialog(ex.getMessage(), Alert.AlertType.WARNING);
}
}
però, non saprei come richiamare il metodo di creazione dell'export che dovrei fare.
ammesso che ci abbia capito qualcosa ovviamente!