Example usage for com.vaadin.ui CssLayout addComponent

List of usage examples for com.vaadin.ui CssLayout addComponent

Introduction

In this page you can find the example usage for com.vaadin.ui CssLayout addComponent.

Prototype

@Override
public void addComponent(Component c) 

Source Link

Document

Add a component into this container.

Usage

From source file:com.mycollab.module.user.ui.components.ImagePreviewCropWindow.java

License:Open Source License

public ImagePreviewCropWindow(final ImageSelectionCommand imageSelectionCommand, final byte[] imageData) {
    super(UserUIContext.getMessage(ShellI18nEnum.OPT_PREVIEW_EDIT_IMAGE));
    MVerticalLayout content = new MVerticalLayout();
    withModal(true).withResizable(false).withWidth("700px").withCenter().withContent(content);

    try {// w  ww.j a  v a2 s. com
        originalImage = ImageIO.read(new ByteArrayInputStream(imageData));
    } catch (IOException e) {
        throw new UserInvalidInputException("Invalid image type");
    }
    originalImage = ImageUtil.scaleImage(originalImage, 650, 650);

    MHorizontalLayout previewBox = new MHorizontalLayout().withMargin(new MarginInfo(false, true, true, false))
            .withFullWidth();

    previewPhoto = new VerticalLayout();
    previewPhoto.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    previewPhoto.setWidth("100px");

    previewBox.with(previewPhoto).withAlign(previewPhoto, Alignment.TOP_LEFT);

    VerticalLayout previewBoxTitle = new VerticalLayout();
    previewBoxTitle.setMargin(new MarginInfo(false, true, false, true));
    previewBoxTitle
            .addComponent(ELabel.html(UserUIContext.getMessage(ShellI18nEnum.OPT_IMAGE_EDIT_INSTRUCTION)));

    MButton cancelBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            clickEvent -> close()).withStyleName(WebThemes.BUTTON_OPTION);

    MButton acceptBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_ACCEPT), clickEvent -> {
        if (scaleImageData != null && scaleImageData.length > 0) {
            try {
                BufferedImage image = ImageIO.read(new ByteArrayInputStream(scaleImageData));
                imageSelectionCommand.process(image);
                close();
            } catch (IOException e) {
                throw new MyCollabException("Error when saving user avatar", e);
            }
        }
    }).withIcon(FontAwesome.CHECK).withStyleName(WebThemes.BUTTON_ACTION);

    MHorizontalLayout controlBtns = new MHorizontalLayout(acceptBtn, cancelBtn);

    previewBoxTitle.addComponent(controlBtns);
    previewBoxTitle.setComponentAlignment(controlBtns, Alignment.TOP_LEFT);
    previewBox.with(previewBoxTitle).expand(previewBoxTitle);

    CssLayout cropBox = new CssLayout();
    cropBox.setWidth("100%");
    VerticalLayout currentPhotoBox = new VerticalLayout();
    Resource resource = new ByteArrayImageResource(ImageUtil.convertImageToByteArray(originalImage),
            "image/png");
    CropField cropField = new CropField(resource);
    cropField.setImmediate(true);
    cropField.setSelectionAspectRatio(1.0f);
    cropField.addValueChangeListener(valueChangeEvent -> {
        VCropSelection newSelection = (VCropSelection) valueChangeEvent.getProperty().getValue();
        int x1 = newSelection.getXTopLeft();
        int y1 = newSelection.getYTopLeft();
        int x2 = newSelection.getXBottomRight();
        int y2 = newSelection.getYBottomRight();
        if (x2 > x1 && y2 > y1) {
            BufferedImage subImage = originalImage.getSubimage(x1, y1, (x2 - x1), (y2 - y1));
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            try {
                ImageIO.write(subImage, "png", outStream);
                scaleImageData = outStream.toByteArray();
                displayPreviewImage();
            } catch (IOException e) {
                LOG.error("Error while scale image: ", e);
            }
        }
    });
    currentPhotoBox.setWidth("520px");
    currentPhotoBox.setHeight("470px");
    currentPhotoBox.addComponent(cropField);
    cropBox.addComponent(currentPhotoBox);

    content.with(previewBox, ELabel.hr(), cropBox);
    displayPreviewImage();
}

From source file:com.mycollab.ui.chart.PieChartWrapper.java

License:Open Source License

@Override
protected final ComponentContainer createLegendBox() {
    final CssLayout mainLayout = new CssLayout();
    mainLayout.addStyleName("legendBoxContent");
    mainLayout.setSizeUndefined();// w ww. j av  a2s .  co m
    final List keys = pieDataSet.getKeys();

    for (int i = 0; i < keys.size(); i++) {
        MHorizontalLayout layout = new MHorizontalLayout().withMargin(new MarginInfo(false, false, false, true))
                .withStyleName("inline-block").withWidthUndefined();
        layout.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);

        final Comparable key = (Comparable) keys.get(i);
        int colorIndex = i % CHART_COLOR_STR.size();
        final String color = "<div style = \" width:13px;height:13px;background: #"
                + CHART_COLOR_STR.get(colorIndex) + "\" />";
        final ELabel lblCircle = ELabel.html(color);

        String btnCaption;
        if (enumKeyCls == null) {
            if (key instanceof Key) {
                btnCaption = String.format("%s (%d)", StringUtils.trim(((Key) key).getDisplayName(), 20, true),
                        pieDataSet.getValue(key).intValue());
            } else {
                btnCaption = String.format("%s (%d)", key, pieDataSet.getValue(key).intValue());
            }
        } else {
            btnCaption = String.format("%s(%d)", UserUIContext.getMessage(enumKeyCls, key.toString()),
                    pieDataSet.getValue(key).intValue());
        }
        MButton btnLink = new MButton(StringUtils.trim(btnCaption, 25, true), clickEvent -> {
            if (key instanceof Key) {
                clickLegendItem(((Key) key).getKey());
            } else {
                clickLegendItem(key.toString());
            }
        }).withStyleName(WebThemes.BUTTON_LINK).withDescription(btnCaption);

        layout.with(lblCircle, btnLink);
        mainLayout.addComponent(layout);
    }
    mainLayout.setWidth("100%");
    return mainLayout;
}

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

License:Open Source License

private void addAttachmentRow(final Content attachment) {
    String docName = attachment.getPath();
    int lastIndex = docName.lastIndexOf("/");
    if (lastIndex != -1) {
        docName = docName.substring(lastIndex + 1, docName.length());
    }/* w  w w .j  a  v a 2 s .  c om*/

    final AbsoluteLayout attachmentLayout = new AbsoluteLayout();
    attachmentLayout.setWidth(WebUIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_WIDTH);
    attachmentLayout.setHeight(WebUIConstants.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.getResource(attachment.getThumbnail()));
    }

    if (MimeTypesUtil.isImageType(docName)) {
        thumbnail.setResource(VaadinResourceFactory.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(UserUIContext.getMessage(FileI18nEnum.OPT_SIZE_VALUE,
            FileUtils.getVolumeDisplay(attachment.getSize())))).setStyle("line-height:1.5em");
    ul.appendChild(new Li().appendText(UserUIContext.getMessage(GenericI18Enum.OPT_LAST_MODIFIED,
            UserUIContext.formatPrettyTime(attachment.getLastModified().getTime()))));
    contentTooltip.appendChild(ul);
    thumbnail.setDescription(contentTooltip.write());
    thumbnail.setWidth(WebUIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_WIDTH);
    thumbnailWrap.addComponent(thumbnail);

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

    MCssLayout attachmentNameWrap = new MCssLayout()
            .withWidth(WebUIConstants.DEFAULT_ATTACHMENT_THUMBNAIL_WIDTH).withStyleName("attachment-name-wrap");

    Label attachmentName = new ELabel(docName).withStyleName(UIConstants.TEXT_ELLIPSIS);
    attachmentNameWrap.addComponent(attachmentName);
    attachmentLayout.addComponent(attachmentNameWrap, "bottom: 0px; left: 0px; right: 0px; z-index: 1;");

    MButton trashBtn = new MButton("", clickEvent -> {
        ConfirmDialogExt.show(UI.getCurrent(),
                UserUIContext.getMessage(GenericI18Enum.DIALOG_DELETE_TITLE, MyCollabUI.getSiteName()),
                UserUIContext.getMessage(GenericI18Enum.CONFIRM_DELETE_ATTACHMENT),
                UserUIContext.getMessage(GenericI18Enum.BUTTON_YES),
                UserUIContext.getMessage(GenericI18Enum.BUTTON_NO), confirmDialog -> {
                    if (confirmDialog.isConfirmed()) {
                        ResourceService attachmentService = AppContextUtil.getSpringBean(ResourceService.class);
                        attachmentService.removeResource(attachment.getPath(), UserUIContext.getUsername(),
                                true, MyCollabUI.getAccountId());
                        ((ComponentContainer) attachmentLayout.getParent()).removeComponent(attachmentLayout);
                    }
                });
    }).withIcon(FontAwesome.TRASH_O).withStyleName("attachment-control");
    attachmentLayout.addComponent(trashBtn, "top: 9px; left: 9px; z-index: 1;");

    MButton downloadBtn = new MButton().withIcon(FontAwesome.DOWNLOAD).withStyleName("attachment-control");
    FileDownloader fileDownloader = new FileDownloader(
            VaadinResourceFactory.getInstance().getStreamResource(attachment.getPath()));
    fileDownloader.extend(downloadBtn);
    attachmentLayout.addComponent(downloadBtn, "right: 9px; top: 9px; z-index: 1;");
    this.addComponent(attachmentLayout);
}

From source file:com.mycollab.vaadin.web.ui.MailFormWindow.java

License:Open Source License

private void initUI() {
    GridLayout mainLayout = new GridLayout(1, 5);
    mainLayout.setWidth("100%");
    mainLayout.setMargin(true);/*  w w w.  jav  a2s.  c om*/
    mainLayout.setSpacing(true);

    CssLayout inputPanel = new CssLayout();
    inputPanel.setWidth("100%");
    inputPanel.setStyleName("mail-panel");

    inputLayout = new GridLayout(3, 4);
    inputLayout.setSpacing(true);
    inputLayout.setWidth("100%");
    inputLayout.setColumnExpandRatio(0, 1.0f);

    inputPanel.addComponent(inputLayout);

    mainLayout.addComponent(inputPanel);

    tokenFieldMailTo = new EmailTokenField();

    inputLayout.addComponent(createTextFieldMail("To:", tokenFieldMailTo), 0, 0);

    if (lstMail != null) {
        for (String mail : lstMail) {
            if (StringUtils.isNotBlank(mail)) {
                if (mail.indexOf("<") > -1) {
                    String strMail = mail.substring(mail.indexOf("<") + 1, mail.lastIndexOf(">"));
                    if (strMail != null && !strMail.equalsIgnoreCase("null")) {

                    }
                } else {

                }
            }
        }
    }

    final TextField subject = new TextField();
    subject.setRequired(true);
    subject.setWidth("100%");
    subjectField = createTextFieldMail("Subject:", subject);
    inputLayout.addComponent(subjectField, 0, 1);

    initButtonLinkCcBcc();

    ccField = createTextFieldMail("Cc:", tokenFieldMailCc);
    bccField = createTextFieldMail("Bcc:", tokenFieldMailBcc);

    final RichTextArea noteArea = new RichTextArea();
    noteArea.setWidth("100%");
    noteArea.setHeight("200px");
    mainLayout.addComponent(noteArea, 0, 1);
    mainLayout.setComponentAlignment(noteArea, Alignment.MIDDLE_CENTER);

    final AttachmentPanel attachments = new AttachmentPanel();
    attachments.setWidth("500px");

    MButton cancelBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            clickEvent -> close()).withStyleName(WebThemes.BUTTON_OPTION);

    MButton sendBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.ACTION_SEND_EMAIL), clickEvent -> {
        if (tokenFieldMailTo.getListRecipient().size() <= 0 || subject.getValue().equals("")) {
            NotificationUtil.showErrorNotification(
                    "To Email field and Subject field must be not empty! Please fulfil them before sending email.");
            return;
        }
        if (UserUIContext.getUser().getEmail() != null && UserUIContext.getUser().getEmail().length() > 0) {
            ExtMailService systemMailService = AppContextUtil.getSpringBean(ExtMailService.class);

            List<File> listFile = attachments.files();
            List<AttachmentSource> attachmentSource = null;
            if (listFile != null && listFile.size() > 0) {
                attachmentSource = new ArrayList<>();
                for (File file : listFile) {
                    attachmentSource.add(new FileAttachmentSource(file));
                }
            }

            systemMailService.sendHTMLMail(UserUIContext.getUser().getEmail(),
                    UserUIContext.getUser().getDisplayName(), tokenFieldMailTo.getListRecipient(),
                    tokenFieldMailCc.getListRecipient(), tokenFieldMailBcc.getListRecipient(),
                    subject.getValue(), noteArea.getValue(), attachmentSource, true);
            close();
        } else {
            NotificationUtil
                    .showErrorNotification("Your email is empty value, please fulfil it before sending email!");
        }
    }).withIcon(FontAwesome.SEND).withStyleName(WebThemes.BUTTON_ACTION);

    MHorizontalLayout controlsLayout = new MHorizontalLayout(attachments, cancelBtn, sendBtn)
            .expand(attachments).withFullWidth();
    mainLayout.addComponent(controlsLayout, 0, 2);
    this.setContent(mainLayout);
}

From source file:com.mycollab.vaadin.web.ui.NotificationComponent.java

License:Open Source License

private Component buildComponentFromNotification(AbstractNotification item) {
    final MHorizontalLayout wrapper = new MHorizontalLayout();
    wrapper.setData(item);/* w w  w. j ava 2 s .  c  o m*/
    wrapper.setDefaultComponentAlignment(Alignment.TOP_LEFT);

    if (item instanceof NewUpdateAvailableNotification) {
        final NewUpdateAvailableNotification notification = (NewUpdateAvailableNotification) item;
        Span spanEl = new Span();
        spanEl.appendText(
                UserUIContext.getMessage(ShellI18nEnum.OPT_HAVING_NEW_VERSION, notification.getVersion()));
        ELabel lbl = ELabel.html(FontAwesome.INFO_CIRCLE.getHtml() + " " + spanEl.write()).withFullWidth();
        CssLayout lblWrapper = new CssLayout();
        lblWrapper.addComponent(lbl);
        wrapper.addComponent(lblWrapper);
        wrapper.expand(lblWrapper);
        if (UserUIContext.isAdmin()) {
            MButton upgradeBtn = new MButton(UserUIContext.getMessage(ShellI18nEnum.ACTION_UPGRADE),
                    clickEvent -> {
                        UI.getCurrent().addWindow(new UpgradeConfirmWindow(notification.getVersion(),
                                notification.getManualDownloadLink(), notification.getInstallerFile()));
                        NotificationComponent.this.setPopupVisible(false);
                    }).withStyleName(UIConstants.BLOCK);
            wrapper.addComponent(upgradeBtn);
        }
    } else if (item instanceof RequestUploadAvatarNotification) {
        wrapper.addComponent(new Label(FontAwesome.EXCLAMATION_TRIANGLE.getHtml() + " "
                + UserUIContext.getMessage(ShellI18nEnum.OPT_REQUEST_UPLOAD_AVATAR), ContentMode.HTML));
        MButton uploadAvatarBtn = new MButton(UserUIContext.getMessage(ShellI18nEnum.ACTION_UPLOAD_AVATAR),
                clickEvent -> {
                    EventBusFactory.getInstance()
                            .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "preview" }));
                    NotificationComponent.this.setPopupVisible(false);
                }).withStyleName(UIConstants.BLOCK);
        wrapper.add(uploadAvatarBtn);
    } else if (item instanceof SmtpSetupNotification) {
        MButton smtpBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.ACTION_SETUP), clickEvent -> {
            EventBusFactory.getInstance()
                    .post(new ShellEvent.GotoUserAccountModule(this, new String[] { "setup" }));
            NotificationComponent.this.setPopupVisible(false);
        }).withStyleName(UIConstants.BLOCK);
        Label lbl = ELabel.html(FontAwesome.EXCLAMATION_TRIANGLE.getHtml() + " "
                + UserUIContext.getMessage(ShellI18nEnum.ERROR_NO_SMTP_SETTING));
        MCssLayout lblWrapper = new MCssLayout(lbl);
        wrapper.with(lblWrapper, smtpBtn).expand(lblWrapper);
    } else {
        LOG.error("Do not render notification " + item);
    }
    return wrapper;
}

From source file:com.mycollab.vaadin.web.ui.VerticalTabsheet.java

License:Open Source License

public VerticalTabsheet() {
    CssLayout contentLayout = new CssLayout();
    new Restrain(contentLayout).setMinHeight("100%");

    navigatorWrapper = new CssLayout();
    navigatorWrapper.setStyleName("navigator-wrap");
    navigatorContainer = new VerticalLayout();
    navigatorWrapper.addComponent(navigatorContainer);

    contentWrapper = new VerticalLayout();
    contentWrapper.setStyleName("container-wrap");
    new Restrain(contentWrapper).setMinHeight("100%");

    tabContainer = new VerticalLayout();
    contentWrapper.addComponent(tabContainer);
    new Restrain(tabContainer).setMinHeight("100%");

    contentLayout.addComponent(navigatorWrapper);
    contentLayout.addComponent(contentWrapper);

    this.setCompositionRoot(contentLayout);
    this.setStyleName(TABSHEET_STYLENAME);
}

From source file:com.nfl.dm.clubsites.cms.articles.subapp.articleeditor.bodyeditor.BodyEditorViewImpl.java

License:Open Source License

private Layout createToolbarFormattingElements() {
    CssLayout wrapper = new CssLayout();
    wrapper.addStyleName("toolbar-elements");
    wrapper.addStyleName("toolbar-formatting");

    for (int i = 0; i < 4; i++) {
        Button addButton = new Button(null, new Button.ClickListener() {
            @Override//from   ww  w  .j  a v a  2s  .  c  om
            public void buttonClick(Button.ClickEvent event) {
                notImplemented();
            }
        });
        addButton.setStyleName("toolbar-formatting-button");
        ThemeResource tableResource = new ThemeResource("img/placeholder.png");
        addButton.setIcon(tableResource);

        wrapper.addComponent(addButton);
    }

    return wrapper;
}

From source file:com.nfl.dm.clubsites.cms.articles.subapp.articleeditor.bodyeditor.BodyEditorViewImpl.java

License:Open Source License

private Layout createToolbarContentElements() {
    ThemeResource placeHolder = new ThemeResource("img/placeholder.png");
    CssLayout wrapper = new CssLayout();
    wrapper.addStyleName("toolbar-elements");
    Button addTableButton = new Button("table", new Button.ClickListener() {
        @Override//ww  w . ja  v a2  s  .  c  om
        public void buttonClick(Button.ClickEvent event) {
            notImplemented();
        }
    });
    addTableButton.setStyleName("ax-shape-button");
    ThemeResource tableResource = new ThemeResource("img/table.png");
    addTableButton.setIcon(tableResource);

    wrapper.addComponent(addTableButton);

    Button addRuleButton = new Button("rule", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            notImplemented();
        }
    });
    addRuleButton.setStyleName("ax-shape-button");
    addRuleButton.setIcon(placeHolder);

    wrapper.addComponent(addRuleButton);

    Button addParagraphButton = new Button("section", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            listener.createSection("Section");
        }
    });
    addParagraphButton.setStyleName("ax-shape-button");
    ThemeResource sectionResource = new ThemeResource("img/section_sign.gif");
    addParagraphButton.setIcon(sectionResource);

    wrapper.addComponent(addParagraphButton);

    Button addPullQuoteButton = new Button("pullquote", new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            notImplemented();
        }
    });
    addPullQuoteButton.setStyleName("ax-shape-button");
    addPullQuoteButton.setIcon(placeHolder);

    wrapper.addComponent(addPullQuoteButton);
    return wrapper;
}

From source file:com.nfl.dm.clubsites.cms.articles.subapp.articleeditor.bodyeditor.BodyEditorViewImpl.java

License:Open Source License

private Layout createToolbarAssetsElements() {
    final CssLayout wrapper = new CssLayout();
    wrapper.addStyleName("toolbar-elements");

    final Button addPhotographButton = new Button("photograph");
    addPhotographButton.addClickListener(new Button.ClickListener() {
        @Override//from ww  w.  jav  a2  s .com
        public void buttonClick(Button.ClickEvent event) {
            listener.openMediaGallery();
        }
    });
    addPhotographButton.setStyleName("ax-shape-button");
    ThemeResource sectionResource = new ThemeResource("img/photograph.png");
    addPhotographButton.setIcon(sectionResource);
    wrapper.addComponent(addPhotographButton);

    List<String> assetElements = Arrays.asList(new String[] { "video", "poll", "related link", "iFrame" });
    for (String name : assetElements) {
        Button addButton = new Button(name, new Button.ClickListener() {
            @Override
            public void buttonClick(Button.ClickEvent event) {
                notImplemented();
            }
        });
        addButton.setStyleName("ax-shape-button");
        ThemeResource tableResource = new ThemeResource("img/placeholder.png");
        addButton.setIcon(tableResource);

        wrapper.addComponent(addButton);
    }

    return wrapper;
}

From source file:com.nfl.dm.clubsites.cms.articles.subapp.articleeditor.navigation.NavigationViewImpl.java

License:Open Source License

@Override
public void setPreview(ViewType viewType, Component preview) {
    CssLayout control = navigationControls.get(viewType);
    if (control != null) {
        control.removeAllComponents();/*from w w  w.  ja  va 2 s  . c  o m*/
        control.addComponent(preview);
    }
}