Пример #1
0
  public void notify(String msg, int type, Action... actions) {
    Pos pos = Pos.CENTER;
    if (cfg.topProperty().get()) {
      pos = Pos.TOP_LEFT;
    } else if (cfg.bottomProperty().get()) {
      pos = Pos.BOTTOM_LEFT;
    } else if (cfg.leftProperty().get()) {
      pos = Pos.TOP_RIGHT;
    } else if (cfg.rightProperty().get()) {
      pos = Pos.TOP_LEFT;
    }

    Notifications notificationBuilder =
        Notifications.create()
            .text(msg)
            .hideAfter(Duration.seconds(10))
            .position(pos)
            .onAction(
                new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent arg0) {}
                });

    notificationBuilder.hideCloseButton();
    notificationBuilder.action(actions);

    Configuration cfg = Configuration.getDefault();
    Color backgroundColour = cfg.colorProperty().getValue();
    if (backgroundColour.getBrightness() < 0.5) {
      notificationBuilder.darkStyle();
    }

    // if (darkStyleChkBox.isSelected()) {
    // notificationBuilder.darkStyle();
    // }

    switch (type) {
      case GUICallback.NOTIFY_WARNING:
        notificationBuilder.showWarning();
        break;
      case GUICallback.NOTIFY_INFO:
        notificationBuilder.showInformation();
        break;
      case GUICallback.NOTIFY_CONNECT:
      case GUICallback.NOTIFY_DISCONNECT:
        notificationBuilder.showConfirm();
        break;
      case GUICallback.NOTIFY_ERROR:
        notificationBuilder.showError();
        break;
      default:
        notificationBuilder.show();
    }
  }
 public boolean isValid() {
   boolean valid = true;
   if (nameTF.getText().isEmpty() || nameTF.getText() == null) {
     valid = false;
     Notifications.create()
         .text("Invalid Product Name")
         .text("Product name cannot be left empty.")
         .hideAfter(Duration.seconds(5))
         .showError();
   }
   if (codeTF.getText().isEmpty() || codeTF.getText() == null) {
     valid = false;
     Notifications.create()
         .text("Invalid Product Code")
         .text("Product code cannot be left empty.")
         .hideAfter(Duration.seconds(5))
         .showError();
   }
   if (typeTF.getSelectionModel().getSelectedItem() == null) {
     valid = false;
     Notifications.create()
         .text("Invalid Product Type Selection")
         .text("Type selection cannot be left empty and must be selected")
         .hideAfter(Duration.seconds(5))
         .showError();
   }
   if (prodFreq.getCheckModel().isEmpty()) {
     valid = false;
     Notifications.create()
         .text("Invalid Frequency")
         .text("Product Frequency selection cannot be left empty and must be selected")
         .hideAfter(Duration.seconds(5))
         .showError();
   }
   if (productExistsInCategory(
       nameTF.getText(), billCategoryTF.getSelectionModel().getSelectedItem())) {
     valid = false;
     Notifications.create()
         .text("Duplicate Product in Bill Category")
         .text("Product Name already exists in this bill category.")
         .hideAfter(Duration.seconds(5))
         .showError();
   }
   return valid;
 }
  public Product returnUpdatedProduct() {
    if (isValid()) {
      try {
        productRow.setName(nameTF.getText());
        productRow.setType(typeTF.getSelectionModel().getSelectedItem());
        productRow.setSupportingFreq(supportedFreq(prodFreq.getCheckModel().getCheckedItems()));
        productRow.setPrice(
            Double.parseDouble(priceTF.getText().isEmpty() ? "0.0" : priceTF.getText()));
        productRow.setMonday(
            Double.parseDouble(mondayTF.getText().isEmpty() ? "0.0" : mondayTF.getText()));
        productRow.setTuesday(
            Double.parseDouble(tuesdayTF.getText().isEmpty() ? "0.0" : tuesdayTF.getText()));
        productRow.setWednesday(
            Double.parseDouble(wednesdayTF.getText().isEmpty() ? "0.0" : wednesdayTF.getText()));
        productRow.setThursday(
            Double.parseDouble(thursdayTF.getText().isEmpty() ? "0.0" : thursdayTF.getText()));
        productRow.setFriday(
            Double.parseDouble(fridayTF.getText().isEmpty() ? "0.0" : fridayTF.getText()));
        productRow.setSaturday(
            Double.parseDouble(saturdayTF.getText().isEmpty() ? "0.0" : saturdayTF.getText()));
        productRow.setSunday(
            Double.parseDouble(sundayTF.getText().isEmpty() ? "0.0" : sundayTF.getText()));
        productRow.setCode(codeTF.getText());
        productRow.setDow(dowTF.getSelectionModel().getSelectedItem());
        productRow.setFirstDeliveryDate(firstDeliveryDate.getValue());
        productRow.setIssueDate(issueDate.getValue());
        productRow.setBillCategory(billCategoryTF.getSelectionModel().getSelectedItem());
        productRow.updateProductRecord();
      } catch (NumberFormatException e) {
        Notifications.create()
            .title("Invalid value")
            .text("Please enter numbers for Price and Monday - Sunday fields")
            .hideAfter(Duration.seconds(5))
            .showError();
        Main._logger.debug("Error :", e);
        e.printStackTrace();
      } catch (Exception e) {

        Main._logger.debug("Error :", e);
        e.printStackTrace();
      }
    }
    return productRow;
  }
  @FXML
  private void changePasswordClicked(ActionEvent evt) {
    TextInputDialog changePwdDialog = new TextInputDialog();
    changePwdDialog.setTitle("Change password");
    changePwdDialog.setHeaderText(
        "Please enter the new password. \nPassword must be atleast 5 characters long.");
    // changePwdDialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK,
    // ButtonType.CANCEL);
    final Button btOk = (Button) changePwdDialog.getDialogPane().lookupButton(ButtonType.OK);
    btOk.addEventFilter(
        ActionEvent.ACTION,
        event -> {
          if (changePwdDialog.getEditor().getText().isEmpty()
              || changePwdDialog.getEditor().getText().length() < 5) {
            Notifications.create()
                .title("Empty password")
                .text(
                    "Password cannot be left empty and must be more than 5 characters. Try again.")
                .hideAfter(Duration.seconds(5))
                .showError();
            event.consume();
          }
        });
    Optional<String> result = changePwdDialog.showAndWait();
    if (result.isPresent()) {
      try {

        Connection con = Main.dbConnection;
        if (!con.isValid(0)) {
          con = Main.reconnect();
        }
        String deleteString = "update admin_login set password =? where username='******'";
        PreparedStatement deleteStmt = con.prepareStatement(deleteString);
        deleteStmt.setString(1, changePwdDialog.getEditor().getText());

        deleteStmt.executeUpdate();
        con.commit();

        Notifications.create()
            .title("Password updated")
            .text("Password was successfully updated. Please login again!")
            .hideAfter(Duration.seconds(5))
            .showInformation();
        logoutClicked(new ActionEvent());
      } catch (SQLException e) {

        Main._logger.debug("Error :", e);
        e.printStackTrace();
        Notifications.create()
            .hideAfter(Duration.seconds(5))
            .title("Delete failed")
            .text("Delete request of hawker bill has failed")
            .showError();
      } catch (IOException e) {

        Main._logger.debug("Error :", e);
        e.printStackTrace();
      } catch (Exception e) {

        Main._logger.debug("Error :", e);
        e.printStackTrace();
      }
    }
  }
Пример #5
0
 public static void notify(String title, String text) {
   Notifications.create().title(title).text(text).show();
 }
Пример #6
0
 public static void notify(String title, String text, Node image) {
   Notifications.create().graphic(image).title(title).text(text).show();
 }