Skip to content

Instantly share code, notes, and snippets.

@fastnsilver
Created June 1, 2012 05:08
Show Gist options
  • Save fastnsilver/2848997 to your computer and use it in GitHub Desktop.
Save fastnsilver/2848997 to your computer and use it in GitHub Desktop.
Revised method impl for EnergyOfferGrid that composes a number of AbstractValidatableColumns into a CompositeValidatableColumn
protected void addPriceMwColumn(final int colIndex, DisplayMode currentDisplayMode) {
// Construct a composite cell for energy offers that includes a pair of text inputs
final List<HasCell<EnergyOfferDTO, String>> columns = new ArrayList<
HasCell<EnergyOfferDTO, String>>();
// this DTO is passed along so that price and mw values for new entries are kept together
final OfferPriceMwPair newOfferPriceMwPair = new OfferPriceMwPair();
// Price
final Column<EnergyOfferDTO, String> priceColumn = generatePriceColumn(colIndex, newOfferPriceMwPair, currentDisplayMode);
columns.add(priceColumn);
// MW
final Column<EnergyOfferDTO, String> mwColumn = generateMwColumn(colIndex, newOfferPriceMwPair, currentDisplayMode);
columns.add(mwColumn);
// Composite
final WrapperCell<EnergyOfferDTO> priceMwColumnInnards = generateWrapperCell(columns);
final CompositeValidatableColumn<EnergyOfferDTO> priceMwColumn = new CompositeValidatableColumn<EnergyOfferDTO>(priceMwColumnInnards);
final StringBuilder colHeader = new StringBuilder();
colHeader.append(UiMessages.INSTANCE.price_mw_header()).append(" ").append(String.valueOf(colIndex + 1));
addColumn(priceMwColumn, colHeader.toString());
setColumnWidth(priceMwColumn, 7, Unit.EM);
setColumnHorizontalAlignment(priceMwColumn, HasHorizontalAlignment.ALIGN_RIGHT);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment