Beispiel #1
0
    // Returns the path to a specified folder relative to a root folder
    protected string GetRelativeName(Art dbFolder)
    {
        if (dbFolder.ID == DbRootItemId)
        {
            return(string.Empty);
        }
        if (dbFolder.ParentID == DbRootItemId)
        {
            return(dbFolder.Name);
        }
        if (!FolderCache.ContainsKey(dbFolder.ParentID.Value))
        {
            return(null);
        }
        string name = GetRelativeName(FolderCache[dbFolder.ParentID.Value]);

        return(name == null ? null : Path.Combine(name, dbFolder.Name));
    }
        public TreePath GetPath(ITabularObject item)
        {
            if (item == null)
            {
                return(TreePath.Empty);
            }

            var stack = new List <object>();

            stack.Add(Model);
            if (item is PartitionViewTable || item is Partition)
            {
                stack.Add(Model.Groups.Partitions);
                if (item is Partition)
                {
                    stack.Add((item as Partition).Table.PartitionViewTable);
                }
                stack.Add(item);
                return(new TreePath(stack.ToArray()));
            }

            if (Options.HasFlag(LogicalTreeOptions.AllObjectTypes) && item != Model)
            {
                // If "Show all object types" is enabled, we need to add the "group" of the item to the stack,
                // to get the complete path. The group can be determined from the type of object:
                switch (item.ObjectType)
                {
                case ObjectType.Culture: stack.Add(Model.Groups.Translations); break;

                case ObjectType.Role: stack.Add(Model.Groups.Roles); break;

                case ObjectType.Perspective: stack.Add(Model.Groups.Perspectives); break;

                case ObjectType.DataSource: stack.Add(Model.Groups.DataSources); break;

                case ObjectType.Relationship: stack.Add(Model.Groups.Relationships); break;

                default:
                    // All other object types should appear in the "Tables" group:
                    stack.Add(Model.Groups.Tables); break;
                }
            }
            if (item is Table)
            {
                stack.Add(item);
            }
            else if (item is ITabularTableObject)
            {
                stack.Add((item as ITabularTableObject).Table);

                var level = item as Level;
                if (level != null)
                {
                    item = level.Hierarchy;
                }

                if (item is IDetailObject && Options.HasFlag(LogicalTreeOptions.DisplayFolders))
                {
                    var dfo = item as IDetailObject;

                    var pathBits   = dfo.Table.Name.ConcatPath(dfo.GetDisplayFolder(Culture)).Split('\\');
                    var folderPath = dfo.Table.Name;
                    for (var i = 1; i < pathBits.Length; i++)
                    {
                        folderPath = folderPath.ConcatPath(pathBits[i]);
                        if (!FolderCache.ContainsKey(folderPath))
                        {
                            Folder.CreateFolder(dfo.Table, FolderHelper.PathFromFullPath(folderPath));
                        }
                        stack.Add(FolderCache[folderPath]);
                    }
                }

                stack.Add(item);
                if (level != null)
                {
                    stack.Add(level);
                }
            }
            return(new TreePath(stack.ToArray()));
        }