]> source.dussan.org Git - vaadin-framework.git/commitdiff
#8324 Splitted VProgressIndicator into Widget and Paintable.
authorJens Jansson <peppe@vaadin.com>
Tue, 31 Jan 2012 09:05:53 +0000 (11:05 +0200)
committerArtur Signell <artur@vaadin.com>
Tue, 31 Jan 2012 13:08:17 +0000 (15:08 +0200)
src/com/vaadin/terminal/gwt/client/ui/VProgressIndicator.java
src/com/vaadin/terminal/gwt/client/ui/VProgressIndicatorPaintable.java [new file with mode: 0644]
src/com/vaadin/ui/ProgressIndicator.java

index f7cc4240b76b99be2c9063d89db3c132ca32255d..cff6bf89bd747dbdc04baa0220a9585ccca86f3f 100644 (file)
@@ -9,20 +9,18 @@ import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Timer;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.terminal.gwt.client.ApplicationConnection;
-import com.vaadin.terminal.gwt.client.VPaintableWidget;
-import com.vaadin.terminal.gwt.client.UIDL;
 import com.vaadin.terminal.gwt.client.Util;
 
-public class VProgressIndicator extends Widget implements VPaintableWidget {
+public class VProgressIndicator extends Widget {
 
-    private static final String CLASSNAME = "v-progressindicator";
+    public static final String CLASSNAME = "v-progressindicator";
     Element wrapper = DOM.createDiv();
     Element indicator = DOM.createDiv();
-    private ApplicationConnection client;
-    private final Poller poller;
-    private boolean indeterminate = false;
+    protected ApplicationConnection client;
+    protected final Poller poller;
+    protected boolean indeterminate = false;
     private boolean pollerSuspendedDueDetach;
-    private int interval;
+    protected int interval;
 
     public VProgressIndicator() {
         setElement(DOM.createDiv());
@@ -34,38 +32,6 @@ public class VProgressIndicator extends Widget implements VPaintableWidget {
         poller = new Poller();
     }
 
-    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
-        this.client = client;
-        if (!uidl.getBooleanAttribute("cached")) {
-            poller.cancel();
-        }
-        if (client.updateComponent(this, uidl, true)) {
-            return;
-        }
-
-        indeterminate = uidl.getBooleanAttribute("indeterminate");
-
-        if (indeterminate) {
-            String basename = CLASSNAME + "-indeterminate";
-            VProgressIndicator.setStyleName(getElement(), basename, true);
-            VProgressIndicator.setStyleName(getElement(), basename
-                    + "-disabled", uidl.getBooleanAttribute("disabled"));
-        } else {
-            try {
-                final float f = Float.parseFloat(uidl
-                        .getStringAttribute("state"));
-                final int size = Math.round(100 * f);
-                DOM.setStyleAttribute(indicator, "width", size + "%");
-            } catch (final Exception e) {
-            }
-        }
-
-        if (!uidl.getBooleanAttribute("disabled")) {
-            interval = uidl.getIntAttribute("pollinginterval");
-            poller.scheduleRepeating(interval);
-        }
-    }
-
     @Override
     protected void onAttach() {
         super.onAttach();
@@ -102,9 +68,4 @@ public class VProgressIndicator extends Widget implements VPaintableWidget {
         }
 
     }
-
-    public Widget getWidgetForPaintable() {
-        return this;
-    }
-
 }
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VProgressIndicatorPaintable.java b/src/com/vaadin/terminal/gwt/client/ui/VProgressIndicatorPaintable.java
new file mode 100644 (file)
index 0000000..39ffe1a
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+
+package com.vaadin.terminal.gwt.client.ui;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.ui.Widget;
+import com.vaadin.terminal.gwt.client.ApplicationConnection;
+import com.vaadin.terminal.gwt.client.UIDL;
+
+public class VProgressIndicatorPaintable extends VAbstractPaintableWidget {
+
+    public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
+
+        // Ensure correct implementation,
+        // but don't let container manage caption etc.
+        if (client.updateComponent(this, uidl, false)) {
+            return;
+        }
+
+        // Save details
+        getWidgetForPaintable().client = client;
+
+        getWidgetForPaintable().indeterminate = uidl
+                .getBooleanAttribute("indeterminate");
+
+        if (getWidgetForPaintable().indeterminate) {
+            String basename = VProgressIndicator.CLASSNAME + "-indeterminate";
+            getWidgetForPaintable().addStyleName(basename);
+            if (uidl.getBooleanAttribute("disabled")) {
+                getWidgetForPaintable().addStyleName(basename + "-disabled");
+            } else {
+                getWidgetForPaintable().removeStyleName(basename + "-disabled");
+            }
+        } else {
+            try {
+                final float f = Float.parseFloat(uidl
+                        .getStringAttribute("state"));
+                final int size = Math.round(100 * f);
+                DOM.setStyleAttribute(getWidgetForPaintable().indicator,
+                        "width", size + "%");
+            } catch (final Exception e) {
+            }
+        }
+
+        if (!uidl.getBooleanAttribute("disabled")) {
+            getWidgetForPaintable().interval = uidl
+                    .getIntAttribute("pollinginterval");
+            getWidgetForPaintable().poller
+                    .scheduleRepeating(getWidgetForPaintable().interval);
+        }
+    }
+
+    @Override
+    protected Widget createWidget() {
+        return GWT.create(VProgressIndicator.class);
+    }
+
+    @Override
+    public VProgressIndicator getWidgetForPaintable() {
+        return (VProgressIndicator) super.getWidgetForPaintable();
+    }
+}
index cc17333cc42d181dd4a5d7d727fcf6964bf66a60..9152a3adaba8d4b9b9d9f9b2a12c2695e46003ce 100644 (file)
@@ -8,7 +8,7 @@ import com.vaadin.data.Property;
 import com.vaadin.data.util.ObjectProperty;
 import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
-import com.vaadin.terminal.gwt.client.ui.VProgressIndicator;
+import com.vaadin.terminal.gwt.client.ui.VProgressIndicatorPaintable;
 
 /**
  * <code>ProgressIndicator</code> is component that shows user state of a
@@ -25,7 +25,7 @@ import com.vaadin.terminal.gwt.client.ui.VProgressIndicator;
  * @since 4
  */
 @SuppressWarnings("serial")
-@ClientWidget(VProgressIndicator.class)
+@ClientWidget(VProgressIndicatorPaintable.class)
 public class ProgressIndicator extends AbstractField<Number> implements
         Property.Viewer, Property.ValueChangeListener {