Exemple #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);
                }
            }));
        }
Exemple #2
0
        /// <summary>
        /// Open desired FolderElement and retrieves its content.
        /// Functionality for the M-Files FolderContentItem types: traditonal folder and external folder has not been implemented.
        /// </summary>
        /// <param name="elm">The FolderElement clicked in the user interface and passed to this function. If the FolderElement passed does not contain a valid lookup id,
        /// the ElementName property is used for resolving the next level.</param>
        /// <returns>List of FolderElements that represent the contents of the clicked FolderElement.</returns>
        /// <throws>Exception if a FolderContentItem is of either traditional or external type</throws>
        public List <FolderElement> GetNextFolder(FolderElement elm)
        {
            // Sanity!!
            if (null == elm)
            {
                throw new ArgumentNullException();
            }
            FolderDef  fDef = new FolderDef();
            TypedValue tv   = new TypedValue();

            if (elm.ElementType == ElementType.ViewFolder)
            {
                if (0 != elm.ElementId)
                {
                    fDef.SetView(elm.ElementId);
                }
                else
                {
                    throw new Exception(String.Format("A folderelement of type {0} was passed, containing an invalid elementId for the ViewFolder.", elm.ElementType.ToString()));
                }
            }
            if (elm.ElementType == ElementType.PropertyFolderVL)
            {
                if (0 != elm.ElementId)
                {
                    tv.SetValue(MFDataType.MFDatatypeLookup, elm.ElementId);
                    fDef.SetPropertyFolder(tv);
                }
                else
                {
                    throw new Exception(String.Format("A folderelement of type {0} was passed, containing an invalid elementId for the PropertyFolder.", elm.ElementType.ToString()));
                }
            }
            if (elm.ElementType == ElementType.PropertyFolderText)
            {
                if (elm.ElementName != "")
                {
                    tv.SetValue(MFDataType.MFDatatypeText, elm.ElementName);
                    fDef.SetPropertyFolder(tv);
                }
                else
                {
                    throw new Exception(String.Format("A folderelement of type {0} was passed, containing an empty ElementName property.", elm.ElementType.ToString()));
                }
            }
            if (elm.ElementType == ElementType.PropertyFolderInt)
            {
                if (elm.ElementName != "" && int.TryParse(elm.ElementName, out int res))
                {
                    tv.SetValue(MFDataType.MFDatatypeInteger, res);
                    fDef.SetPropertyFolder(tv);
                }
                else
                {
                    throw new Exception(String.Format("A folderelement of type {0} was passed. Unable to parse the ElementName property: {1}, it is either not a number or an empty string.", elm.ElementType.ToString(), elm.ElementName));
                }
            }
            if (elm.ElementType == ElementType.PropertyFolderDbl)
            {
                if (elm.ElementName != "" && decimal.TryParse(elm.ElementName, out decimal res))
                {
                    tv.SetValue(MFDataType.MFDatatypeFloating, res);
                    fDef.SetPropertyFolder(tv);
                }
                else
                {
                    throw new Exception(String.Format("A folderelement of type {0} was passed. Unable to parse the ElementName property: {1}, it is either not a decimal or an empty string.", elm.ElementType.ToString(), elm.ElementName));
                }
            }
            currentFolderDefs.Add(-1, fDef);
            return(GetElements(currentFolderDefs, elm));
        }