final List<IColumn<AddressDO, String>> columns = new ArrayList<IColumn<AddressDO, String>>();
final CellItemListener<AddressDO> cellItemListener = new CellItemListener<AddressDO>() {
public void populateItem(final Item<ICellPopulator<AddressDO>> item, final String componentId, final IModel<AddressDO> rowModel)
{
final AddressDO address = rowModel.getObject();
final Serializable highlightedRowId;
if (page instanceof AbstractListPage< ? , ? , ? >) {
highlightedRowId = ((AbstractListPage< ? , ? , ? >) page).getHighlightedRowId();
} else {
highlightedRowId = null;
}
final PersonalAddressDO personalAddress = personalAddressMap.get(address.getId());
appendCssClasses(item, address.getId(), highlightedRowId, address.isDeleted());
if (address.isDeleted() == true) {
// Do nothing further
} else if (personalAddress != null && personalAddress.isFavoriteCard() == true) {
appendCssClasses(item, RowCssClass.FAVORITE_ENTRY);
}
if (address.getAddressStatus().isIn(AddressStatus.LEAVED, AddressStatus.OUTDATED) == true
|| address.getContactStatus().isIn(ContactStatus.DEPARTED, ContactStatus.NON_ACTIVE, ContactStatus.PERSONA_INGRATA,
ContactStatus.UNINTERESTING, ContactStatus.DEPARTED) == true) {
appendCssClasses(item, RowCssClass.MARKED_AS_DELETED);
}
}
};
if (page instanceof AddressCampaignValueMassUpdatePage) {
columns.add(new CellItemListenerPropertyColumn<AddressDO>(new Model<String>(page.getString("created")), getSortable("created",
sortable), "created", cellItemListener));
} else if (massUpdateMode == true && page instanceof AddressCampaignValueListPage) {
final AddressCampaignValueListPage addressCampaignValueListPage = (AddressCampaignValueListPage) page;
columns.add(new CellItemListenerPropertyColumn<AddressDO>("", null, "selected", cellItemListener) {
@Override
public void populateItem(final Item<ICellPopulator<AddressDO>> item, final String componentId, final IModel<AddressDO> rowModel)
{
final AddressDO address = rowModel.getObject();
final CheckBoxPanel checkBoxPanel = new CheckBoxPanel(componentId, addressCampaignValueListPage.new SelectItemModel(address.getId()), null);
item.add(checkBoxPanel);
cellItemListener.populateItem(item, componentId, rowModel);
addRowClick(item, massUpdateMode);
}
});
} else {
columns.add(new CellItemListenerPropertyColumn<AddressDO>(new Model<String>(page.getString("created")), getSortable("created",
sortable), "created", cellItemListener) {
@Override
public void populateItem(final Item<ICellPopulator<AddressDO>> item, final String componentId, final IModel<AddressDO> rowModel)
{
final AddressDO address = rowModel.getObject();
final AddressCampaignValueDO addressCampaignValue = addressCampaignValueMap.get(address.getId());
final Integer addressCampaignValueId = addressCampaignValue != null ? addressCampaignValue.getId() : null;
item.add(new ListSelectActionPanel(componentId, rowModel, AddressCampaignValueEditPage.class, addressCampaignValueId, page,
DateTimeFormatter.instance().getFormattedDateTime(address.getCreated()), AddressCampaignValueEditPage.PARAMETER_ADDRESS_ID,
String.valueOf(address.getId()), AddressCampaignValueEditPage.PARAMETER_ADDRESS_CAMPAIGN_ID, String.valueOf(searchFilter
.getAddressCampaignId())));
addRowClick(item);
cellItemListener.populateItem(item, componentId, rowModel);
}
});
}
columns.add(new CellItemListenerPropertyColumn<AddressDO>(new Model<String>(page.getString("name")), getSortable("name", sortable),
"name", cellItemListener));
columns.add(new CellItemListenerPropertyColumn<AddressDO>(new Model<String>(page.getString("firstName")), getSortable("firstName",
sortable), "firstName", cellItemListener));
columns.add(new CellItemListenerPropertyColumn<AddressDO>(new Model<String>(page.getString("organization")), getSortable(
"organization", sortable), "organization", cellItemListener));
columns.add(new CellItemListenerPropertyColumn<AddressDO>(new Model<String>(page.getString("address.contactStatus")), getSortable(
"contactStatus", sortable), "contactStatus", cellItemListener));
columns.add(new AbstractColumn<AddressDO, String>(new Model<String>(page.getString("address.addressText"))) {
@Override
public void populateItem(final Item<ICellPopulator<AddressDO>> item, final String componentId, final IModel<AddressDO> rowModel)
{
final AddressDO address = rowModel.getObject();
final String addressText = StringHelper.listToString("|", address.getMailingAddressText(), address.getMailingZipCode()
+ " "
+ address.getMailingCity(), address.getMailingCountry());
if (massUpdateMode == false) {
final AddressEditLinkPanel addressEditLinkPanel = new AddressEditLinkPanel(componentId, page, address, addressText);
item.add(addressEditLinkPanel);
} else {
item.add(new Label(componentId, addressText));
}
cellItemListener.populateItem(item, componentId, rowModel);
}
});
columns.add(new CellItemListenerPropertyColumn<AddressDO>(new Model<String>(page.getString("address.addressStatus")), getSortable(
"addressStatus", sortable), "addressStatus", cellItemListener));
columns.add(new AbstractColumn<AddressDO, String>(new Model<String>(page.getString("value"))) {
@Override
public void populateItem(final Item<ICellPopulator<AddressDO>> item, final String componentId, final IModel<AddressDO> rowModel)
{
final AddressDO address = rowModel.getObject();
final Integer id = address.getId();
final AddressCampaignValueDO addressCampaignValue = addressCampaignValueMap.get(id);
if (addressCampaignValue != null) {
item.add(new Label(componentId, addressCampaignValue.getValue()));
item.add(AttributeModifier.append("style", new Model<String>("white-space: nowrap;")));
} else {
item.add(new Label(componentId, ""));
}
cellItemListener.populateItem(item, componentId, rowModel);
}
});
columns.add(new AbstractColumn<AddressDO, String>(new Model<String>(page.getString("comment"))) {
@Override
public void populateItem(final Item<ICellPopulator<AddressDO>> item, final String componentId, final IModel<AddressDO> rowModel)
{
final AddressDO address = rowModel.getObject();
final Integer id = address.getId();
final AddressCampaignValueDO addressCampaignValue = addressCampaignValueMap.get(id);
if (addressCampaignValue != null) {
item.add(new Label(componentId, addressCampaignValue.getComment()));
item.add(AttributeModifier.append("style", new Model<String>("white-space: nowrap;")));
} else {