Question

I have reviewed multiple examples for how to construct a TreeTable from from a Container datasource and just adding items iterating over an Object[][]. Still I'm stuck for my use case.

I have a bean like so...

public class DSRUpdateHourlyDTO implements UniquelyKeyed<AssetOwnedHourlyLocatableId>, Serializable
{
private static final long serialVersionUID = 1L;
private final AssetOwnedHourlyLocatableId id = new AssetOwnedHourlyLocatableId();

private String commitStatus;
private BigDecimal economicMax;
private BigDecimal economicMin;

public void setCommitStatus(String commitStatus) { this.commitStatus = commitStatus; }
public void setEconomicMax(BigDecimal economicMax) { this.economicMax = economicMax; }
public void setEconomicMin(BigDecimal economicMin) { this.economicMin = economicMin; }

public String getCommitStatus() { return commitStatus; }
public BigDecimal getEconomicMax() { return economicMax; }
public BigDecimal getEconomicMin() { return economicMin; }
public AssetOwnedHourlyLocatableId getId() { return id; }

@Override
public AssetOwnedHourlyLocatableId getKey() {
    return getId();
}

}

The AssetOwnedHourlyLocatableId is a compound id. It looks like...

public class AssetOwnedHourlyLocatableId implements Serializable, AssetOwned, HasHour, Locatable,
UniquelyKeyed<AssetOwnedHourlyLocatableId> {

private static final long serialVersionUID = 1L;

private String location;

private String hour;

private String assetOwner;

@Override
public String getLocation() {
    return location;
}

@Override
public void setLocation(final String location) {
    this.location = location;
}

@Override
public String getHour() {
    return hour;
}

@Override
public void setHour(final String hour) {
    this.hour = hour;
}

@Override
public String getAssetOwner() {
    return assetOwner;
}

@Override
public void setAssetOwner(final String assetOwner) {
    this.assetOwner = assetOwner;
}

}

I want to generate a grid where the hours are pivoted into column headers and the location is the only other additional column header.

E.g.,

Location    1   2   3   4   5   6   ...   24

would be the column headers.

Underneath each column you might see...

> L1 
  > Commit Status    Status1 .... Status24
  > Eco Min          EcoMin1 .... EcoMin24
  > Eco Max          EcoMax1 .... EcoMax24
> L2
  > Commit Status    Status1 .... Status24
  > Eco Min          EcoMin1 .... EcoMin24
  > Eco Max          EcoMax1 .... EcoMax24

So, if I'm provided a List<DSRUpdateHourlyDTO> I want to convert it into the presentation format described above.

What would be the best way to do this?

I have a few additional functional requirements.

  • I want to be able to toggle between read-only and editable views of the same table.
  • I want to be able to complete a round-trip to a datasource (e.g., JPAContainerSource).
  • I (will eventually) want to filter items by any part of the compound id.

My challenge is in the adaptation. I well understand the simple use case where I could take the list and simply splat it into a BeanItemContainer and use addNestedContainerProperty and setVisibleColumns. Pivoting properties into columns seems to be what's stumping me.

Was it helpful?

Solution

As it turns out this was an ill-conceived question.

For data entry purposes, one could use a BeanItemContainer and have the columns include nested container property hour from the composite id and instead of a TreeTable, use a Table that has commitStatus, ecoMin and ecoMax as columns. Limitation: you'd only ever query for / submit one assetOwner and location's worth of data.

As for display, where you don't care to filter one assetOwner and location's worth of data, you could pivot the hour info as originally described. You could just convert the original bean into another bean suitable for display (where each hour is its own column).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top