com.skysql.manager.ui.WarningWindow.java Source code

Java tutorial

Introduction

Here is the source code for com.skysql.manager.ui.WarningWindow.java

Source

/*
 * This file is distributed as part of the MariaDB Manager.  It is free
 * software: you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation,
 * version 2.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 51
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Copyright 2012-2014 SkySQL Corporation Ab
 */

package com.skysql.manager.ui;

import com.vaadin.server.ThemeResource;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Embedded;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

/**
 * The Class WarningWindow.
 */
public class WarningWindow extends ModalWindow {

    private static final long serialVersionUID = 0x4C656F6E6172646FL;

    final WarningWindow warningWindow = this;

    /**
     * Instantiates a new warning window.
     *
     * @param caption the caption
     * @param message the message
     * @param label the label
     * @param okListener the ok listener
     */
    public WarningWindow(String caption, String message, String label, Button.ClickListener okListener) {
        super(caption, "60%");

        HorizontalLayout wrapper = new HorizontalLayout();
        wrapper.setWidth("100%");
        wrapper.setMargin(true);
        VerticalLayout iconLayout = new VerticalLayout();
        iconLayout.setWidth("100px");
        wrapper.addComponent(iconLayout);
        Embedded image = new Embedded(null, new ThemeResource("img/warning.png"));
        iconLayout.addComponent(image);
        VerticalLayout textLayout = new VerticalLayout();
        textLayout.setSizeFull();
        wrapper.addComponent(textLayout);
        wrapper.setExpandRatio(textLayout, 1.0f);

        Label msgLabel = new Label(message);
        msgLabel.addStyleName("warning");
        textLayout.addComponent(msgLabel);
        textLayout.setComponentAlignment(msgLabel, Alignment.MIDDLE_CENTER);

        HorizontalLayout buttonsBar = new HorizontalLayout();
        buttonsBar.setStyleName("buttonsBar");
        buttonsBar.setSizeFull();
        buttonsBar.setSpacing(true);
        buttonsBar.setMargin(true);
        buttonsBar.setHeight("49px");

        Label filler = new Label();
        buttonsBar.addComponent(filler);
        buttonsBar.setExpandRatio(filler, 1.0f);

        Button cancelButton = new Button("Cancel");
        buttonsBar.addComponent(cancelButton);
        buttonsBar.setComponentAlignment(cancelButton, Alignment.MIDDLE_RIGHT);

        cancelButton.addClickListener(new Button.ClickListener() {
            private static final long serialVersionUID = 0x4C656F6E6172646FL;

            public void buttonClick(Button.ClickEvent event) {
                warningWindow.close();
            }
        });

        Button okButton = new Button(label);
        okButton.addClickListener(okListener);
        buttonsBar.addComponent(okButton);
        buttonsBar.setComponentAlignment(okButton, Alignment.MIDDLE_RIGHT);

        VerticalLayout windowLayout = (VerticalLayout) this.getContent();
        windowLayout.setSpacing(false);
        windowLayout.setMargin(false);
        windowLayout.addComponent(wrapper);
        windowLayout.addComponent(buttonsBar);

    }

}