diff options
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VUpload.java | 19 | ||||
-rw-r--r-- | src/com/vaadin/ui/Upload.java | 2 | ||||
-rw-r--r-- | tests/src/com/vaadin/tests/components/upload/TestUpload.java | 79 |
3 files changed, 91 insertions, 9 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VUpload.java b/src/com/vaadin/terminal/gwt/client/ui/VUpload.java index 64b86c47b3..aded833138 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VUpload.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VUpload.java @@ -122,8 +122,9 @@ public class VUpload extends FormPanel implements Paintable, if (uidl.hasAttribute("disabled") || uidl.hasAttribute("readonly")) { disableUpload(); - } else if (uidl.getBooleanAttribute("state")) { - enableUploaod(); + } else if (!uidl.getBooleanAttribute("state")) { + // Enable the button only if an upload is not in progress + enableUpload(); } } @@ -150,13 +151,17 @@ public class VUpload extends FormPanel implements Paintable, protected void disableUpload() { submitButton.setEnabled(false); - // fu.getElement().setPropertyBoolean("disabled", true); + if (!submitted) { + // Cannot disable the fileupload while submitting or the file won't + // be submitted at all + fu.getElement().setPropertyBoolean("disabled", true); + } enabled = false; } - protected void enableUploaod() { + protected void enableUpload() { submitButton.setEnabled(true); - // fu.getElement().setPropertyBoolean("disabled", false); + fu.getElement().setPropertyBoolean("disabled", false); enabled = true; } @@ -169,7 +174,7 @@ public class VUpload extends FormPanel implements Paintable, panel.remove(fu); fu = new MyFileUpload(); fu.setName(paintableId + "_file"); - // fu.getElement().setPropertyBoolean("disabled", !enabled); + fu.getElement().setPropertyBoolean("disabled", !enabled); panel.add(fu); panel.add(submitButton); if (immediate) { @@ -189,7 +194,7 @@ public class VUpload extends FormPanel implements Paintable, rebuildPanel(); submitted = false; - enableUploaod(); + enableUpload(); } public void onSubmit(SubmitEvent event) { diff --git a/src/com/vaadin/ui/Upload.java b/src/com/vaadin/ui/Upload.java index dfbbbfc103..e3512a4795 100644 --- a/src/com/vaadin/ui/Upload.java +++ b/src/com/vaadin/ui/Upload.java @@ -244,8 +244,6 @@ public class Upload extends AbstractComponent implements Component.Focusable { target.addAttribute("buttoncaption", buttonCaption); - target.addVariable(this, "fake", true); - target.addUploadStreamVariable(this, "stream"); } diff --git a/tests/src/com/vaadin/tests/components/upload/TestUpload.java b/tests/src/com/vaadin/tests/components/upload/TestUpload.java new file mode 100644 index 0000000000..5b1590196b --- /dev/null +++ b/tests/src/com/vaadin/tests/components/upload/TestUpload.java @@ -0,0 +1,79 @@ +package com.vaadin.tests.components.upload;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.vaadin.tests.components.ComponentTestCase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Upload;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Upload.FinishedEvent;
+import com.vaadin.ui.Upload.Receiver;
+
+public class TestUpload extends ComponentTestCase implements Receiver {
+
+ @Override
+ protected String getDescription() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 3525;
+ }
+
+ @Override
+ protected void setup() {
+ super.setup();
+ Upload u;
+
+ u = new Upload("Undefined wide upload", this);
+ u.setSizeUndefined();
+ addTestComponent(u);
+
+ u.addListener(new Upload.FinishedListener() {
+ public void uploadFinished(FinishedEvent event) {
+ getMainWindow().showNotification("Done");
+ }
+ });
+
+ u = new Upload("300px wide upload", this);
+ u.setWidth("300px");
+ addTestComponent(u);
+
+ addTestComponent(new Button("blah"));
+
+ }
+
+ @Override
+ protected List<Component> createActions() {
+ List<Component> actions = new ArrayList<Component>();
+
+ CheckBox enabled = new CheckBox("Enabled", new ClickListener() {
+
+ public void buttonClick(ClickEvent event) {
+ for (Component c : getTestComponents()) {
+ c.setEnabled(event.getButton().booleanValue());
+ }
+
+ }
+ });
+ enabled.setValue(true);
+ enabled.setImmediate(true);
+ actions.add(enabled);
+
+ return actions;
+ }
+
+ public OutputStream receiveUpload(String filename, String MIMEType) {
+ getMainWindow().showNotification("Receiving upload");
+ return new ByteArrayOutputStream();
+ }
+
+}
|