// add more columns
ListGridField parentField = new ListGridField(FIELD_PARENT, MSG.view_alerts_field_parent());
parentField.setWidth(100);
parentField.setShowHover(true);
parentField.setHoverCustomizer(new HoverCustomizer() {
@Override
public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
if (record.getAttribute(FIELD_PARENT) != null) {
return MSG.view_reports_alertDefinitions_parentHover();
}
return MSG.common_val_na();
}
});
parentField.addRecordClickHandler(new RecordClickHandler() {
@Override
public void onRecordClick(RecordClickEvent event) {
// we only do something if we really have a parent.
// if we have a template parent, we have to get the resource's type and go to the template page for that type
// if we have a group parent, we can directly go to the group's alert def page
Record record = event.getRecord();
AlertDefinition alertDef = copyValues(record);
if (alertDef.getParentId() != null && alertDef.getParentId().intValue() > 0) {
final Integer templateId = alertDef.getParentId().intValue();
final Integer resourceId = alertDef.getResource().getId();
ResourceCriteria resCriteria = new ResourceCriteria();
resCriteria.addFilterId(resourceId);
resCriteria.fetchResourceType(true);
GWTServiceLookup.getResourceService().findResourcesByCriteria(resCriteria,
new AsyncCallback<PageList<Resource>>() {
@Override
public void onSuccess(PageList<Resource> result) {
if (result == null || result.size() != 1) {
CoreGUI.getErrorHandler().handleError(
MSG.view_reports_alertDefinitions_resTypeLoadError());
} else {
int typeId = result.get(0).getResourceType().getId();
CoreGUI.goToView(LinkManager.getAdminTemplatesEditLink(
AlertDefinitionTemplateTypeView.VIEW_ID.getName(), typeId)
+ "/"
+ templateId);
}
}
@Override
public void onFailure(Throwable caught) {
CoreGUI.getErrorHandler().handleError(
MSG.view_reports_alertDefinitions_resTypeLoadError(), caught);
}
});
} else if (alertDef.getParentId() != null && alertDef.getParentId() == 0) {
// handle "View Group Definition"
int resourceId = alertDef.getResource().getId();
int alertDefId = alertDef.getId();
CoreGUI.goToView(LinkManager.getSubsystemAlertDefinitionLink(resourceId, alertDefId));
} else if (alertDef.getGroupAlertDefinition() != null) {
AlertDefinition groupAlertDef = alertDef.getGroupAlertDefinition();
CoreGUI.goToView(LinkManager.getEntityTabLink(EntityContext.forGroup(groupAlertDef.getGroup()),
"Alert", "Definitions") + "/" + groupAlertDef.getId());
}
}
});
fields.add(parentField);
ListGridField resourceField = new ListGridField(FIELD_RESOURCE, MSG.common_title_resource());
resourceField.setCellFormatter(new CellFormatter() {
public String format(Object value, ListGridRecord listGridRecord, int i, int i1) {
String url = LinkManager.getResourceLink(listGridRecord.getAttributeAsInt(AncestryUtil.RESOURCE_ID));
return LinkManager.getHref(url, StringUtility.escapeHtml(value.toString()));
}
});
resourceField.setShowHover(true);
resourceField.setHoverCustomizer(new HoverCustomizer() {
public String hoverHTML(Object value, ListGridRecord listGridRecord, int rowNum, int colNum) {
return AncestryUtil.getResourceHoverHTML(listGridRecord, 0);
}
});
fields.add(resourceField);