From: Dmitrii Rogozin Date: Tue, 5 Aug 2014 09:36:37 +0000 (+0300) Subject: Add method for widgets to tell there is work to be done (#13565) X-Git-Tag: 7.3.0.rc1~11^2~55 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=54707a7219d39e4b60d7cccac3d0f613dc4f1824;p=vaadin-framework.git Add method for widgets to tell there is work to be done (#13565) Change-Id: I4b961443f6c175aaf2e2272f1257670fe6bc9607 --- diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index 6e2c6e757c..90aa0a14d6 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -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 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 index 0000000000..53f7c79fe6 --- /dev/null +++ b/client/src/com/vaadin/client/DeferredWorker.java @@ -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(); +} diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 8c1a92830d..6a2a753d0e 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -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(); + } }