summaryrefslogtreecommitdiffstats
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
parent0121af0c28d92db37dea94050f3453ecf46556b9 (diff)
downloadvaadin-framework-9551d7ca56bb9fced67ced199bf23363ac230f3e.tar.gz
vaadin-framework-9551d7ca56bb9fced67ced199bf23363ac230f3e.zip
Updated ProgressIndicator to use state and rpc (#10008)
Change-Id: Iec3d0c4e9e1432f7dda4aae5c8c4f21cb96f08be
-rw-r--r--client/src/com/vaadin/client/ui/progressindicator/ProgressIndicatorConnector.java59
-rw-r--r--client/src/com/vaadin/client/ui/progressindicator/VProgressIndicator.java63
-rw-r--r--server/src/com/vaadin/ui/ProgressIndicator.java189
-rw-r--r--uitest/src/com/vaadin/tests/components/progressindicator/ProgressIndicatorInvisible.java2
-rw-r--r--uitest/src/com/vaadin/tests/components/progressindicator/ProgressIndicatorTest.java85
5 files changed, 180 insertions, 218 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);
}
+
}
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;
}
}
diff --git a/uitest/src/com/vaadin/tests/components/progressindicator/ProgressIndicatorInvisible.java b/uitest/src/com/vaadin/tests/components/progressindicator/ProgressIndicatorInvisible.java
index 9f632ac806..2c58e9226a 100644
--- a/uitest/src/com/vaadin/tests/components/progressindicator/ProgressIndicatorInvisible.java
+++ b/uitest/src/com/vaadin/tests/components/progressindicator/ProgressIndicatorInvisible.java
@@ -21,7 +21,7 @@ public class ProgressIndicatorInvisible extends TestBase {
final Button b = new Button("Hide container of progress indicator");
addComponent(b);
- b.addListener(new Button.ClickListener() {
+ b.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
// If we skip hiding the layout, hiding the ProgressIndicator
diff --git a/uitest/src/com/vaadin/tests/components/progressindicator/ProgressIndicatorTest.java b/uitest/src/com/vaadin/tests/components/progressindicator/ProgressIndicatorTest.java
new file mode 100644
index 0000000000..7fb016ff57
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/progressindicator/ProgressIndicatorTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2011 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.tests.components.progressindicator;
+
+import java.util.LinkedHashMap;
+
+import com.vaadin.tests.components.abstractfield.AbstractFieldTest;
+import com.vaadin.ui.ProgressIndicator;
+
+public class ProgressIndicatorTest extends AbstractFieldTest<ProgressIndicator> {
+ ProgressIndicator progress = new ProgressIndicator();
+ Command<ProgressIndicator, Float> setValueCommand = new Command<ProgressIndicator, Float>() {
+
+ @Override
+ public void execute(ProgressIndicator c, Float value, Object data) {
+ c.setValue(value);
+ }
+ };
+ private Command<ProgressIndicator, Integer> setPollingIntervalCommand = new Command<ProgressIndicator, Integer>() {
+ @Override
+ public void execute(ProgressIndicator c, Integer value, Object data) {
+ c.setPollingInterval(value);
+ }
+ };
+
+ private Command<ProgressIndicator, Boolean> setIndeterminateCommand = new Command<ProgressIndicator, Boolean>() {
+ @Override
+ public void execute(ProgressIndicator c, Boolean value, Object data) {
+ c.setIndeterminate(value);
+ }
+ };
+
+ @Override
+ protected void createActions() {
+ super.createActions();
+ createSetValueAction();
+ createPollingIntervalAction();
+ createIndeterminateToggle();
+ };
+
+ private void createIndeterminateToggle() {
+ createBooleanAction("Indeterminate", CATEGORY_FEATURES, false,
+ setIndeterminateCommand);
+
+ }
+
+ private void createPollingIntervalAction() {
+ LinkedHashMap<String, Integer> valueOptions = new LinkedHashMap<String, Integer>();
+ for (int i = 100; i <= 3000; i += 200) {
+ valueOptions.put(String.valueOf(i), i);
+ }
+ createSelectAction("Polling interval", CATEGORY_FEATURES, valueOptions,
+ "1500", setPollingIntervalCommand);
+
+ }
+
+ private void createSetValueAction() {
+ LinkedHashMap<String, Float> valueOptions = new LinkedHashMap<String, Float>();
+ for (float f = 0.0f; f <= 1.0f; f += 0.1) {
+ valueOptions.put(String.valueOf(f), f);
+ }
+ createSelectAction("Value", CATEGORY_FEATURES, valueOptions, "0.0",
+ setValueCommand);
+
+ }
+
+ @Override
+ protected Class<ProgressIndicator> getTestClass() {
+ return ProgressIndicator.class;
+ }
+
+}