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:account.management.controller.inventory.StockReportController.java

@FXML
private void onShowClick(ActionEvent event) {
    this.show.setDisable(true);
    String start_date = "1980-01-01", end_date = "2050-12-31";
    try {/*from   ww w.  j a  va2s  . c  o m*/
        start_date = new SimpleDateFormat("yyyy-MM-dd")
                .format(new SimpleDateFormat("yyyy-MM-dd").parse(this.start.getValue().toString()));
        end_date = new SimpleDateFormat("yyyy-MM-dd")
                .format(new SimpleDateFormat("yyyy-MM-dd").parse(this.end.getValue().toString()));

        HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "report/stock")
                .queryString("start", start_date).queryString("end", end_date).asJson();
        JSONArray array = res.getBody().getArray();
        Vector v = new Vector();
        HashMap params = new HashMap();
        params.put("date",
                "From " + new SimpleDateFormat("dd-MM-yyyy")
                        .format(new SimpleDateFormat("yyyy-MM-dd").parse(start_date)) + " To "
                        + new SimpleDateFormat("dd-MM-yyyy")
                                .format(new SimpleDateFormat("yyyy-MM-dd").parse(end_date)));
        for (int i = 0; i < array.length(); i++) {
            JSONObject obj = array.getJSONObject(i);
            String id = String.valueOf(obj.getInt("item_id"));
            String name = getProductName(Integer.parseInt(id));
            String opening_qty = obj.get("opening_qty").toString();
            String opening_price = obj.get("opening_price").toString() == "null" ? "0.0"
                    : obj.get("opening_price").toString();
            String p_qty = obj.get("p_qty").toString() == "null" ? "0.0" : obj.get("p_qty").toString();
            String p_price = obj.get("p_price").toString() == "null" ? "0.0" : obj.get("p_price").toString();
            String s_qty = obj.get("s_qty").toString() == "null" ? "0.0" : obj.get("s_qty").toString();
            String s_price = obj.get("s_price").toString() == "null" ? "0.0" : obj.get("s_price").toString();

            String closing_qty = String
                    .valueOf(Float.parseFloat(opening_qty) + Float.parseFloat(p_qty) - Float.parseFloat(s_qty));

            String closing_total = String.valueOf(
                    Float.parseFloat(opening_price) + Float.parseFloat(p_price) - Float.parseFloat(s_price));
            String closing_rate = String
                    .valueOf(Float.parseFloat(closing_total) / Float.parseFloat(closing_qty));
            v.add(new Stock(0, id, name, opening_qty,
                    String.valueOf(Float.parseFloat(opening_price) / Float.parseFloat(opening_qty)),
                    opening_price, closing_qty, closing_rate, closing_total));

        }

        Report report = new Report();
        report.getReport("src\\report\\StockReport.jrxml", new JRBeanCollectionDataSource(v), params,
                "Stock Report");
        this.show.setDisable(false);
    } catch (Exception ex) {
        Logger.getLogger(StockReportController.class.getName()).log(Level.SEVERE, null, ex);
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setHeaderText(null);
        alert.setContentText("Sorry!! there is an error. Please try again.");
        alert.setGraphic(new ImageView(new Image("resources/error.jpg")));
        alert.showAndWait();
    }
}

From source file:utilitybasedfx.MainGUIController.java

@FXML
public void eventFileOpen(ActionEvent event) {
    boolean success = false;
    boolean projectsFound = false;

    File files[] = new File(Prefs.getSavePath()).listFiles();

    if (files != null) {
        ArrayList<String> choices = new ArrayList<String>();

        for (File f : files) {
            if (f != null && f.isDirectory()) {
                choices.add(f.getName());
            }/*from w w w. ja v  a2  s. co m*/
        }

        if (!choices.isEmpty()) {
            ChoiceDialog<String> dialog = new ChoiceDialog<String>(choices.get(0), choices);
            dialog.setTitle("Open Project");
            dialog.setHeaderText("Please choose a project you would like to load");
            dialog.setContentText("Project:");

            Optional<String> result = dialog.showAndWait();

            if (result.isPresent()) {
                success = true;
                setActiveProject(result.get());
            }

            projectsFound = true;
        }
    }

    if (!success) {
        shouldRefreshFileTree = true;
    }

    if (!projectsFound) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("No projects found");
        alert.setHeaderText("There are no projects found in the following folder");
        alert.setContentText(new File(Prefs.getSavePath()).getAbsolutePath());

        alert.showAndWait();
    }
}

From source file:de.micromata.mgc.application.webserver.config.JettyConfigTabController.java

private void createSslValidate(ValContext ctx) {
    File storePath = new File(".");
    if (StringUtils.isNotBlank(sslKeystorePath.getText()) == true) {
        String sp = sslKeystorePath.getText();
        if (sp.contains("/") == false && sp.contains("\\") == false) {
            if (StringUtils.isBlank(sp) == true) {
                storePath = new File(".");
            } else {
                storePath = new File(new File("."), sp);
            }/*  w  w w.j a  va2  s.  c om*/
        } else {
            storePath = new File(sslKeystorePath.getText());
        }
    }
    if (storePath.getParentFile() == null || storePath.getParentFile().exists() == false) {
        ctx.directError("sslKeystorePath", "The parent path doesn't exists: "
                + (storePath.getParentFile() == null ? "null" : storePath.getParentFile().getAbsolutePath()));
        return;
    }
    if (storePath.exists() && storePath.isDirectory() == true) {
        ctx.directError("sslKeystorePath", "Please give an path to file: " + storePath.getAbsolutePath());
        return;
    }
    if (storePath.exists() == true) {
        Alert alert = new Alert(AlertType.CONFIRMATION);
        alert.setTitle("Overwrite keystore");
        //      alert.setHeaderText("Overwrite the existant keystore file?");
        alert.setContentText("Overwrite the existant keystore file?");
        Optional<ButtonType> result = alert.showAndWait();
        if (result.get() != ButtonType.OK) {
            return;
        }
    }
    if (StringUtils.length(sslKeystorePassword.getText()) < 6) {
        ctx.directError("sslKeystorePassword",
                "Please give a password for Keystore password with at least 6 characters");
        return;
    }
    if (StringUtils.isBlank(sslCertAlias.getText()) == true) {
        ctx.directError("sslCertAlias", "Please give a Alias for the key");
        return;
    }
    KeyTool.generateKey(ctx, storePath, sslKeystorePassword.getText(), sslCertAlias.getText());
    Alert alert = new Alert(AlertType.WARNING);
    alert.setTitle("Certificate created");
    alert.setHeaderText(
            "Certificate created. You are using a self signed certificate, which should not be used in production.");
    alert.setContentText(
            "If you open the browser, will will receive a warning, that the certificate is not secure.\n"
                    + "You have to accept the certificate to continue.");
    Optional<ButtonType> result = alert.showAndWait();
}

From source file:main.TestManager.java

/**
 * Deletes all local tests, downloads tests from the server
 * and saves all downloaded test in the local directory.
 *///from  ww  w.j  a  va  2  s.  com
public static void syncTestsWithServer() {
    FTPClient ftp = new FTPClient();
    boolean error = false;
    try {
        int reply;
        String server = "zajicek.endora.cz";
        ftp.connect(server, 21);

        // After connection attempt, we check the reply code to verify
        // success.
        reply = ftp.getReplyCode();

        //Not connected successfully - inform the user
        if (!FTPReply.isPositiveCompletion(reply)) {
            ftp.disconnect();
            Debugger.println("FTP server refused connection.");
            ErrorInformer.failedSyncing();
            return;
        }
        // LOGIN
        boolean success = ftp.login("plakato", "L13nK4");
        Debugger.println("Login successful: " + success);
        if (success == false) {
            ftp.disconnect();
            ErrorInformer.failedSyncing();
            return;
        }
        ftp.enterLocalPassiveMode();
        // Get all files from the server
        FTPFile[] files = ftp.listFiles();
        System.out.println("Got files! Count: " + files.length);
        // Delete all current test to be replaced with 
        // actulized version
        File[] locals = new File("src/tests/").listFiles();
        for (File f : locals) {
            if (f.getName() == "." || f.getName() == "..") {
                continue;
            }
            f.delete();
        }
        // Copy the files from server to local folder
        int failed = 0;
        for (FTPFile f : files) {
            if (f.isFile()) {
                Debugger.println(f.getName());
                if (f.getName() == "." || f.getName() == "..") {
                    continue;
                }
                File file = new File("src/tests/" + f.getName());
                file.createNewFile();
                OutputStream output = new FileOutputStream(file);
                if (!ftp.retrieveFile(f.getName(), output))
                    failed++;
                output.close();
            }
        }
        // If we failed to download some file, inform the user
        if (failed != 0) {
            ftp.disconnect();
            ErrorInformer.failedSyncing();
            return;
        }
        // Disconnect ftp client or resolve the potential error
        ftp.logout();
    } catch (IOException e) {
        error = true;
        e.printStackTrace();
    } finally {
        if (ftp.isConnected()) {
            try {
                ftp.disconnect();
            } catch (IOException ioe) {
                // do nothing
            }
        }
    }
    if (error) {
        ErrorInformer.failedSyncing();

    }
    Alert alert = new Alert(AlertType.INFORMATION);
    alert.setTitle("Download hotov");
    alert.setHeaderText(null);
    alert.setContentText("Vetky testy boli zo servru spene stiahnut.");

    alert.showAndWait();
    alert.close();
}

From source file:com.gitlab.anlar.lunatic.gui.MainWindowController.java

private void startServer() {
    StartResult result = EmailServer.start(Integer.parseInt(portField.getText()));

    if (result.isSuccessful()) {
        portField.setDisable(true);/*  w w w .  jav a2 s.  c o m*/
        setStartButtonText(true);
    } else {
        Alert alert = new Alert(Alert.AlertType.WARNING);
        alert.setTitle(Messages.get("gui.error.start.title"));
        alert.setHeaderText(Messages.get("gui.error.start.header"));
        alert.setContentText(String.format("%s\n" + Messages.get("gui.error.start.body"), result.getMessage()));

        // expand default width to make sure that second content line fill fit there
        alert.setResizable(true);
        alert.getDialogPane().setPrefWidth(500);

        alert.showAndWait();
    }
}

From source file:staff.Waiter.MenuController.java

@FXML
private void onClickgetListButton(ActionEvent e) throws SQLException, IOException {
    getMenuButton.setDisable(true);//from w  w  w.  j  av  a 2s . co  m
    String itemInfo = "";
    Statement st = conn.createStatement();
    ObservableList<Menu> totallist = menutable.getItems();
    ObservableList<Menu> orderlist = FXCollections.observableArrayList();
    float tprice = 0;
    int ttime = 0;
    String itemDetails = "";//"ITEM NAME               PRICE       QUANTITY    TOTAL\n\n";
    for (Menu i : totallist) {
        if (Integer.parseInt(i.getMquantity()) > 0) {
            orderlist.add(i);
            System.out.println("Id:" + i.getMid() + " Item : " + i.getMname() + " Price " + i.getMprice()
                    + " Quantity: " + i.getMquantity());
            tprice += (i.getMprice() * Integer.parseInt(i.getMquantity()));

            String query = "select ttime from menu where d_id='" + i.getMid() + "'";
            ResultSet rs = st.executeQuery(query);
            rs.next();
            ttime += (rs.getInt("ttime") * Integer.parseInt(i.getMquantity()));
            System.out.println("Total time:" + ttime);

            //itemDetails+=""+i.getMname()+"               Rs."+i.getMprice()+"           "+i.getMquantity()+"          "+(i.getMprice() * Integer.parseInt(i.getMquantity()))+"\n\n";
            itemDetails += "Item    :" + i.getMname() + "       Price    :" + i.getMprice() + "      Qty    :"
                    + i.getMquantity() + "        Total    :"
                    + (i.getMprice() * Integer.parseInt(i.getMquantity())) + "\n\n";
            s[idx++] = i.getMname() + "" + i.getMquantity();
            itemInfo += i.getMname() + "" + i.getMquantity() + "-";

        }
    }

    itemDetails += "TOTAL COST : " + tprice + "\n\n";

    int couponGiven = 0;
    //Checking the validity of coupon if it exists
    if (!couponTextField.getText().equals("")) {

        int coupon = Integer.parseInt(couponTextField.getText());
        couponGiven = coupon;
        String q = "select * from coupon where coupon_id='" + coupon + "' ";
        ResultSet rs1 = st.executeQuery(q);
        if (rs1.next()) {
            Alert a = new Alert(Alert.AlertType.CONFIRMATION);
            a.setTitle("Confirmation");
            a.setHeaderText(null);
            a.setContentText("Great!!Customer has a valid coupon");
            a.showAndWait();

            float discount = rs1.getFloat("discount_percent");
            tprice -= (tprice * discount) / 100;

            itemDetails += "You have been given a discount of " + discount + "%\n\nFinal Cost     :   Rs."
                    + tprice + "\n\n";
        } else {
            Alert a = new Alert(Alert.AlertType.ERROR);
            a.setTitle("Error");
            a.setHeaderText(null);
            a.setContentText("The coupon is not a valid one!!!!");
            a.showAndWait();
        }

    }

    System.out.println("total price:" + tprice);
    totalPrice.setText("Total bill" + tprice);
    //Making an entry in `order` table
    //serialization
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    new ObjectOutputStream(out).writeObject(s);

    String list = new String(Hex.encodeHex(out.toByteArray()));
    System.out.println("IN BYTE FORM:" + list);

    //for unique order_id
    int counter = 0;
    //fetching the c_id of the last customer
    String query = "select * from order_info";
    ResultSet rs = st.executeQuery(query);
    System.out.println("Counter:" + counter);
    while (rs.next()) {
        counter = rs.getInt("order_id");

    }

    counter++;
    System.out.println("Counter:" + counter);
    String status = "pending";
    //PLACING ORDER
    String q = "insert into order_info (list,table_id,time,status,cost,waiter_id,bill_paid,c_id,coupon_id) values('"
            + itemInfo + "'," + tableId + "," + ttime + ",'" + status + "'," + tprice + ",'" + wid + "',0,"
            + c_id + "," + couponGiven + ")";
    System.out.println("here:" + q);
    st.executeUpdate(q);
    //UPDATING TABLE_INFO
    q = "update table_info set order_taken=1 where t_id=" + tableId + " ";
    st.executeUpdate(q);
    //UPDATING `book_and_order
    q = "insert into book_and_order values(" + tableId + "," + counter + "," + c_id + ")";
    st.executeUpdate(q);
}

From source file:account.management.controller.inventory.ProductWiseInventoryReportController.java

@FXML
private void onShowReportClick(ActionEvent event) {
    this.show.setDisable(true);
    try {/*  w  w  w.j  a v  a2 s  .  c  o  m*/

        String id = String.valueOf(this.item.getSelectionModel().getSelectedItem().getId());
        String start_date = "1980-01-01", end_date = "2050-12-31";

        start_date = new SimpleDateFormat("yyyy-MM-dd")
                .format(new SimpleDateFormat("yyyy-MM-dd").parse(this.start.getValue().toString()));
        end_date = new SimpleDateFormat("yyyy-MM-dd")
                .format(new SimpleDateFormat("yyyy-MM-dd").parse(this.end.getValue().toString()));

        HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "report/product/sellPurchase")
                .queryString("id", id).queryString("start", start_date).queryString("end", end_date).asJson();
        JSONArray array = res.getBody().getArray();
        Vector v = new Vector();
        HashMap params = new HashMap();
        params.put("date",
                "From " + new SimpleDateFormat("dd-MM-yyyy")
                        .format(new SimpleDateFormat("yyyy-MM-dd").parse(start_date)) + " To "
                        + new SimpleDateFormat("dd-MM-yyyy")
                                .format(new SimpleDateFormat("yyyy-MM-dd").parse(end_date)));
        params.put("item_name",
                "Inventory report of " + this.item.getSelectionModel().getSelectedItem().getName());
        float total_p_qty = 0, total_s_qty = 0;
        double total_p_param = 0;
        for (int i = 0; i < array.length(); i++) {
            JSONObject obj = array.getJSONObject(i);
            String date = obj.getString("date");
            date = new SimpleDateFormat("dd-MM-yyyy").format(new SimpleDateFormat("yyyy-MM-dd").parse(date));
            String p_qty = obj.get("p_qty").toString() == "null" ? "-" : obj.get("p_qty").toString();
            String p_rate = obj.get("p_rate").toString() == "null" ? "-" : obj.get("p_rate").toString();
            String p_price = obj.get("p_total").toString() == "null" ? "-" : obj.get("p_total").toString();
            String s_qty = obj.get("s_qty").toString() == "null" ? "-" : obj.get("s_qty").toString();
            String s_rate = obj.get("s_rate").toString() == "null" ? "-" : obj.get("s_rate").toString();
            String s_price = obj.get("s_total").toString() == "null" ? "-" : obj.get("s_total").toString();
            System.out.println(s_price);
            v.add(new IndividualProductReport(date, p_qty, p_rate, p_price, s_qty, s_rate, s_price));

            if (!p_qty.equals("-")) {
                total_p_qty += Float.parseFloat(p_qty);
            }
            if (!s_qty.equals("-")) {
                total_s_qty += Float.parseFloat(s_qty);
            }
            if (!p_price.equals("-")) {
                total_p_param += Float.parseFloat(p_price);
            }

        }
        params.put("closing_qty", String.valueOf(total_p_qty - total_s_qty));
        System.out.println(total_p_qty);
        params.put("closing_rate", String.valueOf(total_p_param / total_p_qty));
        params.put("closing_total",
                String.valueOf((total_p_qty - total_s_qty) * (total_p_param / total_p_qty)));
        Report report = new Report();
        report.getReport("src\\report\\IndiviualProductPurchaseSellReport.jrxml",
                new JRBeanCollectionDataSource(v), params, "Product Wise Inventory Report");
        this.show.setDisable(false);
    } catch (Exception e) {
        System.out.println("Exception in show report button click");
        Alert alert = new Alert(Alert.AlertType.ERROR);
        alert.setHeaderText(null);
        alert.setContentText("Sorry!! there is an error. Please try again.");
        alert.setGraphic(new ImageView(new Image("resources/error.jpg")));
        alert.showAndWait();
    }
}

From source file:sendsms.FXMLDocumentController.java

private void parseResponse(String response) {
    if (response == null) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setHeaderText("Por favor verifique su conexin a Internet");
        alert.showAndWait();//from  w w  w .  j  av a  2 s .  c  o  m
    } else {
        try {
            JSONParser jsonParser = new JSONParser();
            JSONObject jsonObject = (JSONObject) jsonParser.parse(response);
            Long status = (Long) jsonObject.get("status");
            if (status == 200) {
                Alert alert = new Alert(AlertType.CONFIRMATION);
                alert.setHeaderText("Mensaje enviado");
                alert.showAndWait();
                listSMS.setValue("MENSAJE");
                textMessage.setText("");
                textOrden.setText("");
                textNumero.setText("");
            } else {
                Alert alert = new Alert(AlertType.WARNING);
                alert.setTitle("Error: " + status);
                alert.setHeaderText("Cdigo: " + jsonObject.get("code"));
                alert.setContentText((String) jsonObject.get("message"));
                alert.showAndWait();
            }
        } catch (ParseException ex) {
            Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:utilitybasedfx.MainGUIController.java

@FXML
public void eventImportSource(ActionEvent event) {
    File selectedDir = Utils.dirChooser("Please choose the project source root folder");
    File sourceDir = new File(Prefs.getSourcePath());

    boolean shouldContinue = true;

    if (selectedDir != null) {
        if (sourceDir.isDirectory()) {
            Alert alert = new Alert(AlertType.CONFIRMATION);
            alert.setTitle("This project already exists!");
            alert.setHeaderText("This project already has a src folder meaning it already has files imported");
            alert.setContentText(//from   w ww . ja  v  a 2 s.  c om
                    "Are you sure you want to import the new source?\nPressing OK will delete the files previous imported to this project and replace them with the new files.");

            Optional<ButtonType> result = alert.showAndWait();
            if (result.get() == ButtonType.OK) {
                sourceDir.delete();
            } else {
                shouldContinue = false;
            }
        }

        if (shouldContinue) {
            shouldRefreshFileTree = true;
            enableWorking(new Task<String>() {
                @Override
                protected String call() throws InterruptedException {
                    updateMessage("Copying Files...");
                    try {
                        FileUtils.copyDirectory(selectedDir, sourceDir);
                    } catch (IOException e) {
                        Utils.stackErrorDialog(e);
                    }
                    updateMessage("");

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

From source file:com.git.ifly6.IRPController.java

@FXML
void changeEndoCap(ActionEvent event) {

    if (endoCapEnabled.isSelected()) {

        String input = "";

        TextInputDialog dialog = new TextInputDialog("Endorsement cap");
        dialog.setTitle("IRP Settings");
        dialog.setHeaderText("Change endorsement cap");
        dialog.setContentText("Enter an integer here:");

        Optional<String> result = dialog.showAndWait();
        if (result.isPresent()) {
            input = result.get();//from  w  w  w . j  a v  a 2  s  . c  o  m
        }

        try {
            int capSet = Integer.parseInt(input);
            endorsementCap = capSet;
            // Write this fact to file.
        } catch (NumberFormatException e) {
            out.log("ERROR. Please provide an integer to the endorsement cap.");
        }

    } else {
        Alert alert = new Alert(AlertType.INFORMATION);
        alert.setTitle("IRP Settings");
        alert.setHeaderText("Endorsement Cap");
        alert.setContentText(
                "You cannot change the endorsement cap if the endorsement cap system is disabled.");
        alert.showAndWait();
    }

    // Show an alert to change the endorsement cap.
    // Save that change to file.
}