diff options
author | Artur Signell <artur@vaadin.com> | 2012-10-22 16:24:05 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2012-10-24 15:33:48 +0300 |
commit | 9551d7ca56bb9fced67ced199bf23363ac230f3e (patch) | |
tree | 45b5ab0195d67335c84e5b8e39a143b7f67f5952 /server | |
parent | 0121af0c28d92db37dea94050f3453ecf46556b9 (diff) | |
download | vaadin-framework-9551d7ca56bb9fced67ced199bf23363ac230f3e.tar.gz vaadin-framework-9551d7ca56bb9fced67ced199bf23363ac230f3e.zip |
Updated ProgressIndicator to use state and rpc (#10008)
Change-Id: Iec3d0c4e9e1432f7dda4aae5c8c4f21cb96f08be
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/ui/ProgressIndicator.java | 189 |
1 files changed, 41 insertions, 148 deletions
diff --git a/server/src/com/vaadin/ui/ProgressIndicator.java b/server/src/com/vaadin/ui/ProgressIndicator.java index 1c35d3d1d8..9fcf2b11f6 100644 --- a/server/src/com/vaadin/ui/ProgressIndicator.java +++ b/server/src/com/vaadin/ui/ProgressIndicator.java @@ -16,19 +16,15 @@ package com.vaadin.ui; -import java.util.Map; - import com.vaadin.data.Property; -import com.vaadin.data.util.ObjectProperty; -import com.vaadin.server.LegacyComponent; -import com.vaadin.server.PaintException; -import com.vaadin.server.PaintTarget; +import com.vaadin.shared.ui.progressindicator.ProgressIndicatorServerRpc; +import com.vaadin.shared.ui.progressindicator.ProgressIndicatorState; /** * <code>ProgressIndicator</code> is component that shows user state of a * process (like long computing or file upload) * - * <code>ProgressIndicator</code> has two mainmodes. One for indeterminate + * <code>ProgressIndicator</code> has two main modes. One for indeterminate * processes and other (default) for processes which progress can be measured * * May view an other property that indicates progress 0...1 @@ -37,32 +33,22 @@ import com.vaadin.server.PaintTarget; * @since 4 */ @SuppressWarnings("serial") -public class ProgressIndicator extends AbstractField<Number> implements - Property.Viewer, Property.ValueChangeListener, LegacyComponent { - - /** - * Content mode, where the label contains only plain text. The getValue() - * result is coded to XML when painting. - */ - public static final int CONTENT_TEXT = 0; - - /** - * Content mode, where the label contains preformatted text. - */ - public static final int CONTENT_PREFORMATTED = 1; +public class ProgressIndicator extends AbstractField<Float> implements + Property.Viewer, Property.ValueChangeListener { - private boolean indeterminate = false; + private ProgressIndicatorServerRpc rpc = new ProgressIndicatorServerRpc() { - private Property dataSource; - - private int pollingInterval = 1000; + @Override + public void poll() { + // Nothing to do. + } + }; /** * Creates an a new ProgressIndicator. */ public ProgressIndicator() { - setPropertyDataSource(new ObjectProperty<Float>(new Float(0), - Float.class)); + this(0.0f); } /** @@ -70,62 +56,27 @@ public class ProgressIndicator extends AbstractField<Number> implements * * @param value */ - public ProgressIndicator(Float value) { - setPropertyDataSource(new ObjectProperty<Float>(value, Float.class)); + public ProgressIndicator(float value) { + setValue(value); + registerRpc(rpc); } /** - * Creates a new instance of ProgressIndicator with stae read from given - * datasource. + * Creates a new instance of ProgressIndicator with state read from the + * given datasource. * * @param contentSource */ public ProgressIndicator(Property contentSource) { setPropertyDataSource(contentSource); + registerRpc(rpc); } - /** - * Sets the component to read-only. Readonly is not used in - * ProgressIndicator. - * - * @param readOnly - * True to enable read-only mode, False to disable it. - */ @Override - public void setReadOnly(boolean readOnly) { - if (dataSource == null) { - throw new IllegalStateException("Datasource must be se"); - } - dataSource.setReadOnly(readOnly); - } + public void beforeClientResponse(boolean initial) { + super.beforeClientResponse(initial); - /** - * Is the component read-only ? Readonly is not used in ProgressIndicator - - * this returns allways false. - * - * @return True if the component is in read only mode. - */ - @Override - public boolean isReadOnly() { - if (dataSource == null) { - throw new IllegalStateException("Datasource must be se"); - } - return dataSource.isReadOnly(); - } - - /** - * Paints the content of this component. - * - * @param target - * the Paint Event. - * @throws PaintException - * if the Paint Operation fails. - */ - @Override - public void paintContent(PaintTarget target) throws PaintException { - target.addAttribute("indeterminate", indeterminate); - target.addAttribute("pollinginterval", pollingInterval); - target.addAttribute("state", getValue().toString()); + getState().state = getValue(); } /** @@ -136,12 +87,8 @@ public class ProgressIndicator extends AbstractField<Number> implements * @see com.vaadin.ui.AbstractField#getValue() */ @Override - public Number getValue() { - if (dataSource == null) { - throw new IllegalStateException("Datasource must be set"); - } - // TODO conversions to eliminate cast - return (Number) dataSource.getValue(); + public Float getValue() { + return super.getValue(); } /** @@ -153,80 +100,33 @@ public class ProgressIndicator extends AbstractField<Number> implements * @see com.vaadin.ui.AbstractField#setValue() */ @Override - public void setValue(Number newValue) { - if (dataSource == null) { - throw new IllegalStateException("Datasource must be set"); - } - dataSource.setValue(newValue); - } - - /** - * @see com.vaadin.ui.AbstractField#getType() - */ - @Override - public Class<? extends Number> getType() { - if (dataSource == null) { - throw new IllegalStateException("Datasource must be set"); - } - return dataSource.getType(); + public void setValue(Float newValue) { + super.setValue(newValue); } - /** - * Gets the viewing data-source property. + /* + * (non-Javadoc) * - * @return the datasource. - * @see com.vaadin.ui.AbstractField#getPropertyDataSource() + * @see com.vaadin.ui.AbstractField#getType() */ @Override - public Property getPropertyDataSource() { - return dataSource; + public Class<Float> getType() { + return Float.class; } - /** - * Sets the property as data-source for viewing. - * - * @param newDataSource - * the new data source. - * @see com.vaadin.ui.AbstractField#setPropertyDataSource(com.vaadin.data.Property) - */ @Override - public void setPropertyDataSource(Property newDataSource) { - // Stops listening the old data source changes - if (dataSource != null - && Property.ValueChangeNotifier.class - .isAssignableFrom(dataSource.getClass())) { - ((Property.ValueChangeNotifier) dataSource).removeListener(this); - } - - // Sets the new data source - dataSource = newDataSource; - - // Listens the new data source if possible - if (dataSource != null - && Property.ValueChangeNotifier.class - .isAssignableFrom(dataSource.getClass())) { - ((Property.ValueChangeNotifier) dataSource).addListener(this); - } - } - - /** - * Gets the mode of ProgressIndicator. - * - * @return true if in indeterminate mode. - */ - public boolean getContentMode() { - return indeterminate; + protected ProgressIndicatorState getState() { + return (ProgressIndicatorState) super.getState(); } /** - * Sets wheter or not the ProgressIndicator is indeterminate. + * Sets whether or not the ProgressIndicator is indeterminate. * - * @param newValue + * @param indeterminate * true to set to indeterminate mode. */ - public void setIndeterminate(boolean newValue) { - indeterminate = newValue; - markAsDirty(); + public void setIndeterminate(boolean indeterminate) { + getState().indeterminate = indeterminate; } /** @@ -235,18 +135,17 @@ public class ProgressIndicator extends AbstractField<Number> implements * @return true to set to indeterminate mode. */ public boolean isIndeterminate() { - return indeterminate; + return getState().indeterminate; } /** * Sets the interval that component checks for progress. * - * @param newValue + * @param pollingInterval * the interval in milliseconds. */ - public void setPollingInterval(int newValue) { - pollingInterval = newValue; - markAsDirty(); + public void setPollingInterval(int pollingInterval) { + getState().pollingInterval = pollingInterval; } /** @@ -255,13 +154,7 @@ public class ProgressIndicator extends AbstractField<Number> implements * @return the interval in milliseconds. */ public int getPollingInterval() { - return pollingInterval; - } - - @Override - public void changeVariables(Object source, Map<String, Object> variables) { - // TODO Remove once LegacyComponent is no longer implemented - + return getState().pollingInterval; } } |