PL-5672 Drop zone for *UploadField

This commit is contained in:
Yuriy Artamonov 2016-06-27 18:24:13 +04:00
parent c36d51f6c8
commit 5a8f5169c4
20 changed files with 489 additions and 21 deletions

View File

@ -485,7 +485,7 @@ configure(webModule) {
compile(group: 'com.haulmont.thirdparty', name: 'popupbutton', version: '2.5.2.cuba.3')
compile(group: 'com.haulmont.thirdparty', name: 'aceeditor', version: '0.8.15')
compile(group: 'org.vaadin.addons', name: 'contextmenu', version: '4.5')
compile(group: 'org.vaadin.addons', name: 'dragdroplayouts', version: '1.2.2.cuba.2')
compile(group: 'org.vaadin.addons', name: 'dragdroplayouts', version: '1.2.2.cuba.3')
provided(servletApi)
@ -617,7 +617,7 @@ configure(webToolkitModule) {
workers = 2
// Performance and widgetset size:
style = 'OBF' // 'OBF' or 'PRETTY' or 'DETAILED'
style = 'PRETTY' // 'OBF' or 'PRETTY' or 'DETAILED'
disableCastChecking = false
optimize = 9
draft = false

View File

@ -37,6 +37,10 @@ public abstract class DesktopAbstractUploadComponent<T extends JComponent>
protected Set<String> permittedExtensions;
// just stub
protected DropZone dropZone;
protected String dropZonePrompt;
@Override
public long getFileSizeLimit() {
return fileSizeLimit;
@ -80,4 +84,22 @@ public abstract class DesktopAbstractUploadComponent<T extends JComponent>
}
return fileSizeLimitString;
}
@Override
public void setDropZone(DropZone dropZone) {
this.dropZone = dropZone;
}
@Override
public DropZone getDropZone() {
return dropZone;
}
public String getDropZonePrompt() {
return dropZonePrompt;
}
public void setDropZonePrompt(String dropZonePrompt) {
this.dropZonePrompt = dropZonePrompt;
}
}

View File

@ -70,6 +70,8 @@ public class FileEditor extends AbstractEditor<FileDescriptor> {
super.init(params);
getDialogOptions().setWidthAuto();
uploadField.setDropZone(new UploadComponentSupport.DropZone(this));
}
@Override

View File

@ -22,6 +22,7 @@ import com.haulmont.cuba.core.global.FileStorageException;
import com.haulmont.cuba.gui.components.AbstractWindow;
import com.haulmont.cuba.gui.components.Button;
import com.haulmont.cuba.gui.components.FileMultiUploadField;
import com.haulmont.cuba.gui.components.UploadComponentSupport;
import com.haulmont.cuba.gui.data.CollectionDatasource;
import com.haulmont.cuba.gui.theme.ThemeConstants;
import com.haulmont.cuba.gui.upload.FileUploadingAPI;
@ -53,6 +54,8 @@ public class MultiUploader extends AbstractWindow {
public void init(Map<String, Object> params) {
super.init(params);
multiUpload.setDropZone(new UploadComponentSupport.DropZone(this));
getDialogOptions()
.setHeight(themeConstants.getInt("cuba.gui.multiupload.height"))
.setResizable(true);

View File

@ -124,4 +124,60 @@ public interface UploadComponentSupport extends Component, Component.HasCaption,
* @return set of file extensions.
*/
Set<String> getPermittedExtensions();
/**
* @return current drop zone
*/
DropZone getDropZone();
/**
* Set drop zone reference to this upload component. Files can be dropped to component of the drop zone
* to be uploaded by this upload component.
*
* @param dropZone drop zone descriptor
*/
void setDropZone(DropZone dropZone);
/**
* @return current drop zone prompt
*/
String getDropZonePrompt();
/**
* Set drop zone prompt that will be shown on drag over window with file.
*
* @param dropZonePrompt drop zone prompt
*/
void setDropZonePrompt(String dropZonePrompt);
/**
* Drop zone descriptor. BoxLayout or Window can be used as drop zone for an upload component.
*/
class DropZone {
protected BoxLayout layout;
protected Window window;
public DropZone(BoxLayout targetLayout) {
this.layout = targetLayout;
}
public DropZone(Window window) {
this.window = window;
}
public BoxLayout getTargetLayout() {
return layout;
}
public Window getTargetWindow() {
return window;
}
public Component getTarget() {
if (window != null) {
return window;
} else {
return layout;
}
}
}
}

View File

@ -230,6 +230,8 @@ upload.unableToUploadFile=Uploading error for file '%s'
upload.uploadingProgressTitle=Uploading
upload.fileTooBig.message=Your file '%s' is too big. File size limit equals %s MB.
upload.fileIncorrectExtension.message=Incorrect file extension. File '%s' is not allowed.
upload.dropZonePrompt=Drop files here
upload.singleDropZonePrompt=Drop file here
paging.nextCaption=Next
paging.prevCaption=Prev

View File

@ -220,6 +220,8 @@ upload.unableToUploadFile=Ошибка загрузки файла '%s'
upload.uploadingProgressTitle=Загрузка файла
upload.fileTooBig.message=Размер файла '%s' превышает ограничение %s МБ
upload.fileIncorrectExtension.message=Неверное расширение файла '%s'.
upload.dropZonePrompt=Загрузите файлы
upload.singleDropZonePrompt=Загрузите файл
paging.nextCaption=Следующая
paging.prevCaption=Предыдущая

View File

@ -443,6 +443,14 @@
<xs:attribute name="expand" type="xs:string"/>
</xs:attributeGroup>
<xs:attributeGroup name="isUploadComponent">
<xs:attribute name="accept" type="xs:string"/>
<xs:attribute name="permittedExtensions" type="xs:string"/>
<xs:attribute name="fileSizeLimit" type="xs:long"/>
<xs:attribute name="dropZone" type="xs:string"/>
<xs:attribute name="dropZonePrompt" type="resourceString"/>
</xs:attributeGroup>
<xs:attributeGroup name="isDatasource">
<xs:attribute name="id" type="xs:string" use="required"/>
<xs:attribute name="class" type="xs:string"/>
@ -914,9 +922,8 @@
<xs:attributeGroup ref="hasCaption"/>
<xs:attributeGroup ref="hasVisibility"/>
<xs:attributeGroup ref="hasEnableProp"/>
<xs:attribute name="accept" type="xs:string"/>
<xs:attribute name="permittedExtensions" type="xs:string"/>
<xs:attribute name="fileSizeLimit" type="xs:long"/>
<xs:attributeGroup ref="isUploadComponent"/>
</xs:complexType>
<!-- FileMultiUploadField -->
@ -928,9 +935,8 @@
<xs:attributeGroup ref="hasVisibility"/>
<xs:attributeGroup ref="hasEnableProp"/>
<xs:attributeGroup ref="hasIcon"/>
<xs:attribute name="accept" type="xs:string"/>
<xs:attribute name="permittedExtensions" type="xs:string"/>
<xs:attribute name="fileSizeLimit" type="xs:long"/>
<xs:attributeGroup ref="isUploadComponent"/>
</xs:complexType>
<!-- Embedded -->

View File

@ -16,8 +16,7 @@
*/
package com.haulmont.cuba.gui.xml.layout.loaders;
import com.haulmont.cuba.gui.components.FileMultiUploadField;
import com.haulmont.cuba.gui.components.FileUploadField;
import com.haulmont.cuba.gui.components.*;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Element;
@ -50,7 +49,9 @@ public class FileMultiUploadFieldLoader extends AbstractComponentLoader<FileMult
loadAccept(resultComponent, element);
loadPermittedExtentions(resultComponent, element);
loadPermittedExtensions(resultComponent, element);
loadDropZone(resultComponent, element);
String fileSizeLimit = element.attributeValue("fileSizeLimit");
if (StringUtils.isNotEmpty(fileSizeLimit)) {
@ -65,10 +66,25 @@ public class FileMultiUploadFieldLoader extends AbstractComponentLoader<FileMult
}
}
protected void loadPermittedExtentions(FileMultiUploadField uploadField, Element element) {
protected void loadPermittedExtensions(FileMultiUploadField uploadField, Element element) {
String permittedExtensions = element.attributeValue("permittedExtensions");
if (StringUtils.isNotEmpty(permittedExtensions)) {
uploadField.setPermittedExtensions(new HashSet<>(Arrays.asList(permittedExtensions.split("\\s*,\\s*"))));
}
}
protected void loadDropZone(FileMultiUploadField uploadField, Element element) {
String dropZoneId = element.attributeValue("dropZone");
if (StringUtils.isNotEmpty(dropZoneId)) {
Component dropZone = context.getFrame().getComponent(dropZoneId);
if (dropZone instanceof BoxLayout) {
uploadField.setDropZone(new UploadComponentSupport.DropZone((BoxLayout) dropZone));
}
}
String dropZonePrompt = element.attributeValue("dropZonePrompt");
if (StringUtils.isNotEmpty(dropZonePrompt)) {
uploadField.setDropZonePrompt(loadResourceString(dropZonePrompt));
}
}
}

View File

@ -16,7 +16,10 @@
*/
package com.haulmont.cuba.gui.xml.layout.loaders;
import com.haulmont.cuba.gui.components.BoxLayout;
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.FileUploadField;
import com.haulmont.cuba.gui.components.UploadComponentSupport;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Element;
@ -49,7 +52,9 @@ public class FileUploadFieldLoader extends AbstractComponentLoader<FileUploadFie
loadAccept(resultComponent, element);
loadPermittedExtentions(resultComponent, element);
loadPermittedExtensions(resultComponent, element);
loadDropZone(resultComponent, element);
String fileSizeLimit = element.attributeValue("fileSizeLimit");
if (StringUtils.isNotEmpty(fileSizeLimit)) {
@ -64,10 +69,25 @@ public class FileUploadFieldLoader extends AbstractComponentLoader<FileUploadFie
}
}
protected void loadPermittedExtentions(FileUploadField uploadField, Element element) {
protected void loadPermittedExtensions(FileUploadField uploadField, Element element) {
String permittedExtensions = element.attributeValue("permittedExtensions");
if (StringUtils.isNotEmpty(permittedExtensions)) {
uploadField.setPermittedExtensions(new HashSet<>(Arrays.asList(permittedExtensions.split("\\s*,\\s*"))));
}
}
protected void loadDropZone(FileUploadField uploadField, Element element) {
String dropZoneId = element.attributeValue("dropZone");
if (StringUtils.isNotEmpty(dropZoneId)) {
Component dropZone = context.getFrame().getComponent(dropZoneId);
if (dropZone instanceof BoxLayout) {
uploadField.setDropZone(new UploadComponentSupport.DropZone((BoxLayout) dropZone));
}
}
String dropZonePrompt = element.attributeValue("dropZonePrompt");
if (StringUtils.isNotEmpty(dropZonePrompt)) {
uploadField.setDropZonePrompt(loadResourceString(dropZonePrompt));
}
}
}

View File

@ -21,10 +21,7 @@ import com.haulmont.cuba.web.toolkit.ui.CubaFileUpload;
import com.haulmont.cuba.web.toolkit.ui.client.fileupload.CubaFileUploadClientRpc;
import com.haulmont.cuba.web.toolkit.ui.client.fileupload.CubaFileUploadServerRpc;
import com.haulmont.cuba.web.toolkit.ui.client.fileupload.CubaFileUploadState;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.Paintable;
import com.vaadin.client.UIDL;
import com.vaadin.client.VCaption;
import com.vaadin.client.*;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.client.ui.Icon;
@ -65,6 +62,7 @@ public class CubaFileUploadConnector extends AbstractComponentConnector implemen
super.onUnregister();
getWidget().cancelAllUploads();
getWidget().setDropZone(null, null);
}
@Override
@ -177,6 +175,12 @@ public class CubaFileUploadConnector extends AbstractComponentConnector implemen
getWidget().permittedExtensions = getState().permittedExtensions;
}
if (stateChangeEvent.hasPropertyChanged("dropZone")) {
ComponentConnector dropZone = (ComponentConnector) getState().dropZone;
getWidget().setDropZone(dropZone != null ? dropZone.getWidget() : null, getState().dropZonePrompt);
}
if (!isEnabled() || isReadOnly()) {
getWidget().disableUpload();
} else {

View File

@ -17,6 +17,7 @@
package com.haulmont.cuba.web.toolkit.ui.client.jqueryfileupload;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
@ -25,6 +26,7 @@ import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Focusable;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.StyleConstants;
import com.vaadin.client.WidgetUtil;
import com.vaadin.client.ui.VButton;
@ -36,6 +38,7 @@ import java.util.Set;
public class CubaFileUploadWidget extends FlowPanel implements Focusable {
public static final String DEFAULT_CLASSNAME = "cuba-fileupload";
public static final String CUBA_FILEUPLOAD_DROPZONE_CLASS = "cuba-fileupload-dropzone";
protected VButton submitButton;
@ -246,6 +249,21 @@ public class CubaFileUploadWidget extends FlowPanel implements Focusable {
fileUpload.setUploadUrl(uploadUrl);
}
public void setDropZone(final Widget dropZone, String dropZonePrompt) {
if (dropZone != null) {
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
fileUpload.setDropZone(dropZone.getElement());
}
});
dropZone.getElement().setAttribute("dropzone-prompt", dropZonePrompt != null ? dropZonePrompt : "");
} else {
fileUpload.setDropZone(null);
}
}
public void setAccept(String accept) {
if (accept != null) {
getFileInputElement().setAttribute("accept", accept);
@ -310,6 +328,7 @@ public class CubaFileUploadWidget extends FlowPanel implements Focusable {
public interface FilePermissionsHandler {
void fileSizeLimitExceeded(String filename);
void fileExtensionNotAllowed(String filename);
}

View File

@ -19,17 +19,33 @@ package com.haulmont.cuba.web.toolkit.ui.client.jqueryfileupload;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.DragOverEvent;
import com.google.gwt.event.dom.client.DragOverHandler;
import com.google.gwt.event.dom.client.DropEvent;
import com.google.gwt.event.dom.client.DropHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.RootPanel;
import fi.jasoft.dragdroplayouts.client.ui.util.HTML5Support;
import java.util.ArrayList;
import java.util.List;
import static com.haulmont.cuba.web.toolkit.ui.client.jqueryfileupload.CubaFileUploadWidget.CUBA_FILEUPLOAD_DROPZONE_CLASS;
public class JQueryFileUploadOverlay {
protected static boolean globalDragDropHandlersAttached = false;
protected static Timer dragStopTimer;
protected Element fileInput;
protected String uploadUrl;
protected List<JavaScriptObject> currentXHRs = new ArrayList<JavaScriptObject>();
protected static List<Element> dropZones = new ArrayList<Element>();
private Element dropZoneElement;
public JQueryFileUploadOverlay(Element fileInput) {
this.fileInput = fileInput;
@ -47,7 +63,7 @@ public class JQueryFileUploadOverlay {
upload.fileupload({
dropZone: upload,
dataType: 'json',
autoUpload : false,
autoUpload: false,
sequentialUploads: true
});
@ -176,4 +192,99 @@ public class JQueryFileUploadOverlay {
protected void fileUploadSucceed(String fileName) {
// change file name in upload window
}
public void setDropZone(Element dropZoneElement) {
setDropZone(fileInput, dropZoneElement);
if (dropZoneElement != null) {
if (!globalDragDropHandlersAttached) {
subscribeGlobalDragDropHandlers();
globalDragDropHandlersAttached = true;
}
if (!dropZones.contains(dropZoneElement)) {
dropZones.add(dropZoneElement);
}
} else {
dropZones.remove(this.dropZoneElement);
}
this.dropZoneElement = dropZoneElement;
}
private void subscribeGlobalDragDropHandlers() {
RootPanel.get().addBitlessDomHandler(new DragOverHandler() {
@Override
public void onDragOver(DragOverEvent event) {
globalDocumentDragOver(event.getNativeEvent());
if (dropZones.size() > 0) {
event.preventDefault();
}
}
}, DragOverEvent.getType());
// prevent misses leading to opening of file inside browser
RootPanel.get().addBitlessDomHandler(new DropHandler() {
@Override
public void onDrop(DropEvent event) {
if (dropZones.size() > 0) {
event.preventDefault();
}
}
}, DropEvent.getType());
// CAUTION add compatibility layer with Vaadin DragDropLayouts
HTML5Support.setGlobalDragOverHandler(new DragOverHandler() {
@Override
public void onDragOver(DragOverEvent event) {
globalDocumentDragOver(event.getNativeEvent());
}
});
}
protected static void globalDocumentDragOver(JavaScriptObject event) {
if (isDragEventContainsFiles(event)) {
// find all drop zones and add classname
for (Element dropZone : dropZones) {
dropZone.addClassName(CUBA_FILEUPLOAD_DROPZONE_CLASS);
}
if (dragStopTimer != null) {
dragStopTimer.cancel();
}
dragStopTimer = new Timer() {
@Override
public void run() {
for (Element dropZone : dropZones) {
dropZone.removeClassName(CUBA_FILEUPLOAD_DROPZONE_CLASS);
}
dragStopTimer = null;
}
};
dragStopTimer.schedule(100);
}
}
protected native void setDropZone(Element fileInput, Element dropZoneElement) /*-{
//noinspection JSUnresolvedFunction
var upload = $wnd.jQuery(fileInput);
upload.fileupload({
dropZone: dropZoneElement
});
}-*/;
protected native static boolean isDragEventContainsFiles(JavaScriptObject event) /*-{
if (event && event.dataTransfer && event.dataTransfer.types) {
for (var i = 0; i < event.dataTransfer.types.length; i++) {
if (event.dataTransfer.types[i] == "Files") {
return true;
}
}
}
return false;
}-*/;
}

View File

@ -36,6 +36,9 @@ public abstract class WebAbstractUploadComponent<T extends com.vaadin.ui.Compone
protected Set<String> permittedExtensions;
protected DropZone dropZone;
protected String dropZonePrompt;
@Override
public long getFileSizeLimit() {
return fileSizeLimit;
@ -79,4 +82,22 @@ public abstract class WebAbstractUploadComponent<T extends com.vaadin.ui.Compone
}
return fileSizeLimitString;
}
@Override
public DropZone getDropZone() {
return dropZone;
}
@Override
public void setDropZone(DropZone dropZone) {
this.dropZone = dropZone;
}
public String getDropZonePrompt() {
return dropZonePrompt;
}
public void setDropZonePrompt(String dropZonePrompt) {
this.dropZonePrompt = dropZonePrompt;
}
}

View File

@ -24,6 +24,7 @@ import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.gui.AppConfig;
import com.haulmont.cuba.gui.components.FileMultiUploadField;
import com.haulmont.cuba.gui.components.Frame;
import com.haulmont.cuba.gui.components.Window;
import com.haulmont.cuba.gui.components.compatibility.MultiUploadFieldListenerWrapper;
import com.haulmont.cuba.gui.theme.ThemeConstants;
import com.haulmont.cuba.gui.upload.FileUploadingAPI;
@ -37,6 +38,7 @@ import com.haulmont.cuba.web.toolkit.ui.CubaMultiUpload;
import com.haulmont.cuba.web.toolkit.ui.UploadComponent;
import com.vaadin.server.Page;
import com.vaadin.server.WebBrowser;
import com.vaadin.ui.Component;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -210,6 +212,7 @@ public class WebFileMultiUploadField extends WebAbstractUploadComponent<UploadCo
impl.setUnableToUploadFileMessage(messages.getMainMessage("upload.unableToUploadFile"));
impl.setCancelButtonCaption(messages.getMainMessage("upload.cancel"));
impl.setCaption(messages.getMainMessage("upload.submit"));
impl.setDropZonePrompt(messages.getMainMessage("upload.dropZonePrompt"));
impl.setDescription(null);
Configuration configuration = AppBeans.get(Configuration.NAME);
@ -430,6 +433,34 @@ public class WebFileMultiUploadField extends WebAbstractUploadComponent<UploadCo
}
}
@Override
public void setDropZone(DropZone dropZone) {
super.setDropZone(dropZone);
if (component instanceof CubaFileUpload) {
if (dropZone == null) {
((CubaFileUpload) component).setDropZone(null);
} else {
com.haulmont.cuba.gui.components.Component target = dropZone.getTarget();
if (target instanceof Window.Wrapper) {
target = ((Window.Wrapper) target).getWrappedWindow();
}
Component vComponent = target.unwrapComposition(Component.class);
((CubaFileUpload) this.component).setDropZone(vComponent);
}
}
}
@Override
public void setDropZonePrompt(String dropZonePrompt) {
super.setDropZonePrompt(dropZonePrompt);
if (component instanceof CubaFileUpload) {
((CubaFileUpload) component).setDropZonePrompt(dropZonePrompt);
}
}
protected void fireFileUploadStart(String fileName, long contentLength) {
if (fileUploadStartListeners != null && !fileUploadStartListeners.isEmpty()) {
FileUploadStartEvent e = new FileUploadStartEvent(fileName, contentLength);

View File

@ -21,6 +21,7 @@ import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.FileStorageException;
import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.gui.components.FileUploadField;
import com.haulmont.cuba.gui.components.Window;
import com.haulmont.cuba.gui.components.compatibility.FileUploadFieldListenerWrapper;
import com.haulmont.cuba.gui.upload.FileUploadingAPI;
import com.haulmont.cuba.web.toolkit.FileUploadTypesHelper;
@ -29,6 +30,7 @@ import com.haulmont.cuba.web.toolkit.ui.CubaUpload;
import com.haulmont.cuba.web.toolkit.ui.UploadComponent;
import com.vaadin.server.Page;
import com.vaadin.server.WebBrowser;
import com.vaadin.ui.Component;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
@ -148,6 +150,7 @@ public class WebFileUploadField extends WebAbstractUploadComponent<UploadCompone
impl.setUnableToUploadFileMessage(messages.getMainMessage("upload.unableToUploadFile"));
impl.setCancelButtonCaption(messages.getMainMessage("upload.cancel"));
impl.setCaption(messages.getMainMessage("upload.submit"));
impl.setDropZonePrompt(messages.getMainMessage("upload.singleDropZonePrompt"));
impl.setDescription(null);
impl.setFileSizeLimit(getActualFileSizeLimit());
@ -342,6 +345,34 @@ public class WebFileUploadField extends WebAbstractUploadComponent<UploadCompone
}
}
@Override
public void setDropZone(DropZone dropZone) {
super.setDropZone(dropZone);
if (component instanceof CubaFileUpload) {
if (dropZone == null) {
((CubaFileUpload) component).setDropZone(null);
} else {
com.haulmont.cuba.gui.components.Component target = dropZone.getTarget();
if (target instanceof Window.Wrapper) {
target = ((Window.Wrapper) target).getWrappedWindow();
}
Component vComponent = target.unwrapComposition(Component.class);
((CubaFileUpload) this.component).setDropZone(vComponent);
}
}
}
@Override
public void setDropZonePrompt(String dropZonePrompt) {
super.setDropZonePrompt(dropZonePrompt);
if (component instanceof CubaFileUpload) {
((CubaFileUpload) component).setDropZonePrompt(dropZonePrompt);
}
}
protected void fireFileUploadStart(String fileName, long contentLength) {
if (fileUploadStartListeners != null && !fileUploadStartListeners.isEmpty()) {
FileUploadStartEvent e = new FileUploadStartEvent(fileName, contentLength);

View File

@ -36,7 +36,9 @@ import org.slf4j.LoggerFactory;
import java.io.OutputStream;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@JavaScript({
"vaadin://resources/jqueryfileupload/jquery.ui.widget-1.11.4.min.js",
@ -284,6 +286,26 @@ public class CubaFileUpload extends AbstractComponent
this.receiver = receiver;
}
public Component getDropZone() {
return (Component) getState(false).dropZone;
}
public void setDropZone(Component component) {
if (getDropZone() != component) {
getState().dropZone = component;
}
}
public String getDropZonePrompt() {
return getState(false).dropZonePrompt;
}
public void setDropZonePrompt(String dropZonePrompt) {
if (!StringUtils.equals(getDropZonePrompt(), dropZonePrompt)) {
getState().dropZonePrompt = dropZonePrompt;
}
}
protected com.vaadin.server.StreamVariable getStreamVariable() {
if (streamVariable == null) {
streamVariable = new com.vaadin.server.StreamVariable() {

View File

@ -17,6 +17,7 @@
package com.haulmont.cuba.web.toolkit.ui.client.fileupload;
import com.vaadin.shared.Connector;
import com.vaadin.shared.annotations.NoLayout;
import com.vaadin.shared.ui.TabIndexState;
@ -52,4 +53,10 @@ public class CubaFileUploadState extends TabIndexState {
@NoLayout
public Set<String> permittedExtensions;
@NoLayout
public Connector dropZone;
@NoLayout
public String dropZonePrompt;
}

View File

@ -100,4 +100,52 @@
float: right;
}
}
.v-layout.#{$primary-stylename}-dropzone {
position: relative;
&:before {
@include box-defaults;
content: "";
position: absolute;
z-index: 10;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
@include valo-textfield-focus-style;
border-radius: $v-border-radius;
outline: 2px solid $v-focus-color;
}
&:after {
content: attr(dropzone-prompt);
font-size: $v-font-size--h1;
position: absolute;
background: $v-panel-background-color;
border: valo-border();
padding: ceil($v-unit-size/2);
border-radius: $v-border-radius;
z-index: 10;
display: block;
top: 50%;
left: 50%;
-webkit-transform: translateY(-50%) translateX(-50%);
-moz-transform: translateY(-50%) translateX(-50%);
-ms-transform: translateY(-50%) translateX(-50%);
transform: translateY(-50%) translateX(-50%);
}
.v-expand {
opacity: 0.5;
}
}
}

View File

@ -54,7 +54,7 @@
}
.#{$primary-stylename} .v-button-focus {
border-color: $cuba-button-focuced-border-color;
border-color: $cuba-button-focused-border-color;
}
.#{$primary-stylename}-progresswindow.v-window {
@ -86,4 +86,49 @@
float: right;
}
}
.v-layout.#{$primary-stylename}-dropzone {
&:before {
@include box-defaults;
content: "";
position: absolute;
z-index: 10;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
box-shadow: 0 0 10px $cuba-field-focused-border-color inset;
outline: 2px solid $cuba-field-focused-border-color;
}
&:after {
content: attr(dropzone-prompt);
font-size: 24px;
font-family: $cuba-havana-fonts;
color: $cuba-havana-font-color;
background-color: white;
border-color: $cuba-field-focused-border-color;
position: absolute;
z-index: 10;
display: block;
top: 50%;
left: 50%;
-webkit-transform: translateY(-50%) translateX(-50%);
-moz-transform: translateY(-50%) translateX(-50%);
-ms-transform: translateY(-50%) translateX(-50%);
transform: translateY(-50%) translateX(-50%);
}
.v-expand {
opacity: 0.5;
}
}
}