Example usage for com.vaadin.ui Button setIcon

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

Introduction

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

Prototype

@Override
public void setIcon(Resource icon) 

Source Link

Document

Sets the component's icon.

Usage

From source file:com.esofthead.mycollab.vaadin.ui.table.CustomizedTableWindow.java

License:Open Source License

public CustomizedTableWindow(final String viewId, final AbstractPagedBeanTable<?, ?> table) {
    super("Customize View");
    this.viewId = viewId;
    this.addStyleName("customize-table-window");
    this.setWidth("400px");
    this.setResizable(false);
    this.setModal(true);
    this.center();

    this.tableItem = table;
    customViewStoreService = ApplicationContextUtil.getSpringBean(CustomViewStoreService.class);

    final VerticalLayout contentLayout = new VerticalLayout();
    contentLayout.setSpacing(true);//w  w  w  .  j  a  v  a2  s  . c om
    contentLayout.setMargin(true);
    this.setContent(contentLayout);

    this.listBuilder = new ListBuilder();
    this.listBuilder.setImmediate(true);
    this.listBuilder.setColumns(0);
    this.listBuilder.setLeftColumnCaption("Available Columns");
    this.listBuilder.setRightColumnCaption("View Columns");
    this.listBuilder.setWidth(100, Sizeable.Unit.PERCENTAGE);

    this.listBuilder.setItemCaptionMode(ItemCaptionMode.EXPLICIT);
    final BeanItemContainer<TableViewField> container = new BeanItemContainer<>(TableViewField.class,
            this.getAvailableColumns());
    this.listBuilder.setContainerDataSource(container);
    Iterator<TableViewField> iterator = getAvailableColumns().iterator();
    while (iterator.hasNext()) {
        TableViewField field = iterator.next();
        this.listBuilder.setItemCaption(field, AppContext.getMessage(field.getDescKey()));
    }
    this.setSelectedViewColumns();
    contentLayout.addComponent(this.listBuilder);
    contentLayout.setComponentAlignment(listBuilder, Alignment.MIDDLE_CENTER);

    Button restoreLink = new Button("Restore to default", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        @Override
        public void buttonClick(ClickEvent event) {
            List<TableViewField> defaultSelectedColumns = tableItem.getDefaultSelectedColumns();
            if (defaultSelectedColumns != null) {
                final List<TableViewField> selectedColumns = new ArrayList<>();
                final BeanItemContainer<TableViewField> container = (BeanItemContainer<TableViewField>) CustomizedTableWindow.this.listBuilder
                        .getContainerDataSource();
                final Collection<TableViewField> itemIds = container.getItemIds();

                for (TableViewField column : defaultSelectedColumns) {
                    for (final TableViewField viewField : itemIds) {
                        if (column.getField().equals(viewField.getField())) {
                            selectedColumns.add(viewField);
                        }
                    }
                }

                CustomizedTableWindow.this.listBuilder.setValue(selectedColumns);
            }

        }
    });
    restoreLink.setStyleName("link");
    contentLayout.addComponent(restoreLink);
    contentLayout.setComponentAlignment(restoreLink, Alignment.MIDDLE_RIGHT);

    final HorizontalLayout buttonControls = new HorizontalLayout();
    buttonControls.setSpacing(true);
    final Button saveBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SAVE),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @SuppressWarnings("unchecked")
                @Override
                public void buttonClick(final ClickEvent event) {
                    final List<TableViewField> selectedColumns = (List<TableViewField>) CustomizedTableWindow.this.listBuilder
                            .getValue();
                    table.setDisplayColumns(selectedColumns);
                    CustomizedTableWindow.this.close();

                    // Save custom table view def
                    CustomViewStore viewDef = new CustomViewStore();
                    viewDef.setSaccountid(AppContext.getAccountId());
                    viewDef.setCreateduser(AppContext.getUsername());
                    viewDef.setViewid(viewId);
                    viewDef.setViewinfo(XStreamJsonDeSerializer.toJson(new ArrayList<>(selectedColumns)));
                    customViewStoreService.saveOrUpdateViewLayoutDef(viewDef);
                }
            });
    saveBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    saveBtn.setIcon(FontAwesome.SAVE);
    buttonControls.addComponent(saveBtn);

    final Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(final ClickEvent event) {
                    CustomizedTableWindow.this.close();
                }
            });
    cancelBtn.setStyleName(UIConstants.THEME_GRAY_LINK);
    buttonControls.addComponent(cancelBtn);

    contentLayout.addComponent(buttonControls);
    contentLayout.setComponentAlignment(buttonControls, Alignment.MIDDLE_CENTER);
}

From source file:com.esofthead.mycollab.vaadin.ui.UserAvatarControlFactory.java

License:Open Source License

public static Button createUserAvatarEmbeddedButton(String avatarId, int size) {
    Button embedded = new Button();
    embedded.setIcon(createAvatarResource(avatarId, size));
    embedded.setStyleName(BaseTheme.BUTTON_LINK);
    return embedded;

}

From source file:com.esofthead.mycollab.vaadin.ui.UserAvatarControlFactory.java

License:Open Source License

public static Button createUserAvatarButtonLink(String userAvatarId, String fullName) {
    Button button = new Button();
    button.setIcon(createAvatarResource(userAvatarId, 48));
    button.setStyleName("link");
    return button;
}

From source file:com.esofthead.mycollab.vaadin.web.ui.AttachmentDisplayComponent.java

License:Open Source License

public void addAttachmentRow(final Content attachment) {
    String docName = attachment.getPath();
    int lastIndex = docName.lastIndexOf("/");
    if (lastIndex != -1) {
        docName = docName.substring(lastIndex + 1, docName.length());
    }//ww  w  . ja  va 2s  .  c o m

    final AbsoluteLayout attachmentLayout = new AbsoluteLayout();
    attachmentLayout.setWidth(UIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_WIDTH);
    attachmentLayout.setHeight(UIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_HEIGHT);
    attachmentLayout.setStyleName("attachment-block");

    CssLayout thumbnailWrap = new CssLayout();
    thumbnailWrap.setSizeFull();
    thumbnailWrap.setStyleName("thumbnail-wrap");

    Link thumbnail = new Link();
    if (StringUtils.isBlank(attachment.getThumbnail())) {
        thumbnail.setIcon(FileAssetsUtil.getFileIconResource(attachment.getName()));
    } else {
        thumbnail.setIcon(VaadinResourceFactory.getInstance().getResource(attachment.getThumbnail()));
    }

    if (MimeTypesUtil.isImageType(docName)) {
        thumbnail.setResource(VaadinResourceFactory.getInstance().getResource(attachment.getPath()));
        new Fancybox(thumbnail).setPadding(0).setVersion("2.1.5").setEnabled(true).setDebug(true);
    }

    Div contentTooltip = new Div().appendChild(new Span().appendText(docName).setStyle("font-weight:bold"));
    Ul ul = new Ul()
            .appendChild(new Li().appendText("Size: " + FileUtils.getVolumeDisplay(attachment.getSize())))
            .setStyle("line-height:1.5em");
    ul.appendChild(new Li().appendText(
            "Last modified: " + AppContext.formatPrettyTime(attachment.getLastModified().getTime())));
    contentTooltip.appendChild(ul);
    thumbnail.setDescription(contentTooltip.write());
    thumbnail.setWidth(UIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_WIDTH);
    thumbnailWrap.addComponent(thumbnail);

    attachmentLayout.addComponent(thumbnailWrap, "top: 0px; left: 0px; bottom: 0px; right: 0px; z-index: 0;");

    CssLayout attachmentNameWrap = new CssLayout();
    attachmentNameWrap.setWidth(UIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_WIDTH);
    attachmentNameWrap.setStyleName("attachment-name-wrap");

    Label attachmentName = new Label(StringUtils.trim(docName, 60, true));
    attachmentName.setStyleName("attachment-name");
    attachmentNameWrap.addComponent(attachmentName);
    attachmentLayout.addComponent(attachmentNameWrap, "bottom: 0px; left: 0px; right: 0px; z-index: 1;");

    Button trashBtn = new Button(null, new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            ConfirmDialogExt.show(UI.getCurrent(),
                    AppContext.getMessage(GenericI18Enum.DIALOG_DELETE_TITLE, AppContext.getSiteName()),
                    AppContext.getMessage(GenericI18Enum.CONFIRM_DELETE_ATTACHMENT),
                    AppContext.getMessage(GenericI18Enum.BUTTON_YES),
                    AppContext.getMessage(GenericI18Enum.BUTTON_NO), new ConfirmDialog.Listener() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        public void onClose(ConfirmDialog dialog) {
                            if (dialog.isConfirmed()) {
                                ResourceService attachmentService = AppContextUtil
                                        .getSpringBean(ResourceService.class);
                                attachmentService.removeResource(attachment.getPath(), AppContext.getUsername(),
                                        AppContext.getAccountId());
                                ((ComponentContainer) attachmentLayout.getParent())
                                        .removeComponent(attachmentLayout);
                            }
                        }
                    });

        }
    });
    trashBtn.setIcon(FontAwesome.TRASH_O);
    trashBtn.setStyleName("attachment-control");
    attachmentLayout.addComponent(trashBtn, "top: 9px; left: 9px; z-index: 1;");

    Button downloadBtn = new Button();
    FileDownloader fileDownloader = new FileDownloader(
            VaadinResourceFactory.getInstance().getStreamResource(attachment.getPath()));
    fileDownloader.extend(downloadBtn);

    downloadBtn.setIcon(FontAwesome.DOWNLOAD);
    downloadBtn.setStyleName("attachment-control");
    attachmentLayout.addComponent(downloadBtn, "right: 9px; top: 9px; z-index: 1;");
    this.addComponent(attachmentLayout);
}

From source file:com.esofthead.mycollab.vaadin.web.ui.AttachmentPanel.java

License:Open Source License

private void displayFileName(File file, final String fileName) {
    final MHorizontalLayout fileAttachmentLayout = new MHorizontalLayout().withFullWidth();
    Button removeBtn = new Button(null, new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override/*ww  w. j av  a  2 s .com*/
        public void buttonClick(ClickEvent event) {
            File file = fileStores.get(fileName);
            if (file != null) {
                file.delete();
            }
            fileStores.remove(fileName);
            AttachmentPanel.this.removeComponent(fileAttachmentLayout);
            if (multiFileUpload != null) {
                multiFileUpload.removeAndReInitMultiUpload();
            }
        }
    });
    removeBtn.setIcon(FontAwesome.TRASH_O);
    removeBtn.addStyleName(UIConstants.BUTTON_ICON_ONLY);
    removeBtn.setWidthUndefined();

    ELabel fileLbl = new ELabel(fileName, ContentMode.HTML).withDescription(fileName)
            .withStyleName(UIConstants.TEXT_ELLIPSIS);
    fileAttachmentLayout.with(
            new ELabel(FileAssetsUtil.getFileIconResource(fileName).getHtml(), ContentMode.HTML)
                    .withWidthUndefined(),
            fileLbl, new ELabel(" - " + FileUtils.getVolumeDisplay(file.length()))
                    .withStyleName(UIConstants.META_INFO).withWidthUndefined(),
            removeBtn).expand(fileLbl);
    this.addComponent(fileAttachmentLayout);
}

From source file:com.esofthead.mycollab.vaadin.web.ui.BuildCriterionComponent.java

License:Open Source License

public BuildCriterionComponent(GenericSearchPanel.SearchLayout<S> searchLayout, Param[] paramFields,
        Class<S> type, String searchCategory) {
    this.hostSearchLayout = searchLayout;
    this.paramFields = paramFields;
    this.type = type;
    this.searchCategory = searchCategory;

    MHorizontalLayout headerBox = new MHorizontalLayout().withMargin(new MarginInfo(true, false, true, true));
    headerBox.setDefaultComponentAlignment(Alignment.TOP_LEFT);
    addComponent(headerBox);//from w  w  w  . j  ava2  s .  com

    Label filterLbl = new Label(AppContext.getMessage(GenericI18Enum.OPT_SAVED_FILTER));
    headerBox.with(filterLbl).withAlign(filterLbl, Alignment.TOP_LEFT);

    filterBox = new MHorizontalLayout();
    headerBox.with(filterBox).withAlign(filterBox, Alignment.TOP_LEFT);

    buildFilterBox(null);

    searchContainer = new MVerticalLayout().withMargin(false);
    searchContainer.setDefaultComponentAlignment(Alignment.TOP_LEFT);

    MHorizontalLayout controlsBtn = new MHorizontalLayout().withMargin(true);

    Button addCriteriaBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_ADD_CRITERIA),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(ClickEvent event) {
                    CriteriaSelectionLayout newCriteriaBar = new CriteriaSelectionLayout(
                            searchContainer.getComponentCount() + 1);
                    searchContainer.addComponent(newCriteriaBar);
                }
            });
    addCriteriaBtn.setStyleName(UIConstants.BUTTON_ACTION);
    addCriteriaBtn.setIcon(FontAwesome.PLUS);

    controlsBtn.with(addCriteriaBtn);

    this.with(searchContainer, controlsBtn);
}

From source file:com.esofthead.mycollab.vaadin.web.ui.BuildCriterionComponent.java

License:Open Source License

private void buildFilterBox(String queryName) {
    filterBox.removeAllComponents();/* w w w .j ava2s.c  o m*/

    SavedSearchResultComboBox filterComboBox = new SavedSearchResultComboBox();
    filterBox.addComponent(filterComboBox);

    Button saveSearchBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_NEW_FILTER),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(ClickEvent event) {
                    buildSaveFilterBox();
                }
            });
    saveSearchBtn.addStyleName(UIConstants.BUTTON_ACTION);
    saveSearchBtn.setIcon(FontAwesome.PLUS);
    filterBox.addComponent(saveSearchBtn);
}

From source file:com.esofthead.mycollab.vaadin.web.ui.BuildCriterionComponent.java

License:Open Source License

private void buildSaveFilterBox() {
    filterBox.removeAllComponents();/*from www. j  a v  a2s  .  com*/

    final TextField queryTextField = new TextField();
    filterBox.addComponent(queryTextField);

    Button saveBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SAVE), new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            String queryText = queryTextField.getValue();
            saveSearchCriteria(queryText);
        }
    });
    saveBtn.setStyleName(UIConstants.BUTTON_ACTION);
    saveBtn.setIcon(FontAwesome.SAVE);
    filterBox.addComponent(saveBtn);

    Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(ClickEvent event) {
                    buildFilterBox(null);
                }
            });
    cancelBtn.addStyleName(UIConstants.BUTTON_OPTION);
    filterBox.addComponent(cancelBtn);
}

From source file:com.esofthead.mycollab.vaadin.web.ui.DynamicQueryParamLayout.java

License:Open Source License

private HorizontalLayout createButtonControls() {
    MHorizontalLayout buttonControls = new MHorizontalLayout()
            .withMargin(new MarginInfo(false, true, false, true));

    Button searchBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SEARCH),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override//w  ww.  j a  v  a2  s.  com
                public void buttonClick(final ClickEvent event) {
                    callSearchAction();
                }
            });
    searchBtn.setStyleName(UIConstants.BUTTON_ACTION);
    searchBtn.setIcon(FontAwesome.SEARCH);

    buttonControls.with(searchBtn).withAlign(searchBtn, Alignment.MIDDLE_CENTER);

    Button clearBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CLEAR),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(final ClickEvent event) {
                    clearFields();
                }
            });
    clearBtn.setStyleName(UIConstants.BUTTON_OPTION);

    buttonControls.with(clearBtn).withAlign(clearBtn, Alignment.MIDDLE_CENTER);

    Button basicSearchBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_BASIC_SEARCH),
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(final ClickEvent event) {
                    ((DefaultGenericSearchPanel<S>) searchPanel).moveToBasicSearchLayout();
                }
            });
    basicSearchBtn.setStyleName(UIConstants.BUTTON_LINK);
    buttonControls.with(basicSearchBtn).withAlign(basicSearchBtn, Alignment.MIDDLE_CENTER);
    return buttonControls;
}

From source file:com.esofthead.mycollab.vaadin.web.ui.EditFormControlsGenerator.java

License:Open Source License

public HorizontalLayout createButtonControls(boolean isSaveBtnVisible, boolean isSaveAndNewBtnVisible,
        boolean isCancelBtnVisible) {
    MHorizontalLayout layout = new MHorizontalLayout().withStyleName("addNewControl");
    layout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    layout.setSizeUndefined();//from   www  .j a  v  a  2s.co m

    if (isSaveBtnVisible) {
        final Button saveBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SAVE),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        if (editForm.validateForm()) {
                            editForm.fireSaveForm();
                        }
                    }
                });
        saveBtn.setIcon(FontAwesome.SAVE);
        saveBtn.setStyleName(UIConstants.BUTTON_ACTION);
        layout.addComponent(saveBtn);
    }

    if (isSaveAndNewBtnVisible) {
        Button saveAndNewBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SAVE_NEW),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        if (editForm.validateForm()) {
                            editForm.fireSaveAndNewForm();
                        }
                    }
                });
        saveAndNewBtn.setIcon(FontAwesome.SHARE_ALT);
        saveAndNewBtn.setStyleName(UIConstants.BUTTON_ACTION);
        layout.addComponent(saveAndNewBtn);
    }

    if (isCancelBtnVisible) {
        Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
                new Button.ClickListener() {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void buttonClick(final ClickEvent event) {
                        editForm.fireCancelForm();
                    }
                });
        cancelBtn.setIcon(FontAwesome.MINUS);
        cancelBtn.setStyleName(UIConstants.BUTTON_OPTION);
        layout.addComponent(cancelBtn);
    }

    return layout;
}