Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.v7.client.ui.upload;
  17. import com.google.gwt.event.dom.client.ChangeEvent;
  18. import com.google.gwt.event.dom.client.ChangeHandler;
  19. import com.vaadin.client.ApplicationConnection;
  20. import com.vaadin.client.Paintable;
  21. import com.vaadin.client.UIDL;
  22. import com.vaadin.client.communication.StateChangeEvent;
  23. import com.vaadin.shared.EventId;
  24. import com.vaadin.shared.ui.Connect;
  25. import com.vaadin.v7.client.ui.AbstractLegacyComponentConnector;
  26. import com.vaadin.v7.client.ui.VUpload;
  27. import com.vaadin.v7.shared.ui.upload.UploadClientRpc;
  28. import com.vaadin.v7.shared.ui.upload.UploadServerRpc;
  29. import com.vaadin.v7.shared.ui.upload.UploadState;
  30. @Connect(com.vaadin.v7.ui.Upload.class)
  31. public class UploadConnector extends AbstractLegacyComponentConnector
  32. implements Paintable {
  33. public UploadConnector() {
  34. registerRpc(UploadClientRpc.class, new UploadClientRpc() {
  35. @Override
  36. public void submitUpload() {
  37. getWidget().submit();
  38. }
  39. });
  40. }
  41. @Override
  42. protected void init() {
  43. super.init();
  44. getWidget().fu.addChangeHandler(new ChangeHandler() {
  45. @Override
  46. public void onChange(ChangeEvent event) {
  47. if (hasEventListener(EventId.CHANGE)) {
  48. getRpcProxy(UploadServerRpc.class)
  49. .change(getWidget().fu.getFilename());
  50. }
  51. }
  52. });
  53. }
  54. @Override
  55. public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
  56. if (!isRealUpdate(uidl)) {
  57. return;
  58. }
  59. if (uidl.hasAttribute("notStarted")) {
  60. getWidget().t.schedule(400);
  61. return;
  62. }
  63. getWidget().setImmediate(getState().immediate);
  64. getWidget().client = client;
  65. getWidget().paintableId = uidl.getId();
  66. getWidget().nextUploadId = uidl.getIntAttribute("nextid");
  67. final String action = client
  68. .translateVaadinUri(uidl.getStringVariable("action"));
  69. getWidget().element.setAction(action);
  70. if (uidl.hasAttribute("buttoncaption")) {
  71. getWidget().submitButton
  72. .setText(uidl.getStringAttribute("buttoncaption"));
  73. getWidget().submitButton.setVisible(true);
  74. } else {
  75. getWidget().submitButton.setVisible(false);
  76. }
  77. getWidget().fu.setName(getWidget().paintableId + "_file");
  78. if (!isEnabled() || isReadOnly()) {
  79. getWidget().disableUpload();
  80. } else if (!uidl.getBooleanAttribute("state")) {
  81. // Enable the button only if an upload is not in progress
  82. getWidget().enableUpload();
  83. getWidget().ensureTargetFrame();
  84. }
  85. }
  86. @Override
  87. public void onStateChanged(StateChangeEvent stateChangeEvent) {
  88. super.onStateChanged(stateChangeEvent);
  89. getWidget().disableTitle(hasTooltip());
  90. }
  91. @Override
  92. public VUpload getWidget() {
  93. return (VUpload) super.getWidget();
  94. }
  95. @Override
  96. public UploadState getState() {
  97. return (UploadState) super.getState();
  98. }
  99. }