Example #1
0
        public static List <TreeElementType> GenerateFlatTree <TreeElementType, DataType>(params DataType[] elements)
            where TreeElementType : TreeElement <DataType>, new()
            where DataType : class, IStratusLabeled
        {
            List <TreeElementType> treeList = new List <TreeElementType>();

            int idCounter = 0;

            // Add root
            TreeElementType root = new TreeElementType();

            root.name  = "Root";
            root.depth = -1;
            root.id    = idCounter++;
            treeList.Add(root);

            // Add the elements right below root
            foreach (var element in elements)
            {
                TreeElementType child = new TreeElementType();
                child.Set(element);
                child.depth = 0;
                child.id    = idCounter++;
                treeList.Add(child);
            }

            return(treeList);
        }
Example #2
0
        public static TreeElementType MakeRoot <TreeElementType>()
            where TreeElementType : TreeElement, new()
        {
            TreeElementType root = new TreeElementType();

            root.name  = "Root";
            root.depth = -1;
            root.id    = 0;
            return(root);
        }
        public TreeElementViewModel(ApplicationViewModel application, string name, TreeElementType? treeElementType = null)
        {
            _application = application;
            Name = name;
            Type = treeElementType.GetValueOrDefault(GuessElementTypeByFileExtension(name));
            _children = new ObservableCollection<TreeElementViewModel>();
            Children = new ReadOnlyObservableCollection<TreeElementViewModel>(_children);

            _commands = new ObservableCollection<CommandViewModel>();
            Commands = new ReadOnlyObservableCollection<CommandViewModel>(_commands);

            if (treeElementType.GetValueOrDefault(TreeElementType.Folder) != TreeElementType.Folder)
            {
                DefaultActionCommand = new CommandViewModel(OnDefaultActionCommand, "Open");

                _commands.Add(DefaultActionCommand);
            }
        }