public class IUpload extends FormPanel implements Paintable, ClickListener,
FormHandler {
-
+
public static final String CLASSNAME = "i-upload";
/**
/**
* Button that initiates uploading
*/
- private Button b;
+ private Button submitButton;
/**
* When expecting big files, programmer may initiate some UI changes when
setWidget(panel);
panel.add(fu);
- // TODO
- b = new Button("Click to Upload");
- b.addClickListener(this);
- panel.add(b);
+ submitButton = new Button();
+ submitButton.addClickListener(this);
+ panel.add(submitButton);
addFormHandler(this);
-
+
setStyleName(CLASSNAME);
}
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- if (client.updateComponent(this, uidl, false)) {
+ if (client.updateComponent(this, uidl, true)) {
return;
}
this.client = client;
paintableId = uidl.getId();
setAction(client.getAppUri());
-
- if (uidl.hasAttribute("caption")) {
- b.setText(uidl.getStringAttribute("caption"));
- }
+ submitButton.setText(uidl.getStringAttribute("buttoncaption"));
fu.setName(paintableId + "_file");
}
}
protected void disableUpload() {
- b.setEnabled(false);
+ submitButton.setEnabled(false);
fu.setVisible(false);
}
protected void enableUploaod() {
- b.setEnabled(true);
+ submitButton.setEnabled(true);
fu.setVisible(true);
}
private int totalBytes;
+ private String buttonCaption = "Upload";
+
/**
* ProgressListener to which information about progress is sent during
* upload
target.addAttribute("state", isUploading);
+ target.addAttribute("buttoncaption", buttonCaption);
+
target.addVariable(this, "fake", true);
target.addUploadStreamVariable(this, "stream");
*/
public void updateProgress(long readBytes, long contentLength);
}
+
+ /**
+ * @return String to be rendered into button that fires uploading
+ */
+ public String getButtonCaption() {
+ return buttonCaption;
+ }
+
+ /**
+ * File uploads usually have button that starts actual upload progress. This
+ * method is used to set text in that button.
+ *
+ * @param buttonCaption
+ * text for uploads button.
+ */
+ public void setButtonCaption(String buttonCaption) {
+ this.buttonCaption = buttonCaption;
+ }
}