Example usage for javafx.scene.control Alert Alert

List of usage examples for javafx.scene.control Alert Alert

Introduction

In this page you can find the example usage for javafx.scene.control Alert Alert.

Prototype

public Alert(@NamedArg("alertType") AlertType alertType) 

Source Link

Document

Creates an alert with the given AlertType (refer to the AlertType documentation for clarification over which one is most appropriate).

Usage

From source file:net.rptools.tokentool.controller.ManageOverlays_Controller.java

private boolean confirmDelete(LinkedList<File> overlayFiles) {
    String confirmationText = I18N.getString("ManageOverlays.dialog.delete.confirmation");

    if (overlayFiles.isEmpty())
        return false;
    else if (overlayFiles.size() == 1) {
        confirmationText += overlayFiles.get(0).getName() + "?";
    } else {// w ww .j ava  2 s .  c  om
        confirmationText += I18N.getString("ManageOverlays.dialog.delete.confirmation.these")
                + overlayFiles.size() + I18N.getString("ManageOverlays.dialog.delete.confirmation.overlays");
    }

    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle(I18N.getString("ManageOverlays.dialog.delete.title"));
    alert.setContentText(confirmationText);

    Optional<ButtonType> result = alert.showAndWait();

    if ((result.isPresent()) && (result.get() == ButtonType.OK)) {
        return true;
    }

    return false;
}

From source file:utilitybasedfx.MainGUIController.java

@FXML
private void eventGenerateMutants(ActionEvent event) {
    MutantViewerController c = Prefs.getController("MutantViewer");

    List<File> actualFiles = new ArrayList<>();
    for (File file : listOfSelectedFiles) {
        actualFiles.add(new File(Prefs.getSourcePath(), file.toString()));
    }//from   w  w  w .  j  a  va  2  s .  c o m

    enableWorking(new Task<String>() {
        @Override
        protected String call() throws InterruptedException {
            File root;
            try {
                root = new File(Prefs.getProjectPath()).getCanonicalFile();
            } catch (IOException ioe) {
                updateMessage("Unable to find root directory");
                return "";
            }
            NewMutationSystem nms = new NewMutationSystem(root);

            updateMessage("Generating Mutants!...");
            try {
                List<Mutant> mutants = nms.generateMutants(actualFiles, listOfTraditionalOps, listOfClassOps);
                updateMessage("");

                c.setMutants(mutants);
                Platform.runLater(c::refreshClassesCbos);
                Platform.runLater(() -> {
                    Prefs.getStage().setScene(Prefs.getScene("MutantViewer"));
                });
            } catch (UnableToGenerateException utg) {
                Platform.runLater(() -> {
                    Alert alert = new Alert(AlertType.ERROR);
                    alert.setTitle("There was an error");
                    alert.setHeaderText("There was an issue generating mutants");
                    alert.setContentText(utg.toString());

                    alert.showAndWait();
                });
            } catch (NoClassFilesException ex) {
                Platform.runLater(() -> {
                    Alert alert = new Alert(AlertType.ERROR);
                    alert.setTitle("There was an error");
                    alert.setHeaderText("There was an issue generating mutants");
                    alert.setContentText(
                            "There is no classes in the following folder\n" + Prefs.getClassPath());

                    alert.showAndWait();
                });
            }

            return ""; //[FIXME] find a way to do this inline function without a class as return type
        }
    });
}

From source file:gmailclientfx.core.GmailClient.java

public static void sendMessage(String to, String subject, String body, List<String> attachments)
        throws Exception {
    // authenticate with gmail smtp server
    SMTPTransport smtpTransport = connectToSmtp("smtp.gmail.com", 587, EMAIL, ACCESS_TOKEN, true);

    // kreiraj MimeMessage objekt
    MimeMessage msg = new MimeMessage(OAuth2Authenticator.getSession());

    // dodaj headere
    msg.addHeader("Content-type", "text/HTML; charset=UTF-8");
    msg.addHeader("format", "flowed");
    msg.addHeader("Content-Transfer-Encoding", "8bit");

    msg.setFrom(new InternetAddress(EMAIL));
    msg.setRecipients(javax.mail.Message.RecipientType.CC, InternetAddress.parse(to));
    msg.setSubject(subject, "UTF-8");
    msg.setReplyTo(InternetAddress.parse(EMAIL, false));

    // tijelo poruke
    BodyPart msgBodyPart = new MimeBodyPart();
    msgBodyPart.setText(body);/*from www . j a v a 2 s  .  c  om*/

    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(msgBodyPart);
    msg.setContent(multipart);

    // dodaj privitke
    if (attachments.size() > 0) {
        for (String attachment : attachments) {
            msgBodyPart = new MimeBodyPart();
            DataSource source = new FileDataSource(attachment);
            msgBodyPart.setDataHandler(new DataHandler(source));
            msgBodyPart.setFileName(source.getName());
            multipart.addBodyPart(msgBodyPart);
        }
        msg.setContent(multipart);
    }
    smtpTransport.sendMessage(msg, InternetAddress.parse(to));

    Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
    alert.setTitle("Poruka poslana!");
    alert.setHeaderText(null);
    alert.setContentText("Email uspjeno poslan!");
    alert.showAndWait();
}

From source file:editeurpanovisu.EquiCubeDialogController.java

/**
 *
 *//* w ww  .j a v a2 s .c  o  m*/
private void validerE2C() {
    if (fileLstFichier == null) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle(rbLocalisation.getString("transformation.traiteImages"));
        alert.setHeaderText(null);
        alert.setContentText(rbLocalisation.getString("transformation.traiteImagesPasFichiers"));
        alert.showAndWait();
    } else {
        Alert alert = new Alert(AlertType.WARNING);
        alert.setTitle(rbLocalisation.getString("transformation.traiteImages"));
        alert.setHeaderText(null);
        alert.setContentText(rbLocalisation.getString("transformation.traiteImagesMessage"));
        alert.showAndWait();

        lblTermine = new Label();
        lblTermine.setText("Traitement en cours");
        lblTermine.setLayoutX(24);
        lblTermine.setLayoutY(250);
        paneChoixTypeFichier.getChildren().add(lblTermine);
        pbBarreAvancement.setId("bar");
        lblTermine.setId("lblTermine");
        pbBarreAvancement.setVisible(true);
        pbBarreImage.setVisible(true);
        Task taskTraitement;
        taskTraitement = tskTraitement();
        pbBarreAvancement.progressProperty().unbind();
        pbBarreImage.setProgress(0.001);
        pbBarreAvancement.setProgress(0.001);
        pbBarreAvancement.progressProperty().bind(taskTraitement.progressProperty());
        lblTermine.textProperty().unbind();
        lblTermine.textProperty().bind(taskTraitement.messageProperty());
        Thread thrTraitement = new Thread(taskTraitement);
        thrTraitement.setDaemon(true);
        thrTraitement.start();
    }
}

From source file:be.makercafe.apps.makerbench.editors.JFXMillEditor.java

private void handleExportAsGCodeFile(ActionEvent e) {

    if (millObject == null) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Oeps an error occured");
        alert.setHeaderText("Cannot export gcode. There is no geometry !");
        alert.setContentText("Please verify that your code generates a valid millcrum object.");
        alert.showAndWait();/*from  www .j  a v  a 2  s . c o m*/
        return;
    }

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export GCODE File");
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("GCODE files (*.gcode)", "*.tap"));

    File f = fileChooser.showSaveDialog(null);

    if (f == null) {
        return;
    }

    String fName = f.getAbsolutePath();

    if (!fName.toLowerCase().endsWith(".gcode")) {
        fName += ".gcode";
    }

    try {
        millObject.get();
        FileUtils.write(new File(fName), millObject.getToSaveGcode());
    } catch (IOException ex) {

        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Oeps an error occured");
        alert.setHeaderText("Cannot export gcode. There went something wrong writing the file.");
        alert.setContentText(
                "Please verify that your file is not read only, is not locked by other user or program, you have enough diskspace.");
        alert.showAndWait();
    }
}

From source file:jp.ac.tohoku.ecei.sb.metabolome.lims.gui.MainWindowController.java

@FXML
void onTableClicked(MouseEvent event) {
    if (event.getClickCount() != 2)
        return;/* w  w w .jav a  2  s  . c  o m*/
    TableView tableView = ((TableView) event.getSource());
    TableView.TableViewFocusModel focusModel = (TableView.TableViewFocusModel) tableView.focusModelProperty()
            .getValue();
    TablePosition position = focusModel.getFocusedCell();
    if (position.getTableColumn() == null)
        return;
    ObservableValue value = position.getTableColumn().getCellObservableValue(position.getRow());
    String valueStr = value.getValue().toString();
    Alert alert = new Alert(Alert.AlertType.INFORMATION);
    alert.setHeaderText(String.format("Value at ID:%d  %s",
            ((LIMSData) tableView.getItems().get(position.getRow())).getId(),
            position.getTableColumn().getText()));
    if (valueStr.length() > 300)
        alert.setContentText(valueStr.substring(0, 300) + "...");
    else
        alert.setContentText(valueStr);

    TextArea textArea = new TextArea(valueStr);
    textArea.setEditable(false);
    alert.getDialogPane().setExpandableContent(textArea);

    event.consume();
    alert.show();
}

From source file:hd3gtv.as5kpc.Serverchannel.java

void appCue(TextField mediaid, Label takenum, TextField showname, Button btncue, Button btnrec) {
    int id;//from   w  ww  .j av a2  s.  c o m
    int take;
    try {
        id = Integer.parseInt(mediaid.getText());
        take = Integer.valueOf(takenum.getText());
    } catch (Exception e) {
        Alert alert = new Alert(AlertType.WARNING);
        alert.setTitle("Media ID");
        alert.setHeaderText("Erreur lors de la rcupration de l'ID, seuls des chiffres sont autoriss.");
        alert.setContentText("Dtail: " + e.getMessage());
        alert.showAndWait();
        return;
    }

    GetFreeClipIdBackgound gfip = getFreeClipIdBackgound(id + getVtrIndex(), take);

    gfip.setOnSucceeded((WorkerStateEvent ev) -> {
        takenum.setText(gfip.getValue().get("take"));
        String first_name = gfip.getValue().get("first_name");
        if (first_name != null) {
            final String _first_name = first_name.substring("00-00 ".length());
            showname.setText(_first_name);
            if (_first_name.endsWith(getServerLabel())) {
                showname.setText(
                        _first_name.substring(0, _first_name.length() - getServerLabel().length()).trim());
            }
        }

        btncue.setDisable(false);
        mediaid.setDisable(false);
        showname.setDisable(false);
        btnrec.setDisable(false);
    });

    gfip.setOnFailed((WorkerStateEvent ev) -> {
        Alert alert = new Alert(AlertType.WARNING);
        alert.setTitle("Cue");
        alert.setHeaderText("Impossible de rcuperer un tat");
        alert.setContentText("La rcupration du statut de l'Id " + id + " n'a pas fonctionn.");
        alert.showAndWait();

        mediaid.setDisable(false);
        showname.setDisable(false);
    });

    gfip.start();

}

From source file:dpfmanager.shell.interfaces.gui.fragment.wizard.Wizard1Fragment.java

public void addIsoFile(File file, boolean ask) {
    if (file == null) {
        return;//w  ww .  j  av a 2 s .c  o m
    }

    // Check valid config
    ImplementationCheckerObjectType rules = ImplementationCheckerLoader.getRules(file.getPath());
    if (rules == null) {
        context.send(BasicConfig.MODULE_MESSAGE, new AlertMessage(AlertMessage.Type.ERROR,
                DPFManagerProperties.getBundle().getString("w1errorReadingIso").replace("%1", file.getPath())));
        return;
    }

    if (ask) {
        DPFManagerProperties.setDefaultDirConfig(file.getParent());
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.setTitle(bundle.getString("w1copyTitle"));
        alert.setHeaderText(bundle.getString("w1copyHeader"));
        alert.setContentText(bundle.getString("w1copyContent"));
        ButtonType buttonTypeYes = new ButtonType(bundle.getString("yes"));
        ButtonType buttonTypeNo = new ButtonType(bundle.getString("no"));
        alert.getButtonTypes().setAll(buttonTypeYes, buttonTypeNo);

        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() == buttonTypeYes) {
            // Copy the file
            boolean needAdd = true, error = false;
            File configFile = new File(DPFManagerProperties.getIsosDir() + "/" + file.getName());
            if (configFile.exists()) {
                configFile.delete();
                needAdd = false;
            }
            try {
                FileUtils.copyFile(file, configFile);
            } catch (IOException e) {
                error = true;
            }
            if (error) {
                // Add source file
                addExternalCheckBox(file.getAbsolutePath(), true);
                context.send(BasicConfig.MODULE_MESSAGE,
                        new AlertMessage(AlertMessage.Type.WARNING, bundle.getString("w1errorCopyConfig")));
            } else if (needAdd) {
                addConfigCheckBox(configFile, true);
            }
        } else {
            addExternalCheckBox(file.getAbsolutePath(), true);
        }
    } else {
        addExternalCheckBox(file.getAbsolutePath(), true);
    }
}

From source file:net.rptools.tokentool.controller.ManageOverlays_Controller.java

private boolean confirmDelete(File dir) {
    String confirmationText = I18N.getString("ManageOverlays.dialog.delete.dir.confirmation");
    long dirSize = FileUtils.listFiles(dir, ImageUtil.SUPPORTED_FILE_FILTER, TrueFileFilter.INSTANCE).size();

    if (dirSize == 0) {
        confirmationText += dir.getName()
                + I18N.getString("ManageOverlays.dialog.delete.dir.confirmation.directory");
    } else {/*from  w  ww .  j a  va 2  s.co m*/
        confirmationText += dir.getName()
                + I18N.getString("ManageOverlays.dialog.delete.dir.directory_containing") + dirSize
                + I18N.getString("ManageOverlays.dialog.delete.dir.overlays");
    }

    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle(I18N.getString("ManageOverlays.dialog.delete.dir.title"));
    alert.setContentText(confirmationText);

    Optional<ButtonType> result = alert.showAndWait();

    if ((result.isPresent()) && (result.get() == ButtonType.OK)) {
        return true;
    }

    return false;
}

From source file:org.cirdles.ambapo.userInterface.AmbapoUIController.java

@FXML
private void convertFileClicked(MouseEvent event) {
    fileToConvert = new File(sourceFileText.getText());

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Specify a file to save");
    fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
    convertedFile = fileChooser.showSaveDialog(mainAnchorPane.getScene().getWindow());

    if (convertedFile != null) {
        try {//from  w w w . j  a v  a2s .  co m

            conversionFileHandler.setCurrentFileLocation(fileToConvert.getCanonicalPath());
            convertButton.setDisable(false);
        } catch (IOException ex) {
            Logger.getLogger(AmbapoUIController.class.getName()).log(Level.SEVERE, null, ex);
            if (!conversionFileHandler.currentFileLocationToConvertIsFile()) {
                Alert alert = new Alert(AlertType.ERROR);
                alert.setTitle("Error");
                alert.setHeaderText("Not a file.");

                alert.showAndWait();
            }
        }

        if (bulkConversionChooser.getValue().equals(bulkConversionChooser.getItems().get(0))) {
            try {
                conversionFileHandler.writeConversionsUTMToLatLong(convertedFile);
                openConvertedFileButton.setDisable(false);
            } catch (Exception ex) {
                Logger.getLogger(AmbapoUIController.class.getName()).log(Level.SEVERE, null, ex);
                Alert alert = new Alert(AlertType.ERROR);
                alert.setTitle("Error");
                alert.setHeaderText("Conversion could not be completed.");
                alert.setContentText("Check if csv file is formatted properly.");

                alert.showAndWait();
            }
        }

        else if (bulkConversionChooser.getValue().equals(bulkConversionChooser.getItems().get(1))) {
            try {
                conversionFileHandler.writeConversionsLatLongToUTM(convertedFile);
                openConvertedFileButton.setDisable(false);
            } catch (Exception ex) {
                Logger.getLogger(AmbapoUIController.class.getName()).log(Level.SEVERE, null, ex);
                Alert alert = new Alert(AlertType.ERROR);
                alert.setTitle("Error");
                alert.setHeaderText("Conversion could not be completed.");
                alert.setContentText("Check if csv file is formatted properly.");

                alert.showAndWait();
            }
        }

        else {
            try {
                conversionFileHandler.writeConversionsLatLongToLatLong(convertedFile);
                openConvertedFileButton.setDisable(false);
            } catch (Exception ex) {
                Logger.getLogger(AmbapoUIController.class.getName()).log(Level.SEVERE, null, ex);
                Alert alert = new Alert(AlertType.ERROR);
                alert.setTitle("Error");
                alert.setHeaderText("Conversion could not be completed.");
                alert.setContentText("Check if csv file is formatted properly.");

                alert.showAndWait();
            }

        }

    }
}