View Javadoc
1   package org.vaadin.hene.expandingtextarea.widgetset.client.ui;
2   
3   import org.vaadin.hene.expandingtextarea.ExpandingTextArea;
4   import org.vaadin.hene.expandingtextarea.widgetset.client.ui.VExpandingTextArea.HeightChangedListener;
5   
6   import com.google.gwt.core.client.GWT;
7   import com.google.gwt.core.client.Scheduler;
8   import com.google.gwt.core.client.Scheduler.ScheduledCommand;
9   import com.vaadin.client.ApplicationConnection;
10  import com.vaadin.client.UIDL;
11  import com.vaadin.client.communication.RpcProxy;
12  import com.vaadin.v7.client.ui.VTextArea;
13  import com.vaadin.v7.client.ui.textarea.TextAreaConnector;
14  import com.vaadin.shared.ui.Connect;
15  
16  @Connect(ExpandingTextArea.class)
17  public class ExpandingTextAreaConnector extends TextAreaConnector implements HeightChangedListener {
18  
19  	private ExpandingTextAreaServerRpc rpc = RpcProxy.create(ExpandingTextAreaServerRpc.class, this);
20  
21      private boolean sendRowsToServerWhenEnabled = false;
22  
23      @Override
24      public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
25          super.updateFromUIDL(uidl, client);
26  
27          if (uidl.hasAttribute("maxRows")) {
28              getWidget().setMaxRows(uidl.getIntAttribute("maxRows"));
29          } else {
30          	getWidget().setMaxRows(null);
31          }
32  
33          getWidget().addStyleName(VTextArea.CLASSNAME);
34  
35          Scheduler.get().scheduleDeferred(new ScheduledCommand() {
36          	public void execute() {
37          		getWidget().checkHeight();
38          	}
39          });
40  
41          if (sendRowsToServerWhenEnabled && isEnabled()) {
42              rpc.setRows(getWidget().getRows());
43              sendRowsToServerWhenEnabled = false;
44          }
45      }
46  
47      @Override
48      protected void updateWidgetStyleNames() {
49          super.updateWidgetStyleNames();
50          getWidget().addStyleName(VExpandingTextArea.CLASSNAME);
51      }
52  
53      @Override
54      protected VExpandingTextArea createWidget() {
55      	VExpandingTextArea widget = GWT.create(VExpandingTextArea.class);
56      	widget.addHeightChangedListener(this);
57          return widget;
58      }
59  
60      @Override
61      public VExpandingTextArea getWidget() {
62          return (VExpandingTextArea) super.getWidget();
63      }
64  
65  	public void heightChanged(int newHeight) {
66          // Vaadin doesn't allow requests from disabled components.
67          // If the component is disabled, set a flag to true so that row count
68          // is transferred when component is enabled (see updateFromUIDL).
69          if (isEnabled()) {
70              rpc.setRows(newHeight);
71          } else {
72              sendRowsToServerWhenEnabled = true;
73          }
74  		getLayoutManager().setNeedsMeasure(this);
75  	}
76  
77  }