Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.wintindustries.pfserver.interfaces.container.components.PFUpload; import com.vaadin.event.dd.DragAndDropEvent; import com.vaadin.event.dd.DropHandler; import com.vaadin.event.dd.acceptcriteria.AcceptAll; import com.vaadin.event.dd.acceptcriteria.AcceptCriterion; import com.vaadin.server.Page; import com.vaadin.ui.Component; import com.vaadin.ui.CssLayout; import com.vaadin.ui.DragAndDropWrapper; import com.vaadin.ui.Html5File; import com.vaadin.ui.Label; import com.vaadin.ui.Notification; import com.wintindustries.pfserver.uploads.PFUploadManager; import java.util.Arrays; /** * * @author Admin */ public class PFDDragAndDropUpload extends CssLayout implements DropHandler { private DragAndDropWrapper dropZone; private CssLayout contentArea; public PFDDragAndDropUpload() { this.setSizeFull(); this.setId("DragDropWrapper"); contentArea = new CssLayout(); contentArea.setSizeFull(); // addComponent(contentArea); prepareDropZone(); } public CssLayout getContentArea() { return contentArea; } /** * Sets up DragAndDropWrapper to accept multi file drops. */ private void prepareDropZone() { System.out.println("REGISTERED DROP ZONE"); if (dropZone == null) { // Component label = new Label(getAreaText(), Label.CONTENT_XHTML); // label.setSizeUndefined(); dropZone = new DragAndDropWrapper(contentArea); dropZone.setDragStartMode(DragAndDropWrapper.DragStartMode.HTML5); dropZone.setStyleName("v-multifileupload-dropzone"); dropZone.setStyleName("drop-area"); dropZone.setSizeFull(); addComponent(dropZone); dropZone.setDropHandler(this); // addStyleName("no-horizontal-drag-hints"); // addStyleName("no-vertical-drag-hints"); } } @Override public void drop(DragAndDropEvent event) { // send these files to the upload system DragAndDropWrapper.WrapperTransferable transfferable = (DragAndDropWrapper.WrapperTransferable) event .getTransferable(); // get wrapper details Html5File[] files = transfferable.getFiles(); // get the incoming files that we want for (Html5File file : files) { PFUploadManager.getUploadManaager().addNewUpload(file, "CHEESE"); } } @Override public AcceptCriterion getAcceptCriterion() { //TODO : MODIFY TO PROVIDE FILTER CRITERION return AcceptAll.get(); //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }