List of usage examples for com.vaadin.ui Upload Upload
public Upload()
From source file:de.unioninvestment.eai.portal.portlet.crud.mvp.views.configuration.DefaultPortletConfigurationView.java
License:Apache License
private VerticalLayout createStatusLayout() { status = new Label(); status.setContentMode(ContentMode.HTML); upload = new Upload(); upload.setImmediate(true);/*from w w w.j ava 2s . c o m*/ upload.setButtonCaption(getMessage("portlet.crud.page.upload.button")); uploadVcsUri = new TextField(); uploadVcsUri.setWidth(400, Unit.PIXELS); uploadVcsButton = new Button(); uploadVcsButton.setCaption(getMessage("portlet.crud.page.upload.vcs.button")); uploadVcsLayout.addComponent(uploadVcsButton); uploadVcsLayout.addComponent(uploadVcsUri); uploadVcsLayout.setSpacing(true); VerticalLayout statusLayout = new VerticalLayout(); statusLayout.setCaption(getMessage("portlet.crud.page.edit.statusHeader")); statusLayout.setSpacing(true); statusLayout.setMargin(true); statusLayout.addComponent(status); statusLayout.addComponent(uploadVcsLayout); statusLayout.addComponent(upload); return statusLayout; }
From source file:de.unioninvestment.eai.portal.portlet.crud.mvp.views.DefaultRowEditingFormView.java
License:Apache License
private Upload buildUpload(final ContainerRow row, final ContainerBlob containerBlob, final FileMetadata metadata, final Link downloadLink) { final Upload upload = new Upload(); if (metadata.getUploadCaption() != null) { upload.setButtonCaption(metadata.getUploadCaption()); } else {//from ww w .java 2 s .c o m upload.setButtonCaption("Upload"); } upload.setImmediate(true); upload.setReceiver(new BlobUploadReceiver()); upload.addFinishedListener(new Upload.FinishedListener() { private static final long serialVersionUID = 1L; @Override public void uploadFinished(FinishedEvent event) { BlobUploadReceiver receiver = (BlobUploadReceiver) upload.getReceiver(); if (receiver.getBaos().size() <= 0 || receiver.getBaos().size() <= metadata.getMaxFileSize()) { containerBlob.setValue(receiver.getBaos().toByteArray()); if (metadata.getFilenameColumn() != null) { row.getValues().put(metadata.getFilenameColumn(), receiver.getFilename()); } if (metadata.getMimetypeColumn() != null) { row.getValues().put(metadata.getMimetypeColumn(), receiver.getMimetype()); } updateDownloadLink(row, containerBlob, metadata, downloadLink); } else { Notification.show( "Ein Datei darauf nicht grer als " + metadata.getMaxFileSize() + " Bytes sein.", Notification.Type.ERROR_MESSAGE); } } }); return upload; }
From source file:edu.nps.moves.mmowgli.modules.actionplans.AddImageDialog.java
License:Open Source License
@SuppressWarnings("serial") @HibernateSessionThreadLocalConstructor//from w w w . ja v a 2 s . c om public AddImageDialog(Object apId) { super("Add an Image"); addStyleName("m-greybackground"); setClosable(false); // no x in corner VerticalLayout mainVL = new VerticalLayout(); mainVL.setSpacing(true); mainVL.setMargin(true); mainVL.setSizeUndefined(); // auto size setContent(mainVL); mainHL = new HorizontalLayout(); mainVL.addComponent(mainHL); mainHL.setSpacing(true); holder = new AbsoluteLayout(); mainHL.addComponent(holder); holder.setWidth("150px"); holder.setHeight("150px"); holder.addStyleName("m-darkgreyborder"); VerticalLayout rightVL = new VerticalLayout(); mainHL.addComponent(rightVL); fromWebCheck = new CheckBox(); fromWebCheck.addStyleName("v-radiobutton"); fromWebCheck.setValue(true); fromWebCheck.setImmediate(true); fromWebCheck.addValueChangeListener(new RadioListener(fromWebCheck)); HorizontalLayout frWebHL = new HorizontalLayout(); rightVL.addComponent(frWebHL); frWebHL.addComponent(fromWebCheck); VerticalLayout frWebVL = new VerticalLayout(); frWebVL.setMargin(true); frWebVL.addStyleName("m-greyborder"); frWebHL.addComponent(frWebVL); frWebVL.setWidth("370px"); frWebVL.addComponent(new Label("From the web:")); HorizontalLayout webHL = new HorizontalLayout(); webHL.setSpacing(true); frWebVL.addComponent(webHL); webHL.addComponent(webUrl = new TextField()); webUrl.setColumns(21); webHL.addComponent(testButt = new Button("Test")); Label sp; webHL.addComponent(sp = new Label()); sp.setWidth("1px"); webHL.setExpandRatio(sp, 1.0f); fromDeskCheck = new CheckBox(); fromDeskCheck.addStyleName("v-radiobutton"); fromDeskCheck.setValue(false); fromDeskCheck.addValueChangeListener(new RadioListener(fromDeskCheck)); fromDeskCheck.setImmediate(true); HorizontalLayout dtHL = new HorizontalLayout(); rightVL.addComponent(dtHL); dtHL.addComponent(fromDeskCheck); VerticalLayout dtopVL = new VerticalLayout(); dtopVL.setMargin(true); dtopVL.addStyleName("m-greyborder"); dtHL.addComponent(dtopVL); dtopVL.setWidth("370px"); dtopVL.addComponent(new Label("From your desktop:")); HorizontalLayout localHL = new HorizontalLayout(); localHL.setSpacing(true); dtopVL.addComponent(localHL); localHL.addComponent(localTF = new TextField()); localTF.setColumns(21); localHL.addComponent(uploadWidget = new Upload()); panel = new UploadStatus(uploadWidget); uploadWidget.setButtonCaption("Browse"); File tempDir = Files.createTempDir(); tempDir.deleteOnExit(); handler = new UploadHandler(uploadWidget, panel, tempDir.getAbsolutePath()); uploadWidget.setReceiver(handler); uploadWidget.setImmediate(true); panel.setWidth("100%"); dtopVL.addComponent(panel); dtopVL.setComponentAlignment(panel, Alignment.TOP_CENTER); HorizontalLayout bottomHL = new HorizontalLayout(); mainVL.addComponent(bottomHL); bottomHL.setSpacing(true); bottomHL.setWidth("100%"); Label spacer; bottomHL.addComponent(spacer = new Label()); spacer.setWidth("100%"); bottomHL.setExpandRatio(spacer, 1.0f); bottomHL.addComponent(cancelButt = new Button("Cancel")); bottomHL.addComponent(submitButt = new Button("Add")); setDisabledFields(); uploadWidget.addFinishedListener(new FinishedListener() { @Override public void uploadFinished(FinishedEvent event) { Object key = HSess.checkInit(); System.out.println("AddImageDialog.uploadFinished()"); String fpath = handler.getFullUploadedPath(); if (fpath != null) { // error of some kind if null if (!MalwareChecker.isFileVirusFree(fpath)) { panel.state.setValue("<span style='color:red;'>Failed malware check</span>"); fpath = null; localTF.setValue(""); HSess.checkClose(key); return; } File f = new File(fpath); f.deleteOnExit(); try { MediaImage mediaImage = InstallImageDialog.putFileImageIntoDbTL(f, f.getName(), event.getMIMEType()); f.delete(); media = mediaImage.media; image = mediaImage.image; media.setCaption(null); Resource res = Mmowgli2UI.getGlobals().getMediaLocator().locate(media); setupEmbeddedImageThumbnail(res, media); localTF.setValue(event.getFilename()); } catch (IOException ex) { Notification.show("Error loading image", Notification.Type.ERROR_MESSAGE); MSysOut.println(ERROR_LOGS, "Error in AddImageDialog loading image: " + ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage()); } } HSess.checkClose(key); } }); testButt.addClickListener(new testWebImageHandler()); submitButt.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (fromWebCheck.getValue()) { if (checkBadUrl(webUrl.getValue(), event.getButton())) return; } UI.getCurrent().removeWindow(AddImageDialog.this); if (closer != null) closer.windowClose(null); } }); cancelButt.addClickListener(new ClickListener() { public void buttonClick(ClickEvent event) { Object key = HSess.checkInit(); if (media != null) { Media.deleteTL(media); media = null; } if (image != null) { Image.deleteTL(image); image = null; } uploadWidget.interruptUpload(); UI.getCurrent().removeWindow(AddImageDialog.this); if (closer != null) closer.windowClose(null); HSess.checkClose(key); } }); webUrl.focus(); }
From source file:edu.nps.moves.mmowgli.modules.userprofile.InstallImageDialog.java
License:Open Source License
@SuppressWarnings("serial") private InstallImageDialog(String topText, InstallImageResultListener lis, boolean showExisting, String nameFilter) {//from w w w . j a v a 2 s . c o m Object sessKey = HSess.checkInit(); listener = lis; setCaption(showExisting ? "Choose Existing or Upload New Image" : "Upload New Image"); setModal(true); setWidth("350px"); VerticalLayout vl; VerticalLayout vLay = new VerticalLayout(); setContent(vLay); vLay.setMargin(true); vLay.setSpacing(true); if (topText != null && topText.length() > 0) { HtmlLabel lab = new HtmlLabel(topText); lab.setWidth("100%"); vLay.addComponent(lab); } if (showExisting) { // put the existing selector in the dialog Criteria crit = HSess.get().createCriteria(Media.class) .add(Restrictions.eq("source", Media.Source.DATABASE)).addOrder(Order.asc("url")); if (nameFilter != null) crit.add(Restrictions.like("handle", nameFilter, MatchMode.ANYWHERE)); @SuppressWarnings({ "unchecked" }) List<Media> mlis = crit.list(); BeanItemContainer<Media> beanContainer = new BeanItemContainer<Media>(Media.class, mlis); vLay.addComponent(existingCB = new CheckBox("Choose from existing images", true)); vLay.addComponent(vl = new VerticalLayout()); vl.addStyleName("m-greyborder"); vl.addStyleName("m-greybackground"); vl.setMargin(true); vl.setSpacing(true); vl.addComponent(sel = new ListSelect()); sel.setWidth("100%"); sel.setNullSelectionAllowed(false); sel.setContainerDataSource(beanContainer); sel.setItemCaptionPropertyId("url"); vl.addComponent(saveExistingButt = new NativeButton("Return selected image", new ClickListener() { @Override public void buttonClick(ClickEvent event) { HSess.init(); mediaImage = new MediaImage((Media) sel.getValue(), null); doneHereTL(); HSess.close(); } })); vLay.addComponent(newCB = new CheckBox("Upload new image", false)); } // Here for the file chooser vLay.addComponent(vl = new VerticalLayout()); vl.addStyleName("m-greyborder"); vl.addStyleName("m-greybackground"); vl.setSpacing(true); vl.setMargin(true); ImgReceiver rec; uploadFileWidget = new Upload();// "Image name", rec = new ImgReceiver()); uploadFileWidget.setReceiver(rec = new ImgReceiver()); uploadFileWidget.setButtonCaption("Browse"); uploadFileWidget.setImmediate(true); uploadFileWidget.addFailedListener(rec); uploadFileWidget.addFinishedListener(rec); uploadFileWidget.setEnabled(showExisting ? false : true); vl.addComponent(uploadFileWidget); vl.addComponent(fileNameTF = new TextField()); fileNameTF.setWidth("100%"); fileNameTF.setEnabled(showExisting ? false : true); fileNameTFState = false; HorizontalLayout hLay; vl.addComponent(hLay = new HorizontalLayout()); hLay.setSpacing(true); hLay.addComponent(saveImageButt = new NativeButton("Save image with above name", rec)); // hLay.addComponent(savedLab = new HtmlLabel("<i>saved</i>")); saveImageButt.setImmediate(true); saveImageButt.addClickListener(rec); saveImageButt.setEnabled(false); saveImageButtState = false; vLay.addComponent(new NativeButton("Close", new ClickListener() { @Override public void buttonClick(ClickEvent event) { HSess.init(); doneHereTL(); HSess.close(); } })); if (showExisting) { existingCB.addValueChangeListener(new CheckBoxListener(existingCB)); newCB.addValueChangeListener(new CheckBoxListener(newCB)); } HSess.checkClose(sessKey); }
From source file:facs.components.UploadBox.java
License:Open Source License
public UploadBox() { this.setCaption(CAPTION); // there has to be a device selected. devices = new NativeSelect("Devices"); devices.setDescription("Select a device in order to upload information for that specific devices."); devices.setNullSelectionAllowed(false); deviceNameToId = new HashMap<String, Integer>(); for (DeviceBean bean : DBManager.getDatabaseInstance().getDevices()) { deviceNameToId.put(bean.getName(), bean.getId()); devices.addItem(bean.getName()); // System.out.println("Bean.getName: " + bean.getName() + " Bean.getId: " + bean.getId()); }/*from w w w . j av a 2 s . c o m*/ occupationGrid = new Grid(); occupationGrid.setSizeFull(); // Create the upload component and handle all its events final Upload upload = new Upload(); upload.setReceiver(this); upload.addProgressListener(this); upload.addFailedListener(this); upload.addSucceededListener(this); upload.setVisible(false); // one can only upload csvs, if a device was selected. devices.addValueChangeListener(new ValueChangeListener() { /** * */ private static final long serialVersionUID = 7890499571475184208L; @Override public void valueChange(ValueChangeEvent event) { upload.setVisible(event.getProperty().getValue() != null); } }); // Put the upload and image display in a panel // Panel panel = new Panel(UPLOAD_CAPTION); // panel.setWidth("100%"); VerticalLayout panelContent = new VerticalLayout(); panelContent.setSpacing(true); // panel.setContent(panelContent); panelContent.addComponent(devices); panelContent.addComponent(upload); panelContent.addComponent(progress); panelContent.addComponent(occupationGrid); panelContent.setMargin(true); panelContent.setSpacing(true); progress.setVisible(false); setCompositionRoot(panelContent); }
From source file:makeithappen.vaadin.custom.control.UploadCustomComponent.java
License:Open Source License
@Override protected Component render() { final HorizontalLayout horizontalLayout = new HorizontalLayout(); label = new Label(); horizontalLayout.addComponent(label); final Upload upload = new Upload(); horizontalLayout.addComponent(upload); return horizontalLayout; }
From source file:org.activiti.explorer.ui.profile.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.addListener(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 ww .ja v a 2 s. co m*/ } else { receiver.reset(); } } }); return changePictureUpload; }
From source file:org.apache.ace.webui.vaadin.AddArtifactWindow.java
License:Apache License
/** * Creates a new {@link AddArtifactWindow} instance. * //from ww w.j a v a2 s. c o m * @param sessionDir * the session directory to temporary place artifacts in; * @param obrUrl * the URL of the OBR to use. */ public AddArtifactWindow(File sessionDir, URL obrUrl, String repositoryXML) { super("Add artifact"); m_sessionDir = sessionDir; m_obrUrl = obrUrl; m_repositoryXML = repositoryXML; setModal(true); setWidth("50em"); setCloseShortcut(KeyCode.ESCAPE); m_artifactsTable = new Table("Artifacts in repository"); m_artifactsTable.addContainerProperty(PROPERTY_SYMBOLIC_NAME, String.class, null); m_artifactsTable.addContainerProperty(PROPERTY_VERSION, String.class, null); m_artifactsTable.addContainerProperty(PROPERTY_PURGE, Button.class, null); m_artifactsTable.setSizeFull(); m_artifactsTable.setSelectable(true); m_artifactsTable.setMultiSelect(true); m_artifactsTable.setImmediate(true); m_artifactsTable.setHeight("15em"); final Table uploadedArtifacts = new Table("Uploaded artifacts"); uploadedArtifacts.addContainerProperty(PROPERTY_SYMBOLIC_NAME, String.class, null); uploadedArtifacts.addContainerProperty(PROPERTY_VERSION, String.class, null); uploadedArtifacts.setSizeFull(); uploadedArtifacts.setSelectable(false); uploadedArtifacts.setMultiSelect(false); uploadedArtifacts.setImmediate(true); uploadedArtifacts.setHeight("15em"); final GenericUploadHandler uploadHandler = new GenericUploadHandler(m_sessionDir) { @Override public void updateProgress(long readBytes, long contentLength) { // TODO Auto-generated method stub } @Override protected void artifactsUploaded(List<UploadHandle> uploads) { for (UploadHandle handle : uploads) { try { URL artifact = handle.getFile().toURI().toURL(); Item item = uploadedArtifacts.addItem(artifact); item.getItemProperty(PROPERTY_SYMBOLIC_NAME).setValue(handle.getFilename()); item.getItemProperty(PROPERTY_VERSION).setValue(""); m_uploadedArtifacts.add(handle.getFile()); } catch (MalformedURLException e) { showErrorNotification("Upload artifact processing failed", "<br />Reason: " + e.getMessage()); logError("Processing of " + handle.getFilename() + " failed.", e); } } } }; final Upload uploadArtifact = new Upload(); uploadArtifact.setCaption("Upload Artifact"); uploadHandler.install(uploadArtifact); final DragAndDropWrapper finalUploadedArtifacts = new DragAndDropWrapper(uploadedArtifacts); finalUploadedArtifacts.setDropHandler(new ArtifactDropHandler(uploadHandler)); addListener(new Window.CloseListener() { public void windowClose(CloseEvent e) { for (File artifact : m_uploadedArtifacts) { artifact.delete(); } } }); HorizontalLayout searchBar = new HorizontalLayout(); searchBar.setMargin(false); searchBar.setSpacing(true); final TextField searchField = new TextField(); searchField.setImmediate(true); searchField.setValue(""); final IndexedContainer dataSource = (IndexedContainer) m_artifactsTable.getContainerDataSource(); m_searchButton = new Button("Search", new ClickListener() { public void buttonClick(ClickEvent event) { String searchValue = (String) searchField.getValue(); dataSource.removeAllContainerFilters(); if (searchValue != null && searchValue.trim().length() > 0) { dataSource.addContainerFilter(PROPERTY_SYMBOLIC_NAME, searchValue, true /* ignoreCase */, false /* onlyMatchPrefix */); } } }); m_searchButton.setImmediate(true); searchBar.addComponent(searchField); searchBar.addComponent(m_searchButton); m_addButton = new Button("Add", new ClickListener() { public void buttonClick(ClickEvent event) { // Import all "local" (existing) bundles... importLocalBundles(m_artifactsTable); // Import all "remote" (non existing) bundles... importRemoteBundles(m_uploadedArtifacts); close(); } }); m_addButton.setImmediate(true); m_addButton.setStyleName(Reindeer.BUTTON_DEFAULT); m_addButton.setClickShortcut(KeyCode.ENTER); VerticalLayout layout = (VerticalLayout) getContent(); layout.setMargin(true); layout.setSpacing(true); layout.addComponent(searchBar); layout.addComponent(m_artifactsTable); layout.addComponent(uploadArtifact); layout.addComponent(finalUploadedArtifacts); // The components added to the window are actually added to the window's // layout; you can use either. Alignments are set using the layout layout.addComponent(m_addButton); layout.setComponentAlignment(m_addButton, Alignment.MIDDLE_RIGHT); searchField.focus(); }
From source file:org.apache.openaz.xacml.admin.view.windows.PIPImportWindow.java
License:Apache License
@AutoGenerated private VerticalLayout buildMainLayout() { // common part: create layout mainLayout = new VerticalLayout(); mainLayout.setImmediate(false);//ww w . j av a2 s . c o m mainLayout.setWidth("-1px"); mainLayout.setHeight("-1px"); mainLayout.setMargin(true); mainLayout.setSpacing(true); // top-level component properties setWidth("-1px"); setHeight("-1px"); // upload_1 upload = new Upload(); upload.setImmediate(false); upload.setWidth("-1px"); upload.setHeight("-1px"); mainLayout.addComponent(upload); return mainLayout; }
From source file:org.apache.openaz.xacml.admin.view.windows.PolicyUploadWindow.java
License:Apache License
@AutoGenerated private VerticalLayout buildMainLayout() { // common part: create layout mainLayout = new VerticalLayout(); mainLayout.setImmediate(false);//from www. jav a 2 s . c om mainLayout.setWidth("-1px"); mainLayout.setHeight("-1px"); mainLayout.setMargin(true); mainLayout.setSpacing(true); // top-level component properties setWidth("-1px"); setHeight("-1px"); // upload upload = new Upload(); upload.setCaption("Upload Xacml Policy File"); upload.setImmediate(false); upload.setWidth("-1px"); upload.setHeight("-1px"); mainLayout.addComponent(upload); // checkBoxImportAttributes checkBoxImportAttributes = new CheckBox(); checkBoxImportAttributes.setCaption("Import attributes into attribute dictionary."); checkBoxImportAttributes.setImmediate(false); checkBoxImportAttributes.setWidth("-1px"); checkBoxImportAttributes.setHeight("-1px"); mainLayout.addComponent(checkBoxImportAttributes); // checkBoxIgnoreStandard checkBoxIgnoreStandard = new CheckBox(); checkBoxIgnoreStandard.setCaption("Ignore Standard Attributes"); checkBoxIgnoreStandard.setImmediate(false); checkBoxIgnoreStandard.setWidth("-1px"); checkBoxIgnoreStandard.setHeight("-1px"); mainLayout.addComponent(checkBoxIgnoreStandard); mainLayout.setComponentAlignment(checkBoxIgnoreStandard, new Alignment(20)); // checkBoxImportObligations checkBoxImportObligations = new CheckBox(); checkBoxImportObligations.setCaption("Import obligations into obligation dictionary."); checkBoxImportObligations.setImmediate(false); checkBoxImportObligations.setWidth("-1px"); checkBoxImportObligations.setHeight("-1px"); mainLayout.addComponent(checkBoxImportObligations); // checkBoxImportAdvice checkBoxImportAdvice = new CheckBox(); checkBoxImportAdvice.setCaption("Import advice into advice dictionary."); checkBoxImportAdvice.setImmediate(false); checkBoxImportAdvice.setWidth("-1px"); checkBoxImportAdvice.setHeight("-1px"); mainLayout.addComponent(checkBoxImportAdvice); return mainLayout; }