Java Code Examples for javafx.scene.control.ButtonType#NO

The following examples show how to use javafx.scene.control.ButtonType#NO . 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: EditorFrame.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private void close() 
{
	DiagramTab diagramTab = getSelectedDiagramTab();
	// we only want to check attempts to close a frame
	if( diagramTab.hasUnsavedChanges() ) 
	{
		// ask user if it is ok to close
		Alert alert = new Alert(AlertType.CONFIRMATION, RESOURCES.getString("dialog.close.ok"), ButtonType.YES, ButtonType.NO);
		alert.initOwner(aMainStage);
		alert.setTitle(RESOURCES.getString("dialog.close.title"));
		alert.setHeaderText(RESOURCES.getString("dialog.close.title"));
		alert.showAndWait();

		if (alert.getResult() == ButtonType.YES) 
		{
			removeGraphFrameFromTabbedPane(diagramTab);
		}
		return;
	} 
	else 
	{
		removeGraphFrameFromTabbedPane(diagramTab);
	}
}
 
Example 2
Source File: EditorFrame.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
/**
 * If a user confirms that they want to close their modified graph, this method
 * will remove it from the current list of tabs.
 * 
 * @param pDiagramTab The current Tab that one wishes to close.
 */
public void close(DiagramTab pDiagramTab) 
{
	if(pDiagramTab.hasUnsavedChanges()) 
	{
		Alert alert = new Alert(AlertType.CONFIRMATION, RESOURCES.getString("dialog.close.ok"), ButtonType.YES, ButtonType.NO);
		alert.initOwner(aMainStage);
		alert.setTitle(RESOURCES.getString("dialog.close.title"));
		alert.setHeaderText(RESOURCES.getString("dialog.close.title"));
		alert.showAndWait();

		if (alert.getResult() == ButtonType.YES) 
		{
			removeGraphFrameFromTabbedPane(pDiagramTab);
		}
	}
	else
	{
		removeGraphFrameFromTabbedPane(pDiagramTab);
	}
}
 
Example 3
Source File: FileEditorTabPane.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 6 votes vote down vote up
boolean canCloseEditor(FileEditor fileEditor) {
	if (!fileEditor.isModified())
		return true;

	Alert alert = mainWindow.createAlert(AlertType.CONFIRMATION,
		Messages.get("FileEditorTabPane.closeAlert.title"),
		Messages.get("FileEditorTabPane.closeAlert.message"), fileEditor.getTab().getText());
	alert.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO, ButtonType.CANCEL);

	// register first characters of Yes and No buttons as keys to close the alert
	for (ButtonType buttonType : Arrays.asList(ButtonType.YES, ButtonType.NO)) {
		Nodes.addInputMap(alert.getDialogPane(),
			consume(keyPressed(KeyCode.getKeyCode(buttonType.getText().substring(0, 1).toUpperCase())), e -> {
				if (!e.isConsumed()) {
					alert.setResult(buttonType);
					alert.close();
				}
			}));
	}

	ButtonType result = alert.showAndWait().get();
	if (result != ButtonType.YES)
		return (result == ButtonType.NO);

	return saveEditor(fileEditor);
}
 
Example 4
Source File: SaveDrawing.java    From latexdraw with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Does save on close.
 */
private void saveOnClose() {
	if(ui.isModified()) {
		saveAs = true;
		final ButtonType type = modifiedAlert.showAndWait().orElse(ButtonType.CANCEL);
		if(type == ButtonType.NO) {
			quit();
		}else {
			if(type == ButtonType.YES) {
				showDialog(fileChooser, saveAs, file, currentFolder, ui, mainstage).ifPresent(f -> {
					file = f;
					super.doCmdBody();
					quit();
				});
			}else {
				ok = false;
			}
		}
	}else {
		quit();
	}
}
 
Example 5
Source File: DockItemWithInput.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** 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 6
Source File: EditorFrame.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Exits the program if no graphs have been modified or if the user agrees to
 * abandon modified graphs.
 */
public void exit() 
{
	final int modcount = getNumberOfUsavedDiagrams();
	if (modcount > 0) 
	{
		Alert alert = new Alert(AlertType.CONFIRMATION, 
				MessageFormat.format(RESOURCES.getString("dialog.exit.ok"), new Object[] { Integer.valueOf(modcount) }),
				ButtonType.YES, 
				ButtonType.NO);
		alert.initOwner(aMainStage);
		alert.setTitle(RESOURCES.getString("dialog.exit.title"));
		alert.setHeaderText(RESOURCES.getString("dialog.exit.title"));
		alert.showAndWait();

		if (alert.getResult() == ButtonType.YES) 
		{
			Preferences.userNodeForPackage(UMLEditor.class).put("recent", aRecentFiles.serialize());
			System.exit(0);
		}
	}
	else 
	{
		Preferences.userNodeForPackage(UMLEditor.class).put("recent", aRecentFiles.serialize());
		System.exit(0);
	}
}
 
Example 7
Source File: MainController.java    From Schillsaver with MIT License 5 votes vote down vote up
/** Deletes all jobs selected within the view's job list. */
private void deleteSelectedJobs() {
    // Prompt the user to confirm their choice.
    final Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
    alert.setTitle("Confirm Deletion");
    alert.setHeaderText("Are you sure you want to delete the job(s)?");
    alert.setContentText("");
    alert.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO);

    final Optional<ButtonType> alertResult = alert.showAndWait();

    if (! alertResult.isPresent() || alertResult.get() == ButtonType.NO) {
        return;
    }

    // Delete jobs if user confirmed choice.
    final MainModel model = (MainModel) super.getModel();
    final MainView view = (MainView) super.getView();

    final ListView<String> jobsList = view.getJobsList();
    final List<String> selectedJobs = FXCollections.observableArrayList(jobsList.getSelectionModel().getSelectedItems());

    for (final String jobName : selectedJobs) {
        view.getJobsList().getItems().remove(jobName);
        model.getJobs().remove(jobName);
    }

    jobsList.getSelectionModel().clearSelection();

    updateButtonStates();
}
 
Example 8
Source File: LoadDrawing.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void doCmdBody() {
	if(ui.isModified()) {
		final ButtonType type = modifiedAlert.showAndWait().orElse(ButtonType.CANCEL);
		if(type == ButtonType.NO) {
			load();
		}else {
			if(type == ButtonType.YES) {
				saveAndLoad();
			}
		}
	}else {
		load();
	}
}
 
Example 9
Source File: DialogLoggerUtil.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
public static boolean showDialogYesNo(String title, String message) {
  Alert alert = new Alert(AlertType.CONFIRMATION, message, ButtonType.YES, ButtonType.NO);
  alert.setTitle(title);
  Optional<ButtonType> result = alert.showAndWait();
  return (result.isPresent() && result.get() == ButtonType.YES);
}
 
Example 10
Source File: DisplayEditorApplication.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private URI getFileResource(final URI original_resource)
{
    try
    {
        // Strip query from resource, because macros etc.
        // are only relevant to runtime, not to editor
        final URI resource = new URI(original_resource.getScheme(), original_resource.getUserInfo(),
                                     original_resource.getHost(), original_resource.getPort(),
                                     original_resource.getPath(), null, null);

        // Does the resource already point to a local file?
        File file = ModelResourceUtil.getFile(resource);
        if (file != null)
        {
            last_local_file = file;
            return file.toURI();
        }

        // Does user want to download into local file?
        final Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        DialogHelper.positionDialog(alert, DockPane.getActiveDockPane(), -200, -100);
        alert.initOwner(DockPane.getActiveDockPane().getScene().getWindow());
        alert.setResizable(true);
        alert.setTitle(Messages.DownloadTitle);
        alert.setHeaderText(MessageFormat.format(Messages.DownloadPromptFMT,
                                                 resource.toString()));
        // Setting "Yes", "No" buttons
        alert.getButtonTypes().clear();
        alert.getButtonTypes().add(ButtonType.YES);
        alert.getButtonTypes().add(ButtonType.NO);
        if (alert.showAndWait().orElse(ButtonType.NO) == ButtonType.NO)
            return null;

        // Prompt for local file
        final File local_file = promptForFilename(Messages.DownloadTitle);
        if (local_file == null)
            return null;

        // In background thread, ..
        JobManager.schedule(Messages.DownloadTitle, monitor ->
        {
            monitor.beginTask("Download " + resource);
            // .. download resource into local file ..
            try
            (
                final InputStream read = ModelResourceUtil.openResourceStream(resource.toString());
            )
            {
                Files.copy(read, local_file.toPath(), StandardCopyOption.REPLACE_EXISTING);
            }
            // .. and then, back on UI thread, open editor for the local file
            Platform.runLater(() -> create(ResourceParser.getURI(local_file)));
        });

        // For now, return null, no editor is opened right away.
    }
    catch (Exception ex)
    {
        ExceptionDetailsErrorDialog.openError("Error", "Cannot load " + original_resource, ex);
    }
    return null;
}
 
Example 11
Source File: AlertHelper.java    From AsciidocFX with Apache License 2.0 4 votes vote down vote up
public static Optional<ButtonType> showYesNoAlert(String alertMessage) {
    AlertDialog deleteAlert = new AlertDialog(AlertType.WARNING, null, ButtonType.YES, ButtonType.NO);
    deleteAlert.setHeaderText(alertMessage);
    return deleteAlert.showAndWait();
}