public bool TrySelect(Identifier id) { Select(id); return treeView.SelectedNode != null; }
private static TreeNode FindNode(TreeNodeCollection nodes, Identifier id) { if (id.Parts.Count > 0) { foreach (TreeNode node in nodes) { if (Equals(node.Text, id.Parts[0])) { if (id.Parts.Count == 1) return node; if (node.Nodes.Count == 0) return null; return FindNode(node.Nodes, id.RemovePrefix(1)); } } } return null; }
public static Identifier ToResultsSummaryIdentifier(Identifier identifier) { return ToResultsIdentifier(identifier, "ResultSummary"); // Not L10N }
public void Select(Identifier id) { treeView.SelectedNode = FindNode(treeView.Nodes, id); }
public Identifier(Identifier parent, Identifier descendent) : this(GetParts(parent), GetParts(descendent)) { }
/// <summary> /// Used when loading a saved Report, this method figures out what to display in the UI. /// The saved Report just has the information necessary to execute the query, which /// is the set of columns to query, and paired with the tables to query. /// This then needs to be transformed back into which columns in the big tree view were /// selected, and whether the "Pivot Results" checkbox was checked. /// </summary> public void GetColumnInfos(Report report, TreeView treeView, out List<NodeData> columnInfos) { // CONSIDER: Why have the base class? if (!(report is SimpleReport)) { throw new InvalidOperationException(Resources.ColumnSet_GetColumnInfos_Unexpected_report_type); } SimpleReport simpleReport = (SimpleReport) report; columnInfos = new List<NodeData>(); var allColumns = new List<ReportColumn>(simpleReport.Columns); var pivotReport = simpleReport as PivotReport; if (pivotReport != null) { allColumns.AddRange(pivotReport.CrossTabValues); } if (allColumns.Count == 0) { return; } var allTables = new HashSet<Type>(from reportColumn in allColumns select reportColumn.Table); Table table = MostManyTable; Identifier prefix = null; while (table != null) { if (allTables.Contains(table.PersistentClass) || allTables.Contains(table.ResultsClass) || allTables.Contains(table.ResultsSummaryClass)) { break; } if (table.Parent == null) { string tableNames = string.Join(", ", (from reportTable in allTables // Not L10N select reportTable.ToString()).ToArray()); throw new InvalidDataException(string.Format(Resources.ColumnSet_GetColumnInfos_Unable_to_find_table_for__0_, tableNames)); } table = table.Parent.ParentTable; prefix = new Identifier(prefix, table.Name); } foreach (var unqualifiedId in allColumns) { Identifier identifier; TableType type = ReportColumn.GetTableType(unqualifiedId.Table); switch (type) { case TableType.result: identifier = JoinIds(prefix, unqualifiedId.Column, ToResultsIdentifier); break; case TableType.summary: identifier = JoinIds(prefix, unqualifiedId.Column, ToResultsSummaryIdentifier); break; default: identifier = JoinIds(prefix, unqualifiedId.Column); break; } columnInfos.Add(FindNodeData(treeView, type, identifier)); } }
private static Identifier JoinIds(Identifier prefix, Identifier suffix) { return new Identifier(prefix, suffix); }
private static IEnumerable<string> GetParts(Identifier identifier) { if (identifier == null) { return new string[0]; } return identifier.Parts; }
/// <summary> /// Finds a NodeData element searching the entire tree. /// </summary> private static NodeData FindNodeData(TreeView root, TableType type, Identifier reportColumn) { foreach (TreeNode node in root.Nodes) { NodeData nodeData = FindNodeData(node, type, reportColumn); if (nodeData != null) { return nodeData; } } return null; }
/// <summary> /// Walks the tree to find the NodeData. /// </summary> private static NodeData FindNodeData(TreeNode root, TableType type, Identifier identifier) { NodeData nodeData = root.Tag as NodeData; if (nodeData != null) { if (nodeData.Results) { if (type == TableType.result && Equals(identifier, ToResultsIdentifier(nodeData.ReportColumn.Column))) return nodeData; } else if (nodeData.ResultsSummary) { if (type == TableType.summary && Equals(identifier, ToResultsSummaryIdentifier(nodeData.ReportColumn.Column))) return nodeData; } else if (type == TableType.node && Equals(nodeData.ReportColumn.Column, identifier)) { return nodeData; } } foreach (TreeNode child in root.Nodes) { NodeData result = FindNodeData(child, type, identifier); if (result != null) return result; } return null; }
protected List<TreeNode> GetTreeNodes(IClassMetadata classMetadata, Identifier identifier) { List<TreeNode> result = new List<TreeNode>(); // Add special ratio names in order after the default ratio name int lastRatioIndex = -1; foreach (String propertyName in classMetadata.PropertyNames) { IType propertyType = classMetadata.GetPropertyType(propertyName); if (propertyType is ManyToOneType) { continue; } var label = propertyName; bool isRatio = RatioPropertyAccessor.IsRatioOrRdotpProperty(label); if (isRatio) label = RatioPropertyAccessor.GetDisplayName(label); else if (AnnotationDef.IsAnnotationProperty(label)) label = AnnotationDef.GetColumnDisplayName(label); else if (label.IndexOf("Ratio", StringComparison.Ordinal) != -1) // Not L10N: Label is only used in this file. Never displayed. lastRatioIndex = result.Count; var columnInfo = CreateColumnInfo(identifier, classMetadata, propertyName); if (columnInfo.IsHidden) { continue; } TreeNode propertyNode = new TreeNode { Name = propertyName, Text = label, Tag = columnInfo }; if (isRatio && lastRatioIndex != -1) result.Insert(++lastRatioIndex, propertyNode); else result.Add(propertyNode); } return result; }
protected NodeData CreateColumnInfo(Identifier parentIdentifier, IClassMetadata classMetadata, String propertyName) { Type type = classMetadata.GetMappedClass(EntityMode.Poco); ColumnInfo columnInfo = Schema.GetColumnInfo(type, propertyName); NodeData nodeData = new NodeData { ReportColumn = new ReportColumn(type, new Identifier(parentIdentifier, propertyName)), Caption = columnInfo.Caption, Format = columnInfo.Format, ColumnType = columnInfo.ColumnType, IsHidden = columnInfo.IsHidden }; return nodeData; }
/// <summary> /// Return the TreeNodes that should be displayed in the column picker UI. /// </summary> public List<TreeNode> GetTreeNodes() { Table table = MostManyTable; TreeNode childNode = null; Identifier identifier = null; while (true) { List<TreeNode> nodes = new List<TreeNode>(); if (childNode != null) { nodes.Add(childNode); } nodes.AddRange(GetTreeNodes(table, identifier)); if (table.Parent == null) { foreach (TreeNode treeNode in nodes) { NodeData nodeData = treeNode.Tag as NodeData; if (nodeData != null) { treeNode.Text = nodeData.Caption; } } return nodes; } childNode = new TreeNode {Name = table.Parent.ChildrenName, Text = table.Parent.ChildrenName}; childNode.Nodes.AddRange(nodes.ToArray()); identifier = new Identifier(identifier, table.Parent.ParentName); table = table.Parent.ParentTable; } }
public bool Resolve(Type table, Identifier identifier, out Type resultTable, out String column) { if (identifier.Parts.Count == 1) { resultTable = table; column = identifier.Parts[0]; return true; } PropertyInfo propertyInfo = table.GetProperty(identifier.Parts[0]); return Resolve(propertyInfo.PropertyType, identifier.RemovePrefix(1), out resultTable, out column); }
private static Identifier JoinIds(Identifier prefix, Identifier suffix, Func<Identifier, Identifier> modPrefix) { return new Identifier(modPrefix(new Identifier(prefix, suffix.Parts[0])), suffix.RemovePrefix(1)); }
public bool StartsWith(Identifier identifier) { if (identifier == null) { return true; } if (identifier.Parts.Count > Parts.Count) { return false; } for (int i = 0; i < identifier.Parts.Count; i++) { if (Parts[i] != identifier.Parts[i]) { return false; } } return true; }
private static Identifier ToResultsIdentifier(Identifier identifier, string suffix) { List<String> parts = new List<String>(); for (int i = 0; i < identifier.Parts.Count - 1; i++) { parts.Add(identifier.Parts[i] + suffix); } parts.Add(identifier.Parts[identifier.Parts.Count - 1]); return new Identifier(parts); }
public Identifier(Identifier parent, String name) : this(GetParts(parent), new[] { name }) { }
private IEnumerable<TreeNode> GetTreeNodes(Table table, Identifier identifier) { List<TreeNode> treeNodes = new List<TreeNode>(); IClassMetadata classMetadata = Schema.GetClassMetadata(table.PersistentClass); if (table.ResultsClass != null) { TreeNode resultsNode = new TreeNode { Name = "Results", Text = ResultText(table, "Results") }; // Not L10N foreach (TreeNode treeNode in GetTreeNodes(Schema.GetClassMetadata(table.ResultsClass), identifier)) { ((NodeData) treeNode.Tag).Results = true; resultsNode.Nodes.Add(treeNode); } treeNodes.Add(resultsNode); } if (table.ResultsSummaryClass != null) { TreeNode resultsSummaryNode = new TreeNode { Name = "ResultsSummary", // Not L10N Text = ResultText(table, "ResultsSummary") // Not L10N }; foreach (TreeNode treeNode in GetTreeNodes(Schema.GetClassMetadata(table.ResultsSummaryClass), identifier)) { ((NodeData)treeNode.Tag).ResultsSummary = true; resultsSummaryNode.Nodes.Add(treeNode); } treeNodes.Add(resultsSummaryNode); } treeNodes.AddRange(GetTreeNodes(classMetadata, identifier)); return treeNodes; }
public Identifier(String ancestor, Identifier descendents) : this(new[] { ancestor }, GetParts(descendents)) { }
protected static IEnumerable<Identifier> AddPrefix(IEnumerable<Identifier> source, Identifier prefix) { List<Identifier> result = new List<Identifier>(); foreach (Identifier id in source) { result.Add(new Identifier(prefix, id)); } return result; }