Example usage for com.vaadin.ui Button addClickListener

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

Introduction

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

Prototype

public Registration addClickListener(ClickListener listener) 

Source Link

Document

Adds the button click listener.

Usage

From source file:com.klwork.explorer.ui.task.UserDetailsComponent.java

License:Apache License

protected void addUserDetails() {
    VerticalLayout detailsLayout = new VerticalLayout();
    addComponent(detailsLayout);// ww w .  j av a  2  s  . c o m

    // Layout for name + skype
    HorizontalLayout nameLayout = new HorizontalLayout();
    nameLayout.setSpacing(true);
    detailsLayout.addComponent(nameLayout);

    // Name 
    Label nameLabel = null;
    if (user != null) {
        nameLabel = new Label(user.getFirstName() + " " + user.getLastName());
        nameLabel.addStyleName(ExplorerLayout.STYLE_LABEL_BOLD);
    } else {
        nameLabel = new Label(" ", Label.CONTENT_XHTML);
    }
    nameLayout.addComponent(nameLabel);

    // Layout for lower details
    HorizontalLayout actionsLayout = new HorizontalLayout();
    actionsLayout.setSpacing(true);
    detailsLayout.addComponent(actionsLayout);

    // Role
    Label roleLabel = new Label(role);
    actionsLayout.addComponent(roleLabel);

    // Action button
    if (clickListener != null) {
        Button button = new Button(buttonCaption);
        button.addStyleName(Reindeer.BUTTON_SMALL);
        button.addClickListener(clickListener);
        actionsLayout.addComponent(button);
    }
}

From source file:com.klwork.explorer.ui.user.ProfilePanel.java

License:Apache License

protected Button initEditProfileButton() {
    Button editProfileButton = new Button(i18nManager.getMessage(Messages.PROFILE_EDIT));
    editProfileButton.setIcon(Images.EDIT);
    editProfileButton.addClickListener(new ClickListener() {
        public void buttonClick(ClickEvent event) {
            editable = true;//  ww  w.ja va  2s .c o m
            initUi();
        }
    });
    return editProfileButton;
}

From source file:com.klwork.explorer.ui.user.ProfilePanel.java

License:Apache License

protected Button initSaveProfileButton() {
    Button saveProfileButton = new Button(i18nManager.getMessage(Messages.PROFILE_SAVE));
    saveProfileButton.setIcon(Images.SAVE);
    saveProfileButton.addClickListener(new ClickListener() {
        public void buttonClick(ClickEvent event) {
            user.setFirstName((String) firstNameField.getValue());
            user.setLastName((String) lastNameField.getValue());
            user.setEmail((String) emailField.getValue());
            identityService.saveUser(user);

            identityService.setUserInfo(user.getId(), Constants.USER_INFO_JOB_TITLE,
                    jobTitleField.getValue().toString());
            if (birthDateField.getValue() != null && !"".equals(birthDateField.getValue().toString())) {
                identityService.setUserInfo(user.getId(), Constants.USER_INFO_BIRTH_DATE,
                        new SimpleDateFormat(Constants.DEFAULT_DATE_FORMAT).format(birthDateField.getValue()));
            }/*from   w  ww. j a v a2  s . co m*/
            identityService.setUserInfo(user.getId(), Constants.USER_INFO_LOCATION,
                    locationField.getValue().toString());
            identityService.setUserInfo(user.getId(), Constants.USER_INFO_PHONE,
                    phoneField.getValue().toString());
            identityService.setUserInfo(user.getId(), Constants.USER_INFO_TWITTER,
                    twitterField.getValue().toString());
            identityService.setUserInfo(user.getId(), Constants.USER_INFO_SKYPE,
                    skypeField.getValue().toString());

            // UI
            editable = false;
            loadProfileData();
            initUi();

            // Update user cache
            ViewToolManager.getUserCache().notifyUserDataChanged(user.getId());
        }
    });
    return saveProfileButton;
}

From source file:com.klwork.flow.act.MyTaskRelatedContentComponent.java

License:Apache License

protected Button getAddButton() {
    // Add content button
    Button addRelatedContentButton = new Button();
    ////from   w  w w . j  a  v a 2s . c o  m
    addRelatedContentButton.addStyleName(ExplorerLayout.STYLE_ADD);
    addRelatedContentButton.addClickListener(new com.vaadin.ui.Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        public void buttonClick(com.vaadin.ui.Button.ClickEvent event) {
            CreateAttachmentPopupWindow popup = new CreateAttachmentPopupWindow();
            //??
            if (task.getProcessInstanceId() != null) {
                popup.setProcessInstanceId(task.getProcessInstanceId());
            }

            // Add listener to update attachments when added
            popup.addListener(new SubmitEventListener() {

                private static final long serialVersionUID = 1L;

                @Override
                protected void submitted(SubmitEvent event) {
                    taskForm.notifyRelatedContentChanged();
                }

                @Override
                protected void cancelled(SubmitEvent event) {
                    // No attachment was added so updating UI isn't
                    // needed.
                }
            });

            ViewToolManager.showPopupWindow(popup);
        }
    });
    return addRelatedContentButton;
}

From source file:com.liferay.vaadin.poc.ui.PortletUI.java

License:Open Source License

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setWidth(100, Unit.PERCENTAGE);
    setContent(layout);//from  w  ww .j a  va  2 s.  c o m
    notes = new BeanItemContainer<Note>(Note.class);

    notes.addBean(new Note(noteCounter++, new Date(), "example note"));

    table = new Table("Notes", notes);
    table.setVisibleColumns(new Object[] { "time", "text" });
    table.setPageLength(7);
    table.setBuffered(false);
    table.setSelectable(true);
    table.setWidth(100, Unit.PERCENTAGE);

    textField = new TextField("Text");
    textField.setWidth(100, Unit.PERCENTAGE);
    layout.addComponent(textField);

    Button addButton = new Button("Add");
    addButton.setWidth(100, Unit.PERCENTAGE);
    layout.addComponent(addButton);
    removeButton = new Button("Remove");
    removeButton.setWidth(100, Unit.PERCENTAGE);
    removeButton.setEnabled(false);
    layout.addComponent(removeButton);

    layout.addComponent(table);

    addButton.addClickListener((event) -> {
        notes.addBean(new Note(noteCounter++, new Date(), textField.getValue()));
    });

    removeButton.addClickListener((event) -> {
        if (selectedNote != null) {
            notes.removeItem(selectedNote);
            selectedNote = null;
        }
        removeButton.setEnabled(selectedNote != null);
    });

    // Handle selection change.
    table.addValueChangeListener((event) -> {
        selectedNote = (Note) table.getValue();
        removeButton.setEnabled(selectedNote != null);
    });
}

From source file:com.logicbomb.newschool.MyAppWidgetSet.LoginWidget.java

public LoginWidget() {
    setMargin(true);/*from ww  w.  ja  va  2 s .co  m*/
    setSpacing(true);

    Panel iPanel = new Panel();
    iPanel.addStyleName("backColorWhite");
    iPanel.setSizeUndefined();

    addComponent(iPanel);

    TextField iTextField = new TextField("Username");
    iTextField.setWidth("300px");
    iTextField.setRequired(true);
    iTextField.setInputPrompt("Your username (eg. joe@email.com)");
    iTextField.setIcon(FontAwesome.USER);
    iTextField.addValidator(new EmailValidator("Username must be an email address"));
    iTextField.setInvalidAllowed(true);
    iTextField.focus();

    PasswordField iPasswordField = new PasswordField("Password");
    iPasswordField.setIcon(FontAwesome.KEY);
    iPasswordField.setWidth("300px");
    iPasswordField.setRequired(true);
    iPasswordField.setValue("");
    iPasswordField.setNullRepresentation("");

    Button iButton = new Button("Login");
    iButton.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            addComponent(new Label("Login Successfully"));
        }
    });

    FormLayout iFormLayout = new FormLayout();
    iFormLayout.setSpacing(true);
    iFormLayout.setMargin(true);
    iFormLayout.addComponent(iTextField);
    iFormLayout.addComponent(iPasswordField);
    iFormLayout.addComponent(iButton);
    iPanel.setContent(iFormLayout);

}

From source file:com.lst.deploymentautomation.vaadin.core.AppLayout.java

License:Open Source License

private void initLayout() {
    addStyleName("app-layout");
    setSizeFull();/*from  ww  w.  j a v  a 2s. c  o m*/

    //main page layout
    layout = new CustomLayout("page");
    layout.setSizeFull();
    setCompositionRoot(layout);

    //navigation menu
    VerticalLayout navLayout = new VerticalLayout();
    navLayout.setSizeFull();
    layout.addComponent(navLayout, "usermenu");
    navigation = new NavigationMenu();
    navigation.addStyleName("navigation-menu");
    layout.addComponent(navigation, "navigation");

    final UserInfo user = ((LspsUI) UI.getCurrent()).getUser();
    LspsUI ui = (LspsUI) UI.getCurrent();

    if (user.hasRight(HumanRights.READ_ALL_TODO) || user.hasRight(HumanRights.READ_OWN_TODO)) {
        addViewItem(navigation, TodoListView.TITLE, TodoListView.ID, FontAwesome.LIST);
    }
    /*if (user.hasRight(HumanRights.ACCESS_DOCUMENTS)) {
       addViewItem(navigation, DocumentsView.TITLE, DocumentsView.ID, FontAwesome.FILE_TEXT_O);
    }
    if (user.hasRight(EngineRights.READ_MODEL) && user.hasRight(EngineRights.CREATE_MODEL_INSTANCE)) {
       addViewItem(navigation, RunModelView.TITLE, RunModelView.ID, FontAwesome.CARET_SQUARE_O_RIGHT);
    }*/

    addNavigationCommandItem(navigation, "Initialize deployment", new NavigationMenu.OpenDocumentCommand(ui, "",
            "'deployment-automation-ui'::InitiateDeploymentDoc", null), FontAwesome.PLAY);
    addNavigationCommandItem(navigation, "Deployments list",
            new NavigationMenu.OpenDocumentCommand(ui, "", "'deployment-automation-ui'::DeploymentsList", null),
            FontAwesome.LIST_OL);

    //user menu
    userMenu = new NavigationMenu();
    userMenu.addStyleName("navigation-menu");
    navLayout.addComponent(userMenu);

    addViewItem(userMenu, SettingsView.TITLE, SettingsView.ID, FontAwesome.COG);

    NavigationCommand logoutCmd = new LogoutCommand((LspsUI) getUI());
    MenuItem logout = addNavigationCommandItem(userMenu, logoutCmd.getTitle(), logoutCmd,
            FontAwesome.POWER_OFF);
    String fullName = user.getPerson().getFullName();
    logout.setDescription(ui.getMessage("nav.logout", fullName));

    boolean collapsed = user.getSettingBoolean("collapsedMenu", false);

    if (collapsed == true) {
        UI.getCurrent().addStyleName("l-menu-collapsed");
    }

    Button button = new Button("");
    button.addStyleName("l-menu-expander");
    button.addStyleName("link");
    navLayout.addComponent(button);
    button.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            boolean collapsed = user.getSettingBoolean("collapsedMenu", false);
            if (collapsed) {
                UI.getCurrent().removeStyleName("l-menu-collapsed");
            } else {
                UI.getCurrent().addStyleName("l-menu-collapsed");
            }
            user.setSetting("collapsedMenu", !collapsed);
        }
    });
}

From source file:com.m1kah.ui.MyVaadinUI.java

License:Open Source License

@Override
protected void init(VaadinRequest request) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);//  w  w w .java 2  s .c o  m
    setContent(layout);

    Button button = new Button("Click Me");
    button.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            layout.addComponent(new Label(messageService.getMessage()));
        }
    });
    layout.addComponent(button);
}

From source file:com.mcparland.john.vaadin_cookbook.CRUD.java

License:Apache License

/**
 * Create the form for the given item./*from   w  w w .j  a v a2  s.c om*/
 * 
 * @param item
 *            the item.
 * @return a layout for the form.
 */
@SuppressWarnings("serial")
private Layout createForm(Item item) {
    FormLayout layout = new FormLayout();
    layout.setSpacing(true);
    layout.setMargin(true);
    final FieldGroup group = new FieldGroup(item);
    for (Object propertyId : group.getUnboundPropertyIds()) {
        layout.addComponent(group.buildAndBind(propertyId));
    }
    Button button = new Button("Commmit");
    button.addClickListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            try {
                group.commit();
            } catch (CommitException e) {
                Notification.show(e.getCause().getMessage(), Notification.Type.ERROR_MESSAGE);
            }
        }
    });
    layout.addComponent(button);
    return layout;
}

From source file:com.mcparland.john.vaadin_cookbook.PriceList.java

License:Apache License

/**
 * Create the table./*from  www .j  a  va 2 s.c o m*/
 * <p>
 * Needs either {@link #PriceList(BeanItemContainer)} or
 * {@link #setContainer(BeanItemContainer)} to have been called first.
 * </p>
 * 
 * @return
 */
@SuppressWarnings("serial")
private Table createTable() {
    if (null == container) {
        return null;
    }

    // Basic table stuff.
    final Table table = new Table();
    table.setContainerDataSource(container);
    table.setEditable(true);

    // Allow items to be removed
    table.addGeneratedColumn("Remove", new Table.ColumnGenerator() {
        /*
         * (non-Javadoc)
         * 
         * @see
         * com.vaadin.ui.Table.ColumnGenerator#generateCell(com.vaadin.ui
         * .Table, java.lang.Object, java.lang.Object)
         */
        @Override
        // NOTE: I've made the itemId parameter final.
        public Object generateCell(Table source, final Object itemId, Object columnId) {
            Button removeButton = new Button("X");

            removeButton.addClickListener(new ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {
                    table.removeItem(itemId);
                }

            });

            return removeButton;
        }
    });

    return table;
}