Ejemplo n.º 1
0
 public bool TrySelect(Identifier id)
 {
     Select(id);
     return treeView.SelectedNode != null;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 3
0
 public static Identifier ToResultsSummaryIdentifier(Identifier identifier)
 {
     return ToResultsIdentifier(identifier, "ResultSummary"); // Not L10N
 }
Ejemplo n.º 4
0
 public void Select(Identifier id)
 {
     treeView.SelectedNode = FindNode(treeView.Nodes, id);
 }
Ejemplo n.º 5
0
 public Identifier(Identifier parent, Identifier descendent)
     : this(GetParts(parent), GetParts(descendent))
 {
 }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 7
0
 private static Identifier JoinIds(Identifier prefix, Identifier suffix)
 {
     return new Identifier(prefix, suffix);
 }
Ejemplo n.º 8
0
 private static IEnumerable<string> GetParts(Identifier identifier)
 {
     if (identifier == null)
     {
         return new string[0];
     }
     return identifier.Parts;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 18
0
 public Identifier(Identifier parent, String name)
     : this(GetParts(parent), new[] { name })
 {
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 20
0
 public Identifier(String ancestor, Identifier descendents)
     : this(new[] { ancestor }, GetParts(descendents))
 {
 }
Ejemplo n.º 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;
 }