Example usage for com.vaadin.ui Upload Upload

List of usage examples for com.vaadin.ui Upload Upload

Introduction

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

Prototype

public Upload() 

Source Link

Document

Creates a new instance of Upload.

Usage

From source file:com.anphat.customer.ui.ImportCustomerUploadForm.java

private void buildGridTermInfo() {
    gridTermInfo = new GridLayout(4, 3);
    CommonUtils.setBasicAttributeLayout(gridTermInfo, GRID_UPLOAD_CAPTION, true);
    gridTermInfo.setImmediate(true);// w ww  . ja v  a 2s  .  co m
    gridTermInfo.setWidth("100%");
    gridTermInfo.setHeight("-1px");

    cboService = CommonUtils.buildComboBox("term.information.service");
    cboService.setRequired(true);
    cboService.setRequiredError(CommonMessages.messageRequire("customerStatusForm.service"));
    cboMineName = CommonUtils.buildComboBox("term.information.mineName");
    cboMineName.setRequired(true);
    tfMineName = CommonUtils.buildTextField(BundleUtils.getString("term.information.mineName"), 100);
    tfMineName.setRequired(true);
    gridTermInfo.addComponent(cboService, 2, 1);
    gridTermInfo.addComponent(cboMineName, 3, 1);
    btnAddMineName = new Button(BundleUtils.getString("button.add.mineName"));
    btnAddMineName.setIcon(new ThemeResource(Constants.ICON.ADD));
    btnAddMineName.setDisableOnClick(true);
    btnAddMineName.addStyleName("v-button-link");
    gridTermInfo.addComponent(btnAddMineName, 3, 2);

    uFileCommonInfo = new Upload();
    uFileCommonInfo.setCaption(Constants.NULL);
    uFileTermInfo = new Upload();
    uFileTermInfo.setCaption(Constants.NULL);
    uFileCommonInfo.setWidth("100%");
    uFileTermInfo.setWidth("100%");

    gridTermInfo.addComponent(uFileTermInfo, 0, 1, 1, 1);

    gridTermInfo.addComponent(uFileCommonInfo, 0, 0, 1, 0);
    gridTermInfo.setComponentAlignment(uFileCommonInfo, Alignment.MIDDLE_CENTER);
    gridTermInfo.setComponentAlignment(uFileTermInfo, Alignment.MIDDLE_CENTER);
}

From source file:com.anphat.list.ui.PopupAddContractTemplateList.java

public PopupAddContractTemplateList() {
    setCaption(BundleUtils.getString("dialog.ContractTemplateList.caption"));
    mainLayout.setImmediate(true);//from  w  w  w  . ja v  a2 s .c  om
    mainLayout.setWidth("100%");
    mainLayout.setHeight("-1px");
    mainLayout.setMargin(true);
    mainLayout.setSpacing(true);
    mainLayout.setStyleName("main-popup");

    addContractTemplateListLayout = new GridLayout();
    CommonUtils.setBasicAttributeLayout(addContractTemplateListLayout,
            BundleUtils.getString("dialog.ContractTemplateList.caption"), true);
    addContractTemplateListLayout.setColumns(4);
    addContractTemplateListLayout.setRows(4);
    setWidth("80.0%");
    setHeight("-1px");
    setModal(true);
    lblCode = new Label();
    lblCode.setImmediate(true);
    lblCode.setWidth("100.0%");
    lblCode.setHeight("-1px");
    lblCode.setValue(BundleUtils.getString("label.ContractTemplateList.code"));
    addContractTemplateListLayout.addComponent(lblCode, 0, 0);

    txtCode = new TextField();
    txtCode.setImmediate(true);
    txtCode.setWidth("100.0%");
    txtCode.setHeight("-1px");
    txtCode.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.TIMEOUT);
    txtCode.setTextChangeTimeout(10);
    addContractTemplateListLayout.addComponent(txtCode, 1, 0);

    lblName = new Label();
    lblName.setImmediate(true);
    lblName.setWidth("100.0%");
    lblName.setHeight("-1px");
    lblName.setValue(BundleUtils.getString("label.ContractTemplateList.name"));
    addContractTemplateListLayout.addComponent(lblName, 2, 0);

    txtName = new TextField();
    txtName.setImmediate(true);
    txtName.setWidth("100.0%");
    txtName.setHeight("-1px");
    txtName.setTextChangeEventMode(AbstractTextField.TextChangeEventMode.TIMEOUT);
    txtName.setTextChangeTimeout(10);
    addContractTemplateListLayout.addComponent(txtName, 3, 0);

    lblPathFile = new Label();
    lblPathFile.setImmediate(true);
    lblPathFile.setWidth("100.0%");
    lblPathFile.setHeight("-1px");
    lblPathFile.setValue(BundleUtils.getString("label.ContractTemplateList.pathFile"));
    uFile = new Upload();
    uFile.setButtonCaption("Ti file");
    uFile.addStyleName("upload-hide");
    uFile.setReceiver(new Upload.Receiver() {
        @Override
        public OutputStream receiveUpload(String filename, String mimeType) {
            if (DataUtil.isStringNullOrEmpty(filename)) {
                CommonUtils.showMessage("err.choosefileBeforeUpload");
                uFile.interruptUpload();
                isUploadSuccess = false;
                return new NullOutputStream();
            }
            String code = txtCode.getValue();
            String name = txtName.getValue();
            if (DataUtil.isStringNullOrEmpty(code)) {
                txtCode.focus();
                CommonUtils.showMessageRequired("label.ContractTemplateList.code");
                uFile.interruptUpload();
                isUploadSuccess = false;
                return new NullOutputStream();
            }
            if (DataUtil.isStringNullOrEmpty(name)) {
                txtName.focus();
                CommonUtils.showMessageRequired("label.ContractTemplateList.name");
                isUploadSuccess = false;
                uFile.interruptUpload();
                return new NullOutputStream();
            }
            long contentLength = uFile.getUploadSize();
            if (contentLength > Constants.FILE_SIZE_IMPORT && contentLength != -1) {
                CommonUtils.showContentLengthValid();
                isUploadSuccess = false;
                uFile.interruptUpload();
                return new NullOutputStream();
            }

            fileNameUploaded = filename;
            FileOutputStream fos = null; // Output stream to write to
            File file = new File(Constants.PATH_TEMPLATE + filename);
            try {
                if (Constants.FORMATFILE.WORD_DOCX.equals(mimeType)) {
                    // Open the file for writing.
                    fos = new FileOutputStream(file);
                    isUploadSuccess = true;
                } else {
                    fileNameUploaded = null;
                    isUploadSuccess = false;
                    uFile.interruptUpload();
                    CommonUtils.showErrorMessage("err.only.docx.file");
                    return new NullOutputStream();
                }
            } catch (final java.io.FileNotFoundException e) {
                fileNameUploaded = null;
                CommonUtils.showErrorMessage("common.message.invalidfileformat");
                isUploadSuccess = false;
                uFile.interruptUpload();
                return new NullOutputStream();
            }
            return fos; // Return the output stream to write to
        }
    });
    uFile.addSucceededListener(e -> {
        if (isUploadSuccess) {
            CommonUtils.showMessage("Ti file thnh cng.");
        }
    });
    //        addContractTemplateListLayout.addComponent(uFile, 0, 1, 1, 1);
    lblService = new Label();
    lblService.setImmediate(true);
    lblService.setWidth("100.0%");
    lblService.setHeight("-1px");
    lblService.setValue(BundleUtils.getString("label.ContractTemplateList.service"));
    addContractTemplateListLayout.addComponent(lblService, 0, 1);

    cboService = new ComboBox();
    cboService.setImmediate(true);
    cboService.setWidth("100.0%");
    cboService.setHeight("-1px");
    addContractTemplateListLayout.addComponent(cboService, 1, 1);

    lblType = new Label();
    lblType.setImmediate(true);
    lblType.setWidth("100.0%");
    lblType.setHeight("-1px");
    lblType.setValue(BundleUtils.getString("label.ContractTemplateList.type"));
    addContractTemplateListLayout.addComponent(lblType, 2, 1);

    cboType = new ComboBox();
    cboType.setImmediate(true);
    cboType.setWidth("100.0%");
    cboType.setHeight("-1px");
    addContractTemplateListLayout.addComponent(cboType, 3, 1);

    lblCreatedDate = new Label();
    lblCreatedDate.setImmediate(true);
    lblCreatedDate.setWidth("100.0%");
    lblCreatedDate.setHeight("-1px");
    lblCreatedDate.setValue(BundleUtils.getString("label.ContractTemplateList.createdDate"));
    //        addContractTemplateListLayout.addComponent(lblCreatedDate, 0, 2);

    popCreatedDate = new PopupDateField();
    popCreatedDate.setImmediate(true);
    popCreatedDate.setWidth("100.0%");
    popCreatedDate.setHeight("-1px");
    //        addContractTemplateListLayout.addComponent(popCreatedDate, 1, 2);
    lblLastUpdatedDate = new Label();
    lblLastUpdatedDate.setImmediate(true);
    lblLastUpdatedDate.setWidth("100.0%");
    lblLastUpdatedDate.setHeight("-1px");
    lblLastUpdatedDate.setValue(BundleUtils.getString("label.ContractTemplateList.lastUpdatedDate"));
    //        addContractTemplateListLayout.addComponent(lblLastUpdatedDate, 2, 2);

    popLastUpdatedDate = new PopupDateField();
    popLastUpdatedDate.setImmediate(true);
    popLastUpdatedDate.setWidth("100.0%");
    popLastUpdatedDate.setHeight("-1px");
    //        addContractTemplateListLayout.addComponent(popLastUpdatedDate, 3, 2);

    lblProvider = new Label();
    lblProvider.setImmediate(true);
    lblProvider.setWidth("100.0%");
    lblProvider.setHeight("-1px");
    lblProvider.setValue(BundleUtils.getString("label.ContractTemplateList.provider"));
    addContractTemplateListLayout.addComponent(lblProvider, 0, 2);

    cboProvider = new ComboBox();
    cboProvider.setImmediate(true);
    cboProvider.setWidth("100.0%");
    cboProvider.setHeight("-1px");
    addContractTemplateListLayout.addComponent(cboProvider, 1, 2);

    lblStatus = new Label();
    lblStatus.setImmediate(true);
    lblStatus.setWidth("100.0%");
    lblStatus.setHeight("-1px");
    lblStatus.setValue(BundleUtils.getString("label.ContractTemplateList.status"));
    addContractTemplateListLayout.addComponent(lblStatus, 2, 2);

    cbxStatus = new ComboBox();
    cbxStatus.setImmediate(true);
    cbxStatus.setWidth("100.0%");
    cbxStatus.setHeight("-1px");
    addContractTemplateListLayout.addComponent(cbxStatus, 3, 2);

    mainLayout.addComponent(addContractTemplateListLayout);
    mainLayout.addComponent(uFile);
    GridManyButton gridBtnPrint = new GridManyButton(
            new String[] { Constants.BUTTON_SAVE, Constants.BUTTON_CLOSE });
    mainLayout.addComponent(gridBtnPrint);
    btnSave = gridBtnPrint.getBtnCommon().get(0);

    btnClose = gridBtnPrint.getBtnCommon().get(1);
    btnClose.addClickListener(e -> {
        close();
    });
    setContent(mainLayout);
}

From source file:com.anphat.statistics.ui.StatisticStaffPointUploadDialog.java

private GridLayout buildGridUpload() {
    uploadInfoLayout = new GridLayout(4, 1);
    CommonUtils.setBasicAttributeLayout(uploadInfoLayout, GRID_UPLOAD_CAPTION, true);
    uFileCommonInfo = new Upload();
    uFileCommonInfo.setCaption(Constants.NULL);
    uFileCommonInfo.setWidth("100%");

    uploadInfoLayout.addComponent(uFileCommonInfo, 0, 0, 1, 0);
    uploadInfoLayout.setComponentAlignment(uFileCommonInfo, Alignment.MIDDLE_CENTER);

    linkTemplate = new Link(LINK_CAPTION, FontAwesome.LINK);
    linkTemplate.setImmediate(true);/*from  w w w  .j ava  2  s .c o m*/
    File file = new File(Constants.PATH_TEMPLATE + "Thong ke diem.xlsx");
    FileDownloader downloader = new FileDownloader(file, "Thong ke diem.xlsx");
    linkTemplate.setResource(downloader);
    uploadInfoLayout.addComponent(linkTemplate, 2, 0);

    return uploadInfoLayout;
}

From source file:com.cms.ui.PopupImportFileUI.java

public PopupImportFileUI() {
    mainLayout.setImmediate(true);//w w w .j  a va 2  s  . co m
    mainLayout.setCaption(BundleUtils.getString("title.choseFile"));
    mainLayout.setWidth("100%");
    mainLayout.setHeight("-1px");
    mainLayout.setMargin(true);
    mainLayout.setSpacing(true);
    mainLayout.setStyleName("main-popup");
    setWidth("30.0%");
    setHeight("-1px");
    setModal(true);

    gridLayout = new GridLayout();
    //        gridLayout.setCaption(MakeURL.makeURLForGrid(BundleUtils.getString("stone.label.search.info")));
    //        gridLayout.setCaptionAsHtml(true);
    gridLayout.setImmediate(false);
    gridLayout.setWidth("100.0%");
    gridLayout.setHeight("-1px");
    gridLayout.setMargin(true);
    gridLayout.setSpacing(true);
    gridLayout.setColumns(2);
    gridLayout.setRows(5);
    gridLayout.setStyleName("custom-feildset");

    uploadFile = new Upload();
    uploadFile.setImmediate(false);
    uploadFile.setWidth("100.0%");
    uploadFile.setHeight("-1px");
    gridLayout.addComponent(uploadFile, 0, 0);

    linkTemplate = new Link();
    linkTemplate.setCaption("Ti file biu mu");
    linkTemplate.setImmediate(false);
    linkTemplate.setWidth("100%");
    linkTemplate.setHeight("-1px");
    gridLayout.addComponent(linkTemplate, 0, 1);

    mainLayout.addComponent(gridLayout);
    setContent(mainLayout);
}

From source file:com.fatminds.vaadin_cmis_integration.demo.DemoPage.java

License:Apache License

@AutoGenerated
private VerticalLayout buildVerticalLayout_2() {
    // common part: create layout
    verticalLayout_2 = new VerticalLayout();
    verticalLayout_2.setImmediate(false);
    verticalLayout_2.setWidth("-1px");
    verticalLayout_2.setHeight("-1px");
    verticalLayout_2.setMargin(false);//from   w w  w .  j ava  2s .c  o  m

    // label_1
    label_1 = new Label();
    label_1.setImmediate(false);
    label_1.setWidth("-1px");
    label_1.setHeight("-1px");
    label_1.setValue("Upload a text or html file");
    verticalLayout_2.addComponent(label_1);
    verticalLayout_2.setComponentAlignment(label_1, new Alignment(33));

    // upload_1
    upload_1 = new Upload();
    upload_1.setImmediate(false);
    upload_1.setWidth("100.0%");
    upload_1.setHeight("100.0%");
    verticalLayout_2.addComponent(upload_1);
    verticalLayout_2.setComponentAlignment(upload_1, new Alignment(33));

    return verticalLayout_2;
}

From source file:com.jain.addon.component.upload.JUploader.java

License:Apache License

public JUploader() {
    setWidth("100%");
    setMargin(new MarginInfo(true, false, true, false));
    setStyleName("j-upload");

    upload = new Upload();
    upload.setWidth("100%");
    upload.setImmediate(true);/*from www. j a va2s.  co  m*/
    addComponent(upload);

    pi = new JProgressIndicator();
    upload.addProgressListener(pi);
    addComponent(pi);
    pi.setVisible(false);

    receiver = new JFileReceiver();
    upload.setReceiver(receiver);

    upload.addSucceededListener(this);
    upload.addStartedListener(this);
}

From source file:com.klwork.explorer.ui.user.ProfilePanel.java

License:Apache License

protected Upload initChangePictureButton() {
    final Upload changePictureUpload = new Upload();
    changePictureUpload.setImmediate(true);
    changePictureUpload.setButtonCaption(i18nManager.getMessage(Messages.PROFILE_CHANGE_PICTURE));

    final InMemoryUploadReceiver receiver = initPictureReceiver(changePictureUpload);
    changePictureUpload.addFinishedListener(new FinishedListener() {
        private static final long serialVersionUID = 1L;

        public void uploadFinished(FinishedEvent event) {
            if (!receiver.isInterruped()) {
                picture = new Picture(receiver.getBytes(), receiver.getMimeType());
                identityService.setUserPicture(userId, picture);

                // reset picture
                imageLayout.removeAllComponents();
                initPicture();/*from  w  w  w .j ava  2s.c  o  m*/
            } else {
                receiver.reset();
            }
        }
    });

    return changePictureUpload;
}

From source file:com.salsaw.msalsa.HomePageView.java

License:Apache License

@AutoGenerated
private GridLayout buildMainLayout() {
    // common part: create layout
    mainLayout = new GridLayout();
    mainLayout.setImmediate(false);//from   ww  w .jav  a 2s  .c o  m
    mainLayout.setWidth("100%");
    mainLayout.setHeight("100%");
    mainLayout.setMargin(false);
    mainLayout.setRows(4);

    // top-level component properties
    setWidth("100.0%");
    setHeight("100.0%");

    // title
    title = new Label();
    title.setImmediate(false);
    title.setWidth("-1px");
    title.setHeight("-1px");
    title.setValue("M-SALSA");
    mainLayout.addComponent(title, 0, 0);
    mainLayout.setComponentAlignment(title, new Alignment(48));

    // uploadInput
    uploadInput = new Upload();
    uploadInput.setCaption("Upload and process align input");
    uploadInput.setImmediate(false);
    uploadInput.setWidth("-1px");
    uploadInput.setHeight("-1px");
    mainLayout.addComponent(uploadInput, 0, 1);
    mainLayout.setComponentAlignment(uploadInput, new Alignment(48));

    return mainLayout;
}

From source file:com.vaushell.treetasker.application.actionbar.TTWActionBar.java

License:Open Source License

@AutoGenerated
private HorizontalLayout buildButtonsLayout() {
    // common part: create layout
    buttonsLayout = new HorizontalLayout();
    buttonsLayout.setImmediate(false);/*w w w. ja v a 2s  .  co m*/
    buttonsLayout.setWidth("1000px");
    buttonsLayout.setHeight("100.0%");
    buttonsLayout.setMargin(false);
    buttonsLayout.setSpacing(true);

    // vBTnewTask
    vBTnewTask = new Button();
    vBTnewTask.setCaption("Insrer une tche");
    vBTnewTask.setIcon(new ThemeResource("icons/newTask.png"));
    vBTnewTask.setImmediate(true);
    vBTnewTask.setDescription("Insrer une tche");
    vBTnewTask.setWidth("-1px");
    vBTnewTask.setHeight("-1px");
    buttonsLayout.addComponent(vBTnewTask);
    buttonsLayout.setComponentAlignment(vBTnewTask, new Alignment(20));

    // vBTaddSubtask
    vBTaddSubtask = new Button();
    vBTaddSubtask.setCaption("Ajouter une sous-tche");
    vBTaddSubtask.setIcon(new ThemeResource("icons/newSubtask.png"));
    vBTaddSubtask.setImmediate(true);
    vBTaddSubtask.setDescription("Ajouter une sous-tche");
    vBTaddSubtask.setWidth("-1px");
    vBTaddSubtask.setHeight("-1px");
    buttonsLayout.addComponent(vBTaddSubtask);
    buttonsLayout.setComponentAlignment(vBTaddSubtask, new Alignment(20));

    // vBTrefresh
    vBTrefresh = new Button();
    vBTrefresh.setCaption("Actualiser");
    vBTrefresh.setIcon(new ThemeResource("icons/refresh.png"));
    vBTrefresh.setImmediate(true);
    vBTrefresh.setDescription("Actualiser la liste des tches");
    vBTrefresh.setWidth("-1px");
    vBTrefresh.setHeight("-1px");
    buttonsLayout.addComponent(vBTrefresh);
    buttonsLayout.setComponentAlignment(vBTrefresh, new Alignment(20));

    // vBTremove
    vBTremove = new Button();
    vBTremove.setCaption("Supprimer");
    vBTremove.setIcon(new ThemeResource("icons/delete.png"));
    vBTremove.setImmediate(true);
    vBTremove.setDescription("Supprimer les tches slectionnes");
    vBTremove.setWidth("-1px");
    vBTremove.setHeight("-1px");
    buttonsLayout.addComponent(vBTremove);
    buttonsLayout.setComponentAlignment(vBTremove, new Alignment(20));

    // vBTcopy
    vBTcopy = new Button();
    vBTcopy.setCaption("Copier");
    vBTcopy.setIcon(new ThemeResource("icons/copy.png"));
    vBTcopy.setImmediate(true);
    vBTcopy.setDescription("Copier les tches slectionnes");
    vBTcopy.setWidth("-1px");
    vBTcopy.setHeight("-1px");
    buttonsLayout.addComponent(vBTcopy);
    buttonsLayout.setComponentAlignment(vBTcopy, new Alignment(20));

    // vBTpaste
    vBTpaste = new Button();
    vBTpaste.setCaption("Coller");
    vBTpaste.setIcon(new ThemeResource("icons/paste.png"));
    vBTpaste.setImmediate(true);
    vBTpaste.setDescription("Coller les tches slectionnes");
    vBTpaste.setWidth("-1px");
    vBTpaste.setHeight("-1px");
    buttonsLayout.addComponent(vBTpaste);
    buttonsLayout.setComponentAlignment(vBTpaste, new Alignment(20));

    // vUPimport
    vUPimport = new Upload();
    vUPimport.setIcon(new ThemeResource("icons/import.png"));
    vUPimport.setImmediate(true);
    vUPimport.setDescription("Importer depuis TaskCoach");
    vUPimport.setWidth("-1px");
    vUPimport.setHeight("-1px");
    buttonsLayout.addComponent(vUPimport);

    // vBTlogout
    vBTlogout = new Button();
    vBTlogout.setCaption("Se dconnecter");
    vBTlogout.setIcon(new ThemeResource("icons/logout.png"));
    vBTlogout.setImmediate(true);
    vBTlogout.setDescription("Se dconnecter");
    vBTlogout.setWidth("-1px");
    vBTlogout.setHeight("-1px");
    buttonsLayout.addComponent(vBTlogout);
    buttonsLayout.setExpandRatio(vBTlogout, 1.0f);
    buttonsLayout.setComponentAlignment(vBTlogout, new Alignment(6));

    return buttonsLayout;
}

From source file:de.catma.ui.repository.wizard.UploadPanel.java

License:Open Source License

private void initComponents() {
    setSpacing(true);/*from  w w  w.j  a  v a 2 s .  c  om*/
    upload = new Upload();
    upload.setButtonCaption("Upload local file");
    upload.setImmediate(true);
    addComponent(upload);

    pi = new ProgressIndicator();
    pi.setVisible(false);
    addComponent(pi);
    setComponentAlignment(pi, Alignment.MIDDLE_CENTER);

    btCancelUpload = new Button("Cancel");
    addComponent(btCancelUpload);
    btCancelUpload.setVisible(false);

    fileLabel = new Label();
    fileLabel.setVisible(false);
    addComponent(fileLabel);
    setComponentAlignment(fileLabel, Alignment.MIDDLE_CENTER);

}