Search in sources :

Example 1 with ListConfirmDialog

use of org.phoenicis.javafx.dialogs.ListConfirmDialog in project POL-POM-5 by PlayOnLinux.

the class ContainerVerbsPanelSkin method createVerbManagementButtons.

/**
 * Creates a container with the buttons for the verb selection management. These buttons consist of:
 * - a button to install all selected verbs
 * - a button to clear/reset the selection
 *
 * @param verbs The {@link GridPane} containing the visual verb installation components
 * @return A container with the buttons for the verb selection management
 */
private HBox createVerbManagementButtons(final GridPane verbs) {
    final Button installButton = new Button(tr("Install selected"));
    installButton.disableProperty().bind(getControl().lockVerbsProperty());
    installButton.setOnAction(event -> {
        getControl().setLockVerbs(true);
        final ContainerDTO container = getControl().getContainer();
        // find the ids of all selected verbs
        final List<ScriptDTO> installationVerbs = verbs.getChildren().stream().filter(element -> element instanceof CheckBox && ((CheckBox) element).isSelected()).map(GridPane::getRowIndex).map(getControl().getVerbScripts()::get).collect(Collectors.toList());
        final List<String> verbNames = installationVerbs.stream().map(ScriptDTO::getScriptName).collect(Collectors.toList());
        final ListConfirmDialog confirmDialog = ListConfirmDialog.builder().withTitle(tr("Install Verbs")).withMessage(tr("Are you sure you want to install the following Verbs:")).withConfirmItems(verbNames).withOwner(getControl().getScene().getWindow()).withYesCallback(() -> {
            final List<String> verbIds = installationVerbs.stream().map(ScriptDTO::getId).collect(Collectors.toList());
            // install the selected verbs
            getControl().getVerbsManager().installVerbs(container.getEngine().toLowerCase(), container.getName(), verbIds, () -> getControl().setLockVerbs(false), e -> Platform.runLater(() -> {
                final ErrorDialog errorDialog = ErrorDialog.builder().withMessage(tr("Error installing Verbs")).withException(e).build();
                errorDialog.showAndWait();
            }));
        }).build();
        confirmDialog.showAndCallback();
        // after the dialog has been closed unlock the verb buttons
        getControl().setLockVerbs(false);
    });
    final Button clearButton = new Button(tr("Clear selection"));
    clearButton.disableProperty().bind(getControl().lockVerbsProperty());
    clearButton.setOnAction(event -> verbs.getChildren().stream().filter(element -> element instanceof CheckBox).map(element -> (CheckBox) element).forEach(verbCheckBox -> verbCheckBox.setSelected(false)));
    return new HBox(installButton, clearButton);
}
Also used : Button(javafx.scene.control.Button) HBox(javafx.scene.layout.HBox) Label(javafx.scene.control.Label) ContainerVerbsPanel(org.phoenicis.javafx.components.container.control.ContainerVerbsPanel) CheckBox(javafx.scene.control.CheckBox) ListConfirmDialog(org.phoenicis.javafx.dialogs.ListConfirmDialog) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) Observable(javafx.beans.Observable) VBox(javafx.scene.layout.VBox) Collectors(java.util.stream.Collectors) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog) Platform(javafx.application.Platform) Text(javafx.scene.text.Text) Priority(javafx.scene.layout.Priority) List(java.util.List) ScrollPane(javafx.scene.control.ScrollPane) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) GridPane(javafx.scene.layout.GridPane) SkinBase(org.phoenicis.javafx.components.common.skin.SkinBase) ScriptDTO(org.phoenicis.repository.dto.ScriptDTO) ListConfirmDialog(org.phoenicis.javafx.dialogs.ListConfirmDialog) HBox(javafx.scene.layout.HBox) ScriptDTO(org.phoenicis.repository.dto.ScriptDTO) GridPane(javafx.scene.layout.GridPane) ErrorDialog(org.phoenicis.javafx.dialogs.ErrorDialog) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) Button(javafx.scene.control.Button) CheckBox(javafx.scene.control.CheckBox) List(java.util.List)

Aggregations

List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Platform (javafx.application.Platform)1 Observable (javafx.beans.Observable)1 Button (javafx.scene.control.Button)1 CheckBox (javafx.scene.control.CheckBox)1 Label (javafx.scene.control.Label)1 ScrollPane (javafx.scene.control.ScrollPane)1 GridPane (javafx.scene.layout.GridPane)1 HBox (javafx.scene.layout.HBox)1 Priority (javafx.scene.layout.Priority)1 VBox (javafx.scene.layout.VBox)1 Text (javafx.scene.text.Text)1 Localisation.tr (org.phoenicis.configuration.localisation.Localisation.tr)1 ContainerDTO (org.phoenicis.containers.dto.ContainerDTO)1 SkinBase (org.phoenicis.javafx.components.common.skin.SkinBase)1 ContainerVerbsPanel (org.phoenicis.javafx.components.container.control.ContainerVerbsPanel)1 ErrorDialog (org.phoenicis.javafx.dialogs.ErrorDialog)1 ListConfirmDialog (org.phoenicis.javafx.dialogs.ListConfirmDialog)1 ScriptDTO (org.phoenicis.repository.dto.ScriptDTO)1