+++ /dev/null
-/*
- * 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.connectors;
-
-import com.google.gwt.event.shared.HandlerRegistration;
-import com.vaadin.client.renderers.CheckBoxRenderer;
-import com.vaadin.client.renderers.ClickableRenderer.RendererClickHandler;
-import com.vaadin.shared.ui.Connect;
-import com.vaadin.shared.ui.grid.renderers.CheckBoxRendererState;
-
-import elemental.json.JsonObject;
-
-/**
- * A connector for {@link com.vaadin.ui.renderers.CheckBoxRenderer}.
- *
- * @since 8.0
- * @author Vaadin Ltd
- */
-@Connect(com.vaadin.ui.renderers.CheckBoxRenderer.class)
-public class CheckBoxRendererConnector
- extends ClickableRendererConnector<Boolean> {
-
- @Override
- public CheckBoxRenderer getRenderer() {
- return (CheckBoxRenderer) super.getRenderer();
- }
-
- @Override
- protected HandlerRegistration addClickHandler(
- RendererClickHandler<JsonObject> handler) {
- return getRenderer().addClickHandler(handler);
- }
-
- @Override
- public CheckBoxRendererState getState() {
- return (CheckBoxRendererState) super.getState();
- }
-}
+++ /dev/null
-/*
- * 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.renderers;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.user.client.ui.CheckBox;
-import com.vaadin.client.ui.VCheckBox;
-import com.vaadin.client.widget.grid.RendererCellReference;
-
-/**
- * A Renderer that displays a boolean value as a checkbox.
- *
- * <p>
- *
- * Click handlers can be added to the renderer, invoked when any of the rendered
- * checkboxes are clicked.
- *
- * @since 8.0
- * @author Vaadin Ltd
- */
-public class CheckBoxRenderer extends ClickableRenderer<Boolean, CheckBox> {
-
- @Override
- public CheckBox createWidget() {
- CheckBox cb = GWT.create(VCheckBox.class);
- cb.addClickHandler(this);
- return cb;
- }
-
- @Override
- public void render(RendererCellReference cell, Boolean data,
- CheckBox widget) {
- widget.setValue(data);
- }
-
-}
+++ /dev/null
-/*
- * 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.ui.renderers;
-
-import java.util.function.BiConsumer;
-import java.util.function.Function;
-
-import com.vaadin.shared.ui.grid.renderers.CheckBoxRendererState;
-
-/**
- * A renderer that displays boolean valued grid columns as checkboxes.
- *
- * @since 8.0
- * @author Vaadin Ltd
- */
-public class CheckBoxRenderer<T> extends ClickableRenderer<T, Boolean> {
-
- /**
- * Creates a new checkbox renderer, given getter and setter functions.
- * Getters and setters are used to update the object corresponding to a
- * given row in the grid on the server side.
- *
- * @param getter
- * function for getting the desired boolean value
- * @param setter
- * function for setting the boolean value after a change from the
- * client side
- */
- public CheckBoxRenderer(Function<T, Boolean> getter,
- BiConsumer<T, Boolean> setter) {
- super(Boolean.class, "");
- addClickListener(clickEvent -> setter.accept(clickEvent.getItem(),
- !getter.apply(clickEvent.getItem())));
- }
-
- @Override
- protected CheckBoxRendererState getState() {
- return (CheckBoxRendererState) super.getState();
- }
-
- @Override
- protected CheckBoxRendererState getState(boolean markAsDirty) {
- return (CheckBoxRendererState) super.getState(markAsDirty);
- }
-}
+++ /dev/null
-/*
- * 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.shared.ui.grid.renderers;
-
-/**
- * Shared state for CheckBoxRenderer.
- *
- * @since 8.0
- */
-public class CheckBoxRendererState extends ClickableRendererState {
-
-}
import com.vaadin.ui.Grid;
import com.vaadin.ui.Label;
import com.vaadin.ui.renderers.ButtonRenderer;
-import com.vaadin.ui.renderers.CheckBoxRenderer;
import com.vaadin.ui.renderers.ImageRenderer;
public class GridClickableRenderers extends AbstractReindeerTestUI {
.setValue(event.getItem().testText + " clicked")))
.setId("buttons").setCaption("Buttons");
- CheckBoxRenderer<TestPOJO> checkBoxRenderer = new CheckBoxRenderer<>(
- pojo -> pojo.truthValue,
- (pojo, newTruthValue) -> pojo.truthValue = newTruthValue);
- checkBoxRenderer.addClickListener(click -> checkBoxValueLabel.setValue(
- click.getItem().testText + " " + click.getItem().truthValue));
- grid.addColumn(pojo -> pojo.truthValue, checkBoxRenderer)
- .setId("checkboxes").setCaption("Checkboxes");
+ ButtonRenderer<TestPOJO> yesNoRenderer = new ButtonRenderer<>();
+ yesNoRenderer.addClickListener(event -> {
+ TestPOJO item = event.getItem();
+ item.truthValue = !item.truthValue;
+ checkBoxValueLabel.setValue(item.testText + " " + item.truthValue);
+ grid.getDataProvider().refreshAll();
+ });
+ grid.addColumn(pojo -> pojo.truthValue ? "Yes" : "No",
+ yesNoRenderer).setCaption("Truth").setId("truth");
grid.setItems(new TestPOJO("first row", "", "button 1 text", true),
new TestPOJO("second row", "", "button 2 text", false));
openTestURL();
Assert.assertTrue(isElementPresent(By.className("v-nativebutton")));
Assert.assertTrue(isElementPresent(By.className("gwt-Image")));
- Assert.assertTrue(isElementPresent(By.className("v-checkbox")));
}
@Test
public void buttonRendererReturnsCorrectItem() {
openTestURL();
- WebElement firstButton = findElements(By.className("v-nativebutton"))
+ WebElement firstRowButton = findElements(By.className("v-nativebutton"))
.get(0);
- WebElement secondButton = findElements(By.className("v-nativebutton"))
- .get(1);
+ WebElement secondRowButton = findElements(By.className("v-nativebutton"))
+ .get(2);
LabelElement label = $(LabelElement.class).get(1);
- firstButton.click();
+ firstRowButton.click();
Assert.assertEquals("first row clicked", label.getText());
- secondButton.click();
+ secondRowButton.click();
Assert.assertEquals("second row clicked", label.getText());
}
@Test
public void checkBoxRendererClick() {
openTestURL();
- WebElement firstCheckBox = findElements(
- By.cssSelector("input[type='checkbox']")).get(0);
- WebElement secondCheckBox = findElements(
- By.cssSelector("input[type='checkbox']")).get(1);
-
+ WebElement firstRowButton = findElements(By.className("v-nativebutton"))
+ .get(1);
+ WebElement secondRowButton = findElements(By.className("v-nativebutton"))
+ .get(3);
LabelElement label = $(LabelElement.class).get(2);
- firstCheckBox.click();
+ firstRowButton.click();
Assert.assertEquals("first row false", label.getText());
- secondCheckBox.click();
+ secondRowButton.click();
Assert.assertEquals("second row true", label.getText());
}
}