summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2014-09-23 17:59:57 +0300
committerVaadin Code Review <review@vaadin.com>2014-09-26 11:23:21 +0000
commit76854f95027dbf85ac68f57f32bfe4a2911f22c2 (patch)
tree0e4e44dc30d7a2c58661c09e1d8adcf6c7ddc397
parentb69401cf20b88d971763aefd5bf7674f1b77c895 (diff)
downloadvaadin-framework-76854f95027dbf85ac68f57f32bfe4a2911f22c2.tar.gz
vaadin-framework-76854f95027dbf85ac68f57f32bfe4a2911f22c2.zip
Implement ProgressBarRenderer (#13334)
Change-Id: I0193878dadec23a5709fa6f5f50591757b99ae04
-rw-r--r--client/src/com/vaadin/client/ui/VProgressBar.java7
-rw-r--r--client/src/com/vaadin/client/ui/grid/renderers/ProgressBarRenderer.java44
-rw-r--r--client/src/com/vaadin/client/ui/grid/renderers/ProgressBarRendererConnector.java34
-rw-r--r--server/src/com/vaadin/ui/components/grid/renderers/ProgressBarRenderer.java39
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/WidgetRenderers.java55
-rw-r--r--uitest/src/com/vaadin/tests/components/grid/WidgetRenderersTest.java40
6 files changed, 216 insertions, 3 deletions
diff --git a/client/src/com/vaadin/client/ui/VProgressBar.java b/client/src/com/vaadin/client/ui/VProgressBar.java
index 8d23d0c36d..00646f7a5e 100644
--- a/client/src/com/vaadin/client/ui/VProgressBar.java
+++ b/client/src/com/vaadin/client/ui/VProgressBar.java
@@ -92,8 +92,9 @@ public class VProgressBar extends Widget implements HasEnabled {
@Override
public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- setStyleName(ApplicationConnection.DISABLED_CLASSNAME, !enabled);
+ if (this.enabled != enabled) {
+ this.enabled = enabled;
+ setStyleName(ApplicationConnection.DISABLED_CLASSNAME, !enabled);
+ }
}
-
}
diff --git a/client/src/com/vaadin/client/ui/grid/renderers/ProgressBarRenderer.java b/client/src/com/vaadin/client/ui/grid/renderers/ProgressBarRenderer.java
new file mode 100644
index 0000000000..01027c2cef
--- /dev/null
+++ b/client/src/com/vaadin/client/ui/grid/renderers/ProgressBarRenderer.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2000-2014 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.grid.renderers;
+
+import com.google.gwt.core.shared.GWT;
+import com.vaadin.client.ui.VProgressBar;
+import com.vaadin.client.ui.grid.FlyweightCell;
+
+/**
+ * A Renderer that represents a double value as a graphical progress bar.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class ProgressBarRenderer extends WidgetRenderer<Double, VProgressBar> {
+
+ @Override
+ public VProgressBar createWidget() {
+ return GWT.create(VProgressBar.class);
+ }
+
+ @Override
+ public void render(FlyweightCell cell, Double data, VProgressBar progressBar) {
+ if (data == null) {
+ progressBar.setEnabled(false);
+ } else {
+ progressBar.setEnabled(true);
+ progressBar.setState(data.floatValue());
+ }
+ }
+}
diff --git a/client/src/com/vaadin/client/ui/grid/renderers/ProgressBarRendererConnector.java b/client/src/com/vaadin/client/ui/grid/renderers/ProgressBarRendererConnector.java
new file mode 100644
index 0000000000..e4c5e2bc00
--- /dev/null
+++ b/client/src/com/vaadin/client/ui/grid/renderers/ProgressBarRendererConnector.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2000-2014 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.grid.renderers;
+
+import com.vaadin.shared.ui.Connect;
+
+/**
+ * A connector for {@link ProgressBarRenderer}.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+@Connect(com.vaadin.ui.components.grid.renderers.ProgressBarRenderer.class)
+public class ProgressBarRendererConnector extends
+ AbstractRendererConnector<Double> {
+
+ @Override
+ public ProgressBarRenderer getRenderer() {
+ return (ProgressBarRenderer) super.getRenderer();
+ }
+}
diff --git a/server/src/com/vaadin/ui/components/grid/renderers/ProgressBarRenderer.java b/server/src/com/vaadin/ui/components/grid/renderers/ProgressBarRenderer.java
new file mode 100644
index 0000000000..80e9361f6f
--- /dev/null
+++ b/server/src/com/vaadin/ui/components/grid/renderers/ProgressBarRenderer.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2000-2014 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.ui.components.grid.renderers;
+
+import com.vaadin.ui.components.grid.AbstractRenderer;
+
+/**
+ * A renderer that represents a double values as a graphical progress bar.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class ProgressBarRenderer extends AbstractRenderer<Double> {
+
+ /**
+ * Creates a new text renderer
+ */
+ public ProgressBarRenderer() {
+ super(Double.class);
+ }
+
+ @Override
+ protected Object doEncode(Double value) {
+ return value != null ? Math.max(Math.min(value, 1), 0) : null;
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/WidgetRenderers.java b/uitest/src/com/vaadin/tests/components/grid/WidgetRenderers.java
new file mode 100644
index 0000000000..a0d0179ecc
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/WidgetRenderers.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2000-2014 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.grid;
+
+import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.components.grid.Grid;
+import com.vaadin.ui.components.grid.Grid.SelectionMode;
+import com.vaadin.ui.components.grid.renderers.ProgressBarRenderer;
+
+public class WidgetRenderers extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ IndexedContainer container = new IndexedContainer();
+ container.addContainerProperty(ProgressBarRenderer.class, Double.class,
+ null);
+
+ container.getItem(container.addItem())
+ .getItemProperty(ProgressBarRenderer.class).setValue(0.5);
+
+ Grid grid = new Grid(container);
+ grid.setId("test-grid");
+ grid.setSelectionMode(SelectionMode.NONE);
+
+ grid.getColumn(ProgressBarRenderer.class).setRenderer(
+ new ProgressBarRenderer());
+
+ addComponent(grid);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Tests the working of widget-based renderers";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return Integer.valueOf(13334);
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/grid/WidgetRenderersTest.java b/uitest/src/com/vaadin/tests/components/grid/WidgetRenderersTest.java
new file mode 100644
index 0000000000..183f2cc90a
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/grid/WidgetRenderersTest.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2000-2014 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.grid;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * TB tests for the various builtin widget-based renderers.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class WidgetRenderersTest extends MultiBrowserTest {
+
+ @Test
+ public void testProgressBarRenderer() {
+ openTestURL();
+
+ assertTrue($(GridElement.class).first().getCell(0, 0)
+ .isElementPresent(By.className("v-progressbar")));
+ }
+}