@Override
public void populateItem(final Item<ICellPopulator<ResourceTO>> cellItem, final String componentId,
final IModel<ResourceTO> model) {
final ResourceTO resourceTO = model.getObject();
final ActionLinksPanel panel = new ActionLinksPanel(componentId, model, getPageReference());
panel.add(new ActionLink() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target) {
resourceTO.setUsyncToken(null);
resourceTO.setRsyncToken(null);
try {
resourceRestClient.update(resourceTO);
info(getString(Constants.OPERATION_SUCCEEDED));
} catch (SyncopeClientCompositeErrorException e) {
error(getString(Constants.ERROR) + ":" + e.getMessage());
LOG.error("While resetting sync token from " + resourceTO.getName(), e);
}
target.add(feedbackPanel);
target.add(resourceContainer);
}
}, ActionLink.ActionType.RESET, "Resources");
panel.add(new ActionLink() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target) {
editResourceWin.setPageCreator(new ModalWindow.PageCreator() {
private static final long serialVersionUID = -7834632442532690940L;
@Override
public Page createPage() {
return new ResourceModalPage(Resources.this.getPageReference(),
editResourceWin, resourceTO, false);
}
});
editResourceWin.show(target);
}
}, ActionLink.ActionType.EDIT, "Resources");
panel.add(new ActionLink() {
private static final long serialVersionUID = -3722207913631435501L;
@Override
public void onClick(final AjaxRequestTarget target) {
try {
resourceRestClient.delete(resourceTO.getName());
info(getString(Constants.OPERATION_SUCCEEDED));
} catch (SyncopeClientCompositeErrorException e) {
error(getString(Constants.ERROR) + ":" + e.getMessage());
LOG.error("While deleting resource " + resourceTO.getName(), e);
}
target.add(feedbackPanel);
target.add(resourceContainer);
}
}, ActionLink.ActionType.DELETE, "Resources");
cellItem.add(panel);
}
});
final AjaxDataTablePanel<ResourceTO, String> table = new AjaxDataTablePanel<ResourceTO, String>(
"resourceDatatable",
columns,
(ISortableDataProvider<ResourceTO, String>) new ResourcesProvider(),
resourcePaginatorRows,
Arrays.asList(new ActionLink.ActionType[] { ActionLink.ActionType.DELETE }),
resourceRestClient,
"name",
"Resources",
getPageReference());
resourceContainer = new WebMarkupContainer("resourceContainer");
resourceContainer.add(table);
resourceContainer.setOutputMarkupId(true);
add(resourceContainer);
setWindowClosedCallback(createResourceWin, resourceContainer);
setWindowClosedCallback(editResourceWin, resourceContainer);
createResourceWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
createResourceWin.setInitialHeight(WIN_HEIGHT);
createResourceWin.setInitialWidth(WIN_WIDTH);
createResourceWin.setCookieName("create-res-modal");
editResourceWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
editResourceWin.setInitialHeight(WIN_HEIGHT);
editResourceWin.setInitialWidth(WIN_WIDTH);
editResourceWin.setCookieName("edit-res-modal");
AjaxLink<Void> createResourceLink =
new ClearIndicatingAjaxLink<Void>("createResourceLink", getPageReference()) {
private static final long serialVersionUID = -7978723352517770644L;
@Override
protected void onClickInternal(final AjaxRequestTarget target) {
createResourceWin.setPageCreator(new ModalWindow.PageCreator() {
private static final long serialVersionUID = -7834632442532690940L;
@Override
public Page createPage() {
return new ResourceModalPage(Resources.this.getPageReference(),
editResourceWin, new ResourceTO(), true);
}
});
createResourceWin.show(target);
}