Browse Source

Merged fix and test case for #3525 - "Cannot re-enable a disabled upload component" from 6.1

svn changeset:9714/svn branch:6.2
tags/6.7.0.beta1
Artur Signell 14 years ago
parent
commit
aee045e3d0

+ 12
- 7
src/com/vaadin/terminal/gwt/client/ui/VUpload.java View File

@@ -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) {

+ 0
- 2
src/com/vaadin/ui/Upload.java View File

@@ -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");
}


+ 79
- 0
tests/src/com/vaadin/tests/components/upload/TestUpload.java View File

@@ -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();
}
}

Loading…
Cancel
Save