Example usage for com.vaadin.ui VerticalLayout setHeight

List of usage examples for com.vaadin.ui VerticalLayout setHeight

Introduction

In this page you can find the example usage for com.vaadin.ui VerticalLayout setHeight.

Prototype

@Override
    public void setHeight(String height) 

Source Link

Usage

From source file:at.peppol.webgui.app.MainWindow.java

License:Mozilla Public License

public void showInitialMainContent(UserFolder<?> userFolder) {
    // ------ START: Main Content -------
    final VerticalLayout mainContentLayout = new VerticalLayout();

    mainContentLayout.addStyleName("margin");
    final VerticalLayout topmain = new VerticalLayout();
    topmain.setSpacing(true);//from  w  ww  .j  ava  2 s . co  m
    topmain.setWidth("100%");
    final Label bigPAWGLabel = new Label("PEPPOL Post Award Web GUI");
    bigPAWGLabel.setStyleName("huge");
    topmain.addComponent(bigPAWGLabel);
    final Label blahContent = new Label(
            "This is a mockup of the GUI that is going" + " to be the PAWG. It is created by the Greek"
                    + " and Austrian teams as a fine replacement " + " of the Demo Client");
    blahContent.setWidth("80%");
    blahContent.addStyleName("big");
    //topmain.addComponent (blahContent);
    //HorizontalLayout itemsPanel = new ShowItemsPanel("Items", um, userFolder);

    final ShowItemsPanel itemsPanel = new ShowItemsPanel("Items", um, userFolder);
    this.itemsPanel = itemsPanel;
    topmain.addComponent(itemsPanel);
    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setSpacing(true);
    topmain.addComponent(buttonsLayout);
    Button loadButton = new Button("Load invoice");
    //topmain.addComponent(loadButton);
    buttonsLayout.addComponent(loadButton);
    loadButton.addListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            Table table = itemsPanel.getTable();
            if (table.getValue() != null) {
                //InvoiceType inv = (InvoiceType)table.getItem(table.getValue()).getItemProperty("invoice").getValue();
                //InvoiceBean invBean = (InvoiceBean)table.getItem(table.getValue());
                InvoiceBean invBean = ((InvoiceBeanContainer) table.getContainerDataSource())
                        .getItem(table.getValue()).getBean();
                //System.out.println("Invoice is: "+invBean);
                showInvoiceForm(invBean);
            }
        }
    });

    Button sendButton = new Button("Send invoice");
    buttonsLayout.addComponent(sendButton);
    sendButton.addListener(new ClickListener() {
        @Override
        public void buttonClick(ClickEvent event) {
            try {
                Table table = itemsPanel.getTable();
                if (table.getValue() != null) {
                    InvoiceBean invBean = ((InvoiceBeanContainer) table.getContainerDataSource())
                            .getItem(table.getValue()).getBean();
                    String path = invBean.getFolderEntryID();
                    FileSystemResource s = new FileSystemResource(path);
                    SendInvoice.sendDocument(s);

                    //file is sent. move invoice to outbox
                    um.moveInvoice(invBean, um.getDrafts(), um.getOutbox());
                    //itemsPanel.getTable().requestRepaint();
                    itemsPanel.init(um.getDrafts());
                }
            } catch (FileNotFoundException e) {
                getWindow().showNotification("Could not find invoice file", Notification.TYPE_ERROR_MESSAGE);
            } catch (Exception e) {
                getWindow().showNotification("Could not send invoice. AP connection error",
                        Notification.TYPE_ERROR_MESSAGE);
                e.printStackTrace();
            }
        }
    });

    final Button learnMoreBtn = new Button("Learn More >>");
    learnMoreBtn.addStyleName("tall default");
    //topmain.addComponent (learnMoreBtn);

    mainContentLayout.addComponent(topmain);
    // ------ END: Main Content ---------
    mainContentLayout.setHeight("100%");
    mainContentLayout.setSizeFull();

    mainContentLayout.setSpacing(true);
    mainContentLayout.setWidth("100%");
    middleContentLayout.setWidth("100%");
    middleContentLayout.setHeight("100%");
    middleContentLayout.setMargin(true);
    // --------
    addComponent(middleContentLayout);
    addComponent(footerLayout);
    if (mainContentComponent != null) {
        middleContentLayout.replaceComponent(mainContentComponent, mainContentLayout);
    } else {
        middleContentLayout.addComponent(mainContentLayout);
    }
    middleContentLayout.setExpandRatio(mainContentLayout, 1);
    mainContentComponent = mainContentLayout;
}

From source file:br.com.anteros.mobileserver.app.form.ConfigurationWindow.java

License:Apache License

public ConfigurationWindow(MobileServerApplication app) {
    this.app = app;
    setCaption("Configurao do Servidor");
    setModal(true);// w ww  . j av a2  s  .co  m
    configurationForm = new ConfigurationForm();
    setClosable(false);
    addComponent(configurationForm);
    setResizable(false);
    setDraggable(false);

    VerticalLayout layout = (VerticalLayout) this.getContent();
    layout.setSpacing(true);

    layout.setWidth("765px");
    layout.setHeight("460px");

    configurationForm.getBtnOk().addListener(this);
    configurationForm.getBtnCancel().addListener(this);

    loadPreferences();
}

From source file:br.com.anteros.mobileserver.app.form.FieldWindow.java

License:Apache License

public FieldWindow(MobileServerApplication app, FieldSynchronism fieldSynchronism, Synchronism objectOwner) {
    if ((fieldSynchronism.getId() == null) || (fieldSynchronism.getId() <= 0)) {
        setCaption("Adicionando");
    } else/*from   w w w  .  j  a v a 2 s  .c o m*/
        setCaption("Editando");
    setModal(true);
    fieldForm = new FieldForm(app, fieldSynchronism, this, objectOwner, false);
    addComponent(fieldForm);

    VerticalLayout layout = (VerticalLayout) this.getContent();

    layout.setWidth("700px");
    layout.setHeight("270px");

}

From source file:br.com.anteros.mobileserver.app.form.LoginWindow.java

License:Apache License

public LoginWindow(MobileServerApplication app) {
    this.app = app;
    setCaption("Login");
    setModal(true);/*from  w w w  .j av  a  2  s .c om*/
    loginForm = new UserLoginForm();
    setClosable(false);
    addComponent(loginForm);
    setResizable(false);

    VerticalLayout layout = (VerticalLayout) this.getContent();
    layout.setSpacing(true);

    layout.setWidth("400px");
    layout.setHeight("150px");

    loginForm.getBtnLogin().addListener(this);
}

From source file:br.com.anteros.mobileserver.app.form.ParameterWindow.java

License:Apache License

public ParameterWindow(MobileServerApplication app, ParameterSynchronism parameterSynchronism,
        Synchronism objectOwner) {//from   w ww. j  av  a2 s . co m
    if ((parameterSynchronism.getId() == null) || (parameterSynchronism.getId() <= 0)) {
        setCaption("Adicionando");
    } else
        setCaption("Editando");
    setModal(true);
    setTheme(Reindeer.THEME_NAME);
    formParameter = new ParameterForm(app, parameterSynchronism, this, objectOwner, false);
    addComponent(formParameter);

    VerticalLayout layout = (VerticalLayout) this.getContent();

    layout.setWidth("700px");
    layout.setHeight("265px");

}

From source file:com.esofthead.mycollab.module.user.accountsettings.customize.view.LogoEditWindow.java

License:Open Source License

private void editPhoto(byte[] imageData) {
    try {// www  . java  2 s  . c  o  m
        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();

    final String logoPath = AppContext.getBillingAccount().getLogopath();
    Resource defaultPhoto = AccountAssetsResolver.createLogoResource(logoPath, 150);
    previewImage = new Embedded(null, defaultPhoto);
    previewImage.setWidth("100px");
    previewBox.addComponent(previewImage);
    previewBox.setComponentAlignment(previewImage, Alignment.TOP_LEFT);

    MVerticalLayout previewBoxRight = new MVerticalLayout().withSpacing(false)
            .withMargin(new MarginInfo(false, true, false, true));

    Label lbPreview = new Label(
            "<p style='margin: 0px;'><strong>To the below is what your logo will look like.</strong></p><p "
                    + "style='margin-top: 0px;'>To make adjustment, you can drag around and resize the selection square below. "
                    + "When you are happy with your photo, click the <strong>Accept</strong> button.</p>",
            ContentMode.HTML);
    previewBoxRight.addComponent(lbPreview);

    MHorizontalLayout controlBtns = new MHorizontalLayout();
    controlBtns.setSizeUndefined();
    controlBtns.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);

    Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            new Button.ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    EventBusFactory.getInstance()
                            .post(new SettingEvent.GotoGeneralSetting(LogoEditWindow.this, null));
                }
            });
    cancelBtn.setStyleName(UIConstants.BUTTON_OPTION);
    controlBtns.with(cancelBtn);

    Button acceptBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_ACCEPT),
            new Button.ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    if (scaleImageData != null && scaleImageData.length > 0) {
                        try {
                            BufferedImage image = ImageIO.read(new ByteArrayInputStream(scaleImageData));
                            AccountLogoService accountLogoService = AppContextUtil
                                    .getSpringBean(AccountLogoService.class);
                            accountLogoService.upload(AppContext.getUsername(), image,
                                    AppContext.getAccountId());
                            Page.getCurrent().getJavaScript().execute("window.location.reload();");
                        } catch (IOException e) {
                            throw new MyCollabException("Error when saving account logo", e);
                        }

                    }

                }
            });
    acceptBtn.setStyleName(UIConstants.BUTTON_ACTION);
    controlBtns.with(acceptBtn);

    previewBoxRight.with(controlBtns).withAlign(controlBtns, Alignment.TOP_LEFT);
    previewBox.with(previewBoxRight).expand(previewBoxRight);
    content.addComponent(previewBox);

    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(150 / 28);
    cropField.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            VCropSelection newSelection = (VCropSelection) event.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("650px");
    currentPhotoBox.setHeight("650px");
    currentPhotoBox.addComponent(cropField);
    cropBox.addComponent(currentPhotoBox);

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

From source file:com.esofthead.mycollab.module.user.accountsettings.profile.view.ProfilePhotoUploadViewImpl.java

License:Open Source License

@SuppressWarnings("serial")
@Override//from  w ww. j av a 2s  . c  o m
public void editPhoto(final byte[] imageData) {
    this.removeAllComponents();
    LOG.debug("Receive avatar upload with size: " + imageData.length);
    try {
        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().withSpacing(true)
            .withMargin(new MarginInfo(false, true, true, false)).withWidth("100%");

    Resource defaultPhoto = UserAvatarControlFactory.createAvatarResource(AppContext.getUserAvatarId(), 100);
    previewImage = new Embedded(null, defaultPhoto);
    previewImage.setWidth("100px");
    previewBox.addComponent(previewImage);
    previewBox.setComponentAlignment(previewImage, Alignment.TOP_LEFT);

    VerticalLayout previewBoxRight = new VerticalLayout();
    previewBoxRight.setMargin(new MarginInfo(false, true, false, true));
    Label lbPreview = new Label(
            "<p style='margin: 0px;'><strong>To the left is what your profile photo will look like.</strong></p><p style='margin-top: 0px;'>To make adjustment, you can drag around and resize the selection square below. When you are happy with your photo, click the &ldquo;Accept&ldquo; button.</p>",
            ContentMode.HTML);
    previewBoxRight.addComponent(lbPreview);

    MHorizontalLayout controlBtns = new MHorizontalLayout();
    controlBtns.setSizeUndefined();

    Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            new Button.ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {
                    EventBusFactory.getInstance()
                            .post(new ProfileEvent.GotoProfileView(ProfilePhotoUploadViewImpl.this, null));
                }
            });
    cancelBtn.setStyleName(UIConstants.THEME_GRAY_LINK);

    Button acceptBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_ACCEPT),
            new Button.ClickListener() {

                @Override
                public void buttonClick(ClickEvent event) {
                    if (scaleImageData != null && scaleImageData.length > 0) {

                        try {
                            BufferedImage image = ImageIO.read(new ByteArrayInputStream(scaleImageData));
                            UserAvatarService userAvatarService = ApplicationContextUtil
                                    .getSpringBean(UserAvatarService.class);
                            userAvatarService.uploadAvatar(image, AppContext.getUsername(),
                                    AppContext.getUserAvatarId());
                            Page.getCurrent().getJavaScript().execute("window.location.reload();");
                        } catch (IOException e) {
                            throw new MyCollabException("Error when saving user avatar", e);
                        }

                    }

                }
            });
    acceptBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    acceptBtn.setIcon(FontAwesome.CHECK);

    controlBtns.with(acceptBtn, cancelBtn).alignAll(Alignment.MIDDLE_LEFT);

    previewBoxRight.addComponent(controlBtns);
    previewBoxRight.setComponentAlignment(controlBtns, Alignment.TOP_LEFT);

    previewBox.addComponent(previewBoxRight);
    previewBox.setExpandRatio(previewBoxRight, 1.0f);

    this.addComponent(previewBox);

    CssLayout cropBox = new CssLayout();
    cropBox.addStyleName(UIConstants.PHOTO_CROPBOX);
    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(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            VCropSelection newSelection = (VCropSelection) event.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("650px");
    currentPhotoBox.setHeight("650px");

    currentPhotoBox.addComponent(cropField);

    cropBox.addComponent(currentPhotoBox);

    this.addComponent(previewBox);
    this.addComponent(cropBox);
    this.setExpandRatio(cropBox, 1.0f);
}

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

License:Open Source License

public ImagePreviewCropWindow(final ImageSelectionCommand imageSelectionCommand, final byte[] imageData) {
    super("Preview and modify image");
    setModal(true);/* www. j  a va2 s  .c o  m*/
    setResizable(false);
    setWidth("700px");
    center();

    MVerticalLayout content = new MVerticalLayout();
    setContent(content);

    try {
        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().withSpacing(true)
            .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));
    Label lbPreview = new Label("<p style='margin: 0px;'><strong>To the bottom is what your profile photo will "
            + "look like.</strong></p>"
            + "<p style='margin-top: 0px;'>To make adjustment, you can drag around and resize the selection square below. "
            + "When you are happy with your photo, click the &ldquo;Accept&ldquo; button.</p>",
            ContentMode.HTML);
    previewBoxTitle.addComponent(lbPreview);

    MHorizontalLayout controlBtns = new MHorizontalLayout();
    controlBtns.setSizeUndefined();

    Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent event) {
                    close();
                }
            });
    cancelBtn.setStyleName(UIConstants.BUTTON_OPTION);

    Button acceptBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_ACCEPT),
            new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent event) {
                    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);
                        }
                    }
                }
            });
    acceptBtn.setStyleName(UIConstants.BUTTON_ACTION);
    acceptBtn.setIcon(FontAwesome.CHECK);

    controlBtns.with(acceptBtn, cancelBtn).alignAll(Alignment.MIDDLE_LEFT);

    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(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            VCropSelection newSelection = (VCropSelection) event.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.esofthead.mycollab.vaadin.ui.FeedbackWindow.java

License:Open Source License

private void initUI() {
    GridLayout mainLayout = new GridLayout(2, 5);
    mainLayout.setMargin(true);/* w w w.ja va  2 s.com*/
    mainLayout.setSpacing(true);

    emailNameTextField = new TextField();
    emailNameTextField.setWidth("500px");
    Label emailName = new Label("Your name: ");

    mainLayout.addComponent(emailName, 0, 0);
    mainLayout.addComponent(emailNameTextField, 1, 0);

    emailTextField = new TextField();
    emailTextField.setWidth("500px");
    emailTextField.setRequired(true);
    Label emailLbl = new Label("Your email: ");

    mainLayout.addComponent(emailLbl, 0, 1);
    mainLayout.addComponent(emailTextField, 1, 1);

    subjectTextField = new TextField();
    subjectTextField.setWidth("500px");
    subjectTextField.setRequired(true);
    Label subjectLbl = new Label("Subject: ");

    mainLayout.addComponent(subjectLbl, 0, 2);
    mainLayout.addComponent(subjectTextField, 1, 2);

    final RichTextArea contentArea = new RichTextArea();
    contentArea.setImmediate(true);
    contentArea.setWidth(500, Sizeable.Unit.PIXELS);
    contentArea.setHeight(200, Sizeable.Unit.PIXELS);
    Label contentLbl = new Label("Your feedback: ");

    mainLayout.addComponent(contentLbl, 0, 3);
    mainLayout.addComponent(contentArea, 1, 3);

    initDefaultData();

    HorizontalLayout controlsLayout = new HorizontalLayout();
    controlsLayout.setWidth("100%");

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

    MultiFileUploadExt uploadExt = new MultiFileUploadExt(attachments);
    uploadExt.addComponent(attachments);

    // Panel attachedFilepanel = new Panel();
    VerticalLayout contentLayout = new VerticalLayout();
    contentLayout.setHeight("80px");
    contentLayout.setStyleName("noneBorder-panel");
    contentLayout.setSizeUndefined();

    contentLayout.addComponent(uploadExt);

    // attachedFilepanel.setContent(contentLayout);

    controlsLayout.addComponent(contentLayout);
    controlsLayout.setComponentAlignment(contentLayout, Alignment.BOTTOM_LEFT);
    controlsLayout.setExpandRatio(contentLayout, 1.0f);

    controlsLayout.setSpacing(true);

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

                @Override
                public void buttonClick(ClickEvent event) {
                    FeedbackWindow.this.close();
                }
            });

    cancelBtn.setStyleName(UIConstants.THEME_GRAY_LINK);
    controlsLayout.addComponent(cancelBtn);
    controlsLayout.setComponentAlignment(cancelBtn, Alignment.MIDDLE_RIGHT);

    Button sendBtn = new Button("Send", new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            String email = emailTextField.getValue().toString().trim();
            String subject = subjectTextField.getValue().toString().trim();
            if (!StringUtils.isValidEmail(email)) {
                NotificationUtil.showWarningNotification("The email is not valid, please check it again!");
                return;
            }
            if (!email.equals("") && !subject.equals("")) {
                ExtMailService systemMailService = ApplicationContextUtil.getSpringBean(ExtMailService.class);
                List<File> listFile = attachments.getListFile();
                List<EmailAttachementSource> emailAttachmentSource = null;

                if (CollectionUtils.isNotEmpty(listFile)) {
                    emailAttachmentSource = new ArrayList<EmailAttachementSource>();
                    for (File file : listFile) {
                        emailAttachmentSource.add(new FileEmailAttachmentSource(file));
                    }
                }

                String nameEmailFrom = emailNameTextField.getValue().toString().trim();
                nameEmailFrom = nameEmailFrom.equals("") ? email : nameEmailFrom;
                String toEmail = SiteConfiguration.getSendErrorEmail();

                FeedbackWindow.this.close();

                systemMailService.sendHTMLMail(email, nameEmailFrom,
                        Arrays.asList(new MailRecipientField(toEmail, toEmail)), null, null, subject,
                        contentArea.getValue().toString(), emailAttachmentSource);

            } else {
                NotificationUtil.showWarningNotification(
                        "The email field and subject field must be not empty! Please fulfil them before pressing enter button.");
            }
        }
    });
    sendBtn.setStyleName(UIConstants.THEME_GREEN_LINK);
    controlsLayout.addComponent(sendBtn);
    controlsLayout.setComponentAlignment(sendBtn, Alignment.MIDDLE_RIGHT);
    mainLayout.addComponent(controlsLayout, 0, 4, 1, 4);

    this.setContent(mainLayout);
}

From source file:com.esspl.datagen.ui.ResultView.java

License:Open Source License

public ResultView(final DataGenApplication dataGenApplication, ArrayList<GeneratorBean> rowList) {
    log.debug("ResultView constructor start");
    VerticalLayout layout = (VerticalLayout) this.getContent();
    layout.setMargin(false);/*www.j ava2  s  .  c o m*/
    layout.setSpacing(false);
    layout.setHeight("500px");
    layout.setWidth("600px");

    Button close = new Button("Close", new ClickListener() {
        public void buttonClick(ClickEvent event) {
            log.info("ResultView - Close Button clicked");
            dataGenApplication.getMainWindow().removeWindow(event.getButton().getWindow());
        }
    });
    close.setIcon(DataGenConstant.CLOSE_ICON);

    String dataOption = dataGenApplication.generateType.getValue().toString();
    Generator genrator = null;
    if (dataOption.equalsIgnoreCase("xml")) {
        genrator = new XmlDataGenerator();
    } else if (dataOption.equalsIgnoreCase("sql")) {
        genrator = new SqlDataGenerator();
    } else if (dataOption.equalsIgnoreCase("csv")) {
        genrator = new CsvDataGenerator();
    }

    if (genrator == null) {
        log.info("ResultView - genrator object is null");
        dataGenApplication.getMainWindow().removeWindow(this);
        return;
    }

    //Data generated from respective command class and shown in the modal window
    final TextArea message = new TextArea();
    message.setSizeFull();
    message.setHeight("450px");
    message.setWordwrap(false);
    message.setStyleName("noResizeTextArea");
    message.setValue(genrator.generate(dataGenApplication, rowList));
    layout.addComponent(message);

    Button copy = new Button("Copy", new ClickListener() {
        public void buttonClick(ClickEvent event) {
            log.info("ResultView - Copy Button clicked");
            //As on Unix environment, it gives headless exception we need to handle it
            try {
                //StringSelection stringSelection = new StringSelection(message.getValue().toString());
                Transferable tText = new StringSelection(message.getValue().toString());
                Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                clipboard.setContents(tText, null);
            } catch (HeadlessException e) {
                dataGenApplication.getMainWindow()
                        .showNotification("Due to some problem Text could not be copied.");
                e.printStackTrace();
            }
        }
    });
    copy.setIcon(DataGenConstant.COPY_ICON);

    Button execute = new Button("Execute", new ClickListener() {
        public void buttonClick(ClickEvent event) {
            log.info("ResultView - Execute Button clicked");
            dataGenApplication.tabSheet.setSelectedTab(dataGenApplication.executor);
            dataGenApplication.executor.setScript(message.getValue().toString());
            dataGenApplication.getMainWindow().removeWindow(event.getButton().getWindow());
        }
    });
    execute.setIcon(DataGenConstant.EXECUTOR_ICON);

    Button export = new Button("Export to File", new ClickListener() {
        public void buttonClick(ClickEvent event) {
            log.info("ResultView - Export to File Button clicked");
            String dataOption = dataGenApplication.generateType.getValue().toString();
            DataGenStreamUtil resource = null;
            try {
                if (dataOption.equalsIgnoreCase("xml")) {
                    File tempFile = File.createTempFile("tmp", ".xml");
                    BufferedWriter out = new BufferedWriter(new FileWriter(tempFile));
                    out.write(message.getValue().toString());
                    out.close();
                    resource = new DataGenStreamUtil(dataGenApplication, "data.xml", "text/xml", tempFile);
                } else if (dataOption.equalsIgnoreCase("csv")) {
                    File tempFile = File.createTempFile("tmp", ".csv");
                    BufferedWriter out = new BufferedWriter(new FileWriter(tempFile));
                    out.write(message.getValue().toString());
                    out.close();
                    resource = new DataGenStreamUtil(dataGenApplication, "data.csv", "text/csv", tempFile);
                } else if (dataOption.equalsIgnoreCase("sql")) {
                    File tempFile = File.createTempFile("tmp", ".sql");
                    BufferedWriter out = new BufferedWriter(new FileWriter(tempFile));
                    out.write(message.getValue().toString());
                    out.close();
                    resource = new DataGenStreamUtil(dataGenApplication, "data.sql", "text/plain", tempFile);
                }
                getWindow().open(resource, "_self");
            } catch (FileNotFoundException e) {
                log.info("ResultView - Export to File Error - " + e.getMessage());
                e.printStackTrace();
            } catch (IOException e) {
                log.info("ResultView - Export to File Error - " + e.getMessage());
                e.printStackTrace();
            } catch (Exception e) {
                log.info("ResultView - Export to File Error - " + e.getMessage());
                e.printStackTrace();
            }
        }
    });
    export.setIcon(DataGenConstant.EXPORT_ICON);

    HorizontalLayout bttnBar = new HorizontalLayout();
    if (dataOption.equalsIgnoreCase("sql")) {
        bttnBar.addComponent(execute);
    }
    bttnBar.addComponent(export);
    bttnBar.addComponent(copy);
    bttnBar.addComponent(close);
    layout.addComponent(bttnBar);
    layout.setComponentAlignment(bttnBar, Alignment.MIDDLE_CENTER);
    log.debug("ResultView constructor end");
}