You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DisablingUpload.java 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.vaadin.tests.components.upload;
  2. import java.io.ByteArrayOutputStream;
  3. import java.io.OutputStream;
  4. import com.vaadin.annotations.Push;
  5. import com.vaadin.server.VaadinRequest;
  6. import com.vaadin.shared.communication.PushMode;
  7. import com.vaadin.tests.components.AbstractTestUIWithLog;
  8. import com.vaadin.ui.Button;
  9. import com.vaadin.ui.UI;
  10. import com.vaadin.ui.Upload;
  11. @Push
  12. public class DisablingUpload extends AbstractTestUIWithLog {
  13. @Override
  14. protected void setup(VaadinRequest request) {
  15. Upload ul = new Upload(
  16. "Uploading anything will disable the Upload on SucceededListener",
  17. new Upload.Receiver() {
  18. @Override
  19. public OutputStream receiveUpload(String s, String s1) {
  20. return new ByteArrayOutputStream();
  21. }
  22. });
  23. Button button = new Button("Disable upload from Button click", e -> {
  24. ul.setEnabled(!ul.isEnabled());
  25. });
  26. button.setId("button-id");
  27. ul.addSucceededListener(e -> {
  28. ul.setEnabled(false);
  29. log("File has been uploaded.");
  30. });
  31. ul.addStartedListener(e -> {
  32. log("File upload starts");
  33. });
  34. Button pushButton = new Button("Set the Push Mode");
  35. pushButton.setId("push-button");
  36. Button stateButton = new Button("" + ul.isEnabled());
  37. stateButton.setId("state-button");
  38. stateButton.addClickListener(event -> {
  39. stateButton.setCaption("" + ul.isEnabled());
  40. });
  41. pushButton.addClickListener(event -> {
  42. if (UI.getCurrent().getPushConfiguration().getPushMode()
  43. .isEnabled()) {
  44. UI.getCurrent().getPushConfiguration()
  45. .setPushMode(PushMode.DISABLED);
  46. pushButton.setCaption("enable push mode");
  47. } else {
  48. UI.getCurrent().getPushConfiguration()
  49. .setPushMode(PushMode.AUTOMATIC);
  50. pushButton.setCaption("disable push mode");
  51. }
  52. });
  53. addComponents(ul, button, pushButton, stateButton);
  54. }
  55. }