Java Code Examples for javafx.scene.control.ButtonType#CANCEL
The following examples show how to use
javafx.scene.control.ButtonType#CANCEL .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DisplayWindow.java From marathonv5 with Apache License 2.0 | 7 votes |
private boolean closeEditor(IEditor e) { if (e == null) { return true; } if (e.isDirty()) { Optional<ButtonType> result = FXUIUtils.showConfirmDialog(DisplayWindow.this, "File \"" + e.getName() + "\" Modified. Do you want to save the changes ", "File \"" + e.getName() + "\" Modified", AlertType.CONFIRMATION, ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); ButtonType shouldSaveFile = result.get(); if (shouldSaveFile == ButtonType.CANCEL) { return false; } if (shouldSaveFile == ButtonType.YES) { File file = save(e); if (file == null) { return false; } EditorDockable dockable = (EditorDockable) e.getData("dockable"); dockable.updateKey(); } } return true; }
Example 2
Source File: Group.java From marathonv5 with Apache License 2.0 | 6 votes |
public static Group createGroup(GroupType type, Path path, String name) { List<Group> groups = getGroups(type); for (Group g : groups) { if (g.getName().equals(name)) { Optional<ButtonType> option = FXUIUtils.showConfirmDialog(null, type.fileType() + " `" + g.getName() + "` name is already used.", "Duplicate " + type.fileType() + " Name", AlertType.CONFIRMATION); if (!option.isPresent() || option.get() == ButtonType.CANCEL) { return null; } } } Group group = new Group(name); try { Files.write(path, (type.fileCommentHeader() + group.toJSONString()).getBytes()); return new Group(path.toFile()); } catch (IOException e) { return null; } }
Example 3
Source File: FileHandler.java From marathonv5 with Apache License 2.0 | 5 votes |
@Override public File saveAs(String script, Window parent, String filename) throws IOException { boolean saved = false; while (!saved) { File file = askForFile(parent, filename); if (file == null) { return null; } ButtonType option = ButtonType.YES; if (file.exists()) { if (nameValidateChecker != null && !nameValidateChecker.okToOverwrite(file)) { return null; } Optional<ButtonType> result = FXUIUtils.showConfirmDialog(parent, "File " + file.getName() + " already exists. Do you want to overwrite?", "File exists", AlertType.CONFIRMATION, ButtonType.YES, ButtonType.NO); option = result.get(); } if (option == ButtonType.YES) { setCurrentFile(file); saveToFile(currentFile, script); return file; } if (option == ButtonType.CANCEL) { return null; } } return null; }
Example 4
Source File: CRSChooser.java From sis with Apache License 2.0 | 5 votes |
/** * Show a modal dialog to select a {@link CoordinateReferenceSystem}. * * @param parent parent frame of widget. * @param crs {@link CoordinateReferenceSystem} to edit. * @return modified {@link CoordinateReferenceSystem}. */ public static CoordinateReferenceSystem showDialog(Object parent, CoordinateReferenceSystem crs) { final CRSChooser chooser = new CRSChooser(); chooser.crsProperty.set(crs); final Alert alert = new Alert(Alert.AlertType.NONE); final DialogPane pane = alert.getDialogPane(); pane.setContent(chooser); alert.getButtonTypes().setAll(ButtonType.OK,ButtonType.CANCEL); alert.setResizable(true); final ButtonType res = alert.showAndWait().orElse(ButtonType.CANCEL); return res == ButtonType.CANCEL ? null : chooser.crsProperty.get(); }
Example 5
Source File: AlertDialog.java From AsciidocFX with Apache License 2.0 | 5 votes |
public AlertDialog() { super(AlertType.WARNING, null, ButtonType.YES, ButtonType.CANCEL); super.setTitle("Warning"); super.initModality(Modality.WINDOW_MODAL); setDefaultIcon(super.getDialogPane()); showAlwaysOnTop(this); }
Example 6
Source File: CircuitSim.java From CircuitSim with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean checkUnsavedChanges() { clearSelection(); if(editHistory.editStackSize() != savedEditStackSize) { Alert alert = new Alert(AlertType.CONFIRMATION); alert.initOwner(stage); alert.initModality(Modality.WINDOW_MODAL); alert.setTitle("Unsaved changes"); alert.setHeaderText("Unsaved changes"); alert.setContentText("There are unsaved changes, do you want to save them?"); ButtonType discard = new ButtonType("Discard", ButtonData.NO); alert.getButtonTypes().add(discard); Optional<ButtonType> result = alert.showAndWait(); if(result.isPresent()) { if(result.get() == ButtonType.OK) { saveCircuitsInternal(); return saveFile == null; } else { return result.get() == ButtonType.CANCEL; } } } return false; }
Example 7
Source File: DockItemWithInput.java From phoebus with Eclipse Public License 1.0 | 5 votes |
/** Called when user tries to close the tab * * <p>Derived class may override. * * @return Should the tab close? Otherwise it stays open. */ protected boolean okToClose() { if (! isDirty()) return true; final String text = MessageFormat.format(Messages.DockAlertMsg, getLabel()); final Alert prompt = new Alert(AlertType.NONE, text, ButtonType.NO, ButtonType.CANCEL, ButtonType.YES); prompt.setTitle(Messages.DockAlertTitle); prompt.getDialogPane().setMinSize(300, 100); prompt.setResizable(true); DialogHelper.positionDialog(prompt, getTabPane(), -200, -100); final ButtonType result = prompt.showAndWait().orElse(ButtonType.CANCEL); // Cancel the close request if (result == ButtonType.CANCEL) return false; // Close without saving? if (result == ButtonType.NO) return true; // Save in background job ... JobManager.schedule(Messages.Save, monitor -> save(monitor)); // .. and leave the tab open, so user can then try to close again return false; }
Example 8
Source File: ResourceView.java From marathonv5 with Apache License 2.0 | 5 votes |
private void delete(ObservableList<TreeItem<Resource>> selectedItems) { Optional<ButtonType> option = Optional.empty(); ArrayList<TreeItem<Resource>> items = new ArrayList<>(selectedItems); for (TreeItem<Resource> treeItem : items) { option = treeItem.getValue().delete(option); if (option.isPresent() && option.get() == ButtonType.CANCEL) { break; } } }
Example 9
Source File: ConfirmationDialog.java From mcaselector with MIT License | 5 votes |
public ConfirmationDialog(Stage primaryStage, Translation title, Translation headerText, String cssPrefix) { super( AlertType.WARNING, "", ButtonType.OK, ButtonType.CANCEL ); initStyle(StageStyle.UTILITY); getDialogPane().getStyleClass().add(cssPrefix + "-confirmation-dialog-pane"); getDialogPane().getStylesheets().addAll(primaryStage.getScene().getStylesheets()); titleProperty().bind(title.getProperty()); headerTextProperty().bind(headerText.getProperty()); contentTextProperty().bind(Translation.DIALOG_CONFIRMATION_QUESTION.getProperty()); }
Example 10
Source File: Blurb.java From marathonv5 with Apache License 2.0 | 4 votes |
private void onCancel() { selection = ButtonType.CANCEL; dispose(); }
Example 11
Source File: Utils.java From blobsaver with GNU General Public License v3.0 | 4 votes |
static void newReportableError(String msg) { Alert alert = new Alert(Alert.AlertType.ERROR, msg + "\n\nPlease create a new issue on Github or PM me on Reddit.", githubIssue, redditPM, ButtonType.CANCEL); alert.showAndWait(); reportError(alert); }
Example 12
Source File: UpdateApplication.java From phoebus with Eclipse Public License 1.0 | 4 votes |
private void promptForUpdate(final Node node, final Instant new_version) { final File install_location = Locations.install(); // Want to update install_location, but that's locked on Windows, // and replacing the jars of a running application might be bad. // So download into a stage area. // The start script needs to be aware of this stage area // and move it to the install location on startup. final File stage_area = new File(install_location, "update"); final StringBuilder buf = new StringBuilder(); buf.append("You are running version ") .append(TimestampFormats.DATETIME_FORMAT.format(Update.current_version)) .append("\n") .append("The new version is dated ") .append(TimestampFormats.DATETIME_FORMAT.format(new_version)) .append("\n\n") .append("The update will replace the installation in\n") .append(install_location) .append("\n(").append(stage_area).append(")") .append("\nwith the content of ") .append(Update.update_url) .append("\n\n") .append("Do you want to update?\n"); final Alert prompt = new Alert(AlertType.INFORMATION, buf.toString(), ButtonType.OK, ButtonType.CANCEL); prompt.setTitle(NAME); prompt.setHeaderText("A new version of this software is available"); prompt.setResizable(true); DialogHelper.positionDialog(prompt, node, -600, -350); prompt.getDialogPane().setPrefSize(600, 300); if (prompt.showAndWait().orElse(ButtonType.CANCEL) == ButtonType.OK) { // Show job manager to display progress ApplicationService.findApplication(JobViewerApplication.NAME).create(); // Perform update JobManager.schedule(NAME, monitor -> { Update.downloadAndUpdate(monitor, stage_area); Update.adjustCurrentVersion(); if (! monitor.isCanceled()) Platform.runLater(() -> restart(node)); }); } else { // Remove the update button StatusBar.getInstance().removeItem(start_update); start_update = null; } }
Example 13
Source File: AlterTopicDialog.java From kafka-message-tool with MIT License | 4 votes |
private void closeThisDialogWithCancelStatus() { returnButtonType = ButtonType.CANCEL; stage.close(); }
Example 14
Source File: AddTopicDialog.java From kafka-message-tool with MIT License | 4 votes |
private void closeThisDialogWithCancelStatus() { returnButtonType = ButtonType.CANCEL; stage.close(); }
Example 15
Source File: AlertHelper.java From AsciidocFX with Apache License 2.0 | 4 votes |
static Alert buildDeleteAlertDialog(List<Path> pathsLabel) { Alert deleteAlert = new WindowModalAlert(Alert.AlertType.WARNING, null, ButtonType.YES, ButtonType.CANCEL); deleteAlert.setHeaderText("Do you want to delete selected path(s)?"); DialogPane dialogPane = deleteAlert.getDialogPane(); ObservableList<Path> paths = Optional.ofNullable(pathsLabel) .map(FXCollections::observableList) .orElse(FXCollections.emptyObservableList()); if (paths.isEmpty()) { dialogPane.setContentText("There are no files selected."); deleteAlert.getButtonTypes().clear(); deleteAlert.getButtonTypes().add(ButtonType.CANCEL); return deleteAlert; } ListView<Path> listView = new ListView<>(paths); listView.setId("listOfPaths"); GridPane gridPane = new GridPane(); gridPane.addRow(0, listView); GridPane.setHgrow(listView, Priority.ALWAYS); double minWidth = 200.0; double maxWidth = Screen.getScreens().stream() .mapToDouble(s -> s.getBounds().getWidth() / 3) .min().orElse(minWidth); double prefWidth = paths.stream() .map(String::valueOf) .mapToDouble(s -> s.length() * 7) .max() .orElse(maxWidth); double minHeight = IntStream.of(paths.size()) .map(e -> e * 70) .filter(e -> e <= 300 && e >= 70) .findFirst() .orElse(200); gridPane.setMinWidth(minWidth); gridPane.setPrefWidth(prefWidth); gridPane.setPrefHeight(minHeight); dialogPane.setContent(gridPane); return deleteAlert; }
Example 16
Source File: AlertHelper.java From AsciidocFX with Apache License 2.0 | 4 votes |
public static Optional<ButtonType> showAlert(String alertMessage) { AlertDialog deleteAlert = new AlertDialog(AlertType.WARNING, null, ButtonType.YES, ButtonType.CANCEL); deleteAlert.setHeaderText(alertMessage); return deleteAlert.showAndWait(); }
Example 17
Source File: MyTab.java From AsciidocFX with Apache License 2.0 | 4 votes |
private synchronized void save() { FileTime latestModifiedTime = IOHelper.getLastModifiedTime(getPath()); if (Objects.nonNull(latestModifiedTime) && Objects.nonNull(getLastModifiedTime())) { if (latestModifiedTime.compareTo(getLastModifiedTime()) > 0) { this.select(); ButtonType buttonType = AlertHelper.conflictAlert(getPath()).orElse(ButtonType.CANCEL); if (buttonType == ButtonType.CANCEL) { return; } if (buttonType == AlertHelper.LOAD_FILE_SYSTEM_CHANGES) { load(); } } else { if (!isNew() && !isChanged()) { return; } } } if (Objects.isNull(getPath())) { final FileChooser fileChooser = directoryService.newFileChooser(String.format("Save file")); fileChooser.getExtensionFilters().addAll(ExtensionFilters.ASCIIDOC); fileChooser.getExtensionFilters().addAll(ExtensionFilters.MARKDOWN); fileChooser.getExtensionFilters().addAll(ExtensionFilters.ALL); File file = fileChooser.showSaveDialog(null); if (Objects.isNull(file)) return; setPath(file.toPath()); setTabText(file.toPath().getFileName().toString()); } String editorValue = editorPane.getEditorValue(); IOHelper.createDirectories(getPath().getParent()); Optional<Exception> exception = IOHelper.writeToFile(getPath(), editorValue, TRUNCATE_EXISTING, CREATE, SYNC); if (exception.isPresent()) { return; } setLastModifiedTime(IOHelper.getLastModifiedTime(getPath())); setChangedProperty(false); ObservableList<Item> recentFiles = storedConfigBean.getRecentFiles(); recentFiles.remove(new Item(getPath())); recentFiles.add(0, new Item(getPath())); directoryService.setInitialDirectory(Optional.ofNullable(getPath().toFile())); }
Example 18
Source File: Utils.java From blobsaver with GNU General Public License v3.0 | 4 votes |
static void newReportableError(String msg, String toCopy) { Alert alert = new Alert(Alert.AlertType.ERROR, msg + "\n\nPlease create a new issue on Github or PM me on Reddit. The log has been copied to your clipboard.", githubIssue, redditPM, ButtonType.CANCEL); alert.showAndWait(); reportError(alert, toCopy); }