diff options
author | Aleksi Hietanen <aleksi@vaadin.com> | 2016-08-25 19:06:30 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-08-26 08:23:40 +0000 |
commit | 0c8f57d60aba5f4dbad10cf818ae98dc9cb8d47a (patch) | |
tree | 1746dcf20199bac3dedf462dbacb876ea9acedf4 | |
parent | 4a6a632b1f57a1ddbb437036cb5d17f98f827b47 (diff) | |
download | vaadin-framework-0c8f57d60aba5f4dbad10cf818ae98dc9cb8d47a.tar.gz vaadin-framework-0c8f57d60aba5f4dbad10cf818ae98dc9cb8d47a.zip |
Implement new ProgressBar
Change-Id: Ie5c4b0f4d9bc65e484f08832343ba97fff61a9b6
12 files changed, 204 insertions, 27 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/progressbar/ProgressBarConnector.java b/client/src/main/java/com/vaadin/client/ui/progressbar/ProgressBarConnector.java new file mode 100644 index 0000000000..88d01ce2e5 --- /dev/null +++ b/client/src/main/java/com/vaadin/client/ui/progressbar/ProgressBarConnector.java @@ -0,0 +1,55 @@ +/* + * Copyright 2000-2016 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.client.ui.progressbar; + +import com.vaadin.client.communication.StateChangeEvent; +import com.vaadin.client.ui.AbstractFieldConnector; +import com.vaadin.client.ui.VProgressBar; +import com.vaadin.shared.ui.Connect; +import com.vaadin.shared.ui.progressindicator.ProgressBarState; +import com.vaadin.ui.ProgressBar; + +/** + * Connector for {@link VProgressBar}. + * + * @since 7.1 + * @author Vaadin Ltd + */ +@Connect(ProgressBar.class) +public class ProgressBarConnector extends AbstractFieldConnector { + + public ProgressBarConnector() { + super(); + } + + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + super.onStateChanged(stateChangeEvent); + getWidget().setIndeterminate(getState().indeterminate); + getWidget().setState(getState().state); + } + + @Override + public ProgressBarState getState() { + return (ProgressBarState) super.getState(); + } + + @Override + public VProgressBar getWidget() { + return (VProgressBar) super.getWidget(); + } + +} diff --git a/server/src/main/java/com/vaadin/ui/ProgressBar.java b/server/src/main/java/com/vaadin/ui/ProgressBar.java new file mode 100644 index 0000000000..f06170f677 --- /dev/null +++ b/server/src/main/java/com/vaadin/ui/ProgressBar.java @@ -0,0 +1,123 @@ +package com.vaadin.ui; + +import org.jsoup.nodes.Element; + +import com.vaadin.shared.ui.progressindicator.ProgressBarState; +import com.vaadin.ui.declarative.DesignAttributeHandler; +import com.vaadin.ui.declarative.DesignContext; + +/** + * A component for displaying progress. + * <p> + * The default mode is to show the current progress internally represented by a + * floating point value between 0 and 1 (inclusive). The progress bar can also + * be in an indeterminate mode showing an animation indicating that the task is + * running but without providing any information about the current progress. + * + * @since 8.0 + * @author Vaadin Ltd + */ +public class ProgressBar extends AbstractComponent { + + private static final float DEFAULT_VALUE = 0f; + + /** + * Creates a new progress bar initially set to 0% progress. + */ + public ProgressBar() { + this(DEFAULT_VALUE); + } + + /** + * Creates a new progress bar with the given initial value. + * + * @param progress + * the initial progress value + */ + public ProgressBar(float progress) { + setValue(Float.valueOf(progress)); + } + + /** + * Gets the value of this progress bar. The value is a <code>float</code> + * between 0 and 1 where 0 represents no progress at all and 1 represents + * fully completed. + * + * @return the current progress value + */ + public float getValue() { + return getState(false).state; + } + + /** + * Sets the value of this progress bar. The value is a <code>float</code> + * between 0 and 1 where 0 represents no progress at all and 1 represents + * fully completed. + * + * @param newValue + * the current progress value + */ + public void setValue(float newValue) { + getState().state = newValue; + } + + @Override + protected ProgressBarState getState() { + return (ProgressBarState) super.getState(); + } + + @Override + protected ProgressBarState getState(boolean markAsDirty) { + return (ProgressBarState) super.getState(markAsDirty); + } + + /** + * Sets whether or not this progress indicator is indeterminate. In + * indeterminate mode there is an animation indicating that the task is + * running but without providing any information about the current progress. + * + * @param indeterminate + * <code>true</code> to set to indeterminate mode; otherwise + * <code>false</code> + */ + public void setIndeterminate(boolean indeterminate) { + getState().indeterminate = indeterminate; + } + + /** + * Gets whether or not this progress indicator is indeterminate. In + * indeterminate mode there is an animation indicating that the task is + * running but without providing any information about the current progress. + * + * @return <code>true</code> if set to indeterminate mode; otherwise + * <code>false</code> + */ + public boolean isIndeterminate() { + return getState(false).indeterminate; + } + + @Override + public void readDesign(Element design, DesignContext designContext) { + super.readDesign(design, designContext); + if (design.hasAttr("value") && !design.attr("value").isEmpty()) { + setValue(DesignAttributeHandler.readAttribute("value", + design.attributes(), Float.class)); + } + } + + @Override + public void writeDesign(Element design, DesignContext designContext) { + super.writeDesign(design, designContext); + Float defaultValue = ((ProgressBar) designContext + .getDefaultInstance(this)).getValue(); + DesignAttributeHandler.writeAttribute("value", design.attributes(), + getValue(), defaultValue, Float.class); + } + + /** + * Resets the value of this component, effectively displaying zero progress. + */ + public void reset() { + setValue(DEFAULT_VALUE); + } +} diff --git a/shared/src/main/java/com/vaadin/shared/ui/progressindicator/ProgressBarState.java b/shared/src/main/java/com/vaadin/shared/ui/progressindicator/ProgressBarState.java index 02c438ac20..13e78b9b2d 100644 --- a/shared/src/main/java/com/vaadin/shared/ui/progressindicator/ProgressBarState.java +++ b/shared/src/main/java/com/vaadin/shared/ui/progressindicator/ProgressBarState.java @@ -34,6 +34,6 @@ public class ProgressBarState extends AbstractFieldState { } public boolean indeterminate = false; @NoLayout - public Float state = 0.0f; + public float state = 0.0f; } diff --git a/uitest-common/src/main/java/com/vaadin/v7/testbench/customelements/ProgressBarElement.java b/uitest-common/src/main/java/com/vaadin/testbench/customelements/ProgressBarElement.java index 15eafb76da..30874d1fee 100644 --- a/uitest-common/src/main/java/com/vaadin/v7/testbench/customelements/ProgressBarElement.java +++ b/uitest-common/src/main/java/com/vaadin/testbench/customelements/ProgressBarElement.java @@ -13,14 +13,14 @@ * License for the specific language governing permissions and limitations under * the License. */ -package com.vaadin.v7.testbench.customelements; +package com.vaadin.testbench.customelements; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import com.vaadin.testbench.elementsbase.ServerClass; -@ServerClass("com.vaadin.v7.ui.ProgressBar") +@ServerClass("com.vaadin.ui.ProgressBar") public class ProgressBarElement extends com.vaadin.testbench.elements.ProgressBarElement { diff --git a/uitest/src/main/java/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayout.java b/uitest/src/main/java/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayout.java index ffb8e33361..39329d7341 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayout.java +++ b/uitest/src/main/java/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayout.java @@ -9,9 +9,9 @@ import com.vaadin.server.VaadinRequest; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; import com.vaadin.ui.Button.ClickListener; -import com.vaadin.v7.ui.ProgressBar; import com.vaadin.ui.GridLayout; import com.vaadin.ui.Label; +import com.vaadin.ui.ProgressBar; import com.vaadin.ui.UI; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; diff --git a/uitest/src/main/java/com/vaadin/tests/components/progressindicator/ProgressBarStaticReindeer.java b/uitest/src/main/java/com/vaadin/tests/components/progressindicator/ProgressBarStaticReindeer.java index 108d8cf9a7..b55d489c41 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/progressindicator/ProgressBarStaticReindeer.java +++ b/uitest/src/main/java/com/vaadin/tests/components/progressindicator/ProgressBarStaticReindeer.java @@ -18,8 +18,8 @@ package com.vaadin.tests.components.progressindicator; import com.vaadin.annotations.Theme; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ProgressBar; import com.vaadin.ui.themes.Reindeer; -import com.vaadin.v7.ui.ProgressBar; @Theme(Reindeer.THEME_NAME) public class ProgressBarStaticReindeer extends AbstractTestUI { diff --git a/uitest/src/main/java/com/vaadin/tests/components/progressindicator/ProgressBarStaticRuno.java b/uitest/src/main/java/com/vaadin/tests/components/progressindicator/ProgressBarStaticRuno.java index 457d7571b1..799780dea1 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/progressindicator/ProgressBarStaticRuno.java +++ b/uitest/src/main/java/com/vaadin/tests/components/progressindicator/ProgressBarStaticRuno.java @@ -18,8 +18,8 @@ package com.vaadin.tests.components.progressindicator; import com.vaadin.annotations.Theme; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ProgressBar; import com.vaadin.ui.themes.Runo; -import com.vaadin.v7.ui.ProgressBar; @Theme(Runo.THEME_NAME) public class ProgressBarStaticRuno extends AbstractTestUI { diff --git a/uitest/src/main/java/com/vaadin/tests/components/progressindicator/ProgressBarTest.java b/uitest/src/main/java/com/vaadin/tests/components/progressindicator/ProgressBarTest.java index 68dfa767a3..568357a34a 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/progressindicator/ProgressBarTest.java +++ b/uitest/src/main/java/com/vaadin/tests/components/progressindicator/ProgressBarTest.java @@ -20,9 +20,10 @@ import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.v7.ui.ProgressBar; -import com.vaadin.v7.ui.ProgressIndicator; +import com.vaadin.ui.Component; import com.vaadin.ui.Label; +import com.vaadin.ui.ProgressBar; +import com.vaadin.v7.ui.ProgressIndicator; public class ProgressBarTest extends AbstractTestUI { @@ -48,7 +49,7 @@ public class ProgressBarTest extends AbstractTestUI { } } }; - private ProgressBar progressBar; + private Component progressBar; private int counter = 0; @Override @@ -84,7 +85,7 @@ public class ProgressBarTest extends AbstractTestUI { updateThread.start(); } - private void useComponent(ProgressBar progressBar) { + private void useComponent(Component progressBar) { if (this.progressBar != null) { removeComponent(this.progressBar); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/slider/SliderValueFromDataSource.java b/uitest/src/main/java/com/vaadin/tests/components/slider/SliderValueFromDataSource.java index 02ed9fc8ef..cb183e5e9f 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/slider/SliderValueFromDataSource.java +++ b/uitest/src/main/java/com/vaadin/tests/components/slider/SliderValueFromDataSource.java @@ -3,9 +3,9 @@ package com.vaadin.tests.components.slider; import com.vaadin.data.Binder; import com.vaadin.server.VaadinRequest; import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ProgressBar; import com.vaadin.ui.Slider; import com.vaadin.v7.data.util.BeanItem; -import com.vaadin.v7.ui.ProgressBar; public class SliderValueFromDataSource extends AbstractTestUI { @@ -35,12 +35,14 @@ public class SliderValueFromDataSource extends AbstractTestUI { (b, doubleValue) -> item.getItemProperty("floatValue") .setValue((float) (doubleValue / 10.0))); binder.bind(bean); - addComponent(slider); - ProgressBar pi = new ProgressBar(); - pi.setWidth("200px"); - pi.setPropertyDataSource(item.getItemProperty("floatValue")); - addComponent(pi); + ProgressBar progressBar = new ProgressBar(); + progressBar.setWidth("200px"); + + slider.addValueChangeListener( + event -> progressBar.setValue(event.getValue().floatValue())); + + addComponents(slider, progressBar); } @Override diff --git a/uitest/src/main/java/com/vaadin/tests/themes/valo/Sliders.java b/uitest/src/main/java/com/vaadin/tests/themes/valo/Sliders.java index 9c1e4705e9..58a66f37b8 100644 --- a/uitest/src/main/java/com/vaadin/tests/themes/valo/Sliders.java +++ b/uitest/src/main/java/com/vaadin/tests/themes/valo/Sliders.java @@ -20,10 +20,10 @@ import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; import com.vaadin.shared.ui.slider.SliderOrientation; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; +import com.vaadin.ui.ProgressBar; import com.vaadin.ui.Slider; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.themes.ValoTheme; -import com.vaadin.v7.ui.ProgressBar; public class Sliders extends VerticalLayout implements View { public Sliders() { diff --git a/uitest/src/main/java/com/vaadin/tests/themes/valo/Tables.java b/uitest/src/main/java/com/vaadin/tests/themes/valo/Tables.java index daf330bc4a..3baa249473 100644 --- a/uitest/src/main/java/com/vaadin/tests/themes/valo/Tables.java +++ b/uitest/src/main/java/com/vaadin/tests/themes/valo/Tables.java @@ -28,13 +28,13 @@ import com.vaadin.ui.DateField; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; import com.vaadin.ui.Notification; +import com.vaadin.ui.ProgressBar; import com.vaadin.ui.Slider; import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.themes.ValoTheme; import com.vaadin.v7.data.Container; import com.vaadin.v7.ui.ComboBox; import com.vaadin.v7.ui.OptionGroup; -import com.vaadin.v7.ui.ProgressBar; import com.vaadin.v7.ui.Table; import com.vaadin.v7.ui.Table.Align; import com.vaadin.v7.ui.Table.ColumnGenerator; @@ -178,8 +178,7 @@ public class Tables extends VerticalLayout implements View { table.removeGeneratedColumn("progress"); if (componentsInRows) { - table.addContainerProperty("textfield", TextField.class, - null); + table.addContainerProperty("textfield", TextField.class, null); table.addGeneratedColumn("textfield", new ColumnGenerator() { @Override public Object generateCell(Table source, Object itemId, @@ -194,8 +193,7 @@ public class Tables extends VerticalLayout implements View { } }); - table.addContainerProperty("datefield", TextField.class, - null); + table.addContainerProperty("datefield", TextField.class, null); table.addGeneratedColumn("datefield", new ColumnGenerator() { @Override public Object generateCell(Table source, Object itemId, @@ -257,8 +255,7 @@ public class Tables extends VerticalLayout implements View { } }); - table.addContainerProperty("optiongroup", TextField.class, - null); + table.addContainerProperty("optiongroup", TextField.class, null); table.addGeneratedColumn("optiongroup", new ColumnGenerator() { @Override public Object generateCell(Table source, Object itemId, diff --git a/uitest/src/test/java/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayoutTest.java b/uitest/src/test/java/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayoutTest.java index 44cdcbec1d..c2ec77fee3 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayoutTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/NoLayoutUpdateWhichNeedsLayoutTest.java @@ -19,9 +19,9 @@ import org.junit.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.support.ui.ExpectedCondition; +import com.vaadin.testbench.customelements.ProgressBarElement; import com.vaadin.testbench.elements.ButtonElement; import com.vaadin.tests.tb3.SingleBrowserTest; -import com.vaadin.v7.testbench.customelements.ProgressBarElement; public class NoLayoutUpdateWhichNeedsLayoutTest extends SingleBrowserTest { @@ -30,8 +30,7 @@ public class NoLayoutUpdateWhichNeedsLayoutTest extends SingleBrowserTest { openTestURL("debug"); ButtonElement open = $(ButtonElement.class).id("openWindow"); open.click(); - final ProgressBarElement progress = $( - ProgressBarElement.class).first(); + final ProgressBarElement progress = $(ProgressBarElement.class).first(); waitUntil(new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver input) { |