示例#1
0
 public bool TrySelect(Identifier id)
 {
     Select(id);
     return treeView.SelectedNode != null;
 }
示例#2
0
        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;
        }
示例#3
0
 public static Identifier ToResultsSummaryIdentifier(Identifier identifier)
 {
     return ToResultsIdentifier(identifier, "ResultSummary"); // Not L10N
 }
示例#4
0
 public void Select(Identifier id)
 {
     treeView.SelectedNode = FindNode(treeView.Nodes, id);
 }
示例#5
0
 public Identifier(Identifier parent, Identifier descendent)
     : this(GetParts(parent), GetParts(descendent))
 {
 }
示例#6
0
        /// <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));
            }
        }
示例#7
0
 private static Identifier JoinIds(Identifier prefix, Identifier suffix)
 {
     return new Identifier(prefix, suffix);
 }
示例#8
0
 private static IEnumerable<string> GetParts(Identifier identifier)
 {
     if (identifier == null)
     {
         return new string[0];
     }
     return identifier.Parts;
 }
示例#9
0
 /// <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;
 }
示例#10
0
 /// <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;
 }
示例#11
0
 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;
 }
示例#12
0
 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;
 }
示例#13
0
 /// <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;
     }
 }
示例#14
0
 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);
 }
示例#15
0
 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));
 }
示例#16
0
 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;
 }
示例#17
0
 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);
 }
示例#18
0
 public Identifier(Identifier parent, String name)
     : this(GetParts(parent), new[] { name })
 {
 }
示例#19
0
 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;
 }
示例#20
0
 public Identifier(String ancestor, Identifier descendents)
     : this(new[] { ancestor }, GetParts(descendents))
 {
 }
示例#21
0
 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;
 }