PDA

View Full Version : java.util.List in Grid



gaboo
2 Mar 2012, 11:49 PM
Hi there!

I would like to make a grid from an object which has a List type attribute.
The data object looks like this:



public interface Data {
public String getName();
public List<Double> getData(); // List size = 20 for example
}


So the grid would have 21 columns (String, Double, Double, Double....).
Is it possible to write a PropertyAccess<Data> interface which presents all the Doubles for the grid?

Best regards
gaboo

gaboo
10 Mar 2012, 12:02 AM
Hi,

The simple answer is a custom ValueProvider like this one:


public class StatValueProvider implements ValueProvider<StatRow, Integer> {


private int month;

public StatValueProvider(int month) {
this.month = month;
}


@Override
public Integer getValue(StatRow object) {
return object.getMonths().get(month);
}


@Override
public void setValue(StatRow object, Integer value) {
}


@Override
public String getPath() {
return null;
}


}


In this case the StatRow.getMonths() method is a List<Integer>.

Best regards

G.