dhbw.clippinggorilla.userinterface.windows.ConfirmationDialog.java Source code

Java tutorial

Introduction

Here is the source code for dhbw.clippinggorilla.userinterface.windows.ConfirmationDialog.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dhbw.clippinggorilla.userinterface.windows;

import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.themes.ValoTheme;
import dhbw.clippinggorilla.objects.group.GroupUtils;
import dhbw.clippinggorilla.utilities.language.Language;
import dhbw.clippinggorilla.utilities.language.Word;

/**
 *
 * @author frank
 */
public class ConfirmationDialog extends Window {

    public static void show(String confirmationText, Runnable onOk, Runnable onCancel) {
        ConfirmationDialog confirmationDialog = new ConfirmationDialog(confirmationText, onOk, onCancel);
    }

    public static void show(String confirmationText, Runnable onOk) {
        ConfirmationDialog confirmationDialog = new ConfirmationDialog(confirmationText, onOk, () -> {
        });
    }

    public ConfirmationDialog(String confirmationText, Runnable onOk, Runnable onCancel) {
        addCloseListener(ce -> onCancel.run());
        setCaption(Language.get(Word.CONFIRMATION));

        VerticalLayout root = new VerticalLayout();
        root.setSpacing(false);
        root.setMargin(false);
        root.setSizeFull();

        Label text = new Label(confirmationText);
        text.setStyleName(ValoTheme.LABEL_H3);
        text.setWidth("100%");
        VerticalLayout layoutText = new VerticalLayout(text);
        layoutText.setSizeFull();
        layoutText.addStyleName("tags");
        layoutText.setSpacing(false);

        root.addComponent(layoutText);

        Label ignoreMe = new Label();

        Button ok = new Button(Language.get(Word.OK));
        ok.addClickListener(c -> {
            close();
            onOk.run();
        });
        ok.addStyleName(ValoTheme.BUTTON_DANGER);

        Button cancel = new Button(Language.get(Word.CANCEL));
        cancel.addClickListener(c -> {
            close();
            onCancel.run();
        });
        cancel.addStyleName(ValoTheme.BUTTON_FRIENDLY);

        GridLayout footer = new GridLayout(3, 1);
        footer.setSpacing(true);
        footer.setSizeUndefined();
        footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR);
        footer.setWidth("100%");
        footer.addStyleName("menubar");
        footer.addComponents(ignoreMe, ok, cancel);
        footer.setColumnExpandRatio(0, 5);
        footer.setComponentAlignment(ok, Alignment.MIDDLE_CENTER);
        footer.setComponentAlignment(cancel, Alignment.MIDDLE_CENTER);
        root.setExpandRatio(layoutText, 5);
        root.addComponent(footer);

        setContent(root);
        setModal(true);
        center();
        setDraggable(false);
        setResizable(false);
        setWidth("350px");
        setHeight("200px");
        UI.getCurrent().addWindow(this);

    }

}