Example usage for com.vaadin.ui HorizontalLayout getParent

List of usage examples for com.vaadin.ui HorizontalLayout getParent

Introduction

In this page you can find the example usage for com.vaadin.ui HorizontalLayout getParent.

Prototype

@Override
    public HasComponents getParent() 

Source Link

Usage

From source file:com.esofthead.mycollab.mobile.ui.MobileAttachmentUtils.java

License:Open Source License

public static Component renderAttachmentFieldRow(final Content attachment,
        Button.ClickListener additionalListener) {
    String docName = attachment.getPath();
    int lastIndex = docName.lastIndexOf("/");
    if (lastIndex != -1) {
        docName = docName.substring(lastIndex + 1, docName.length());
    }//from   w  ww.j  a  v a2 s  .c o  m

    final HorizontalLayout attachmentLayout = new HorizontalLayout();
    attachmentLayout.setSpacing(true);
    attachmentLayout.setStyleName("attachment-row");
    attachmentLayout.setWidth("100%");
    attachmentLayout.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);

    CssLayout thumbnailWrap = new CssLayout();
    thumbnailWrap.setWidth("25px");
    thumbnailWrap.setHeight("40px");
    thumbnailWrap.setStyleName("thumbnail-wrap");

    Image thumbnail = new Image(null);
    if (org.apache.commons.lang3.StringUtils.isBlank(attachment.getThumbnail())) {
        thumbnail.setSource(DEFAULT_SOURCE);
    } else {
        thumbnail.setSource(VaadinResourceManager.getResourceManager()
                .getImagePreviewResource(attachment.getThumbnail(), DEFAULT_SOURCE));
    }
    thumbnail.setWidth("100%");
    thumbnailWrap.addComponent(thumbnail);
    attachmentLayout.addComponent(thumbnailWrap);

    Label attachmentLink = new Label(docName);
    attachmentLayout.addComponent(attachmentLink);
    attachmentLayout.setExpandRatio(attachmentLink, 1.0f);

    Button removeAttachment = new Button(
            "<span aria-hidden=\"true\" data-icon=\"" + IconConstants.DELETE + "\"></span>",
            new Button.ClickListener() {
                private static final long serialVersionUID = 1L;

                @Override
                public void buttonClick(ClickEvent event) {

                    ConfirmDialog.show(UI.getCurrent(),
                            AppContext.getMessage(GenericI18Enum.CONFIRM_DELETE_ATTACHMENT),
                            AppContext.getMessage(GenericI18Enum.BUTTON_YES),
                            AppContext.getMessage(GenericI18Enum.BUTTON_NO), new ConfirmDialog.CloseListener() {
                                private static final long serialVersionUID = 1L;

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

                }
            });
    if (additionalListener != null) {
        removeAttachment.addClickListener(additionalListener);
    }
    removeAttachment.setHtmlContentAllowed(true);
    removeAttachment.setStyleName("link");
    attachmentLayout.addComponent(removeAttachment);

    return attachmentLayout;
}