Java Code Examples for javafx.scene.control.Alert.AlertType#CONFIRMATION

The following examples show how to use javafx.scene.control.Alert.AlertType#CONFIRMATION . 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: CircuitSim.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
boolean confirmAndDeleteCircuit(CircuitManager circuitManager, boolean removeTab) {
	Alert alert = new Alert(AlertType.CONFIRMATION);
	alert.initOwner(stage);
	alert.initModality(Modality.WINDOW_MODAL);
	alert.setTitle("Delete \"" + circuitManager.getName() + "\"?");
	alert.setHeaderText("Delete \"" + circuitManager.getName() + "\"?");
	alert.setContentText("Are you sure you want to delete this circuit?");
	
	Optional<ButtonType> result = alert.showAndWait();
	if(!result.isPresent() || result.get() != ButtonType.OK) {
		return false;
	} else {
		deleteCircuit(circuitManager, removeTab, true);
		return true;
	}
}
 
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: ScanEditor.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void execute(UndoableAction action)
{
    final ScanInfoModel infos = scan_info_model.get();
    if (infos != null)
    {
        // Warn that changes to the running scan are limited
        final Alert dlg = new Alert(AlertType.CONFIRMATION);
        dlg.setHeaderText("");
        dlg.setContentText(Messages.scan_active_prompt);
        dlg.setResizable(true);
        dlg.getDialogPane().setPrefSize(600, 300);
        DialogHelper.positionDialog(dlg, scan_tree, -100, -100);
        if (dlg.showAndWait().get() != ButtonType.OK)
            return;

        // Only property change is possible while running.
        // Adding/removing commands detaches from the running scan.
        if (! (action instanceof ChangeProperty))
            detachFromScan();
    }
    super.execute(action);
}
 
Example 4
Source File: AppUtils.java    From java-ml-projects with Apache License 2.0 5 votes vote down vote up
public static boolean askIfOk(String msg) {
	Alert dialog = new Alert(AlertType.CONFIRMATION);
	dialog.setTitle("Confirmation");
	dialog.setResizable(true);
	dialog.setContentText(msg);
	dialog.setHeaderText(null);
	dialog.showAndWait();
	return dialog.getResult() == ButtonType.OK;
}
 
Example 5
Source File: FXMLTimingController.java    From pikatimer with GNU General Public License v3.0 5 votes vote down vote up
public void clearAllTimes(ActionEvent fxevent){
    //TODO: Prompt and then remove all times associated with that timing location 
    // _or_ all timing locations
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Clear Timing Data...");
    alert.setHeaderText("Clear Timing Data:");
    alert.setContentText("Do you want to clear the times for all locations or just the " + selectedTimingLocation.getLocationName()+ " location?");

    ButtonType allButtonType = new ButtonType("All Times");
    
    ButtonType currentButtonType = new ButtonType(selectedTimingLocation.getLocationName() + " Times",ButtonData.YES);
    ButtonType cancelButtonType = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);

    alert.getButtonTypes().setAll(cancelButtonType, allButtonType,  currentButtonType );

    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == allButtonType){
        // ... user chose All
        timingDAO.clearAllTimes();
        // itterate over all of the timing locations
        timingLocationList.stream().forEach(tl -> {tl.getInputs().stream().forEach(tli -> {tli.clearLocalReads();});});
    } else if (result.get() == currentButtonType) {
        // ... user chose "Two"
        selectedTimingLocation.getInputs().stream().forEach(tli -> {tli.clearReads();});
    } else {
        // ... user chose CANCEL or closed the dialog
    }
 
}
 
Example 6
Source File: AlertWithToggleDemo.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void start(final Stage stage)
{
    AlertWithToggle dialog = new AlertWithToggle(AlertType.CONFIRMATION, "Test",
            "This is a test\nAnother line");
    System.out.println("Selected: " + dialog.showAndWait());
    System.out.println("Hide from now on: " + dialog.isHideSelected());

    dialog = new AlertWithToggle(AlertType.WARNING,
            "Just using\nheader text",
            "");
    System.out.println("Selected: " + dialog.showAndWait());
    System.out.println("Hide from now on: " + dialog.isHideSelected());

}
 
Example 7
Source File: PhoebusApplication.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Close the main stage
 *
 *  <p>If there are more stages open, warn user that they will be closed.
 *
 *  <p>When called from the onCloseRequested handler of the primary stage, we must
 *  _not_ send another close request to it because that would create an infinite
 *  loop.
 *
 *  @param main_stage_already_closing
 *            Primary stage when called from its onCloseRequested handler, else <code>null</code>
 *  @return <code>true</code> on success, <code>false</code> when some panel doesn't want to close
 */
private boolean closeMainStage(final Stage main_stage_already_closing)
{
    final List<Stage> stages = DockStage.getDockStages();

    if (stages.size() > 1)
    {
        final Alert dialog = new Alert(AlertType.CONFIRMATION);
        dialog.setTitle(Messages.ExitTitle);
        dialog.setHeaderText(Messages.ExitHdr);
        dialog.setContentText(Messages.ExitContent);
        DialogHelper.positionDialog(dialog, stages.get(0).getScene().getRoot(), -200, -200);
        if (dialog.showAndWait().orElse(ButtonType.CANCEL) != ButtonType.OK)
            return false;
    }

    // If called from the main stage that's already about to close,
    // skip that one when closing all stages
    if (main_stage_already_closing != null)
        stages.remove(main_stage_already_closing);

    // Save current state, _before_ tabs are closed and thus
    // there's nothing left to save
    final File memfile = XMLMementoTree.getDefaultFile();
    MementoHelper.saveState(memfile, last_opened_file, default_application, isMenuVisible(), isToolbarVisible());

    if (!closeStages(stages))
        return false;

    // Once all other stages are closed,
    // potentially check the main stage.
    if (main_stage_already_closing != null && !DockStage.isStageOkToClose(main_stage_already_closing))
        return false;
    return true;
}
 
Example 8
Source File: FXMLParticipantController.java    From pikatimer with GNU General Public License v3.0 5 votes vote down vote up
public void clearParticipants(ActionEvent fxevent){
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Confirm Participant Removal");
    alert.setHeaderText("This will remove all Participants from the event.");
    alert.setContentText("This action cannot be undone. Are you sure you want to do this?");

    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == ButtonType.OK){
        participantDAO.clearAll();
        resetForm(); 
    } else {
        // ... user chose CANCEL or closed the dialog
    }
    
}
 
Example 9
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 10
Source File: SaveAndRestoreWithSplitController.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private void deleteSnapshots(ObservableList<Node> selectedItems) {
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle(Messages.promptDeleteSelectedTitle);
    alert.setHeaderText(Messages.promptDeleteSelectedHeader);
    alert.setContentText(Messages.promptDeleteSelectedContent);
    Optional<ButtonType> result = alert.showAndWait();
    if (result.isPresent() && result.get().equals(ButtonType.OK)) {
        selectedItems.stream().forEach(item -> deleteListItem(item));
    }
}
 
Example 11
Source File: CommentListCell.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a Dialog for getting deletion confirmation
 * @param item Item to be deleted
 */
private void showDialog(Comment item) {
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitleText("Confirm deletion");
    alert.setContentText("This comment will be deleted permanently.\nDo you want to continue?");
    
    Button yes = new Button("Yes, delete permanently");
    yes.setOnAction(e -> {
        alert.setResult(ButtonType.YES); 
        alert.hide();
    });
    yes.setDefaultButton(true);
    
    Button no = new Button("No");
    no.setCancelButton(true);
    no.setOnAction(e -> {
        alert.setResult(ButtonType.NO); 
        alert.hide();
    });
    alert.getButtons().setAll(yes, no);
    
    Optional result = alert.showAndWait();
    if (result.isPresent() && result.get().equals(ButtonType.YES)) {
        /*
        With confirmation, delete the item from the ListView. This will be
        propagated to the Cloud, and from there to the rest of the clients
        */
        listViewProperty().get().getItems().remove(item);
    }
}
 
Example 12
Source File: ClientDisplay.java    From Open-Lowcode with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * displays a modal popup and waits for answer
 * 
 * @param message    what to display as main message
 * @param yesmessage what to display on button for yes
 * @param nomessage  what to display on button for no
 * @return true if answer is yes, false if answer of the popup is false
 */
public boolean displayModalPopup(String message, String yesmessage, String nomessage) {
	Alert alert = new Alert(AlertType.CONFIRMATION);
	alert.setTitle("Unsaved data warning");
	alert.setContentText("There is unsaved data. Do you want to continue and lose data ?");

	Optional<ButtonType> result = alert.showAndWait();
	if (result.get() == ButtonType.OK)
		return true;
	return false;
}
 
Example 13
Source File: CircuitSim.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 14
Source File: UserGuiInteractor.java    From kafka-message-tool with MIT License 5 votes vote down vote up
@Override
public boolean getYesNoDecision(String title,
                                String header,
                                String content) {
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.initOwner(owner);
    alert.setTitle(title);
    alert.setHeaderText(header);
    alert.getDialogPane().setContent(getTextNodeContent(content));

    decorateWithCss(alert);

    Optional<ButtonType> result = alert.showAndWait();
    return result.get() == ButtonType.OK;
}
 
Example 15
Source File: GitFxDialog.java    From GitFx with Apache License 2.0 5 votes vote down vote up
public void gitConfirmationDialog(String title, String header, String content) {
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle(title);
    alert.setHeaderText(header);
    alert.setContentText(content);

    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == ButtonType.OK) {
        setResponse(GitFxDialogResponse.OK);
    } else {
        setResponse(GitFxDialogResponse.CANCEL);
    }
}
 
Example 16
Source File: MainApp_Controller.java    From Path-of-Leveling with MIT License 5 votes vote down vote up
public boolean custom_editor_exit_with_validate(){
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Save changes");
    alert.setHeaderText("Any changes you made will be saved upon exit.");
    alert.setContentText("Are you ok with this?");

    Optional<ButtonType> result = alert.showAndWait();
    if (result.get() == ButtonType.OK){
        return validateToLauncher();
    }else{
        parent.returnToLauncher();
        return true;
    }
}
 
Example 17
Source File: UserHeadEditViewImpl.java    From oim-fx with MIT License 5 votes vote down vote up
private void initEvent() {

		alert = new Alert(AlertType.CONFIRMATION, "");
		alert.initModality(Modality.APPLICATION_MODAL);
		alert.initOwner(frame);
		alert.getDialogPane().setContentText("确定选择");
		alert.getDialogPane().setHeaderText(null);

		frame.setWidth(430);
		frame.setHeight(580);
		frame.setResizable(false);
		frame.setTitlePaneStyle(2);
		frame.setTitle("选择头像");

		frame.setCenter(p);
		frame.show();


		p.setPrefWrapLength(400);
		p.showWaiting(true, WaitingPane.show_waiting);
		appContext.add(new ExecuteTask() {

			@Override
			public void execute() {
				init(p);
			}
		});
	}
 
Example 18
Source File: BetonQuestEditor.java    From BetonQuest-Editor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Shows a confirmation pop-up window with specified translated message.
 * Returns result - true if the user confirms the action, false if he wants
 * to cancel it.
 *
 * @param message ID of message
 * @return true if confirmed, false otherwise
 */
public static boolean confirm(String message) {
	Alert alert = new Alert(AlertType.CONFIRMATION);
	alert.setHeaderText(BetonQuestEditor.getInstance().getLanguage().getString(message));
	alert.getDialogPane().getStylesheets().add(instance.getClass().getResource("resource/style.css").toExternalForm());
	Optional<ButtonType> action = alert.showAndWait();
	if (action.isPresent() && action.get() == ButtonType.OK) {
		return true;
	}
	return false;
}
 
Example 19
Source File: AbstractChartMeasurement.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
public AbstractChartMeasurement(final ParameterMeasurements plugin, final String measurementName, final AxisMode axisMode, final int requiredNumberOfIndicators,
        final int requiredNumberOfDataSets) {
    if (plugin == null) {
        throw new IllegalArgumentException("plugin is null");
    }
    this.plugin = plugin;
    this.measurementName = measurementName;
    this.axisMode = axisMode;
    this.requiredNumberOfIndicators = requiredNumberOfIndicators;
    this.requiredNumberOfDataSets = requiredNumberOfDataSets;

    plugin.getChartMeasurements().add(this);

    alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle("Measurement Config Dialog");
    alert.setHeaderText("Please, select data set and/or other parameters:");
    alert.initModality(Modality.APPLICATION_MODAL);

    final DecorationPane decorationPane = new DecorationPane();
    decorationPane.getChildren().add(gridPane);
    alert.getDialogPane().setContent(decorationPane);
    alert.getButtonTypes().setAll(buttonOK, buttonDefault, buttonRemove);
    alert.setOnCloseRequest(evt -> alert.close());
    // add data set selector if necessary (ie. more than one data set available)
    dataSetSelector = new DataSetSelector(plugin, requiredNumberOfDataSets);
    if (dataSetSelector.getNumberDataSets() >= 1) {
        lastLayoutRow = shiftGridPaneRowOffset(dataSetSelector.getChildren(), lastLayoutRow);
        gridPane.getChildren().addAll(dataSetSelector.getChildren());
    }

    valueIndicatorSelector = new ValueIndicatorSelector(plugin, axisMode, requiredNumberOfIndicators); // NOPMD
    lastLayoutRow = shiftGridPaneRowOffset(valueIndicatorSelector.getChildren(), lastLayoutRow);
    gridPane.getChildren().addAll(valueIndicatorSelector.getChildren());
    valueField.setMouseTransparent(true);
    GridPane.setVgrow(dataViewWindow, Priority.NEVER);
    dataViewWindow.setOnMouseClicked(mouseHandler);

    getValueIndicatorsUser().addListener(valueIndicatorsUserChangeListener);

    dataViewWindow.nameProperty().bindBidirectional(title);
    setTitle(AbstractChartMeasurement.this.getClass().getSimpleName()); // NOPMD

    dataSet.addListener(dataSetChangeListener);
    dataSetChangeListener.changed(dataSet, null, null);

    getMeasurementPlugin().getDataView().getVisibleChildren().add(dataViewWindow);
}
 
Example 20
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);
}