use of com.vaadin.v7.data.Item in project charts by vaadin.
the class ChartWithExternalContainer method createContainerView1.
private ContainerDataSeries createContainerView1(Container vaadinContainer) {
ContainerDataSeries container = new ContainerDataSeries(vaadinContainer);
container.setName("Order item quantities");
container.setPlotOptions(new PlotOptionsPie());
container.setYPropertyId(ExampleUtil.ORDER_QUANTITY_PROPERTY_ID);
container.setNamePropertyId(ExampleUtil.ORDER_DESCRIPTION_PROPERTY_ID);
return container;
}
use of com.vaadin.v7.data.Item in project charts by vaadin.
the class ContainerWithLotsOfData method createContainer.
@SuppressWarnings("unchecked")
private ContainerDataSeries createContainer() {
IndexedContainer vaadinContainer = new IndexedContainer();
ContainerDataSeries container = new ContainerDataSeries(vaadinContainer);
vaadinContainer.addContainerProperty("y", Number.class, null);
for (int i = 0; i < getContainerData().length; i++) {
Item item = vaadinContainer.addItem(i);
item.getItemProperty("y").setValue(getContainerData()[i]);
}
container.setName("USD to EUR");
container.setPlotOptions(new PlotOptionsArea());
container.setYPropertyId("y");
return container;
}
use of com.vaadin.v7.data.Item in project charts by vaadin.
the class ContainerDataSeriesBeanSerializer method createDataArray.
private ArrayNode createDataArray(Container container, Map<String, Object> pidMap) {
ArrayNode data = JsonNodeFactory.instance.arrayNode();
Mode mode = null;
for (Object o : pidMap.keySet()) {
if (!(o.equals(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1) || o.equals(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2))) {
mode = Mode.OBJECT;
break;
}
}
Object xProperty = pidMap.get(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1);
if (xProperty == null) {
xProperty = ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1;
}
Object yProperty = pidMap.get(ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2);
if (yProperty == null) {
yProperty = ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2;
}
checkRequiredProperties(container, pidMap, yProperty);
if (mode != Mode.OBJECT) {
if (container.getContainerPropertyIds().contains(xProperty)) {
mode = Mode.XY;
} else {
mode = Mode.ONLY_Y;
}
}
for (Object iid : container.getItemIds()) {
Item item = container.getItem(iid);
switch(mode) {
case ONLY_Y:
addValue(data, item.getItemProperty(yProperty));
break;
case XY:
Property itemPropertyX = item.getItemProperty(xProperty);
Property itemPropertyY = item.getItemProperty(yProperty);
if (itemPropertyX.getValue() != null && itemPropertyY.getValue() != null) {
ArrayNode entryArray = JsonNodeFactory.instance.arrayNode();
data.add(entryArray);
addValue(entryArray, itemPropertyX);
addValue(entryArray, itemPropertyY);
} else {
data.addNull();
}
break;
default:
// render as json object
ObjectNode entryObject = JsonNodeFactory.instance.objectNode();
Property<?> x = item.getItemProperty(xProperty);
if (x != null) {
addNamedValue(entryObject, ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE1, x);
}
Property<?> y = item.getItemProperty(yProperty);
if (y != null) {
addNamedValue(entryObject, ContainerDataSeries.SERIES_DEFAULT_ATTRIBUTE2, y);
}
Iterator<String> iter = pidMap.keySet().iterator();
while (iter.hasNext()) {
String name = iter.next();
Object id = pidMap.get(name);
if (!id.equals(xProperty) && !id.equals(yProperty)) {
addNamedValue(entryObject, name, item.getItemProperty(id));
}
}
data.add(entryObject);
break;
}
}
return data;
}
use of com.vaadin.v7.data.Item in project charts by vaadin.
the class ContainerSeriesJSONSerializationTest method serialize_ContainerWithLowAndHighValues_LowAndHighValuesSerialized.
@Test
public void serialize_ContainerWithLowAndHighValues_LowAndHighValuesSerialized() {
containerSeries.setHighPropertyId("somehigh");
containerSeries.setLowPropertyId("somelow");
vaadinContainer.removeContainerProperty("y");
vaadinContainer.addContainerProperty("somehigh", Number.class, null);
vaadinContainer.addContainerProperty("somelow", Number.class, null);
Item item = vaadinContainer.getItem(vaadinContainer.addItem());
item.getItemProperty("somehigh").setValue(5);
item.getItemProperty("somelow").setValue(-5);
assertEquals("{\"data\":[{\"high\":5,\"low\":-5}]}", toJSON(containerSeries));
}
Aggregations