Search in sources :

Example 1 with Downloader

use of org.monarchinitiative.loinc2hpo.io.Downloader in project loinc2hpo by monarch-initiative.

the class MainController method downloadHPO.

@FXML
public void downloadHPO(ActionEvent e) {
    String dirpath = Loinc2HpoPlatform.getLOINC2HPODir().getAbsolutePath();
    File f = new File(dirpath);
    if (f == null || !(f.exists() && f.isDirectory())) {
        logger.trace("Cannot download hp.obo, because directory not existing at " + f.getAbsolutePath());
        return;
    }
    String BASENAME = "hp.obo";
    String BASENAME_OWL = "hp.owl";
    ProgressIndicator pb = new ProgressIndicator();
    javafx.scene.control.Label label = new javafx.scene.control.Label("downloading hp.obo/.owl...");
    FlowPane root = new FlowPane();
    root.setPadding(new Insets(10));
    root.setHgap(10);
    root.getChildren().addAll(label, pb);
    Scene scene = new Scene(root, 400, 100);
    Stage window = new Stage();
    window.setTitle("HPO download");
    window.setScene(scene);
    Task hpodownload = new Downloader(dirpath, HP_OBO_URL, BASENAME, pb);
    new Thread(hpodownload).start();
    hpodownload = new Downloader(dirpath, HP_OWL_URL, BASENAME_OWL, pb);
    new Thread(hpodownload).start();
    window.show();
    hpodownload.setOnSucceeded(event -> {
        window.close();
        logger.trace(String.format("Successfully downloaded hpo to %s", dirpath));
        String fullpath = String.format("%s%shp.obo", dirpath, File.separator);
        String fullpath_owl = String.format("%s%shp.owl", dirpath, File.separator);
        model.setPathToHpOboFile(fullpath);
        model.setPathToHpOwlFile(fullpath_owl);
        model.writeSettings();
        configurationComplete.set(isConfigurationCompleted());
    });
    hpodownload.setOnFailed(event -> {
        window.close();
        logger.error("Unable to download HPO obo file");
    });
    // Thread thread = new Thread(hpodownload);
    // thread.start();
    e.consume();
}
Also used : Task(javafx.concurrent.Task) Insets(javafx.geometry.Insets) Downloader(org.monarchinitiative.loinc2hpo.io.Downloader) javafx.scene.control(javafx.scene.control) Scene(javafx.scene.Scene) FlowPane(javafx.scene.layout.FlowPane) Stage(javafx.stage.Stage) WriteToFile(org.monarchinitiative.loinc2hpo.io.WriteToFile) FXML(javafx.fxml.FXML)

Aggregations

Task (javafx.concurrent.Task)1 FXML (javafx.fxml.FXML)1 Insets (javafx.geometry.Insets)1 Scene (javafx.scene.Scene)1 javafx.scene.control (javafx.scene.control)1 FlowPane (javafx.scene.layout.FlowPane)1 Stage (javafx.stage.Stage)1 Downloader (org.monarchinitiative.loinc2hpo.io.Downloader)1 WriteToFile (org.monarchinitiative.loinc2hpo.io.WriteToFile)1