]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add method for widgets to tell there is work to be done (#13565)
authorDmitrii Rogozin <dmitrii@vaadin.com>
Tue, 5 Aug 2014 09:36:37 +0000 (12:36 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 6 Aug 2014 13:45:00 +0000 (13:45 +0000)
Change-Id: I4b961443f6c175aaf2e2272f1257670fe6bc9607

client/src/com/vaadin/client/ApplicationConnection.java
client/src/com/vaadin/client/DeferredWorker.java [new file with mode: 0644]
client/src/com/vaadin/client/ui/VScrollTable.java

index 6e2c6e757ca3e0ca08e377782ee65af6969cfdb6..90aa0a14d676f6f6baaac5de2a62e1f86d8fbfee 100644 (file)
@@ -598,14 +598,23 @@ public class ApplicationConnection implements HasHandlers {
         }
     }
 
+    /**
+     * Checks if there is some work to be done on the client side
+     * 
+     * @return true if the client has some work to be done, false otherwise
+     */
+    private boolean isActive() {
+        return isWorkPending() || hasActiveRequest()
+                || isExecutingDeferredCommands();
+    }
+
     private native void initializeTestbenchHooks(
             ComponentLocator componentLocator, String TTAppId)
     /*-{
         var ap = this;
         var client = {};
         client.isActive = $entry(function() {
-            return ap.@com.vaadin.client.ApplicationConnection::hasActiveRequest()()
-                    || ap.@com.vaadin.client.ApplicationConnection::isExecutingDeferredCommands()();
+            return ap.@com.vaadin.client.ApplicationConnection::isActive()();
         });
         var vi = ap.@com.vaadin.client.ApplicationConnection::getVersionInfo()();
         if (vi) {
@@ -1319,6 +1328,30 @@ public class ApplicationConnection implements HasHandlers {
         }
     }
 
+    /**
+     * Checks if the client has running or scheduled commands
+     */
+    private boolean isWorkPending() {
+        ConnectorMap connectorMap = getConnectorMap();
+        JsArrayObject<ServerConnector> connectors = connectorMap
+                .getConnectorsAsJsArray();
+        int size = connectors.size();
+        for (int i = 0; i < size; i++) {
+            ServerConnector conn = connectors.get(i);
+            ComponentConnector compConn = null;
+            if (conn instanceof ComponentConnector) {
+                compConn = (ComponentConnector) conn;
+                Widget wgt = compConn.getWidget();
+                if (wgt instanceof DeferredWorker) {
+                    if (((DeferredWorker) wgt).isWorkPending()) {
+                        return true;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+
     /**
      * Checks if deferred commands are (potentially) still being executed as a
      * result of an update from the server. Returns true if a deferred command
@@ -1483,6 +1516,7 @@ public class ApplicationConnection implements HasHandlers {
         if (json.containsKey("typeMappings")) {
             configuration.addComponentMappings(
                     json.getValueMap("typeMappings"), widgetSet);
+
         }
 
         VConsole.log("Handling resource dependencies");
@@ -1717,6 +1751,7 @@ public class ApplicationConnection implements HasHandlers {
                 for (int i = 0; i < needsUpdateLength; i++) {
                     String childId = dump.get(i);
                     ServerConnector child = connectorMap.getConnector(childId);
+
                     if (child instanceof ComponentConnector
                             && ((ComponentConnector) child)
                                     .delegateCaptionHandling()) {
diff --git a/client/src/com/vaadin/client/DeferredWorker.java b/client/src/com/vaadin/client/DeferredWorker.java
new file mode 100644 (file)
index 0000000..53f7c79
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.client;
+
+/**
+ * Give widgets the possibility to indicate to the framework that there is work
+ * scheduled to be executed in the near future and that the framework should
+ * wait for this work to complete before assuming the UI has reached a steady
+ * state.
+ */
+public interface DeferredWorker {
+    /**
+     * @returns true, if there are operations pending which must be executed
+     *          before reaching a steady state
+     */
+    public boolean isWorkPending();
+}
index 8c1a92830d1c899ace6af295ad936deae723ef17..6a2a753d0e63769f4ab5a9dd92d0de74dd59faf2 100644 (file)
@@ -80,6 +80,7 @@ import com.vaadin.client.ApplicationConnection;
 import com.vaadin.client.BrowserInfo;
 import com.vaadin.client.ComponentConnector;
 import com.vaadin.client.ConnectorMap;
+import com.vaadin.client.DeferredWorker;
 import com.vaadin.client.Focusable;
 import com.vaadin.client.MouseEventDetailsBuilder;
 import com.vaadin.client.StyleConstants;
@@ -126,7 +127,7 @@ import com.vaadin.shared.ui.table.TableConstants;
  */
 public class VScrollTable extends FlowPanel implements HasWidgets,
         ScrollHandler, VHasDropHandler, FocusHandler, BlurHandler, Focusable,
-        ActionOwner, SubPartAware {
+        ActionOwner, SubPartAware, DeferredWorker {
 
     public static final String STYLENAME = "v-table";
 
@@ -7924,4 +7925,12 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
             addCloseHandler.removeHandler();
         }
     }
+
+    /*
+     * Return true if component need to perform some work and false otherwise.
+     */
+    @Override
+    public boolean isWorkPending() {
+        return lazyAdjustColumnWidths.isRunning();
+    }
 }