summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-10-22 16:24:05 +0300
committerArtur Signell <artur@vaadin.com>2012-10-24 15:33:48 +0300
commit9551d7ca56bb9fced67ced199bf23363ac230f3e (patch)
tree45b5ab0195d67335c84e5b8e39a143b7f67f5952 /client
parent0121af0c28d92db37dea94050f3453ecf46556b9 (diff)
downloadvaadin-framework-9551d7ca56bb9fced67ced199bf23363ac230f3e.tar.gz
vaadin-framework-9551d7ca56bb9fced67ced199bf23363ac230f3e.zip
Updated ProgressIndicator to use state and rpc (#10008)
Change-Id: Iec3d0c4e9e1432f7dda4aae5c8c4f21cb96f08be
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ui/progressindicator/ProgressIndicatorConnector.java59
-rw-r--r--client/src/com/vaadin/client/ui/progressindicator/VProgressIndicator.java63
2 files changed, 53 insertions, 69 deletions
diff --git a/client/src/com/vaadin/client/ui/progressindicator/ProgressIndicatorConnector.java b/client/src/com/vaadin/client/ui/progressindicator/ProgressIndicatorConnector.java
index d75bc8d0c3..40b3a227c4 100644
--- a/client/src/com/vaadin/client/ui/progressindicator/ProgressIndicatorConnector.java
+++ b/client/src/com/vaadin/client/ui/progressindicator/ProgressIndicatorConnector.java
@@ -16,52 +16,45 @@
package com.vaadin.client.ui.progressindicator;
-import com.google.gwt.user.client.DOM;
-import com.vaadin.client.ApplicationConnection;
-import com.vaadin.client.Paintable;
-import com.vaadin.client.UIDL;
+import com.google.gwt.user.client.Timer;
+import com.vaadin.client.communication.RpcProxy;
+import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.shared.ui.Connect;
+import com.vaadin.shared.ui.progressindicator.ProgressIndicatorServerRpc;
+import com.vaadin.shared.ui.progressindicator.ProgressIndicatorState;
import com.vaadin.ui.ProgressIndicator;
@Connect(ProgressIndicator.class)
-public class ProgressIndicatorConnector extends AbstractFieldConnector
- implements Paintable {
+public class ProgressIndicatorConnector extends AbstractFieldConnector {
@Override
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-
- if (!isRealUpdate(uidl)) {
- return;
- }
+ public ProgressIndicatorState getState() {
+ return (ProgressIndicatorState) super.getState();
+ }
- // Save details
- getWidget().client = client;
+ ProgressIndicatorServerRpc rpc = RpcProxy.create(
+ ProgressIndicatorServerRpc.class, this);
- getWidget().indeterminate = uidl.getBooleanAttribute("indeterminate");
+ private Timer poller = new Timer() {
- if (getWidget().indeterminate) {
- String basename = VProgressIndicator.CLASSNAME + "-indeterminate";
- getWidget().addStyleName(basename);
- if (!isEnabled()) {
- getWidget().addStyleName(basename + "-disabled");
- } else {
- getWidget().removeStyleName(basename + "-disabled");
- }
- } else {
- try {
- final float f = Float.parseFloat(uidl
- .getStringAttribute("state"));
- final int size = Math.round(100 * f);
- DOM.setStyleAttribute(getWidget().indicator, "width", size
- + "%");
- } catch (final Exception e) {
- }
+ @Override
+ public void run() {
+ rpc.poll();
}
+ };
+
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
+ getWidget().setIndeterminate(getState().indeterminate);
+ getWidget().setState(getState().state);
+
if (isEnabled()) {
- getWidget().interval = uidl.getIntAttribute("pollinginterval");
- getWidget().poller.scheduleRepeating(getWidget().interval);
+ poller.scheduleRepeating(getState().pollingInterval);
+ } else {
+ poller.cancel();
}
}
diff --git a/client/src/com/vaadin/client/ui/progressindicator/VProgressIndicator.java b/client/src/com/vaadin/client/ui/progressindicator/VProgressIndicator.java
index f090cbee5f..ef3be0320a 100644
--- a/client/src/com/vaadin/client/ui/progressindicator/VProgressIndicator.java
+++ b/client/src/com/vaadin/client/ui/progressindicator/VProgressIndicator.java
@@ -16,23 +16,21 @@
package com.vaadin.client.ui.progressindicator;
+import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
-import com.google.gwt.user.client.Timer;
+import com.google.gwt.user.client.ui.HasEnabled;
import com.google.gwt.user.client.ui.Widget;
-import com.vaadin.client.ApplicationConnection;
-import com.vaadin.client.Util;
-public class VProgressIndicator extends Widget {
+public class VProgressIndicator extends Widget implements HasEnabled {
public static final String CLASSNAME = "v-progressindicator";
Element wrapper = DOM.createDiv();
Element indicator = DOM.createDiv();
- protected ApplicationConnection client;
- protected final Poller poller;
+
protected boolean indeterminate = false;
- private boolean pollerSuspendedDueDetach;
- protected int interval;
+ protected float state = 0.0f;
+ private boolean enabled;
public VProgressIndicator() {
setElement(DOM.createDiv());
@@ -41,43 +39,36 @@ public class VProgressIndicator extends Widget {
wrapper.appendChild(indicator);
indicator.setClassName(CLASSNAME + "-indicator");
wrapper.setClassName(CLASSNAME + "-wrapper");
- poller = new Poller();
}
- @Override
- protected void onAttach() {
- super.onAttach();
- if (pollerSuspendedDueDetach) {
- poller.scheduleRepeating(interval);
- }
+ public void setIndeterminate(boolean indeterminate) {
+ this.indeterminate = indeterminate;
+ setStyleName(CLASSNAME + "-indeterminate", indeterminate);
}
- @Override
- protected void onDetach() {
- super.onDetach();
- if (interval > 0) {
- poller.cancel();
- pollerSuspendedDueDetach = true;
- }
+ public void setState(float state) {
+ final int size = Math.round(100 * state);
+ indicator.getStyle().setWidth(size, Unit.PCT);
}
- @Override
- public void setVisible(boolean visible) {
- super.setVisible(visible);
- if (!visible) {
- poller.cancel();
- }
+ public boolean isIndeterminate() {
+ return indeterminate;
+ }
+
+ public float getState() {
+ return state;
}
- class Poller extends Timer {
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
- @Override
- public void run() {
- if (!client.hasActiveRequest()
- && Util.isAttachedAndDisplayed(VProgressIndicator.this)) {
- client.sendPendingVariableChanges();
- }
- }
+ @Override
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ setStyleName("v-disabled", !enabled);
}
+
}