public static Int32 CompareStaticFirst(RecordTemplateItem itemA, RecordTemplateItem itemB) { if (itemA.Category.HasFlag(NodeInTemplateRole.Dynamic) && itemB.Category.HasFlag(NodeInTemplateRole.Static)) { return(-1); } if (itemA.Category.HasFlag(NodeInTemplateRole.Static) && itemB.Category.HasFlag(NodeInTemplateRole.Dynamic)) { return(1); } if (itemA.Category.HasFlag(NodeInTemplateRole.Dynamic)) { return(-1); } if (itemA.Category.HasFlag(NodeInTemplateRole.Static)) { return(1); } return(0); }
public RecordTemplate GetTemplate(NodeGraph ParentRoot, Boolean trimItems = true) { RecordTemplate template = new RecordTemplate(); template.Category = Category; template.SubXPath = Root.path.removeStartsWith(ParentRoot.path); Int32 dynamicItems = 0; Int32 staticItems = 0; foreach (var lpair in LeafsByRelativePath) { RecordTemplateItem item = new RecordTemplateItem(); if (lpair.Value.item != null) { item.Category = lpair.Value.item.Category; } if (trimItems) { var pathParts = lpair.Key.SplitSmart("/"); item.SubXPath = pathParts.First(); } else { item.SubXPath = lpair.Key; } if (item.Category.HasFlag(NodeInTemplateRole.Dynamic)) { dynamicItems++; } if (item.Category.HasFlag(NodeInTemplateRole.Static)) { staticItems++; } template.items.Add(item); } Boolean isDynamic = template.Category.HasFlag(NodeInTemplateRole.Dynamic); Boolean isStatic = template.Category.HasFlag(NodeInTemplateRole.Static); if (isDynamic && isStatic) { template.Role = RecordTemplateRole.RowDataAndContextProvider; if (staticItems == 1) { template.items.Sort(RecordTemplateTools.CompareStaticFirst); template.items.Reverse(); } } else if (isDynamic) { template.Role = RecordTemplateRole.RowDataProvider; } else if (isStatic) { template.Role = RecordTemplateRole.GeneralContextProvider; template.RecordSelectionLimit = 1; } return(template); }