View Javadoc
1   /*
2    * Copyright 2000-2013 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  
17  package com.vaadin.client.ui.upload;
18  
19  import com.vaadin.client.ApplicationConnection;
20  import com.vaadin.client.Paintable;
21  import com.vaadin.client.UIDL;
22  import com.vaadin.client.ui.AbstractComponentConnector;
23  import com.vaadin.client.ui.VUpload;
24  import com.vaadin.shared.ui.Connect;
25  import com.vaadin.ui.Upload;
26  
27  @Connect(Upload.class)
28  public class UploadConnector extends AbstractComponentConnector implements
29          Paintable {
30  
31      @Override
32      public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
33          if (!isRealUpdate(uidl)) {
34              return;
35          }
36          if (uidl.hasAttribute("notStarted")) {
37              getWidget().t.schedule(400);
38              return;
39          }
40          if (uidl.hasAttribute("forceSubmit")) {
41              getWidget().submit();
42              return;
43          }
44          getWidget().setImmediate(getState().immediate);
45          getWidget().client = client;
46          getWidget().paintableId = uidl.getId();
47          getWidget().nextUploadId = uidl.getIntAttribute("nextid");
48          final String action = client.translateVaadinUri(uidl
49                  .getStringVariable("action"));
50          getWidget().element.setAction(action);
51          if (uidl.hasAttribute("buttoncaption")) {
52              getWidget().submitButton.setText(uidl
53                      .getStringAttribute("buttoncaption"));
54              getWidget().submitButton.setVisible(true);
55          } else {
56              getWidget().submitButton.setVisible(false);
57          }
58          getWidget().fu.setName(getWidget().paintableId + "_file");
59  
60          if (!isEnabled() || isReadOnly()) {
61              getWidget().disableUpload();
62          } else if (!uidl.getBooleanAttribute("state")) {
63              // Enable the button only if an upload is not in progress
64              getWidget().enableUpload();
65              getWidget().ensureTargetFrame();
66          }
67      }
68  
69      @Override
70      public VUpload getWidget() {
71          return (VUpload) super.getWidget();
72      }
73  }