Esempio n. 1
0
        private void ExpandTreeViewItem(TreeViewItem parent, FolderDefs folderDefs = null)
        {
            // Sanity.
            if (null == parent)
            {
                return;
            }
            folderDefs = folderDefs ?? new FolderDefs();

            // Remove anything including the "loading" item.
            parent.Items.Clear();

            this.Dispatcher.BeginInvoke(new Action(() =>
            {
                // Get everything in the passed location.
                foreach (var item in vault.ViewOperations.GetFolderContents(folderDefs).Cast <FolderContentItem>())
                {
                    // Get the folder defs to use for this node.
                    var tag       = folderDefs.Clone();
                    var folderDef = new FolderDef();

                    // Create the tree view item depending on the type of item we've got.
                    var treeViewItem = new TreeViewItem();
                    switch (item.FolderContentItemType)
                    {
                    // Render views.
                    case MFFolderContentItemType.MFFolderContentItemTypeViewFolder:
                        {
                            // Set up the folder def to go "into" this view.
                            folderDef.SetView(item.View.ID);

                            // Set the header to the view name.
                            treeViewItem.Header = item.View.Name;
                        }
                        break;

                    // Render property groups.
                    case MFFolderContentItemType.MFFolderContentItemTypePropertyFolder:
                        {
                            // Set up the folder def to go "into" this grouping.
                            folderDef.SetPropertyFolder(item.PropertyFolder);

                            // Set the header to the grouping name.
                            treeViewItem.Header = item.PropertyFolder.DisplayValue;
                        }
                        break;

                    default:
                        // We should also handle other types of content, but this will do for now.
                        continue;
                    }
                    if (null == treeViewItem.Header)
                    {
                        continue;
                    }

                    // Set up the tag.
                    tag.Add(tag.Count + 1, folderDef);
                    treeViewItem.Tag = tag;

                    // Add the item to the list.
                    treeViewItem.Items.Add(new TreeViewItem()
                    {
                        Header = "Loading...", IsEnabled = false
                    });
                    treeViewItem.Expanded += TreeViewItem_Expanded;
                    parent.Items.Add(treeViewItem);
                }
            }));
        }
Esempio n. 2
0
        // Helper method to get FolderContentItems from the vault and convert them to FolderElements
        private List <FolderElement> GetElements(FolderDefs folderDefs, FolderElement elm = null)
        {
            currentFolderContent = new List <FolderElement>();
            // get the collection of FolderContentItems
            var content = vault.ViewOperations.GetFolderContents(folderDefs);

            if (content.Count == 0)
            {
                // the selscted FolderElement is an empty folder. Can be prevented by setting filter on View to only show documents.
                FolderElement e = new FolderElement()
                {
                    ElementId = 0, ElementName = "Nothing to see here!", ElementType = ElementType.PropertyFolderVL
                };
                currentFolderContent.Add(e);
                ListCurrentFolderElements(currentFolderContent); // for testing!!
                return(currentFolderContent);

                //Optionally we throw an exception
                throw new EmptyFolderException(folderDefs.Count, elm.ElementName);
            }
            foreach (var item in content)
            {
                FolderElement e = new FolderElement();
                if ((item as FolderContentItem).FolderContentItemType == MFFolderContentItemType.MFFolderContentItemTypePropertyFolder)
                {
                    //convert to FolderElement with appropriate data and add to list of folderelement
                    TypedValue tv = (item as FolderContentItem).PropertyFolder;
                    e.ElementName = tv.DisplayValue;
                    if (tv.DataType == MFDataType.MFDatatypeLookup)
                    {
                        e.ElementId   = tv.GetLookupID();
                        e.ElementType = ElementType.PropertyFolderVL;
                    }
                    else
                    {
                        e.ElementId = 0;
                    }
                    if (tv.DataType == MFDataType.MFDatatypeText)
                    {
                        e.ElementType = ElementType.PropertyFolderText;
                    }
                    if (tv.DataType == MFDataType.MFDatatypeInteger)
                    {
                        e.ElementType = ElementType.PropertyFolderInt;
                    }
                    if (tv.DataType == MFDataType.MFDatatypeFloating)
                    {
                        e.ElementType = ElementType.PropertyFolderDbl;
                    }
                    currentFolderContent.Add(e);
                    continue;
                }

                if ((item as FolderContentItem).FolderContentItemType == MFFolderContentItemType.MFFolderContentItemTypeViewFolder)
                {
                    //convert to FolderElement with appropriate data and add to list of folderelement
                    View v = (item as FolderContentItem).View;
                    e.ElementName = v.Name;
                    e.ElementId   = v.ID;
                    e.ElementType = ElementType.ViewFolder;

                    currentFolderContent.Add(e);
                    continue;
                }
                if ((item as FolderContentItem).FolderContentItemType == MFFolderContentItemType.MFFolderContentItemTypeObjectVersion)
                {
                    //convert to FolderElement with appropriate data and add to list of folderelement
                    ObjectVersion obj = (item as FolderContentItem).ObjectVersion;
                    // we will not display objects that are not documents. Depending on customers use, we may need  implement functionality that works for document collections
                    if (obj.ObjVer.Type != (int)MFBuiltInObjectType.MFBuiltInObjectTypeDocument || obj.FilesCount == 0)
                    {
                        continue;
                    }
                    e.ElementName = obj.Title;
                    e.ElementId   = obj.ObjVer.ID;
                    if (obj.FilesCount != 1 && obj.FilesCount > 0)
                    {
                        e.ElementType = ElementType.MultiFile;
                    }
                    else
                    {
                        e.ElementType = ElementType.Document;
                    }

                    currentFolderContent.Add(e);
                    continue;
                }
                else
                {
                    throw new NotImplementedException(String.Format("Unable to process FolderContentItem of type: {0}", (item as FolderContentItem).FolderContentItemType.ToString()));
                }


                //convert to FolderElement with appropriate data and add to list of folderelement
            }
            if (!(currentFolderContent.Count > 0))
            {
                //the selected folder contains only empty multi-file documents
                FolderElement e = new FolderElement()
                {
                    ElementId = 0, ElementName = "Nothing to see here!", ElementType = ElementType.PropertyFolderVL
                };
                currentFolderContent.Add(e);
                ListCurrentFolderElements(currentFolderContent); // for testing!!
                return(currentFolderContent);

                //Optionally we throw an exception
                throw new EmptyFolderException(folderDefs.Count, elm.ElementName);
            }
            ListCurrentFolderElements(currentFolderContent); // for testing!!
            // Set the global boolean canNavigateBackwards to true
            canNavigateBackwards = true;
            //return list of FolderElements
            return(currentFolderContent);
        }