@Override protected void configureTable() { super.configureTable(); ListGrid listGrid = getListGrid(); ListGridField resourceNameField = listGrid.getField(MeasurementDataTraitCriteria.SORT_FIELD_RESOURCE_NAME); resourceNameField.setCellFormatter( new CellFormatter() { public String format(Object o, ListGridRecord listGridRecord, int i, int i1) { String url = LinkManager.getResourceLink( listGridRecord.getAttributeAsInt(AncestryUtil.RESOURCE_ID)); return LinkManager.getHref(url, o.toString()); } }); resourceNameField.setShowHover(true); resourceNameField.setHoverCustomizer( new HoverCustomizer() { public String hoverHTML( Object value, ListGridRecord listGridRecord, int rowNum, int colNum) { return AncestryUtil.getResourceHoverHTML(listGridRecord, 0); } }); resourceNameField.setCanGroupBy(true); AncestryUtil.setupAncestryListGridField(listGrid); }
public ResourceLookupComboBoxItem(String name, String title) { super(name, title); setHint(MSG.widget_resourceSelector_selectResource()); setShowHintInField(false); setOptionDataSource(new ResourceDatasource()); ListGridField nameField = new ListGridField("name", MSG.common_title_name(), 250); nameField.setShowHover(true); nameField.setHoverCustomizer( new HoverCustomizer() { public String hoverHTML( Object value, ListGridRecord listGridRecord, int rowNum, int colNum) { return AncestryUtil.getResourceHoverHTML(listGridRecord, 0); } }); ListGridField ancestryField = new ListGridField(AncestryUtil.RESOURCE_ANCESTRY, MSG.common_title_ancestry(), 300); // needs to use a different cell formatter than what AncestryUtil.setupAncestryListGridField // creates ancestryField.setCellFormatter( new CellFormatter() { public String format(Object o, ListGridRecord listGridRecord, int rowNum, int colNum) { return AncestryUtil.getAncestryValue(listGridRecord, false); } }); AncestryUtil.setupAncestryListGridFieldHover(ancestryField); ListGridField descriptionField = new ListGridField("description", MSG.common_title_description()); ListGridField categoryField = new ListGridField("category", MSG.common_title_category(), 60); ListGridField availabilityField = new ListGridField("currentAvailability", MSG.common_title_availability(), 55); availabilityField.setAlign(Alignment.CENTER); setPickListFields(nameField, ancestryField, descriptionField, categoryField, availabilityField); setValueField("id"); setDisplayField("name"); setPickListWidth(800); setTextMatchStyle(TextMatchStyle.SUBSTRING); setCompleteOnTab(true); setAddUnknownValues(false); }
@Override public ArrayList<ListGridField> getListGridFields() { ArrayList<ListGridField> fields = super.getListGridFields(); // hide the created/modified fields, we don't need to show them by default // add cell formatter on the name field so we can make it a link for (ListGridField field : fields) { String fieldName = field.getName(); if (fieldName.equals(FIELD_CTIME) || fieldName.equals(FIELD_MTIME)) { field.setHidden(true); } else if (fieldName.equals(FIELD_NAME)) { field.setCellFormatter( new CellFormatter() { @Override public String format(Object value, ListGridRecord record, int rowNum, int colNum) { AlertDefinition alertDef = copyValues(record); int resourceId = alertDef.getResource().getId(); int alertDefId = alertDef.getId(); String link = LinkManager.getSubsystemAlertDefinitionLink(resourceId, alertDefId); return "<a href=\"" + link + "\">" + StringUtility.escapeHtml(alertDef.getName()) + "</a>"; } }); } } // 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.getAdminTemplatesLink() + "/Alert/" + typeId + "/" + templateId); } } @Override public void onFailure(Throwable caught) { CoreGUI.getErrorHandler() .handleError( MSG.view_reports_alertDefinitions_resTypeLoadError(), caught); } }); } else if (alertDef.getGroupAlertDefinition() != null) { AlertDefinition groupAlertDef = alertDef.getGroupAlertDefinition(); CoreGUI.goToView( LinkManager.getEntityTabLink( EntityContext.forGroup(groupAlertDef.getResourceGroup()), "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 SeleniumUtility.getLocatableHref( url, StringUtility.escapeHtml(value.toString()), null); } }); 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); ListGridField ancestryField = AncestryUtil.setupAncestryListGridField(); fields.add(ancestryField); return fields; }
@Override protected void configureTable() { getListGrid().setEmptyMessage(MSG.view_messageCenter_noRecentMessages()); updateTitleCanvas( MSG.view_messageCenter_lastNMessages( String.valueOf(CoreGUI.getMessageCenter().getMaxMessages()))); ListGridField severityField = new ListGridField(FIELD_SEVERITY); severityField.setType(ListGridFieldType.ICON); severityField.setAlign(Alignment.CENTER); severityField.setShowValueIconOnly(true); HashMap<String, String> severityIcons = new HashMap<String, String>(5); severityIcons.put(Severity.Blank.name(), getSeverityIcon(Severity.Blank)); severityIcons.put(Severity.Info.name(), getSeverityIcon(Severity.Info)); severityIcons.put(Severity.Warning.name(), getSeverityIcon(Severity.Warning)); severityIcons.put(Severity.Error.name(), getSeverityIcon(Severity.Error)); severityIcons.put(Severity.Fatal.name(), getSeverityIcon(Severity.Fatal)); severityField.setValueIcons(severityIcons); severityField.setShowHover(true); severityField.setHoverCustomizer( new HoverCustomizer() { @Override public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) { try { Severity severity = ((Message) record.getAttributeAsObject(FIELD_OBJECT)).getSeverity(); switch (severity) { case Info: return MSG.common_severity_info(); case Warning: return MSG.common_severity_warn(); case Error: return MSG.common_severity_error(); case Fatal: return MSG.common_severity_fatal(); } } catch (Throwable e) { Log.error("Cannot get severity hover", e); } return null; } }); severityField.setSortNormalizer( new SortNormalizer() { @Override public Object normalize(ListGridRecord record, String fieldName) { try { Severity severity = ((Message) record.getAttributeAsObject(FIELD_OBJECT)).getSeverity(); return Integer.valueOf(severity.ordinal()); } catch (Throwable e) { Log.error("Cannot get sort nomalizer", e); } return Integer.valueOf(0); } }); ListGridField timeField = new ListGridField(FIELD_TIME, MSG.view_messageCenter_messageTime()); timeField.setType(ListGridFieldType.TIME); timeField.setAttribute("displayFormat", TimeFormatter.TOPADDEDTIME); timeField.setAlign(Alignment.LEFT); timeField.setShowHover(true); timeField.setHoverCustomizer(TimestampCellFormatter.getHoverCustomizer(FIELD_TIME)); ListGridField messageField = new ListGridField(FIELD_CONCISEMESSAGE, MSG.common_title_message()); severityField.setWidth(25); timeField.setWidth("15%"); messageField.setWidth("*"); getListGrid().setFields(severityField, timeField, messageField); setListGridDoubleClickHandler( new DoubleClickHandler() { @Override public void onDoubleClick(DoubleClickEvent event) { try { ListGrid listGrid = (ListGrid) event.getSource(); ListGridRecord[] selectedRows = listGrid.getSelection(); if (selectedRows != null && selectedRows.length > 0) { Message message = (Message) selectedRows[0].getAttributeAsObject( FIELD_OBJECT); // show the first selected showDetails(message); } } catch (Throwable e) { Log.error("Cannot show details for message", e); } } }); addTableAction( extendLocatorId("delete"), MSG.common_button_delete(), MSG.common_msg_areYouSure(), new AbstractTableAction(TableActionEnablement.ANY) { @Override public void executeAction(ListGridRecord[] selection, Object actionValue) { try { for (ListGridRecord record : selection) { Object doomed = record.getAttributeAsObject(FIELD_OBJECT); CoreGUI.getMessageCenter().getMessages().remove(doomed); } refresh(); } catch (Throwable e) { Log.error("Cannot delete messages", e); } } }); addTableAction( extendLocatorId("deleteAll"), MSG.common_button_delete_all(), MSG.common_msg_areYouSure(), new AbstractTableAction(TableActionEnablement.ALWAYS) { @Override public void executeAction(ListGridRecord[] selection, Object actionValue) { try { CoreGUI.getMessageCenter().getMessages().clear(); refresh(); } catch (Throwable e) { Log.error("Cannot delete all messages", e); } } }); LinkedHashMap<String, Integer> maxMessagesMap = new LinkedHashMap<String, Integer>(); maxMessagesMap.put("10", Integer.valueOf("10")); maxMessagesMap.put("25", Integer.valueOf("25")); maxMessagesMap.put("50", Integer.valueOf("50")); maxMessagesMap.put("100", Integer.valueOf("100")); maxMessagesMap.put("200", Integer.valueOf("200")); addTableAction( extendLocatorId("maxMessageMenu"), MSG.view_messageCenter_maxMessages(), null, maxMessagesMap, new AbstractTableAction(TableActionEnablement.ALWAYS) { @Override public void executeAction(ListGridRecord[] selection, Object actionValue) { try { Integer maxSize = (Integer) actionValue; CoreGUI.getMessageCenter().setMaxMessages(maxSize.intValue()); updateTitleCanvas(MSG.view_messageCenter_lastNMessages(maxSize.toString())); refresh(); } catch (Throwable e) { Log.error("Cannot set max messages", e); } } }); /* // TODO only for testing, remove this when done testing addTableAction(extendLocatorId("test"), "TEST MSG", null, new AbstractTableAction(TableActionEnablement.ALWAYS) { @Override public void executeAction(ListGridRecord[] selection, Object actionValue) { for (Severity severity : java.util.EnumSet.allOf(Severity.class)) { Message m = new Message(severity.name() + ':' + System.currentTimeMillis(), severity); CoreGUI.getMessageCenter().notify(m); } } }); */ // initial population of the list with current messages try { refresh(); } catch (Throwable e) { Log.error("Cannot perform initial refresh", e); } }