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:org.vaadin.webinars.springandvaadin.aspectj.ui.ChatView.java

License:Apache License

@PostConstruct
void init() {//w  w  w.  j a  v a  2s. c  o  m
    setSizeFull();
    setMargin(true);
    setSpacing(true);

    roomLabel = new Label();
    roomLabel.addStyleName(Reindeer.LABEL_H1);
    addComponent(roomLabel);

    messagesPanel = new Panel();
    messagesPanel.setSizeFull();
    addComponent(messagesPanel);
    setExpandRatio(messagesPanel, 1f);

    messagesLayout = new VerticalLayout();
    messagesLayout.setMargin(true);
    messagesLayout.setSpacing(true);
    messagesPanel.setContent(messagesLayout);

    HorizontalLayout bar = new HorizontalLayout();
    bar.setSpacing(true);
    addComponent(bar);

    message = new TextField();
    bar.addComponent(message);

    post = new Button("Post", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            chatService
                    .post(new ChatMessage(((AspectJManagedUI) getUI()).getAuthor(), room, message.getValue()));
            message.setValue("");
            message.focus();
        }
    });
    post.setClickShortcut(ShortcutAction.KeyCode.ENTER);
    bar.addComponent(post);
}

From source file:org.vaadin.webinars.springandvaadin.aspectj.ui.RoomsView.java

License:Apache License

@PostConstruct
void init() {/*from  w  w  w .j a v a  2  s .  com*/
    setSizeFull();
    setMargin(true);
    setSpacing(true);

    HorizontalLayout bar = new HorizontalLayout();
    bar.setSpacing(true);
    addComponent(bar);

    newRoomField = new TextField();
    bar.addComponent(newRoomField);
    newRoomField.setInputPrompt("Enter name of new room");
    newRoomField.setWidth("15em");

    addRoom = new Button("Add room", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            chatService.createRoom(newRoomField.getValue());
            newRoomField.setValue("");
        }
    });
    bar.addComponent(addRoom);

    rooms = new ListSelect("Rooms");
    rooms.setWidth("200px");
    rooms.setHeight("100%");
    rooms.setNullSelectionAllowed(false);
    addComponent(rooms);
    setExpandRatio(rooms, 1);
    for (String room : chatService.getRooms()) {
        rooms.addItem(room);
    }

    goToRoom = new Button("Go to selected room", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            getUI().getNavigator().navigateTo("chat/" + rooms.getValue());
        }
    });
    addComponent(goToRoom);
}

From source file:org.vaadin.webinars.springandvaadin.bootexample.ContactRepository.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();/*from   www.j  a  v  a  2  s  .c o  m*/
    layout.setMargin(true);
    layout.setSpacing(true);
    setContent(layout);

    Label title = new Label("Contacts");
    title.addStyleName(Reindeer.LABEL_H1);
    layout.addComponent(title);

    contactsContainer = new BeanItemContainer<>(Contact.class);

    contactsTable = new Table();
    contactsTable.setSizeFull();
    contactsTable.setContainerDataSource(contactsContainer);
    contactsTable.setVisibleColumns("firstName", "lastName", "email");

    layout.addComponent(contactsTable);
    layout.setExpandRatio(contactsTable, 1f);

    HorizontalLayout toolbar = new HorizontalLayout();
    toolbar.setSpacing(true);
    layout.addComponent(toolbar);

    refresh = new Button("Refresh", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            refresh();
        }
    });
    toolbar.addComponent(refresh);

    add = new Button("Add...", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            addWindow(new NewContactWindow());
        }
    });
    toolbar.addComponent(add);

    refresh();
}

From source file:org.vaadin.webinars.springandvaadin.i18n.ui.I18nUI.java

License:Apache License

@Override
protected void init(VaadinRequest request) {
    setLocale(request.getLocale());/* w  w w  .  j  a v  a2s  . c  o  m*/

    getPage().setTitle(messageSource.getMessage("page.title", null, getLocale()));

    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    setContent(layout);

    final TextField textField = new TextField(messageSource.getMessage("textField.caption", null, getLocale()));
    layout.addComponent(textField);

    final Button button = new Button(messageSource.getMessage("button.caption", null, getLocale()));
    button.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            Notification.show(messageSource.getMessage("greeting.caption",
                    new Object[] { textField.getValue() }, getLocale()));
        }
    });
    layout.addComponent(button);

    final Button swe = new Button("P svenska", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            LocaleContextHolder.setLocale(new Locale("sv"));
            getPage().reload();
        }
    });
    layout.addComponent(swe);

    final Button eng = new Button("In English", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            LocaleContextHolder.setLocale(new Locale("en"));
            getPage().reload();
        }
    });
    layout.addComponent(eng);

}

From source file:pl.edu.agh.samm.testapp.SAMMTestApplication.java

License:Apache License

private Button createRemoveSlaveButton() {
    final Button removeSlaveButton = new Button("Remove slave");

    removeSlaveButton.addClickListener(new Button.ClickListener() {
        @Override/*from w  w  w .ja va  2 s.  c om*/
        public void buttonClick(ClickEvent event) {
            try {
                WorkloadGeneratorFacade.getInstance().removeSlave();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    return removeSlaveButton;
}

From source file:pl.edu.agh.samm.testapp.SAMMTestApplication.java

License:Apache License

private Button createAddSlaveButton() {
    final Button addSlaveButton = new Button("Add slave");

    addSlaveButton.addClickListener(new Button.ClickListener() {
        @Override//from w  w  w .ja va  2 s .  c  om
        public void buttonClick(ClickEvent event) {
            WorkloadGeneratorFacade.getInstance().addSlave();
        }
    });

    return addSlaveButton;
}

From source file:pl.edu.agh.samm.testapp.SAMMTestApplication.java

License:Apache License

private Button createGenerationControlButton() {
    final Button generationControl = new Button(START_WORKLOAD);
    generationControl.addClickListener(new Button.ClickListener() {
        @Override//from w  w  w . java  2 s.  com
        public void buttonClick(ClickEvent event) {
            try {
                WorkloadGeneratorFacade workloadGeneratorFacade = WorkloadGeneratorFacade.getInstance();
                if (generationControl.getCaption().equals(START_WORKLOAD)) {
                    publishMessage("Starting expressions generation...");
                    workloadGeneratorFacade
                            .startGenerating(Long.parseLong(expressionsPerMinuteTextField.getValue()));
                    publishMessage("Started expressions generation");
                    generationControl.setCaption(STOP_WORKLOAD);
                } else {
                    publishMessage("Stopping expressions generation...");
                    workloadGeneratorFacade.stopGenerating();
                    publishMessage("Stopped expressions generation");
                    generationControl.setCaption(START_WORKLOAD);
                }
            } catch (InterruptedException e) {
                publishMessage("Error! " + e.getMessage());
                e.printStackTrace();
            }
        }
    });
    return generationControl;
}

From source file:ru.codeinside.adm.ui.GroupEditor.java

License:Mozilla Public License

private void showEditor(String nameGroup) {
    List<Group> groups = AdminServiceProvider.get().findGroupByName(nameGroup);
    for (final Group g : groups) {
        Label header = new Label(
                " : " + g.getTitle() + " (" + nameGroup + ")");
        header.setStyleName("h2");
        addComponent(header);// w  w  w .java  2  s.  co m
        Button delete = new Button("", new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                String confirmMessage = " ,    ?";
                Window confirmWindow = new ConfirmWindow(confirmMessage);
                confirmWindow.addListener(new Listener() {
                    @Override
                    public void componentEvent(Event event) {
                        if (event instanceof ConfirmWindow.ConfirmOkEvent) {
                            AdminServiceProvider.get().deleteGroup(g.getId());
                            table.removeItem(g.getName());
                        }
                    }
                });
                getWindow().addWindow(confirmWindow);
            }
        });
        addComponent(delete);
    }
    final FilterTable all = new FilterTable();
    all.setCaption("? ? " + typeGroup.toLowerCase());
    table(all);
    final FilterTable current = new FilterTable();
    current.setCaption(" " + typeGroup.toLowerCase());
    table(current);
    addListener(all, current, current);
    addListener(current, all, current);
    addTableContent(all, current);
}

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

License:Open Source License

/**
 * Creates a new RoleDeleteEditor instance.
 *
 * @param userServiceAdmin The user admin service for editing the role.
 *//*  w  w  w  .ja v  a  2  s  . c  om*/
public RoleDeleteEditor(APSSimpleUserServiceAdmin userServiceAdmin) {
    this.userServiceAdmin = userServiceAdmin;
    this.setStyleName(CSS.APS_EDITING_TEXT);

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

    this.idPanel = new Panel();
    this.idPanel.setCaption("Role id");
    this.idLabel = new Label("");
    this.idPanel.addComponent(this.idLabel);
    verticalLayout.addComponent(idPanel);

    this.descriptionPanel = new Panel();
    this.descriptionPanel.setCaption("Description");
    this.descriptionLabel = new Label("");
    this.descriptionPanel.addComponent(this.descriptionLabel);
    verticalLayout.addComponent(this.descriptionPanel);

    this.subRolesPanel = new Panel();
    this.subRolesPanel.setCaption("Sub roles");
    this.subRolesLabel = new Label("");
    this.subRolesPanel.addComponent(this.subRolesLabel);
    verticalLayout.addComponent(this.subRolesPanel);

    HorizontalLayout horizontalLayout = new HorizontalLayout();
    verticalLayout.addComponent(horizontalLayout);
    horizontalLayout.setSpacing(true);

    Button deleteButton = new Button("Delete");
    deleteButton.addListener(new Button.ClickListener() {
        /** Click handling. */
        @Override
        public void buttonClick(Button.ClickEvent event) {
            delete();
        }
    });
    horizontalLayout.addComponent(deleteButton);

    Button cancelButton = new Button("Cancel");
    cancelButton.addListener(new Button.ClickListener() {
        /** Click handling. */
        @Override
        public void buttonClick(Button.ClickEvent event) {
            cancel();
        }
    });
    horizontalLayout.addComponent(cancelButton);

    setContent(verticalLayout);
}

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

License:Open Source License

/**
 * Creates a new RoleEditor instance./*from  w ww.ja v  a 2 s.c om*/
 *
 * @param userServiceAdmin The user admin service for editing the role.
 */
public RoleEditor(APSSimpleUserServiceAdmin userServiceAdmin) {
    this.userServiceAdmin = userServiceAdmin;

    this.setStyleName(CSS.APS_EDITING_TEXT);

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

    // Role id, master and description.
    {
        HorizontalLayout horizLayout = new HorizontalLayout();
        horizLayout.setSpacing(true);

        this.idTextField = new TextField("Role id");
        this.idTextField.setColumns(30);
        this.idTextField.setImmediate(false);
        this.idTextField.setEnabled(true);
        horizLayout.addComponent(this.idTextField);

        this.masterRole = new CheckBox("Master Role");
        this.masterRole.setImmediate(false);
        this.masterRole.setEnabled(true);
        horizLayout.addComponent(this.masterRole);

        verticalLayout.addComponent(horizLayout);

        this.descriptionTextArea = new TextArea("Description of role");
        this.descriptionTextArea.setRows(3);
        this.descriptionTextArea.setColumns(60);
        this.descriptionTextArea.setImmediate(false);
        this.descriptionTextArea.setEnabled(true);
        verticalLayout.addComponent(this.descriptionTextArea);
    }

    // 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();
                removeSubRole(itemId);
            }

            @Override
            public AcceptCriterion getAcceptCriterion() {
                return new RoleAcceptCriterion(RoleEditor.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 sub roles of the role");
        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();
                addSubRole(itemId);
            }

            @Override
            public AcceptCriterion getAcceptCriterion() {
                return new RoleAcceptCriterion(RoleEditor.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);

        /* Help text for the role tables. */
        HelpText roleHelptext = new HelpText(
                "Drag and drop roles back and forth to set or remove a role. Also note that it is fully possible to "
                        + "create circular role dependencies. Don't!");
        verticalLayout.addComponent(roleHelptext);
    }

    // Save / Cancel
    {
        HorizontalLayout horizontalLayout = new HorizontalLayout();
        verticalLayout.addComponent(horizontalLayout);
        horizontalLayout.setSpacing(true);

        Button saveButton = new Button("Save");
        saveButton.addListener(new Button.ClickListener() {
            /** Click handling. */
            @Override
            public void buttonClick(Button.ClickEvent event) {
                save();
            }
        });
        horizontalLayout.addComponent(saveButton);

        Button cancelButton = new Button("Cancel");
        cancelButton.addListener(new Button.ClickListener() {
            /** Click handling. */
            @Override
            public void buttonClick(Button.ClickEvent event) {
                cancel();
            }
        });
        horizontalLayout.addComponent(cancelButton);
    }

    setContent(verticalLayout);
}