@Override
public void populateItem(
Item<ICellPopulator<CreditPaths>> cellItem,
String componentId, IModel<CreditPaths> rowModel) {
CreditPaths twoPartnersPaths = rowModel.getObject();
User creditor = twoPartnersPaths.getCreditor();
cellItem.add(new Label(componentId, creditor == null ? "???" : creditor.getDisplayName()));
}
});
//Available amount
columns.add(new AbstractColumn<CreditPaths, String>(new ResourceModel(MKEY_MAX_AMOUNT)) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<CreditPaths>> cellItem, String componentId,
IModel<CreditPaths> rowModel) {
CreditPaths twoPartnersPaths = rowModel.getObject();
BigDecimal maxAmount = BigDecimal.ZERO;
for(CreditPath path: twoPartnersPaths.getPaths()) {
maxAmount = maxAmount.add(creditLineReader.getAvailableAmount(path.getPath()));
}
cellItem.add(new Label(componentId, maxAmount.toString()));
}
});
//Number of paths between two partners
columns.add(new AbstractColumn<CreditPaths, String>(new ResourceModel(MKEY_PATHS_COUNT)) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<CreditPaths>> cellItem, String componentId,
IModel<CreditPaths> rowModel) {
CreditPaths twoPartnersPaths = rowModel.getObject();
cellItem.add(new Label(componentId, String.valueOf(twoPartnersPaths.getPaths().size())));
}
});
//Amount input column
columns.add(new AbstractColumn<CreditPaths, String>(new ResourceModel(MKEY_AMOUNT)) {
private static final long serialVersionUID = 1L;
@Override
public void populateItem(Item<ICellPopulator<CreditPaths>> cellItem, String componentId,
final IModel<CreditPaths> rowModel) {
final CreditPaths twoPartnersPathsContainer = rowModel.getObject();
cellItem.add(new AttributeAppender("style", ";width:110px;"));//TODO: constant
cellItem.add(new AjaxEditorLink<BigDecimal>(componentId, new Model<BigDecimal>(BigDecimal.ZERO)) {
private static final long serialVersionUID = 1L;
private NumberTextField<BigDecimal> amountInput;
@Override
protected boolean onValueSubmit(AjaxRequestTarget target) {
BigDecimal newValue = amountInput.getModelObject();
boolean success = true;
try {
rowModel.setObject(
creditLineWriter.roteDebt(twoPartnersPathsContainer, newValue));
target.add(creditPathsTable);
} catch (DebtRotingException e) {
CreditorsPanel.this.error(getString(MKEY_ERROR_DEBT_ROUTNG));
target.add(messagesPanel);
success = false;
}
return success;
}
@Override
protected Component getFormControl(String controlId, final IModel<BigDecimal> model) {
InputPanel<Void> inputPanel = new InputPanel<Void>(controlId) {
private static final long serialVersionUID = 1L;
@Override
protected Component createControl(String controlId) {
amountInput = new NumberTextField<BigDecimal>(controlId, model, BigDecimal.class);
amountInput.setOutputMarkupId(true);
amountInput.add(new AttributeAppender("style", ";width:80px;"));//TODO: constant
return amountInput;
}
};
return inputPanel;
}
});
}
@Override
public String getCssClass() {
return CSSCLASS_AMOUNT_COL;
}
});
ISortableDataProvider<CreditPaths, String> dataProvider = new ListSortableProvider<CreditPaths>() {
private static final long serialVersionUID = 1L;
@Override
protected List<CreditPaths> getItems() {
User debtor = authorizedUserService.getCurrentUser();
Contract contract = (Contract) getDefaultModelObject();
Contract persistedContract = contractReader.getContract(contract.getId());
contract = contractReader.getContract(contract.getId());
Collection<User> creditors = contractInformant.getCreditors(persistedContract);
return creditPathFinder.findPaths(debtor, creditors, BigDecimal.ZERO);