List of usage examples for com.vaadin.ui Upload Upload
public Upload(String caption, Receiver uploadReceiver)
From source file:com.peergreen.webconsole.scope.deployment.internal.DeploymentScope.java
License:Open Source License
@PostConstruct public void init() { deploymentViewManager = createDeploymentViewManager(); OptionGroup option = new OptionGroup(); HorizontalLayout toolBar = new HorizontalLayout(); toolBar.setWidth("100%"); toolBar.setSpacing(true);/* w w w . j a v a 2 s. c om*/ toolBar.setMargin(true); VerticalLayout uploadLayout = new VerticalLayout(); Upload uploader = new Upload("Upload a file here", null); uploader.setButtonCaption("Upload"); final FileUploader fileUploader = new FileUploader(deploymentViewManager, notifierService, artifactBuilder, option); uploader.setReceiver(fileUploader); uploader.addSucceededListener(fileUploader); uploader.addStartedListener(fileUploader); uploadLayout.addComponent(uploader); HorizontalLayout target = new HorizontalLayout(); option.addContainerProperty("id", String.class, null); option.setItemCaptionPropertyId("id"); option.addItem(DeployableContainerType.DEPLOYABLE.attribute()).getItemProperty("id") .setValue("Add to deployables"); option.addItem(DeployableContainerType.DEPLOYED.attribute()).getItemProperty("id").setValue("Deploy"); option.addItem(DeployableContainerType.DEPLOYMENT_PLAN.attribute()).getItemProperty("id") .setValue("Create a deployment plan"); option.addStyleName("horizontal"); option.select(DeployableContainerType.DEPLOYABLE.attribute()); target.addComponent(option); uploadLayout.addComponent(target); toolBar.addComponent(uploadLayout); Label infoLabel = new Label("Drop files here to create a deployment plan"); infoLabel.setSizeUndefined(); final VerticalLayout deploymentPlanMaker = new VerticalLayout(infoLabel); deploymentPlanMaker.setComponentAlignment(infoLabel, Alignment.MIDDLE_CENTER); Button draft = new Button("A draft is under construction"); draft.addStyleName("link"); draft.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { deploymentViewManager.showDeploymentPlanView(); } }); draft.setVisible(false); deploymentViewManager.setDeploymentPlanDraftViewer(draft); deploymentPlanMaker.addComponent(draft); deploymentPlanMaker.setComponentAlignment(draft, Alignment.TOP_CENTER); deploymentPlanMaker.setSizeFull(); deploymentPlanMaker.addStyleName("drop-area"); deploymentPlanMakerWrapper = new DragAndDropWrapper(deploymentPlanMaker); deploymentPlanMakerWrapper.setSizeFull(); toolBar.addComponent(deploymentPlanMakerWrapper); addComponent(toolBar); addComponent(framesContainer); setExpandRatio(framesContainer, 1.5f); helpWindow = notifierService.createHelpOverlay("Deployment module", "<p>To deploy, or undeploy, artifacts, you can drag and drop elements from deployables panel " + "to deployed panel and vice versa.</p>" + "<p>You can also drag files from desktop and drop them where you want to add them."); }
From source file:com.piccritic.website.post.CreatePost.java
public void setupImagereceiver() { if (upload != null) { form.removeComponent(upload);/*from www .jav a 2s.co m*/ } receiver = new ImageReceiver(handle, post); upload = new Upload("Upload Image Here", receiver); upload.addSucceededListener(this); upload.addStartedListener(e -> { confirm.setEnabled(false); }); upload.setButtonCaption(null); upload.addChangeListener(e -> { if (e.getFilename() != null) { upload.setButtonCaption("Upload"); } }); form.addComponent(upload); form.addComponent(confirm); }
From source file:com.squadd.UI.UploadGroupImageWindow.java
protected void configureDownload() { // Show uploaded file in this placeholder image = new Image(""); image.setVisible(false);//from w ww .ja v a2 s. co m image.setHeight("256px"); // Implement both receiver that saves upload in a file and // listener for successful upload class ImageReceiver implements Upload.Receiver, Upload.SucceededListener { private static final long serialVersionUID = -1276759102490466761L; public java.io.File file; public OutputStream receiveUpload(String filename, String mimeType) { // Create upload stream FileOutputStream fos = null; // Stream to write to try { // Open the file for writing. grp.setLastUploadDate(System.currentTimeMillis()); String path = new ImageGetter().getPath(grp); file = new java.io.File(path); fos = new FileOutputStream(file); } catch (final java.io.FileNotFoundException e) { new Notification("Could not open file<br/>", e.getMessage(), Notification.Type.ERROR_MESSAGE) .show(Page.getCurrent()); return null; } return fos; // Return the output stream to write to } public void uploadSucceeded(Upload.SucceededEvent event) { // Show the uploaded file in the image viewer userImageFile = new File(); userImageFile.setPath(file.getPath()); image.setVisible(true); image.setSource(new FileResource(file)); } } ; ImageReceiver receiver = new ImageReceiver(); // Create the upload with a caption and set receiver later upload = new Upload("", receiver); //upload.setButtonCaption("Ok"); upload.addSucceededListener(receiver); }
From source file:com.tapas.evidence.fe.components.EvidenceUpload.java
License:Apache License
public EvidenceUpload(final IUiMessageSource messageSource, final Locale locale) { this.messagesource = messageSource; this.locale = locale; this.setSizeUndefined(); root = new Panel(getMessage("upload.component.caption")); setCompositionRoot(root);/*from ww w . ja va2 s . c o m*/ UIUtils.clearBorder(root); ((AbstractLayout) root.getContent()).setMargin(false); // Create the Upload component. upload = new Upload(getMessage("upload.upload.caption"), this); upload.setImmediate(true); // Use a custom button caption instead of plain "Upload". upload.setButtonCaption(getMessage("upload.button.caption")); // Listen for events regarding the success of upload. upload.addListener((Upload.SucceededListener) this); upload.addListener((Upload.FailedListener) this); upload.addListener((Upload.StartedListener) this); // Create a panel for displaying the uploaded image. imagePanel = new Panel(getMessage("upload.image.caption")); ((AbstractLayout) imagePanel.getContent()).setMargin(false); status = new Label(getMessage("upload.image.notloaded")); imagePanel.setWidth("200px"); imagePanel.setHeight("150px"); root.addComponent(imagePanel); root.addComponent(status); root.addComponent(upload); }
From source file:com.trivago.mail.pigeon.web.components.mail.UploadHtmlFileComponent.java
License:Apache License
public UploadHtmlFileComponent() { root = new Panel("Upload HTML Version"); setCompositionRoot(root);//from w w w. ja v a 2 s .c o m // Create the Upload component. upload = new Upload("HTML-File", this); // Use a custom button caption instead of plain "Upload". upload.setButtonCaption("Upload Now"); // Listen for events regarding the success of upload. upload.addListener((Upload.SucceededListener) this); upload.addListener((Upload.FailedListener) this); root.addComponent(upload); root.addComponent(new Label("Click 'Browse' to " + "select a file and then click 'Upload'.")); }
From source file:com.trivago.mail.pigeon.web.components.mail.UploadTextFileComponent.java
License:Apache License
public UploadTextFileComponent() { root = new Panel("Upload Text Version"); setCompositionRoot(root);/*w w w. ja va2 s . c om*/ // Create the Upload component. upload = new Upload("Text-File", this); // Use a custom button caption instead of plain "Upload". upload.setButtonCaption("Upload Now"); // Listen for events regarding the success of upload. upload.addListener((Upload.SucceededListener) this); upload.addListener((Upload.FailedListener) this); root.addComponent(upload); root.addComponent(new Label("Click 'Browse' to " + "select a file and then click 'Upload'.")); }
From source file:com.trivago.mail.pigeon.web.components.recipients.UploadCsvFileComponent.java
License:Apache License
public UploadCsvFileComponent() { root = new Panel("Upload Text Version"); setCompositionRoot(root);//w w w .j a va 2 s . com // Create the Upload component. upload = new Upload("CSV-File", this); // Use a custom button caption instead of plain "Upload". upload.setButtonCaption("Upload Now"); // Listen for events regarding the success of upload. upload.addListener((Upload.SucceededListener) this); upload.addListener((Upload.FailedListener) this); root.addComponent(upload); root.addComponent(new Label("Click 'Browse' to " + "select a file and then click 'Upload'.")); }
From source file:control.ExperimentImportController.java
License:Open Source License
public void init(final String user) { ExperimentImportController control = this; Upload upload = new Upload("Upload your file here", uploader); view.initView(upload);/*from www .j a v a 2 s. com*/ 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(); view.resetAfterUpload(); 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 { view.setRegEnabled(false); prep = new SamplePreparator(); Map<String, Set<String>> experimentTypeVocabularies = new HashMap<String, Set<String>>(); experimentTypeVocabularies.put("Q_ANTIBODY", vocabs.getAntibodiesMap().keySet()); experimentTypeVocabularies.put("Q_CHROMATOGRAPHY_TYPE", vocabs.getChromTypesMap().keySet()); experimentTypeVocabularies.put("Q_MS_DEVICE", new HashSet<String>(vocabs.getDeviceMap().values())); experimentTypeVocabularies.put("Q_MS_LCMS_METHOD", new HashSet<String>(vocabs.getLcmsMethods())); VocabularyValidator validator = new VocabularyValidator(experimentTypeVocabularies); boolean readSuccess = prep.processTSV(file, getImportType()); boolean vocabValid = false; if (readSuccess) { msProperties = prep.getSpecialExperimentsOfTypeOrNull("Q_MS_MEASUREMENT"); mhcProperties = prep.getSpecialExperimentsOfTypeOrNull("Q_MHC_LIGAND_EXTRACTION"); List<Map<String, Object>> metadataList = new ArrayList<Map<String, Object>>(); if (msProperties != null) metadataList.addAll(msProperties.values()); if (mhcProperties != null) metadataList.addAll(mhcProperties.values()); vocabValid = validator.validateExperimentMetadata(metadataList); } if (readSuccess && vocabValid) { List<SampleSummaryBean> summaries = prep.getSummary(); for (SampleSummaryBean s : summaries) { String translation = reverseTaxMap.get(s.getFullSampleContent()); if (translation != null) s.setSampleContent(translation); } Styles.notification("Upload successful", "Experiment was successfully uploaded and read.", NotificationType.SUCCESS); switch (getImportType()) { // Standard hierarchic QBiC design case QBIC: view.setSummary(summaries); view.setProcessed(prep.getProcessed()); view.setRegEnabled(true); projectInfo = prep.getProjectInfo(); break; // Standard non-hierarchic design without QBiC specific keywords case Standard: Map<String, List<String>> catToVocabulary = new HashMap<String, List<String>>(); catToVocabulary.put("Species", new ArrayList<String>(taxMap.keySet())); catToVocabulary.put("Tissues", new ArrayList<String>(tissueMap.keySet())); catToVocabulary.put("Analytes", new ArrayList<String>(analytesVocabulary)); Map<String, List<String>> missingCategoryToValues = new HashMap<String, List<String>>(); missingCategoryToValues.put("Species", new ArrayList<String>(prep.getSpeciesSet())); missingCategoryToValues.put("Tissues", new ArrayList<String>(prep.getTissueSet())); missingCategoryToValues.put("Analytes", new ArrayList<String>(prep.getAnalyteSet())); initMissingInfoListener(prep, missingCategoryToValues, catToVocabulary); break; // MHC Ligands that have already been measured (Filenames exist) case MHC_Ligands_Finished: catToVocabulary = new HashMap<String, List<String>>(); catToVocabulary.put("Species", new ArrayList<String>(taxMap.keySet())); catToVocabulary.put("Tissues", new ArrayList<String>(tissueMap.keySet())); catToVocabulary.put("Analytes", new ArrayList<String>(analytesVocabulary)); missingCategoryToValues = new HashMap<String, List<String>>(); missingCategoryToValues.put("Species", new ArrayList<String>(prep.getSpeciesSet())); missingCategoryToValues.put("Tissues", new ArrayList<String>(prep.getTissueSet())); missingCategoryToValues.put("Analytes", new ArrayList<String>(prep.getAnalyteSet())); initMissingInfoListener(prep, missingCategoryToValues, catToVocabulary); break; default: logger.error("Error parsing tsv: " + prep.getError()); // view.showError(prep.getError()); Styles.notification("Failed to read file.", prep.getError(), NotificationType.ERROR); break; } } else { if (!readSuccess) { String error = prep.getError(); Styles.notification("Failed to read file.", error, NotificationType.ERROR); } else { String error = validator.getError(); Styles.notification("Failed to process file.", error, NotificationType.ERROR); } if (!file.delete()) logger.error("uploaded tmp file " + file.getAbsolutePath() + " could not be deleted!"); } } catch (IOException e) { e.printStackTrace(); } } else { // view.showError(error); 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 All")) { view.getRegisterButton().setEnabled(false); view.showRegistration(); // collect experiment information complexExperiments = new ArrayList<OpenbisExperiment>(); complexExperiments .addAll(collectComplexExperiments(msProperties, ExperimentType.Q_MS_MEASUREMENT)); complexExperiments.addAll( collectComplexExperiments(mhcProperties, ExperimentType.Q_MHC_LIGAND_EXTRACTION)); openbisCreator.registerProjectWithExperimentsAndSamplesBatchWise(view.getSamples(), projectInfo.getDescription(), complexExperiments, view.getProgressBar(), view.getProgressLabel(), new RegisteredSamplesReadyRunnable(view, control), user, projectInfo.isPilot()); List<String> tsv = prep.getOriginalTSV(); switch (getImportType()) { case Standard: case MHC_Ligands_Finished: String tsvContent = addBarcodesToTSV(tsv, view.getSamples(), getImportType()); view.setTSVWithBarcodes(tsvContent, uploader.getFileNameWithoutExtension() + "_with_barcodes"); break; default: break; } } } private Collection<? extends OpenbisExperiment> collectComplexExperiments( Map<String, Map<String, Object>> propsMap, ExperimentType type) { List<OpenbisExperiment> res = new ArrayList<OpenbisExperiment>(); if (propsMap != null) { for (String code : propsMap.keySet()) res.add(new OpenbisExperiment(code, type, propsMap.get(code))); } return res; } }; view.getRegisterButton().addClickListener(cl); }
From source file:cz.zcu.pia.social.network.frontend.components.profile.profile.ComponentEditProfile.java
@Override @PostConstruct//from w ww.j a v a 2s. c o m public void postConstruct() { receiver = appContext.getBean(ImageUploader.class); Upload upload = new Upload(msgs.getMessage("upload.image"), receiver); upload.setButtonCaption(msgs.getMessage("upload")); upload.addSucceededListener(receiver); upload.addFailedListener(new Upload.FailedListener() { @Override public void uploadFailed(Upload.FailedEvent event) { Notification.show(msgs.getMessage("upload.not.ok")); } }); this.layout.addComponent(upload, "upload"); super.postConstruct(); this.password.setVisible(false); this.passwordRepeat.setVisible(false); this.validation.setVisible(false); }
From source file:cz.zcu.pia.social.network.frontend.components.profile.profile.ComponentProfile.java
/** * Post Construct/* ww w . ja va 2 s .co m*/ */ @PostConstruct public void postConstruct() { if (!securityHelper.isAuthenticated()) { ((MyUI) UI.getCurrent().getUI()).getNavigator().navigateTo(ViewHome.NAME); return; } Users user = usersService.getUserByUsername(securityHelper.getLogedInUser().getUsername()); if (user == null) { return; } this.addComponent(editProfile); editProfile.setUser(user); editProfile.setVisible(false); editProfile.setParentReference(this); setLabels(user); editButton = new Button(msgs.getMessage("edit")); editButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(Button.ClickEvent event) { buttonEditFunction(event); } }); if (securityHelper.getLogedInUser().getUserImageName() != null) { reloadImage(); } else { ImageUploader receiver = appContext.getBean(ImageUploader.class); receiver.setParentReference(this); Upload upload = new Upload(msgs.getMessage("upload.image"), receiver); upload.setButtonCaption(msgs.getMessage("upload")); upload.addSucceededListener(receiver); upload.addFailedListener(new Upload.FailedListener() { @Override public void uploadFailed(Upload.FailedEvent event) { Notification.show(msgs.getMessage("upload.not.ok")); } }); layout.addComponent(upload, "picture"); } fullname = new Label(user.getName() + " " + user.getSurname()); layout.addComponent(fullname, "name"); Label usernameLabel = new Label(msgs.getMessage("username") + ":"); Label postsLabel = new Label(msgs.getMessage("number-of-posts") + ":"); Label followersLabel = new Label(msgs.getMessage("number-of-followers") + ":"); usernameLabel.setWidth(LABEL_WIDTH, Unit.PIXELS); postsLabel.setWidth(LABEL_WIDTH, Unit.PIXELS); followersLabel.setWidth(LABEL_WIDTH, Unit.PIXELS); layout.addComponent(usernameLabel, "usernameLabel"); layout.addComponent(postsLabel, "numberPostsLabel"); layout.addComponent(followersLabel, "numberFollowersLabel"); layout.addComponent(username, "username"); layout.addComponent(numberOfposts, "numberPosts"); layout.addComponent(numberOfFollowers, "numberFollowers"); layout.addComponent(editButton, "button"); }