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 | |
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
11 files changed, 76 insertions, 42 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"); diff --git a/server/src/main/java/com/vaadin/ui/Upload.java b/server/src/main/java/com/vaadin/ui/Upload.java index 5d2d4763e7..a08fce099e 100644 --- a/server/src/main/java/com/vaadin/ui/Upload.java +++ b/server/src/main/java/com/vaadin/ui/Upload.java @@ -62,14 +62,14 @@ import com.vaadin.util.ReflectTools; * ProgressListener and updating the indicator in updateProgress(). * * <p> - * Setting upload component immediate initiates the upload as soon as a file is - * selected, instead of the common pattern of file selection field and upload - * button. + * Setting upload component immediate with {@link #setImmediateMode(boolean)} + * initiates the upload as soon as a file is selected, instead of the common + * pattern of file selection field and upload button. * * <p> - * Note! Because of browser dependent implementations of - * <input type="file"> element, setting size for Upload component is not - * supported. For some browsers setting size may work to some extend. + * Note! Because of browser dependent implementations of <input type="file"> + * element, setting size for Upload component is not supported. For some + * browsers setting size may work to some extend. * * @author Vaadin Ltd. * @since 3.0 @@ -991,7 +991,7 @@ public class Upload extends AbstractComponent * {@link #submitUpload()}. * <p> * In case the Upload is used in immediate mode using - * {@link #setImmediate(boolean)}, the file choose (html input with type + * {@link #setImmediateMode(boolean)}, the file choose (html input with type * "file") is hidden and only the button with this text is shown. * <p> * @@ -1048,8 +1048,8 @@ public class Upload extends AbstractComponent @Override public boolean listenProgress() { - return (progressListeners != null - && !progressListeners.isEmpty()); + return progressListeners != null + && !progressListeners.isEmpty(); } @Override @@ -1128,28 +1128,39 @@ public class Upload extends AbstractComponent } /** - * Returns the immediate mode of the component. + * Sets the immediate mode of the upload. * <p> - * An immediate mode Upload component displays the browser file choosing + * If the upload is in immediate mode, it displays the browser file choosing * button immediately, whereas a non-immediate upload only shows a Vaadin * button. * <p> * The default mode of an Upload component is non-immediate. * - * @return true if the component is in immediate mode, false if the - * component if not in immediate mode + * @param immediateMode + * {@code true} for immediate mode, {@code false} for not */ - @Override - public boolean isImmediate() { - if (getExplicitImmediateValue() != null) { - return getExplicitImmediateValue(); - } else { - return false; - } + public void setImmediateMode(boolean immediateMode) { + getState().immediateMode = immediateMode; + } + + /** + * Returns the immediate mode of the upload. + * + * @return {@code true} if the upload is in immediate mode, {@code false} if + * the upload is not in immediate mode + * @see #setImmediateMode(boolean) + */ + public boolean isImmediateMode() { + return getState(false).immediateMode; } @Override protected UploadState getState() { return (UploadState) super.getState(); } + + @Override + protected UploadState getState(boolean markAsDirty) { + return (UploadState) super.getState(markAsDirty); + } } diff --git a/shared/src/main/java/com/vaadin/shared/ui/upload/UploadState.java b/shared/src/main/java/com/vaadin/shared/ui/upload/UploadState.java index fcbe7cc1d4..6c42a50928 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/upload/UploadState.java +++ b/shared/src/main/java/com/vaadin/shared/ui/upload/UploadState.java @@ -24,6 +24,9 @@ import com.vaadin.shared.AbstractComponentState; */ public class UploadState extends AbstractComponentState { + /** Is the upload component in immediate mode or not */ + public boolean immediateMode; + { primaryStyleName = "v-upload"; } diff --git a/uitest/src/main/java/com/vaadin/tests/TestForStyledUpload.java b/uitest/src/main/java/com/vaadin/tests/TestForStyledUpload.java index 7344d05403..8bd16c8461 100644 --- a/uitest/src/main/java/com/vaadin/tests/TestForStyledUpload.java +++ b/uitest/src/main/java/com/vaadin/tests/TestForStyledUpload.java @@ -74,7 +74,7 @@ public class TestForStyledUpload extends LegacyApplication up = new Upload(null, buffer); up.setButtonCaption("Select file"); - up.setImmediate(true); + up.setImmediateMode(true); up.addFinishedListener(this); up.addFailedListener(this); up.addSucceededListener(this); diff --git a/uitest/src/main/java/com/vaadin/tests/TestForUpload.java b/uitest/src/main/java/com/vaadin/tests/TestForUpload.java index e5cc82374d..56c10a13c3 100644 --- a/uitest/src/main/java/com/vaadin/tests/TestForUpload.java +++ b/uitest/src/main/java/com/vaadin/tests/TestForUpload.java @@ -105,7 +105,7 @@ public class TestForUpload extends CustomComponent main.addComponent(textFieldValue); up = new Upload("Upload", buffer); - up.setImmediate(true); + up.setImmediateMode(true); up.addListener(new Listener() { private static final long serialVersionUID = -8319074730512324303L; diff --git a/uitest/src/main/java/com/vaadin/tests/components/uitest/components/UploadCssTest.java b/uitest/src/main/java/com/vaadin/tests/components/uitest/components/UploadCssTest.java index 9aac96c88f..1fa591ebc0 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/uitest/components/UploadCssTest.java +++ b/uitest/src/main/java/com/vaadin/tests/components/uitest/components/UploadCssTest.java @@ -14,7 +14,7 @@ public class UploadCssTest { up = new Upload(); up.setId("upload" + debugIdCounter++); - up.setImmediate(true); + up.setImmediateMode(true); parent.addComponent(up); } } diff --git a/uitest/src/main/java/com/vaadin/tests/components/upload/TestImmediateUploadInFormLayout.java b/uitest/src/main/java/com/vaadin/tests/components/upload/TestImmediateUploadInFormLayout.java index 4cd28936b5..8235b7170c 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/upload/TestImmediateUploadInFormLayout.java +++ b/uitest/src/main/java/com/vaadin/tests/components/upload/TestImmediateUploadInFormLayout.java @@ -36,7 +36,7 @@ public class TestImmediateUploadInFormLayout FormLayout formLayout = new FormLayout(); formLayout.setWidth("100%"); Upload u = new Upload("Upload in FormLayout", this); - u.setImmediate(true); + u.setImmediateMode(true); formLayout.addComponent(u); addTestComponent(formLayout); diff --git a/uitest/src/main/java/com/vaadin/tests/components/upload/TestUploadAndDisableOnSuccess.java b/uitest/src/main/java/com/vaadin/tests/components/upload/TestUploadAndDisableOnSuccess.java index 299195d266..f2b076b60a 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/upload/TestUploadAndDisableOnSuccess.java +++ b/uitest/src/main/java/com/vaadin/tests/components/upload/TestUploadAndDisableOnSuccess.java @@ -44,7 +44,7 @@ public class TestUploadAndDisableOnSuccess extends ComponentTestCase<Upload> final Upload u; u = new Upload(null, this); - u.setImmediate(true); + u.setImmediateMode(true); addTestComponent(u); l = new Label(getUploadcount()); diff --git a/uitest/src/main/java/com/vaadin/tests/components/upload/UploadImmediateButtonWidth.java b/uitest/src/main/java/com/vaadin/tests/components/upload/UploadImmediateButtonWidth.java index ce866c37ba..9b5de2ed51 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/upload/UploadImmediateButtonWidth.java +++ b/uitest/src/main/java/com/vaadin/tests/components/upload/UploadImmediateButtonWidth.java @@ -44,7 +44,7 @@ public class UploadImmediateButtonWidth extends AbstractReindeerTestUI { upload.setId(id); upload.setWidth(width); - upload.setImmediate(true); + upload.setImmediateMode(true); return upload; } diff --git a/uitest/src/main/java/com/vaadin/tests/themes/valo/ImmediateUpload.java b/uitest/src/main/java/com/vaadin/tests/themes/valo/ImmediateUpload.java index 7c6df0e990..30f472114e 100644 --- a/uitest/src/main/java/com/vaadin/tests/themes/valo/ImmediateUpload.java +++ b/uitest/src/main/java/com/vaadin/tests/themes/valo/ImmediateUpload.java @@ -35,14 +35,14 @@ public class ImmediateUpload extends AbstractTestUI { @Override protected void setup(VaadinRequest request) { + // by default is not in immediate mode Upload upload = new Upload(); upload.setId("upload"); - upload.setImmediate(false); addComponent(upload); Upload immediateUpload = new Upload(); immediateUpload.setId("immediateupload"); - immediateUpload.setImmediate(true); + immediateUpload.setImmediateMode(true); addComponent(immediateUpload); } |