List of usage examples for com.vaadin.ui Upload Upload
public Upload(String caption, Receiver uploadReceiver)
From source file:org.lunifera.vaaclipse.ui.preferences.addon.internal.impexp.ImportPreferences.java
License:Open Source License
@Override public Component getComponent(OptionDialog optionDialog) { CssLayout layout = new CssLayout(); layout.addStyleName("import"); Upload upload = new Upload("Select file with preferences for upload", this); upload.setWidth("100%"); upload.setButtonCaption("Upload"); upload.addSucceededListener(this); layout.addComponent(upload);/*from www . jav a2 s .co m*/ layout.addComponent(new Label("Select preferences to import")); createPreferencesTable(layout, new ArrayList<PreferencesPage>()); createStatusLabel(layout, "Choose file with preferences"); return layout; }
From source file:org.s23m.cell.editor.semanticdomain.ui.components.MultitabPanel.java
License:Mozilla Public License
private void addImageUploadControls(final DetailsData detailsData) { final Embedded img = new Embedded("Icon", EditorIcon.VERTEX.getIconImage()); final FileReceiver receiver = new FileReceiver(); final Upload upload = new Upload("", receiver); upload.addListener(new Upload.FinishedListener() { public void uploadFinished(final FinishedEvent event) { final String imgContent = receiver.getBase64ContentString(); final byte[] imgData = SerializerHolder.getS23MInstanceSerializer(SerializationType.XML) .decodeBase64StringToByteArray(imgContent); DataOutputStream os = null; try { final String id = detailsData.getInstance().identity().identifier().toString(); final String resourcePath = File.createTempFile(id, "").getAbsolutePath(); os = new DataOutputStream(new FileOutputStream(resourcePath)); os.write(imgData);/*w w w . j ava2 s. co m*/ img.setSource(new FileResource(new File(resourcePath), application)); } catch (final IOException e) { e.printStackTrace(); } finally { try { if (os != null) { os.close(); } } catch (final IOException e) { } } receiver.clearCache(); } }); detailsForm.getLayout().addComponent(img); detailsForm.getLayout().addComponent(upload); }
From source file:org.universAAL.ucc.controller.desktop.ToolController.java
public void buttonClick(ClickEvent event) { if (event.getButton() == toolWin.getuStoreButton()) { Embedded em = new Embedded("", new ExternalResource(createLink())); em.setType(Embedded.TYPE_BROWSER); em.setWidth("100%"); em.setHeight("850px"); Window w = new Window("uStore"); w.setWidth("1250px"); w.setHeight("800px"); VerticalLayout v = new VerticalLayout(); w.center();/* ww w . j ava2s. c o m*/ v.addComponent(em); w.setContent(v); app.getMainWindow().removeWindow(toolWin); app.getMainWindow().addWindow(w); } if (event.getButton() == toolWin.getOpenAAL()) { // Embedded em = new Embedded("", new ExternalResource( // "http://wiki.openaal.org")); // em.setType(Embedded.TYPE_BROWSER); // em.setWidth("100%"); // em.setHeight("800px"); // Window w = new Window("openAAL"); // w.setWidth("1250px"); // w.setHeight("800px"); // VerticalLayout v = new VerticalLayout(); // w.center(); // v.addComponent(em); // w.setContent(v); BrowseServicesWindow pw = new BrowseServicesWindow(app); PurchasedServicesController pc = new PurchasedServicesController(pw, app); app.getMainWindow().removeWindow(toolWin); app.getMainWindow().addWindow(pw); } if (event.getButton() == toolWin.getInstallButton()) { // Later uncomment again only for testing commented out! Upload up = new Upload("", new AALServiceReceiver()); up.setButtonCaption(res.getString("install.button")); up.addListener((Upload.FinishedListener) this); up.addListener((Upload.FailedListener) this); installWindow = new Window(res.getString("install.win.caption")); installWindow.setResizable(false); installWindow.center(); installWindow.setWidth("400px"); VerticalLayout v = new VerticalLayout(); v.setSizeFull(); v.setSpacing(true); v.setMargin(true); v.addComponent(up); installWindow.setContent(v); app.getMainWindow().removeWindow(toolWin); app.getMainWindow().addWindow(installWindow); } if (event.getButton() == toolWin.getLogoutButton()) { DesktopController.setCurrentPassword(""); DesktopController.setCurrentUser(""); // if(!DesktopController.web.getSocket().isClosed()) { // try { // DesktopController.web.getSocket().close(); // } catch (IOException e) { // e.printStackTrace(); // } // } app.close(); } if (event.getButton() == toolWin.getUninstallButton()) { app.getMainWindow().removeWindow(toolWin); List<RegisteredService> ids = new ArrayList<RegisteredService>(); Document doc = Model.getSrvDocument(); NodeList nodeList = doc.getElementsByTagName("service"); for (int i = 0; i < nodeList.getLength(); i++) { RegisteredService srv = new RegisteredService(); Element element = (Element) nodeList.item(i); System.err.println(element.getAttribute("serviceId")); srv.setServiceId(element.getAttribute("serviceId")); NodeList srvChilds = element.getChildNodes(); for (int j = 0; j < srvChilds.getLength(); j++) { Node n = srvChilds.item(j); if (n.getNodeName().equals("application")) { Element e = (Element) n; srv.getAppId().add(e.getAttribute("appId")); } if (n.getNodeName().equals("bundle")) { Element b = (Element) n; srv.getBundleId().add(b.getAttribute("id")); srv.setBundleVersion(b.getAttribute("version")); } if (n.getNodeName().equals("menuEntry")) { Element e = (Element) n; srv.setMenuName(e.getAttribute("entryName")); srv.setIconURL(e.getAttribute("iconURL")); srv.setProvider(e.getAttribute("vendor")); srv.setServiceClass(e.getAttribute("serviceClass")); srv.setUserID(e.getAttribute("userID")); } } ids.add(srv); } DeinstallWindow dw = new DeinstallWindow(ids); app.getMainWindow().addWindow(dw); DeinstallController dc = new DeinstallController(dw, app); // frontend.uninstallService(Activator.getSessionKey(), "28002"); // frontend.getInstalledUnitsForService(Activator.getSessionKey(), "28002"); } if (event.getButton() == toolWin.getPersonButton()) { AddNewPersonWindow apw = null; try { apw = new AddNewPersonWindow(null, null, app); } catch (JAXBException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } app.getMainWindow().removeWindow(toolWin); app.getMainWindow().addWindow(apw); } if (event.getButton() == toolWin.getConfigButton()) { AddNewHardwareWindow anhw = null; try { anhw = new AddNewHardwareWindow(null, null, app); } catch (JAXBException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } app.getMainWindow().removeWindow(toolWin); app.getMainWindow().addWindow(anhw); } if (event.getButton() == toolWin.getEditHW()) { RoomsWindow hardWare = null; try { hardWare = new RoomsWindow(app); } catch (JAXBException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } app.getMainWindow().removeWindow(toolWin); app.getMainWindow().addWindow(hardWare); } if (event.getButton() == toolWin.getEditPerson()) { HumansWindow hw = null; try { hw = new HumansWindow(app); } catch (JAXBException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } app.getMainWindow().removeWindow(toolWin); app.getMainWindow().addWindow(hw); } if (event.getButton() == toolWin.getEditUC()) { WhichBundleShouldBeConfiguredWindow uc = new WhichBundleShouldBeConfiguredWindow("Use Cases"); app.getMainWindow().removeWindow(toolWin); app.getMainWindow().addWindow(uc); } }
From source file:org.vaadin.tori.component.AuthoringComponent.java
License:Apache License
private Upload buildAttachUpload() { final Receiver receiver = new Receiver() { @Override/*from w ww . j a v a 2 s. c o m*/ public OutputStream receiveUpload(final String filename, final String mimeType) { attachmentData = new ByteArrayOutputStream(); attachmentFileName = filename; return attachmentData; } }; final Upload attach = new Upload(null, receiver); attach.setButtonCaption("Add Attachment..."); attach.setImmediate(true); attach.addSucceededListener(new Upload.SucceededListener() { @Override public void uploadSucceeded(final SucceededEvent event) { attachments.put(attachmentFileName, attachmentData.toByteArray()); attachmentFileName = null; attachmentData = null; updateAttachmentList(); } }); attach.addStartedListener(new Upload.StartedListener() { @Override public void uploadStarted(final StartedEvent event) { if (maxFileSize > 0 && event.getContentLength() > maxFileSize) { attach.interruptUpload(); Notification.show("File size too large"); return; } } }); return attach; }
From source file:probe.com.view.core.QuantDataUploader.java
/** * initialize the upload unit layout/*from w w w. j a v a 2 s . co m*/ */ private void initLayouts() { Label selectFileTitle = new Label( "<h4 style='font-family:verdana;font-weight:bold;'><strong aligen='center' style='font-family:verdana;color:#00000;'>Upload New File</strong></h4>"); selectFileTitle.setContentMode(ContentMode.HTML); selectFileTitle.setHeight("45px"); selectFileTitle.setWidth("100%"); this.addComponent(selectFileTitle); this.setComponentAlignment(selectFileTitle, Alignment.TOP_CENTER); upload = new Upload(null, this); upload.setStyleName("small"); upload.setVisible(true); upload.setHeight("30px"); upload.setWidth("100%"); upload.setButtonCaption("UPLOAD ADD / EDIT EXPERIMENT"); upload.addSucceededListener(this); this.addComponent(upload); }
From source file:ru.codeinside.gses.activiti.ftarchive.AttachmentField.java
License:Mozilla Public License
public AttachmentField(final String taskId, final String fieldId, final String name, FileValue attachment, boolean signature) { this.signature = signature; upload = new Upload(null, this); if (!signature) { upload.setButtonCaption(" "); upload.setImmediate(true);/*from w w w .j a va2 s. c o m*/ upload.addListener(new Upload.StartedListener() { private static final long serialVersionUID = 1L; @Override public void uploadStarted(Upload.StartedEvent event) { indicator.setValue(0f); indicator.setVisible(true); sizeInfo.setValue("0/" + event.getContentLength()); } }); upload.addListener(new Upload.ProgressListener() { private static final long serialVersionUID = 1L; public void updateProgress(long readBytes, long contentLength) { indicator.setValue((float) readBytes / (float) contentLength); sizeInfo.setValue("" + readBytes + "/" + contentLength); } }); upload.addListener(new Upload.SucceededListener() { private static final long serialVersionUID = 1L; @Override public void uploadSucceeded(Upload.SucceededEvent event) { removeOldValue(); String fileName = event.getFilename(); String fileType = event.getMIMEType(); FileValue value; if (taskId != null) { try { value = Flash.flash().getExecutorService().saveBytesBuffer(taskId, fieldId, fileName, fileType, tmpFile); } finally { tmpFile.delete(); } } else { value = new TmpFileValue(fileName, fileType, tmpFile); } setValue(value); setDownloadLink(createDownloadLink(value)); resetUpload(); } }); upload.addListener(new Upload.FailedListener() { private static final long serialVersionUID = 1L; @Override public void uploadFailed(Upload.FailedEvent event) { if (tmpFile != null) { tmpFile.delete(); tmpFile = null; } getWindow().showNotification(" " + name, Window.Notification.TYPE_HUMANIZED_MESSAGE); } }); upload.addListener(new Upload.FinishedListener() { private static final long serialVersionUID = 1L; @Override public void uploadFinished(Upload.FinishedEvent event) { indicator.setVisible(false); sizeInfo.setValue(null); } }); indicator.setVisible(false); indicator.setWidth(100, Sizeable.UNITS_PIXELS); layout.setSpacing(true); layout.addComponent(indicator); layout.addComponent(sizeInfo); } setCaption(name); setValidationVisible(true); setRequiredError(" !"); initRemoveAttachmentButton(); if (taskId != null) { Some<FileValue> optionalFile = Flash.flash().getExecutorService().getFileBuffer(taskId, fieldId); if (optionalFile.isPresent()) { FileValue newValue = optionalFile.get(); setValue(newValue); setDownloadLink(createDownloadLink(newValue)); } else { initAttachmentValue(attachment); } } else { initAttachmentValue(attachment); } if (!signature) { layout.addComponent(upload); layout.addComponent(removeAttachmentButton); } setCompositionRoot(layout); }
From source file:ru.codeinside.gses.webui.manager.DirectoryPanel.java
License:Mozilla Public License
static Component createDirectoryPanel() { HorizontalSplitPanel horSplit = new HorizontalSplitPanel(); horSplit.setSizeFull();/* w w w. ja va 2s . c o m*/ horSplit.setMargin(true); Panel panel00 = new Panel(); Panel panel01 = new Panel(); Panel panel10 = new Panel(); horSplit.setFirstComponent(panel00); VerticalLayout vl = new VerticalLayout(); horSplit.setSecondComponent(vl); vl.addComponent(panel01); vl.addComponent(panel10); vl.setSpacing(true); horSplit.setWidth("100%"); vl.setHeight("100%"); panel00.setHeight("100%"); panel00.setWidth("100%"); panel01.setWidth("100%"); panel01.setHeight("100%"); panel10.setHeight("100%"); horSplit.setSplitPosition(35); vl.setExpandRatio(panel01, 0.25f); vl.setExpandRatio(panel10, 0.75f); final Table dirMapTable = ManagerWorkplace.createDirectoryMapTable(); final FilterTable directoryTable = ManagerWorkplace.createDirectoryTable(); dirMapTable.setVisible(false); final Form createFieldForm = new Form(); createFieldForm.setCaption(" ? ?"); final TextField keyField = new TextField(""); keyField.setRequired(true); keyField.setMaxLength(254); createFieldForm.addField("key", keyField); final TextField valField = new TextField(""); valField.setRequired(true); valField.setMaxLength(1022); createFieldForm.addField("val", valField); createFieldForm.setVisible(false); Button addButton = new Button("", new AddTupleButtonListener(createFieldForm, directoryTable, keyField, valField, dirMapTable)); createFieldForm.addField("submit", addButton); directoryTable.addListener(new DirectoryTableChangeListener(createFieldForm, directoryTable, dirMapTable)); ManagerWorkplace.buildContainer(directoryTable, createFieldForm, dirMapTable); directoryTable.setColumnHeaders(new String[] { "?", "", "" }); final Form createDirectory = new Form(); createDirectory.setCaption(" ?"); final TextField field = new TextField("?"); field.setRequired(true); field.setMaxLength(255); field.setRequiredError(" ?"); createDirectory.addField("name", field); Button createButton = new Button("", new CreateDirectoryButtonListener(field, createDirectory, directoryTable)); createDirectory.addField("submit", createButton); Panel loadPanel = new Panel(); loadPanel.setCaption(" ?"); UploadDirectory events = new UploadDirectory(directoryTable, dirMapTable); Upload c = new Upload("", events); c.addListener(events); c.setButtonCaption(""); loadPanel.addComponent(c); VerticalLayout verticalLayout = new VerticalLayout(); verticalLayout.setSizeFull(); verticalLayout.setSpacing(true); verticalLayout.addComponent(loadPanel); verticalLayout.addComponent(createDirectory); verticalLayout.addComponent(directoryTable); panel00.addComponent(verticalLayout); panel01.addComponent(createFieldForm); dirMapTable.setSizeFull(); dirMapTable.setPageLength(13); panel10.addComponent(dirMapTable); return horSplit; }
From source file:ui.button.AddCertificateButton.java
License:Apache License
public AddCertificateButton(final Integer userId, final String language, final Achievement a) { super(Translator.getTranslation("Add Certificate", language), FontAwesome.CERTIFICATE); setDescription(Translator.getTranslation("Add Certificate", language)); addClickListener(new Button.ClickListener() { @Override//w ww .j av a 2 s. c o m public void buttonClick(Button.ClickEvent event) { UploadReceiver receiver = new CertificateUploadReceiver(userId, language, a); Upload upload = new Upload(Translator.getTranslation("Add Certificate", language), receiver); upload.addSucceededListener((Upload.SucceededListener) receiver); String wcaption = Translator.getTranslation("Upload", language); final Window window = new Window(wcaption, upload); window.center(); //window.setModal(true); window.setStyleName("window"); receiver.setWindow(window); window.addCloseListener(new Window.CloseListener() { @Override public void windowClose(Window.CloseEvent e) { window.close(); } }); getUI().addWindow(window); } }); }
From source file:ui.button.AddPhotoButton.java
License:Apache License
public AddPhotoButton(final Integer userId, final String language) { super(Translator.getTranslation("Add professional photo", language), FontAwesome.CAMERA_RETRO); setDescription(Translator.getTranslation("Add professional photo", language)); addClickListener(new Button.ClickListener() { @Override//from w w w . jav a2s . co m public void buttonClick(Button.ClickEvent event) { UploadReceiver receiver = new PhotoUploadReceiver(userId, language); Upload upload = new Upload(Translator.getTranslation("Choose your best photo", language), receiver); upload.addSucceededListener((Upload.SucceededListener) receiver); String wcaption = Translator.getTranslation("Upload a photo", language); final Window window = new Window(wcaption, upload); window.center(); //window.setModal(true); window.setStyleName("window"); receiver.setWindow(window); window.addCloseListener(new Window.CloseListener() { @Override public void windowClose(Window.CloseEvent e) { window.close(); } }); getUI().addWindow(window); } }); }
From source file:views.BatchUpload.java
License:Open Source License
public BatchUpload() { setMargin(true);//from www . j a v a 2s.com setSpacing(true); // file upload component Upload upload = new Upload("Upload your file here", uploader); addComponent(this.upload); upload.setEnabled(false); // sample registration button register = new Button("Register People"); register.setVisible(false); addComponent(register); upload.setButtonCaption("Upload"); // Listen for events regarding the success of upload. upload.addFailedListener(uploader); upload.addSucceededListener(uploader); FinishedListener uploadFinListener = new FinishedListener() { /** * */ private static final long serialVersionUID = -8413963075202260180L; public void uploadFinished(FinishedEvent event) { String uploadError = uploader.getError(); File file = uploader.getFile(); if (file.getPath().endsWith("up_")) { String msg = "No file selected."; logger.warn(msg); Styles.notification("Failed to read file.", msg, NotificationType.ERROR); if (!file.delete()) logger.error("uploaded tmp file " + file.getAbsolutePath() + " could not be deleted!"); } else { if (uploadError == null || uploadError.isEmpty()) { String msg = "Upload successful!"; logger.info(msg); // try { setRegEnabled(false); SQLBatchParser parser = new SQLBatchParser(); if (parser.processTSV()) { // TODO = prep.getObjects(); Styles.notification("Upload successful", "New people information successfully uploaded and read.", NotificationType.SUCCESS); } else { String error = parser.getError(); Styles.notification("Failed to read file.", error, NotificationType.ERROR); if (!file.delete()) logger.error( "uploaded tmp file " + file.getAbsolutePath() + " could not be deleted!"); } // } catch (IOException e) { // e.printStackTrace(); // } } else { Styles.notification("Failed to upload file.", uploadError, NotificationType.ERROR); if (!file.delete()) logger.error("uploaded tmp file " + file.getAbsolutePath() + " could not be deleted!"); } } } }; upload.addFinishedListener(uploadFinListener); // view.initUpload(upload); Button.ClickListener cl = new Button.ClickListener() { /** * */ private static final long serialVersionUID = 1L; /** * */ @Override public void buttonClick(ClickEvent event) { String src = event.getButton().getCaption(); if (src.equals("Register People")) { register.setEnabled(false); } } }; register.addClickListener(cl); }