@Override public ListGridRecord copyValues(AlertDefinition from) { // in order to support sorting our list grid on the parent and resource columns, // we have to assign these to something that is sortable ListGridRecord record = super.copyValues(from); Resource resource = from.getResource(); record.setAttribute(FIELD_RESOURCE, resource.getName()); Integer parentId = from.getParentId(); // a valid non-zero number means the alert def came from a template AlertDefinition groupAlertDefinition = from.getGroupAlertDefinition(); if (parentId != null && parentId.intValue() > 0) { record.setAttribute(FIELD_PARENT, "<b>" + MSG.view_alert_definition_for_type() + "</b>"); } else if (groupAlertDefinition != null) { record.setAttribute(FIELD_PARENT, "<b>" + MSG.view_alert_definition_for_group() + "</b>"); } // for ancestry handling record.setAttribute(AncestryUtil.RESOURCE_ID, resource.getId()); record.setAttribute(AncestryUtil.RESOURCE_NAME, resource.getName()); record.setAttribute(AncestryUtil.RESOURCE_ANCESTRY, resource.getAncestry()); record.setAttribute(AncestryUtil.RESOURCE_TYPE_ID, resource.getResourceType().getId()); return record; }
private void buildFavoriteResourcesMenu( Favorites favorites, Menu menu, Set<Integer> resourceIds, AncestryUtil.MapWrapper typesWrapper) { if (resourceIds.isEmpty()) { menu.setItems(); return; } List<MenuItem> items = new ArrayList<MenuItem>(resourceIds.size()); for (final Integer resourceId : resourceIds) { Resource resource = favorites.getResource(resourceId); if (null == resource) { // if the resource is gone just skip it continue; } MenuItem item = new MenuItem(resource.getName()); item.setIcon(ImageManager.getResourceIcon(resource)); // build a subMenu to display a disambiguated resource item.setAttribute(AncestryUtil.RESOURCE_ID, resourceId); item.setAttribute(AncestryUtil.RESOURCE_NAME, resource.getName()); item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY, resource.getAncestry()); item.setAttribute(AncestryUtil.RESOURCE_TYPE_ID, resource.getResourceType().getId()); item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_TYPES, typesWrapper); Menu ancestryMenu = new Menu(); MenuItem ancestryItem = new MenuItem(AncestryUtil.getAncestryHoverHTML(item, -1)); ancestryItem.setEnabled(false); ancestryMenu.setItems(ancestryItem); ancestryMenu.setSubmenuDirection("left"); ancestryMenu.setAutoWidth(); item.setSubmenu(ancestryMenu); item.addClickHandler( new com.smartgwt.client.widgets.menu.events.ClickHandler() { public void onClick(MenuItemClickEvent event) { CoreGUI.goToView(LinkManager.getResourceLink(resourceId)); } }); items.add(item); } menu.setCanSelectParentItems(Boolean.TRUE); menu.setItems(items.toArray(new MenuItem[items.size()])); }
/** * Additional processing to support a cross-resource view) * * @param result * @param response * @param request */ protected void dataRetrieved( final PageList<AlertDefinition> result, final DSResponse response, final DSRequest request) { HashSet<Integer> typesSet = new HashSet<Integer>(); HashSet<String> ancestries = new HashSet<String>(); for (AlertDefinition alertDefinition : result) { Resource resource = alertDefinition.getResource(); if (null != resource) { typesSet.add(resource.getResourceType().getId()); ancestries.add(resource.getAncestry()); } } // In addition to the types of the result resources, get the types of their ancestry typesSet.addAll(AncestryUtil.getAncestryTypeIds(ancestries)); ResourceTypeRepository typeRepo = ResourceTypeRepository.Cache.getInstance(); typeRepo.getResourceTypes( typesSet.toArray(new Integer[typesSet.size()]), new TypesLoadedCallback() { public void onTypesLoaded(Map<Integer, ResourceType> types) { // Smartgwt has issues storing a Map as a ListGridRecord attribute. Wrap it in a pojo. AncestryUtil.MapWrapper typesWrapper = new AncestryUtil.MapWrapper(types); Record[] records = buildRecords(result); for (Record record : records) { // To avoid a lot of unnecessary String construction, be lazy about building // ancestry hover text. // Store the types map off the records so we can build a detailed hover string as // needed. record.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_TYPES, typesWrapper); // Build the decoded ancestry Strings now for display record.setAttribute( AncestryUtil.RESOURCE_ANCESTRY_VALUE, AncestryUtil.getAncestryValue(record)); } response.setData(records); response.setTotalRows( result .getTotalSize()); // for paging to work we have to specify size of full result // set processResponse(request.getRequestId(), response); } }); }
private void buildRecentlyViewedMenu( Favorites favorites, Menu menu, List<Integer> recentResourceIds, List<Integer> recentGroupIds, AncestryUtil.MapWrapper typesWrapper) { if (recentResourceIds.isEmpty() && recentGroupIds.isEmpty()) { return; } List<MenuItem> items = new ArrayList<MenuItem>(recentResourceIds.size() + recentGroupIds.size() + 1); for (final Integer resourceId : recentResourceIds) { Resource resource = favorites.getResource(resourceId); if (null == resource) { // if the resource is gone just skip it continue; } MenuItem item = new MenuItem(resource.getName()); item.setIcon(ImageManager.getResourceIcon(resource)); // build a subMenu to display a disambiguated resource item.setAttribute(AncestryUtil.RESOURCE_ID, resourceId); item.setAttribute(AncestryUtil.RESOURCE_NAME, resource.getName()); item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY, resource.getAncestry()); item.setAttribute(AncestryUtil.RESOURCE_TYPE_ID, resource.getResourceType().getId()); item.setAttribute(AncestryUtil.RESOURCE_ANCESTRY_TYPES, typesWrapper); Menu ancestryMenu = new Menu(); MenuItem ancestryItem = new MenuItem(AncestryUtil.getAncestryHoverHTML(item, -1)); ancestryItem.setEnabled(false); ancestryMenu.setItems(ancestryItem); ancestryMenu.setSubmenuDirection("left"); ancestryMenu.setAutoWidth(); item.setSubmenu(ancestryMenu); item.addClickHandler( new com.smartgwt.client.widgets.menu.events.ClickHandler() { public void onClick(MenuItemClickEvent event) { CoreGUI.goToView(LinkManager.getResourceLink(resourceId)); } }); items.add(item); } if (!recentResourceIds.isEmpty() && !recentGroupIds.isEmpty()) { items.add(new MenuItemSeparator()); } for (final Integer groupId : recentGroupIds) { ResourceGroupComposite groupComposite = favorites.getGroupComposite(groupId); if (null == groupComposite) { // if the resource group is gone just skip it continue; } final ResourceGroup group = groupComposite.getResourceGroup(); MenuItem item = new MenuItem(String.valueOf(groupId)); item.setTitle(group.getName()); item.setIcon( ImageManager.getGroupIcon( group.getGroupCategory(), groupComposite.getExplicitAvailabilityType())); item.addClickHandler( new com.smartgwt.client.widgets.menu.events.ClickHandler() { public void onClick(MenuItemClickEvent event) { CoreGUI.goToView(LinkManager.getResourceGroupLink(group)); } }); items.add(item); } menu.setCanSelectParentItems(Boolean.TRUE); menu.setItems(items.toArray(new MenuItem[items.size()])); }