Ejemplo n.º 1
0
  public static void showTaskProgressDialog(
      Window ownerWindow, Task task, boolean showTaskMessage) {
    final Stage dialog = new Stage();
    task.setOnSucceeded(event -> dialog.close());
    task.setOnCancelled(event -> dialog.close());
    dialog.initStyle(StageStyle.UTILITY);
    dialog.initModality(Modality.APPLICATION_MODAL);
    dialog.initOwner(ownerWindow);
    dialog.titleProperty().bind(task.titleProperty());
    //        dialog.setTitle(ResourceManager.getMessage("title.dialog.processing"));
    dialog.setOnCloseRequest(
        event ->
            Logger.getLogger(Dialogs.class)
                .info(ResourceManager.getMessage("notification.task.terminatedByUser")));

    ProgressBar progressBar = new ProgressBar(0);
    progressBar.progressProperty().bind(task.progressProperty());
    progressBar.setMaxWidth(Double.MAX_VALUE);
    progressBar.getStyleClass().add("dark");

    Label label = new Label(ResourceManager.getMessage("label.pleaseWaitWhile"));
    Label taskMessage = new Label();
    taskMessage.textProperty().bind(task.messageProperty());

    Button cancelButton = new Button(ResourceManager.getMessage("label.button.cancel"));
    cancelButton.setOnAction(
        event -> {
          task.cancel();
          Logger.getLogger(Dialogs.class)
              .info(ResourceManager.getMessage("notification.task.terminatedByUser"));
        });

    ButtonBar buttonBar = new ButtonBar();
    buttonBar.getButtons().add(cancelButton);

    VBox dialogVBox = new VBox();
    dialogVBox.setFillWidth(true);
    dialogVBox.setSpacing(5);
    dialogVBox.setPadding(new Insets(5));
    dialogVBox.setPrefSize(300, VBox.USE_COMPUTED_SIZE);
    dialogVBox.getChildren().add(label);
    if (showTaskMessage) {
      dialogVBox.getChildren().add(taskMessage);
    }
    dialogVBox.getChildren().add(progressBar);
    dialogVBox.getChildren().add(buttonBar);

    Scene dialogScene = new Scene(dialogVBox);
    dialogScene.getStylesheets().add(ResourceManager.getUIThemeStyle());
    dialog.setScene(dialogScene);
    dialog.setResizable(false);
    dialog.show();
  }
Ejemplo n.º 2
0
 public static void showErrorDialog(String header, String content) {
   Alert alert = new Alert(Alert.AlertType.ERROR);
   alert.setTitle(ResourceManager.getMessage("title.dialog.error"));
   alert.setHeaderText(header);
   alert.setContentText(content);
   alert.showAndWait();
 }
Ejemplo n.º 3
0
  public static Range showRangeDialog(String title, String header) {
    final Range[] retVal = {null};

    Dialog<Range> dialog = new Dialog<>();
    dialog.setTitle(title);
    dialog.setHeaderText(header);

    IntegerProperty fromFieldProperty = new SimpleIntegerProperty(),
        toFieldProperty = new SimpleIntegerProperty();

    //        dialog.setGraphic(new ImageView(this.getClass().getResource("login.png").toString()));

    // Set the button types.
    ButtonType generateButtonType =
        new ButtonType(ResourceManager.getMessage("label.button.ok"), ButtonBar.ButtonData.OK_DONE);
    dialog.getDialogPane().getButtonTypes().addAll(generateButtonType, ButtonType.CANCEL);

    // Create the username and password labels and fields.
    GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(20, 150, 10, 10));

    TextField fromTextField = new TextField();
    fromTextField.textProperty().bindBidirectional(fromFieldProperty, new NumberStringConverter());

    TextField toTextField = new TextField();
    toTextField.textProperty().bindBidirectional(toFieldProperty, new NumberStringConverter());

    grid.add(new Label("From:"), 0, 0);
    grid.add(fromTextField, 1, 0);
    grid.add(new Label("To:"), 0, 1);
    grid.add(toTextField, 1, 1);

    // Enable/Disable login button depending on whether a username was entered.
    Node loginButton = dialog.getDialogPane().lookupButton(generateButtonType);
    loginButton.setDisable(true);

    // Do some validation (using the Java 8 lambda syntax).
    fromTextField
        .textProperty()
        .addListener(
            (observable, oldValue, newValue) -> {
              loginButton.setDisable(
                  newValue.trim().isEmpty()
                      || toTextField.getText().trim().isEmpty()
                      || Integer.valueOf(newValue.trim())
                              .compareTo(Integer.valueOf(toTextField.getText().trim()))
                          > 0);
            });

    toTextField
        .textProperty()
        .addListener(
            (observable, oldValue, newValue) -> {
              loginButton.setDisable(
                  fromTextField.getText().trim().isEmpty()
                      || newValue.trim().isEmpty()
                      || Integer.valueOf(fromTextField.getText().trim())
                              .compareTo(Integer.valueOf(newValue.trim()))
                          > 0);
            });

    dialog.getDialogPane().setContent(grid);

    // Request focus on the username field by default.
    Platform.runLater(() -> fromTextField.requestFocus());

    // Convert the result to a username-password-pair when the login button is clicked.
    dialog.setResultConverter(
        dialogButton -> {
          if (dialogButton == generateButtonType) {
            return new IntegerRange(fromFieldProperty.get(), toFieldProperty.get());
          }
          return null;
        });

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

    result.ifPresent(range -> retVal[0] = range);

    return retVal[0];
  }
Ejemplo n.º 4
0
 public static IDMVersion showIDMVersionPopup() {
   String title = ResourceManager.getMessage("title.dialog.idmVersion");
   String header = ResourceManager.getMessage("label.pleaseChooseIdmVersion");
   String content = ResourceManager.getMessage("label.idmVersion");
   return showChoicePopup(title, header, content, Arrays.asList(IDMVersion.values()));
 }