Example usage for com.vaadin.ui Button.ClickListener Button.ClickListener

List of usage examples for com.vaadin.ui Button.ClickListener Button.ClickListener

Introduction

In this page you can find the example usage for com.vaadin.ui Button.ClickListener Button.ClickListener.

Prototype

Button.ClickListener

Source Link

Usage

From source file:se.natusoft.osgi.aps.apsuseradminweb.vaadin.components.editors.UserEditor.java

License:Open Source License

/**
 * Creates a new UserEditor instance.// w ww .java 2 s  .  c o m
 *
 * @param userServiceAdmin The user admin service for editing the user.
 */
public UserEditor(APSSimpleUserServiceAdmin userServiceAdmin) {
    this.userServiceAdmin = userServiceAdmin;

    this.setStyleName(CSS.APS_EDITING_TEXT);

    VerticalLayout verticalLayout = new VerticalLayout();
    verticalLayout.setSpacing(true);
    verticalLayout.setMargin(true);
    verticalLayout.setStyleName(CSS.APS_EDITING_TEXT + " " + CSS.APS_CONTENT_PANEL);

    // User id & Auth
    {
        HorizontalLayout firstRowLayout = new HorizontalLayout();
        firstRowLayout.setSpacing(true);

        this.userId = new TextField("User id");
        this.userId.setColumns(30);
        this.userId.setImmediate(true);
        this.userId.setEnabled(true);

        firstRowLayout.addComponent(this.userId);

        this.authCurrent = new PasswordField("Current auth");
        this.authCurrent.setColumns(30);
        this.authCurrent.setImmediate(true);
        this.authCurrent.setEnabled(true);

        firstRowLayout.addComponent(this.authCurrent);

        verticalLayout.addComponent(firstRowLayout);

        HorizontalLayout secondRowLayout = new HorizontalLayout();
        secondRowLayout.setSpacing(true);

        this.authNewOne = new PasswordField("New auth");
        this.authNewOne.setColumns(30);
        this.authNewOne.setImmediate(true);
        this.authNewOne.setEnabled(true);

        secondRowLayout.addComponent(this.authNewOne);

        this.authNewTwo = new PasswordField("New auth confirm");
        this.authNewTwo.setColumns(30);
        this.authNewTwo.setImmediate(true);
        this.authNewTwo.setEnabled(true);

        secondRowLayout.addComponent(this.authNewTwo);

        verticalLayout.addComponent(secondRowLayout);
    }

    // User Properties
    {
        this.propertiesEditor = new Table();
        this.propertiesEditor.setSelectable(true);
        this.propertiesEditor.setCaption("User properties");
        this.propertiesEditor.setPageLength(8);
        this.propertiesEditor.setEditable(true);
        this.propertiesEditor.setSizeFull();
        this.propertiesEditor.setColumnExpandRatio(USER_PROPS_KEY, 0.3f);
        this.propertiesEditor.setColumnExpandRatio(USER_PROPS_VALUE, 0.7f);
        this.propertiesEditor.setTableFieldFactory(new EditFieldFactory());
        this.propertiesEditor.addListener(new ItemClickEvent.ItemClickListener() {
            @Override
            public void itemClick(ItemClickEvent event) {
                selectDeselectProperty(event.getItemId());
            }
        });
        verticalLayout.addComponent(this.propertiesEditor);

        // Buttons + info row
        {
            HorizontalLayout plusMinusRow = new HorizontalLayout();
            plusMinusRow.setSpacing(true);

            this.plusButton = new Button("+");
            this.plusButton.addListener(new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent event) {
                    addProperty();
                }
            });
            plusMinusRow.addComponent(this.plusButton);

            this.minusButton = new Button("-");
            this.minusButton.addListener(new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent event) {
                    deleteProperty();
                }
            });
            this.minusButton.setEnabled(false);
            plusMinusRow.addComponent(this.minusButton);

            this.propsHelpText = new HelpText(
                    "Press + to add new property, select property and press - to delete.");
            plusMinusRow.addComponent(this.propsHelpText);

            verticalLayout.addComponent(plusMinusRow);
        }
    }

    // Roles
    {
        HorizontalLayout rolesLayout = new HorizontalLayout();
        rolesLayout.setSizeFull();

        // Available
        this.availableRoles = new Table("Available roles");
        this.availableRoles.setImmediate(true);
        this.availableRoles.setPageLength(10);
        this.availableRoles.setSortAscending(true);
        this.availableRoles.setSizeFull();
        this.availableRoles.setDragMode(Table.TableDragMode.ROW);
        this.availableRoles.setDropHandler(new DropHandler() {
            @Override
            public void drop(DragAndDropEvent event) {
                DataBoundTransferable t = (DataBoundTransferable) event.getTransferable();
                Object itemId = t.getItemId();
                removeRole(itemId);
            }

            @Override
            public AcceptCriterion getAcceptCriterion() {
                return new RoleAcceptCriterion(UserEditor.this.availableRoles);
            }
        });
        VerticalLayout availableRolesFrame = new VerticalLayout();
        availableRolesFrame.setMargin(false, true, false, false);
        availableRolesFrame.addComponent(this.availableRoles);
        rolesLayout.addComponent(availableRolesFrame);

        // Selected
        this.selectedRoles = new Table("Selected roles");
        this.selectedRoles.setImmediate(true);
        this.selectedRoles.setPageLength(10);
        this.selectedRoles.setSortAscending(true);
        this.selectedRoles.setSizeFull();
        this.selectedRoles.setDragMode(Table.TableDragMode.ROW);
        this.selectedRoles.setDropHandler(new DropHandler() {
            @Override
            public void drop(DragAndDropEvent event) {
                DataBoundTransferable t = (DataBoundTransferable) event.getTransferable();
                Object itemId = t.getItemId();
                addRole(itemId);
            }

            @Override
            public AcceptCriterion getAcceptCriterion() {
                return new RoleAcceptCriterion(UserEditor.this.selectedRoles);
            }
        });
        VerticalLayout selectedRolesFrame = new VerticalLayout();
        selectedRolesFrame.setMargin(false, false, false, true);
        selectedRolesFrame.addComponent(this.selectedRoles);
        rolesLayout.addComponent(selectedRolesFrame);

        rolesLayout.setExpandRatio(availableRolesFrame, 0.5f);
        rolesLayout.setExpandRatio(selectedRolesFrame, 0.5f);

        verticalLayout.addComponent(rolesLayout);

        this.roleHelptext = new HelpText("Drag and drop roles back and forth to set or remove a role.");
        verticalLayout.addComponent(this.roleHelptext);
    }

    // Save & Cancel
    {
        HorizontalLayout saveCancelLayout = new HorizontalLayout();
        saveCancelLayout.setSpacing(true);

        this.saveButton = new Button("Save");
        this.saveButton.addListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                save();
            }
        });
        saveCancelLayout.addComponent(saveButton);

        Button cancelButton = new Button("Cancel");
        cancelButton.addListener(new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                cancel();
            }
        });
        saveCancelLayout.addComponent(cancelButton);

        verticalLayout.addComponent(saveCancelLayout);
    }

    setContent(verticalLayout);
}

From source file:se.natusoft.osgi.aps.tools.web.vaadin.VaadinLoginDialogHandler.java

License:Open Source License

/**
 * Creates a new VaadinLoginDialogHandler.
 *
 * @param appWindow The Vaadin application window to add the popup login dialog to.
 * @param loginHandler A handler for doing the login from the login dialog input.
 *///from  w  ww.  j av  a  2 s .com
public VaadinLoginDialogHandler(Window appWindow, LoginHandler loginHandler) {
    this.appWindow = appWindow;
    this.loginHandler = loginHandler;

    // Create Login window dialog
    this.loginWindow = new Window("Login");
    this.loginWindow.setModal(true);
    this.loginWindow.setWidth("300px");

    VerticalLayout dialogLayout = new VerticalLayout();
    dialogLayout.setSpacing(true);
    dialogLayout.setMargin(true);
    this.userName = new TextField("User:");
    this.userName.setColumns(20);
    dialogLayout.addComponent(this.userName);
    this.password = new PasswordField("Password");
    this.password.setColumns(20);
    this.password.setImmediate(true);
    this.password.addListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            login();
        }
    });
    dialogLayout.addComponent(password);
    Button loginButton = new Button("Login");
    loginButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            login();
        }
    });
    dialogLayout.addComponent(loginButton);
    this.loginWindow.setContent(dialogLayout);
}