From ce2df6d10370c669a512e96f0693fc37cf02aca1 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 25 Mar 2013 23:37:45 +0200 Subject: Enable setting loading indicator delays from the server (#7448) * Refactored LoadingIndicator to a separate class on client side to enable customization and to remove clutter from ApplicationConnection Change-Id: I12e94294beed9c65a5710bdfe2486bc0f1b92bd9 --- server/src/com/vaadin/ui/LoadingIndicator.java | 159 +++++++++++++++++++++++++ server/src/com/vaadin/ui/UI.java | 12 ++ 2 files changed, 171 insertions(+) create mode 100644 server/src/com/vaadin/ui/LoadingIndicator.java (limited to 'server') diff --git a/server/src/com/vaadin/ui/LoadingIndicator.java b/server/src/com/vaadin/ui/LoadingIndicator.java new file mode 100644 index 0000000000..5740ee772d --- /dev/null +++ b/server/src/com/vaadin/ui/LoadingIndicator.java @@ -0,0 +1,159 @@ +/* + * Copyright 2000-2013 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.ui; + +import java.io.Serializable; + +import com.vaadin.shared.ui.ui.UIState.LoadingIndicatorConfiguration; + +/** + * Provides method for configuring the loading indicator. + * + * @author Vaadin Ltd + * @since 7.1 + */ +public interface LoadingIndicator extends Serializable { + /** + * Sets the delay before the loading indicator is shown. The default is + * 300ms. + * + * @param initialDelay + * The initial delay (in ms) + */ + public void setInitialDelay(int initialDelay); + + /** + * Returns the delay before the loading indicator is shown. + * + * @return The initial delay (in ms) + */ + public int getInitialDelay(); + + /** + * Sets the delay before the loading indicator goes into the "delay" state. + * The delay is calculated from the time when the loading indicator was + * triggered. The default is 1500ms. + * + * @param delayStateDelay + * The delay before going into the "delay" state (in ms) + */ + public void setDelayStateDelay(int delayStateDelay); + + /** + * Returns the delay before the loading indicator goes into the "delay" + * state. The delay is calculated from the time when the loading indicator + * was triggered. + * + * @return The delay before going into the "delay" state (in ms) + */ + public int getDelayStateDelay(); + + /** + * Sets the delay before the loading indicator goes into the "wait" state. + * The delay is calculated from the time when the loading indicator was + * triggered. The default is 5000ms. + * + * @param waitStateDelay + * The delay before going into the "wait" state (in ms) + */ + public void setWaitStateDelay(int waitStateDelay); + + /** + * Returns the delay before the loading indicator goes into the "wait" + * state. The delay is calculated from the time when the loading indicator + * was triggered. + * + * @return The delay before going into the "wait" state (in ms) + */ + public int getWaitStateDelay(); +} + +class LoadingIndicatorImpl implements LoadingIndicator { + private UI ui; + + public LoadingIndicatorImpl(UI ui) { + this.ui = ui; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.LoadingIndicator#setInitialDelay(int) + */ + @Override + public void setInitialDelay(int initialDelay) { + getState().initialDelay = initialDelay; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.LoadingIndicator#getInitialDelay() + */ + @Override + public int getInitialDelay() { + return getState(false).initialDelay; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.LoadingIndicator#setDelayStateDelay(int) + */ + @Override + public void setDelayStateDelay(int delayStateDelay) { + getState().delayStateDelay = delayStateDelay; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.LoadingIndicator#getDelayStateDelay() + */ + @Override + public int getDelayStateDelay() { + return getState(false).delayStateDelay; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.LoadingIndicator#setWaitStateDelay(int) + */ + @Override + public void setWaitStateDelay(int waitStateDelay) { + getState().waitStateDelay = waitStateDelay; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.LoadingIndicator#getWaitStateDelay() + */ + @Override + public int getWaitStateDelay() { + return getState(false).waitStateDelay; + } + + private LoadingIndicatorConfiguration getState() { + return ui.getState().loadingIndicatorConfiguration; + } + + private LoadingIndicatorConfiguration getState(boolean markAsDirty) { + return ui.getState(markAsDirty).loadingIndicatorConfiguration; + } + +} diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index e9499da7f3..a20c2b2087 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -116,6 +116,8 @@ public abstract class UI extends AbstractSingleComponentContainer implements private Page page = new Page(this); + private LoadingIndicator loadingIndicator = new LoadingIndicatorImpl(this); + /** * Scroll Y position. */ @@ -1106,4 +1108,14 @@ public abstract class UI extends AbstractSingleComponentContainer implements public Tooltip getTooltip() { return tooltip; } + + /** + * Retrieves the object used for configuring the loading indicator. + * + * @return The instance used for configuring the loading indicator + */ + public LoadingIndicator getLoadingIndicator() { + return loadingIndicator; + } + } -- cgit v1.2.3