Browse Source

Allow arbitrary serializable types as Renderer data type (#15410)

Change-Id: If535c5603116be204e11936f9186ce3856b74b03
tags/7.5.0.rc1
Johannes Dahlström 9 years ago
parent
commit
8da6cbdd02

+ 2
- 1
client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java View File

import com.vaadin.shared.communication.ClientRpc; import com.vaadin.shared.communication.ClientRpc;
import com.vaadin.shared.communication.ServerRpc; import com.vaadin.shared.communication.ServerRpc;
import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.Connect;

import elemental.json.JsonValue; import elemental.json.JsonValue;


public class ConnectorBundle { public class ConnectorBundle {
frameworkHandledTypes.add(Set.class); frameworkHandledTypes.add(Set.class);
frameworkHandledTypes.add(Byte.class); frameworkHandledTypes.add(Byte.class);
frameworkHandledTypes.add(Character.class); frameworkHandledTypes.add(Character.class);
frameworkHandledTypes.add(Void.class);
} }


private boolean serializationHandledByFramework(JType setterType) { private boolean serializationHandledByFramework(JType setterType) {

+ 2
- 0
client-compiler/src/com/vaadin/server/widgetsetutils/metadata/RendererVisitor.java View File

JType presentationType = getPresentationType(type, logger); JType presentationType = getPresentationType(type, logger);
bundle.setPresentationType(type, presentationType); bundle.setPresentationType(type, presentationType);


bundle.setNeedsSerialize(presentationType);

logger.log(Type.DEBUG, "Presentation type of " + type + " is " logger.log(Type.DEBUG, "Presentation type of " + type + " is "
+ presentationType); + presentationType);
} }

+ 25
- 0
uitest/src/com/vaadin/tests/components/grid/BeanRenderer.java View File

/*
* 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.tests.widgetset.client.SimpleTestBean;
import com.vaadin.ui.Grid.AbstractRenderer;

public class BeanRenderer extends AbstractRenderer<SimpleTestBean> {
public BeanRenderer() {
super(SimpleTestBean.class, "");
}
}

+ 15
- 0
uitest/src/com/vaadin/tests/components/grid/CustomRenderer.java View File

import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.tests.widgetset.TestingWidgetSet; import com.vaadin.tests.widgetset.TestingWidgetSet;
import com.vaadin.tests.widgetset.client.SimpleTestBean;
import com.vaadin.ui.Grid; import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.SelectionMode; import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.Label; import com.vaadin.ui.Label;


private static final Object INT_ARRAY_PROPERTY = "int array"; private static final Object INT_ARRAY_PROPERTY = "int array";
private static final Object VOID_PROPERTY = "void"; private static final Object VOID_PROPERTY = "void";
private static final Object BEAN_PROPERTY = "pojo";


static final Object ITEM_ID = "itemId1"; static final Object ITEM_ID = "itemId1";
static final String DEBUG_LABEL_ID = "debuglabel"; static final String DEBUG_LABEL_ID = "debuglabel";
container.addContainerProperty(INT_ARRAY_PROPERTY, int[].class, container.addContainerProperty(INT_ARRAY_PROPERTY, int[].class,
new int[] {}); new int[] {});
container.addContainerProperty(VOID_PROPERTY, Void.class, null); container.addContainerProperty(VOID_PROPERTY, Void.class, null);
container.addContainerProperty(BEAN_PROPERTY, SimpleTestBean.class,
null);


Item item = container.addItem(ITEM_ID); Item item = container.addItem(ITEM_ID);


.getItemProperty(INT_ARRAY_PROPERTY); .getItemProperty(INT_ARRAY_PROPERTY);
propertyIntArray.setValue(new int[] { 1, 1, 2, 3, 5, 8, 13 }); propertyIntArray.setValue(new int[] { 1, 1, 2, 3, 5, 8, 13 });


@SuppressWarnings("unchecked")
Property<SimpleTestBean> propertyPojo = item
.getItemProperty(BEAN_PROPERTY);
SimpleTestBean bean = new SimpleTestBean();
bean.setValue(42);
propertyPojo.setValue(bean);

Label debugLabel = new Label(INIT_DEBUG_LABEL_CAPTION); Label debugLabel = new Label(INIT_DEBUG_LABEL_CAPTION);
debugLabel.setId(DEBUG_LABEL_ID); debugLabel.setId(DEBUG_LABEL_ID);


Grid grid = new Grid(container); Grid grid = new Grid(container);

grid.getColumn(INT_ARRAY_PROPERTY).setRenderer(new IntArrayRenderer()); grid.getColumn(INT_ARRAY_PROPERTY).setRenderer(new IntArrayRenderer());
grid.getColumn(VOID_PROPERTY).setRenderer( grid.getColumn(VOID_PROPERTY).setRenderer(
new RowAwareRenderer(debugLabel)); new RowAwareRenderer(debugLabel));
grid.getColumn(BEAN_PROPERTY).setRenderer(new BeanRenderer());

grid.setSelectionMode(SelectionMode.NONE); grid.setSelectionMode(SelectionMode.NONE);

addComponent(grid); addComponent(grid);
addComponent(debugLabel); addComponent(debugLabel);
} }

+ 7
- 0
uitest/src/com/vaadin/tests/components/grid/CustomRendererTest.java View File

findDebugLabel().getText()); findDebugLabel().getText());
} }


@Test
public void testBeanRenderer() throws Exception {
openTestURL();

assertEquals("SimpleTestBean(42)", findGrid().getCell(0, 2).getText());
}

private GridElement findGrid() { private GridElement findGrid() {
List<GridElement> elements = $(GridElement.class).all(); List<GridElement> elements = $(GridElement.class).all();
return elements.get(0); return elements.get(0);

+ 1
- 0
uitest/src/com/vaadin/tests/serialization/EncodeResultDisplayTest.java View File



int logRow = 0; int logRow = 0;


Assert.assertEquals("Void: null", getLogRow(logRow++));
Assert.assertEquals("SimpleTestBean: {\"value\":5}", Assert.assertEquals("SimpleTestBean: {\"value\":5}",
getLogRow(logRow++)); getLogRow(logRow++));
Assert.assertEquals("List: [\"Three\",\"Four\"]", getLogRow(logRow++)); Assert.assertEquals("List: [\"Three\",\"Four\"]", getLogRow(logRow++));

+ 3
- 0
uitest/src/com/vaadin/tests/widgetset/client/EncoderResultDisplayConnector.java View File

new Type(List.class.getName(), new Type[] { TypeData new Type(List.class.getName(), new Type[] { TypeData
.getType(String.class) })); .getType(String.class) }));
reportEncode(new SimpleTestBean(5)); reportEncode(new SimpleTestBean(5));

reportEncode(Void.class.getSimpleName(), null,
TypeData.getType(Void.class));
} }


private void reportEncode(Object value) { private void reportEncode(Object value) {

+ 39
- 0
uitest/src/com/vaadin/tests/widgetset/client/grid/PojoRendererConnector.java View File

/*
* 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.widgetset.client.grid;

import com.vaadin.client.connectors.AbstractRendererConnector;
import com.vaadin.client.renderers.Renderer;
import com.vaadin.client.widget.grid.RendererCellReference;
import com.vaadin.shared.ui.Connect;
import com.vaadin.tests.widgetset.client.SimpleTestBean;

@Connect(com.vaadin.tests.components.grid.BeanRenderer.class)
public class PojoRendererConnector extends
AbstractRendererConnector<SimpleTestBean> {

public static class BeanRenderer implements Renderer<SimpleTestBean> {
@Override
public void render(RendererCellReference cell, SimpleTestBean bean) {
cell.getElement().setInnerText(bean.toString());
}
}

@Override
public BeanRenderer getRenderer() {
return (BeanRenderer) super.getRenderer();
}
}

Loading…
Cancel
Save