diff options
author | Pekka Hyvönen <pekka@vaadin.com> | 2016-10-06 17:16:31 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-10-07 13:38:13 +0000 |
commit | 8ef496dbde9578cbab3e05f9d81238d4da9806e6 (patch) | |
tree | 400e9e6aa0d08b7d0d0f78caf8203255bc10a303 /client/src | |
parent | 8d825141f239a6f39a6d4ebd3b48ced7e97fc61b (diff) | |
download | vaadin-framework-8ef496dbde9578cbab3e05f9d81238d4da9806e6.tar.gz vaadin-framework-8ef496dbde9578cbab3e05f9d81238d4da9806e6.zip |
Separate immediate mode for Upload from AbstactComponent.immediate
Makes it possible to remove the immediate from AbstractComponent.
Part 2 / 2 of adding proper Upload immediateMode, first was to move
old Upload to v7 compatiblity packages.
Change-Id: Iff99df70d9465fa1f3bad4baae44a0488eba01c0
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/VUpload.java | 46 | ||||
-rw-r--r-- | client/src/main/java/com/vaadin/client/ui/upload/UploadConnector.java | 2 |
2 files changed, 34 insertions, 14 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VUpload.java b/client/src/main/java/com/vaadin/client/ui/VUpload.java index 913bec568a..708d6fe5df 100644 --- a/client/src/main/java/com/vaadin/client/ui/VUpload.java +++ b/client/src/main/java/com/vaadin/client/ui/VUpload.java @@ -48,15 +48,17 @@ import com.vaadin.shared.ui.upload.UploadServerRpc; * Note, we are not using GWT FormPanel as we want to listen submitcomplete * events even though the upload component is already detached. * + * @author Vaadin Ltd + * */ public class VUpload extends SimplePanel { - private final class MyFileUpload extends FileUpload { + private final class VFileUpload extends FileUpload { @Override public void onBrowserEvent(Event event) { super.onBrowserEvent(event); if (event.getTypeInt() == Event.ONCHANGE) { - if (immediate && fu.getFilename() != null + if (isImmediateMode() && fu.getFilename() != null && !"".equals(fu.getFilename())) { submit(); } @@ -80,7 +82,7 @@ public class VUpload extends SimplePanel { * <p> * For internal use only. May be removed or replaced in the future. */ - public FileUpload fu = new MyFileUpload(); + public FileUpload fu = new VFileUpload(); Panel panel = new FlowPanel(); @@ -118,7 +120,7 @@ public class VUpload extends SimplePanel { private boolean enabled = true; - private boolean immediate; + private boolean immediateMode; private Hidden maxfilesize = new Hidden(); @@ -144,7 +146,7 @@ public class VUpload extends SimplePanel { submitButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { - if (immediate) { + if (isImmediateMode()) { // fire click on upload (eg. focused button and hit space) fireNativeClick(fu.getElement()); } else { @@ -162,16 +164,34 @@ public class VUpload extends SimplePanel { form.enctype = encoding; }-*/; - /** For internal use only. May be removed or replaced in the future. */ - public void setImmediate(boolean booleanAttribute) { - if (immediate != booleanAttribute) { - immediate = booleanAttribute; - if (immediate) { + /** + * Sets the upload in immediate mode. + * + * @param immediateMode + * {@code true} for immediate mode, {@code false} for + * non-immediate mode + */ + public void setImmediateMode(boolean immediateMode) { + if (this.immediateMode != immediateMode) { + this.immediateMode = immediateMode; + if (immediateMode) { fu.sinkEvents(Event.ONCHANGE); fu.sinkEvents(Event.ONFOCUS); + } else { + fu.unsinkEvents(Event.ONCHANGE); + fu.unsinkEvents(Event.ONFOCUS); } } - setStyleName(getElement(), CLASSNAME + "-immediate", immediate); + setStyleName(getElement(), CLASSNAME + "-immediate", immediateMode); + } + + /** + * Returns whether this component is in immediate mode or not. + * + * @return {@code true} for immediate mode, {@code false} for not + */ + public boolean isImmediateMode() { + return immediateMode; } private static native void fireNativeClick(Element element) @@ -223,12 +243,12 @@ public class VUpload extends SimplePanel { private void rebuildPanel() { panel.remove(submitButton); panel.remove(fu); - fu = new MyFileUpload(); + fu = new VFileUpload(); fu.setName(paintableId + "_file"); fu.getElement().setPropertyBoolean("disabled", !enabled); panel.add(fu); panel.add(submitButton); - if (immediate) { + if (isImmediateMode()) { fu.sinkEvents(Event.ONCHANGE); } } diff --git a/client/src/main/java/com/vaadin/client/ui/upload/UploadConnector.java b/client/src/main/java/com/vaadin/client/ui/upload/UploadConnector.java index 031c50e3b8..f84b07d964 100644 --- a/client/src/main/java/com/vaadin/client/ui/upload/UploadConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/upload/UploadConnector.java @@ -68,7 +68,7 @@ public class UploadConnector extends AbstractComponentConnector getWidget().t.schedule(400); return; } - getWidget().setImmediate(getState().immediate); + getWidget().setImmediateMode(getState().immediateMode); getWidget().client = client; getWidget().paintableId = uidl.getId(); getWidget().nextUploadId = uidl.getIntAttribute("nextid"); |