Example usage for com.vaadin.ui Button addListener

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

Introduction

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

Prototype

@Override
    public Registration addListener(Component.Listener listener) 

Source Link

Usage

From source file:org.apache.ace.webui.vaadin.VaadinClient.java

License:Apache License

private Button createManageResourceProcessorsButton() {
    // Solves ACE-224
    Button button = new Button("RP");
    button.addListener(new Button.ClickListener() {
        @Override//from  ww w  .j ava2 s  .c  o  m
        public void buttonClick(ClickEvent event) {
            showManageResourceProcessorsDialog();
        }
    });
    return button;
}

From source file:org.apache.ace.webui.vaadin.VaadinClient.java

License:Apache License

private Button createRegisterTargetsButton() {
    final Button button = new Button("R");
    button.setDisableOnClick(true);/*w ww .j  av a 2 s.c  om*/
    button.setImmediate(true);
    button.setEnabled(false);
    button.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            m_targetsPanel.registerSelectedTargets();
        }
    });
    m_targetsPanel.addListener(new ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            TargetsPanel targetsPanel = (TargetsPanel) event.getProperty();

            Collection<?> itemIDs = (Collection<?>) targetsPanel.getValue();

            boolean enabled = false;
            for (Object itemID : itemIDs) {
                if (targetsPanel.isItemRegistrationNeeded(itemID)) {
                    enabled = true;
                    break;
                }
            }

            button.setEnabled(enabled);
        }
    });
    return button;
}

From source file:org.axonframework.examples.addressbook.vaadin.ui.SearchView.java

License:Apache License

public SearchView() {
    setCaption("Search for contacts");
    setSizeFull();//  w w  w  .  j a v a 2  s .c  o m

    FormLayout formLayout = new FormLayout();
    setContent(formLayout);

    tf = new TextField("Search term");
    fieldToSearch = new NativeSelect("Field to search");
    saveSearch = new CheckBox("Save search");
    searchName = new TextField("Search name");
    Button search = new Button("Search");
    search.addListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            performSearch();
        }
    });
    for (int i = 0; i < ContactContainer.NATURAL_COL_ORDER.length; i++) {
        fieldToSearch.addItem(ContactContainer.NATURAL_COL_ORDER[i]);
        fieldToSearch.setItemCaption(ContactContainer.NATURAL_COL_ORDER[i],
                ContactContainer.COL_HEADERS_ENGLISH[i]);
    }
    fieldToSearch.setValue("name");
    fieldToSearch.setNullSelectionAllowed(false);
    saveSearch.setValue(true);
    addComponent(tf);
    addComponent(fieldToSearch);
    addComponent(saveSearch);
    addComponent(searchName);
    addComponent(search);

    saveSearch.setImmediate(true);
    saveSearch.addListener(new Button.ClickListener() {
        public void buttonClick(Button.ClickEvent event) {
            searchName.setVisible(event.getButton().booleanValue());
        }
    });
}

From source file:org.eclipse.skalli.view.component.LinkWindow.java

License:Open Source License

/**
 * Render the window// w w w. ja  v  a 2 s  .c  om
 */
@SuppressWarnings("serial")
private void createContents(String title) {
    setModal(true);
    setCaption(title);

    setWidth("400px"); //$NON-NLS-1$
    setHeight("300px"); //$NON-NLS-1$

    root = new VerticalLayout();
    root.setMargin(true);
    root.setSpacing(true);

    final ComboBox cbLinkGroup = new ComboBox("Link Group");
    cbLinkGroup.setInputPrompt("Enter a new group name or select from the list");
    cbLinkGroup.setWidth("100%"); //$NON-NLS-1$
    for (String groupName : knownGroups) {
        cbLinkGroup.addItem(groupName);
    }
    if (oldGroup != null && knownGroups.contains(oldGroup.getCaption())) {
        cbLinkGroup.select(oldGroup.getCaption());
    }
    cbLinkGroup.setImmediate(true);
    cbLinkGroup.setNullSelectionAllowed(false);
    cbLinkGroup.setNewItemsAllowed(true);
    cbLinkGroup.setNewItemHandler(new NewItemHandler() {
        @Override
        public void addNewItem(String newGroupName) {
            cbLinkGroup.removeAllItems();
            for (String groupName : knownGroups) {
                cbLinkGroup.addItem(groupName);
            }
            if (!cbLinkGroup.containsId(newGroupName)) {
                cbLinkGroup.addItem(newGroupName);
            }
            cbLinkGroup.select(newGroupName);
        }
    });
    cbLinkGroup.setRequired(true);
    cbLinkGroup.addValidator(new StringValidator());
    root.addComponent(cbLinkGroup);

    final TextField tfLinkCaption = new TextField("Page Title");
    tfLinkCaption.setInputPrompt("Enter a descriptive name for the page");
    tfLinkCaption.setWidth("100%"); //$NON-NLS-1$
    tfLinkCaption.setImmediate(true);
    tfLinkCaption.setRequired(true);
    tfLinkCaption.addValidator(new StringValidator());
    if (link != null) {
        tfLinkCaption.setValue(link.getLabel());
    }
    root.addComponent(tfLinkCaption);

    final TextField tfLinkURL = new TextField("URL");
    tfLinkURL.setInputPrompt("e.g. http://www.your-site.domain/path");
    tfLinkURL.setWidth("100%"); //$NON-NLS-1$
    tfLinkURL.setImmediate(true);
    tfLinkURL.setRequired(true);
    tfLinkURL.addValidator(new StringValidator());
    tfLinkURL.addValidator(new URLValidator());
    if (link != null) {
        tfLinkURL.setValue(link.getUrl());
    }
    root.addComponent(tfLinkURL);

    final Button okAndCloseButton = new Button("OK & Close");
    okAndCloseButton.setIcon(ICON_BUTTON_OK);
    okAndCloseButton.setDescription("Performs the action and closes the dialog.");
    okAndCloseButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            validateInput(cbLinkGroup);
            validateInput(tfLinkURL);
            validateInput(tfLinkCaption);

            if (cbLinkGroup.isValid() && tfLinkURL.isValid() && tfLinkCaption.isValid()) {
                String groupName = String.valueOf(cbLinkGroup.getValue());
                String linkLabel = String.valueOf(tfLinkCaption.getValue());
                String linkUrl = String.valueOf(tfLinkURL.getValue());

                if (linkAddedHandler != null) {
                    Link link = new Link(linkUrl, linkLabel);
                    linkAddedHandler.onLinkAdded(groupName, link);
                    close();
                }

                if (linkModifiedHandler != null) {
                    boolean linkModified = !link.getLabel().equals(linkLabel) || !link.getUrl().equals(linkUrl);
                    link.setLabel(linkLabel);
                    link.setUrl(linkUrl);
                    linkModifiedHandler.onLinkModified(oldGroup, groupName, link, linkModified);
                    close();
                }
            }
        }
    });
    root.addComponent(okAndCloseButton);

    root.setSizeFull();
    setContent(root);
}

From source file:org.eclipse.skalli.view.component.MultiComboBox.java

License:Open Source License

private Button createAddButton() {
    Button b = new Button("Add");
    b.setStyleName(Button.STYLE_LINK);
    b.addStyleName(STYLE_BUTTON);//  w ww  .j av a 2 s  .  c  om
    b.setDescription("Add another entry");
    b.setEnabled(!readOnly);
    b.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            ComboBox cb = createComboBox(null);
            cb.setWidth(columns, Select.UNITS_EM);
            comboBoxEntries.add(new ComboBoxElement(cb));
            layout.removeAllComponents();
            renderComboBoxes();
        }
    });
    return b;
}

From source file:org.eclipse.skalli.view.component.MultiComboBox.java

License:Open Source License

private Button createRemoveButton() {
    Button b = new Button("Remove");
    b.setStyleName(Button.STYLE_LINK);
    b.addStyleName(STYLE_BUTTON);//from  w w w  . ja v a 2  s. co m
    b.setDescription("Remove this entry");
    b.setEnabled(!readOnly);
    b.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Button b = event.getButton();
            Iterator<ComboBoxElement> it = comboBoxEntries.iterator();
            while (it.hasNext()) {
                ComboBoxElement element = it.next();
                if (element.removeButton == b) {
                    it.remove();
                    break;
                }
            }
            layout.removeAllComponents();
            renderComboBoxes();
        }
    });
    return b;
}

From source file:org.eclipse.skalli.view.component.MultiLinkField.java

License:Open Source License

@SuppressWarnings({ "serial", "deprecation" })
private void render() {
    layout.removeAllComponents();/*  www.  jav a 2 s  .  c  o  m*/
    if (!readOnly) {
        layout.setColumns(2);
    }

    int groupsIdx = 0;
    int groupsSize = linkGroups.getItems().size();
    for (final LinkGroup linkGroup : linkGroups.getItems()) {
        Label linkGroupLabel = new Label(linkGroup.getCaption());
        linkGroupLabel.addStyleName(STYLE_LABEL_GROUP);

        layout.addComponent(linkGroupLabel);
        layout.setComponentAlignment(linkGroupLabel, Alignment.TOP_RIGHT);

        if (!readOnly) {
            Button btnUpGroup = null;
            Button btnDownGroup = null;
            Button btnRemoveGroup = null;
            // up
            if (groupsIdx > 0) {
                btnUpGroup = new Button("up");
                btnUpGroup.setStyleName(Button.STYLE_LINK);
                btnUpGroup.addStyleName(STYLE_BUTTON_GROUPACTION);
                btnUpGroup.setDescription(String.format("Move up group '%s'", linkGroup.getCaption()));
                btnUpGroup.addListener(new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        modified = linkGroups.moveUp(linkGroup);
                        renderIfModified();
                    }
                });
            }
            // down
            if (groupsIdx < groupsSize - 1) {
                btnDownGroup = new Button("down");
                btnDownGroup.setStyleName(Button.STYLE_LINK);
                btnDownGroup.addStyleName(STYLE_BUTTON_GROUPACTION);
                btnDownGroup.setDescription(String.format("Move down group '%s'", linkGroup.getCaption()));
                btnDownGroup.addListener(new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        modified = linkGroups.moveDown(linkGroup);
                        renderIfModified();
                    }
                });
            }
            // remove
            btnRemoveGroup = new Button("remove");
            btnRemoveGroup.setStyleName(Button.STYLE_LINK);
            btnRemoveGroup.addStyleName(STYLE_BUTTON_GROUPACTION);
            btnRemoveGroup.setDescription(String.format("Remove group '%s'", linkGroup.getCaption()));
            btnRemoveGroup.addListener(new Button.ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    modified = linkGroups.remove(linkGroup);
                    renderIfModified();
                }
            });

            HorizontalLayout toolbar = getToolbar(btnUpGroup, btnDownGroup, btnRemoveGroup);
            layout.addComponent(toolbar);
            layout.setComponentAlignment(toolbar, Alignment.TOP_RIGHT);
        }

        layout.newLine();

        Collection<Link> links = linkGroup.getItems();
        int linksIdx = 0;
        int linksSize = links.size();
        for (final Link link : links) {

            if (readOnly) {
                // view
                Label linkLabel = new Label(link.getLabel());
                linkLabel.addStyleName(STYLE_LABEL_LINK);
                linkLabel.setDescription(StringUtils.abbreviate(link.getUrl(), 50));
                layout.addComponent(linkLabel);
                layout.setComponentAlignment(linkLabel, Alignment.TOP_LEFT);
            } else {
                // edit
                Button btnEditLink = new Button(link.getLabel());
                btnEditLink.setStyleName(Button.STYLE_LINK);
                btnEditLink.addStyleName(STYLE_LABEL_LINK);
                btnEditLink.setDescription(String.format("Edit link '%s' %s", link.getLabel(),
                        StringUtils.isBlank(link.getUrl()) ? "" : "[" + link.getUrl() + "]"));
                btnEditLink.addListener(new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        LinkWindow editLinkWindow = new LinkWindow(MultiLinkField.this, linkGroups.getItems(),
                                linkGroup, link, MultiLinkField.this);
                        editLinkWindow.show();
                    }
                });
                layout.addComponent(btnEditLink);
                layout.setComponentAlignment(btnEditLink, Alignment.TOP_LEFT);
            }

            if (!readOnly) {
                Button btnUpLink = null;
                Button btnDownLink = null;
                Button btnRemoveLink = null;
                // up
                if (linksIdx > 0) {
                    btnUpLink = new Button("up");
                    btnUpLink.setStyleName(Button.STYLE_LINK);
                    btnUpLink.addStyleName(STYLE_BUTTON_LINKACTION);
                    btnUpLink.setDescription(String.format("Move up link '%s'", link.getLabel()));
                    btnUpLink.addListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(ClickEvent event) {
                            modified = linkGroup.moveUp(link);
                            renderIfModified();
                        }
                    });
                }
                // down
                if (linksIdx < linksSize - 1) {
                    btnDownLink = new Button("down");
                    btnDownLink.setStyleName(Button.STYLE_LINK);
                    btnDownLink.addStyleName(STYLE_BUTTON_LINKACTION);
                    btnDownLink.setDescription(String.format("Move down link '%s'", link.getLabel()));
                    btnDownLink.addListener(new Button.ClickListener() {
                        @Override
                        public void buttonClick(ClickEvent event) {
                            modified = linkGroup.moveDown(link);
                            renderIfModified();
                        }
                    });
                }
                // remove
                btnRemoveLink = new Button("remove");
                btnRemoveLink.setStyleName(Button.STYLE_LINK);
                btnRemoveLink.addStyleName(STYLE_BUTTON_LINKACTION);
                btnRemoveLink.setDescription(String.format("Remove link '%s'", link.getLabel()));
                btnRemoveLink.addListener(new Button.ClickListener() {
                    @Override
                    public void buttonClick(ClickEvent event) {
                        modified = linkGroup.remove(link);
                        if (linkGroup.getItems().isEmpty()) {
                            linkGroups.remove(linkGroup);
                        }
                        renderIfModified();
                    }
                });

                HorizontalLayout toolbar = getToolbar(btnUpLink, btnDownLink, btnRemoveLink);
                layout.addComponent(toolbar);
                layout.setComponentAlignment(toolbar, Alignment.TOP_RIGHT);
            }

            layout.newLine();

            linksIdx++;
        }

        groupsIdx++;
    }

    if (!readOnly) {
        Button btnAddLink = new Button(buttonCaption, new Button.ClickListener() {
            @Override
            public void buttonClick(ClickEvent event) {
                LinkWindow addLinkWindow = new LinkWindow(MultiLinkField.this, linkGroups.getItems(),
                        MultiLinkField.this);
                addLinkWindow.show();
            }
        });
        btnAddLink.setStyleName(Button.STYLE_LINK);
        btnAddLink.addStyleName(STYLE_BUTTON_ADD);
        btnAddLink.setDescription("Add Link");
        layout.addComponent(btnAddLink);
    }
}

From source file:org.eclipse.skalli.view.component.MultiTextField.java

License:Open Source License

private Button createAddButton() {
    Button b = new Button("Add");
    b.setStyleName(Button.STYLE_LINK);
    b.addStyleName(STYLE_BUTTON);//  w  w  w  .  ja v  a2s  . com
    b.setDescription("Add another entry");
    //b.setIcon(ICON_BUTTON_ADD);
    b.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            TextField tf = createTextField("");
            textFieldEntries.add(new TextFieldEntry(tf));
            layout.removeAllComponents();
            renderTextFields();
        }
    });
    return b;
}

From source file:org.eclipse.skalli.view.component.MultiTextField.java

License:Open Source License

private Button createRemoveButton() {
    Button b = new Button("Remove");
    b.setStyleName(Button.STYLE_LINK);
    b.addStyleName(STYLE_BUTTON);/*www  .  j a v a  2s .co  m*/
    b.setDescription("Remove this entry");
    //b.setIcon(ICON_BUTTON_REMOVE);
    b.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Button b = event.getButton();
            Iterator<TextFieldEntry> it = textFieldEntries.iterator();
            while (it.hasNext()) {
                TextFieldEntry textFieldEntry = it.next();
                if (textFieldEntry.removeButton == b) {
                    it.remove();
                    break;
                }
            }
            layout.removeAllComponents();
            renderTextFields();
        }
    });
    return b;
}

From source file:org.eclipse.skalli.view.component.PeopleSearchWindow.java

License:Open Source License

private void createContents() {
    setModal(true);/*from   w  w w .ja  va 2s.  c o  m*/
    setCaption("Search people...");

    setWidth("310px"); //$NON-NLS-1$
    setHeight("400px"); //$NON-NLS-1$

    root = new VerticalLayout();
    root.setMargin(true);
    root.setSpacing(true);

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

    searchField = new TextField("Search for:");
    searchField.setWidth("20em"); //$NON-NLS-1$
    searchField.setImmediate(true);
    searchField.addListener(new ValueChangeListener() {
        @Override
        public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
            search((String) searchField.getValue());
            list.focus();
        }
    });
    search.addComponent(searchField);
    search.setComponentAlignment(searchField, Alignment.BOTTOM_LEFT);
    search.setExpandRatio(searchField, 1.0f);

    Button searchButton = new NativeButton("", new Button.ClickListener() { //$NON-NLS-1$
        @Override
        public void buttonClick(ClickEvent event) {
            search((String) searchField.getValue());
        }
    });
    searchButton.setDescription("Search");
    searchButton.setStyleName(STYLE_USER_DOSEARCH);
    search.addComponent(searchButton);
    search.setComponentAlignment(searchButton, Alignment.BOTTOM_LEFT);
    search.setExpandRatio(searchButton, 0);

    root.addComponent(search);

    list = new ListSelect("Search results:", dataSource);
    list.setSizeFull();
    list.setMultiSelect(true);
    list.setImmediate(true);

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

    Button addButton = new Button("Add");
    addButton.setIcon(ICON_BUTTON_ADD_SELECTED);
    addButton.setDescription("Adds the selected person to the list.");
    addButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Set<User> values = (Set<User>) list.getValue();
            if (selectHandler != null && values != null) {
                selectHandler.onPeopleSelected(values);
                list.removeAllItems();
                searchField.setValue(""); //$NON-NLS-1$
                searchField.focus();
            }
        }
    });
    buttons.addComponent(addButton);

    Button addAndCloseButton = new Button("Add & Close");
    addAndCloseButton.setIcon(ICON_BUTTON_ADD_SELECTED);
    addAndCloseButton.setDescription("Adds the selected person to the list and closes the dialog.");
    addAndCloseButton.addListener(new Button.ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Set<User> values = (Set<User>) list.getValue();
            if (selectHandler != null && values != null) {
                selectHandler.onPeopleSelected(values);
                close();
            }
        }
    });
    buttons.addComponent(addAndCloseButton);

    root.addComponent(list);
    root.addComponent(buttons);
    root.setSizeFull();
    root.setExpandRatio(list, 1);
    //    root.setStyleName(STYLE_LAYOUT);
    setContent(root);
    searchField.focus();
}