/DeveloperBranches/Ken/Previous/TreeBuilder/ViewModels/TreeBuilderTreeNodeFolder.cs
# · C# · 300 lines · 255 code · 45 blank · 0 comment · 12 complexity · 3afe51a3b56ec981a977c81365415d43 MD5 · raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using UIObjects.TreeViewInterfaces;
- using AbstraX.ClientInterfaces;
- using System.Collections.ObjectModel;
- using TreeBuilder.Contracts;
- using MvvmTreeView;
- using System.Windows.Controls;
- using System.Diagnostics;
- using SL4PopupMenu;
- using System.Windows;
-
- namespace TreeBuilder.ViewModels
- {
- public class TreeBuilderTreeNodeFolder : TreeBuilderTreeNodeBase
- {
- private ITreeNodeFolder folder;
- private bool allowDrop;
-
- public TreeBuilderTreeNodeFolder(ITreeBuilderService treeBuilderService, ITreeView treeView, ITreeNodeFolder folder, ITreeNode parent) : base(treeBuilderService, treeView, parent)
- {
- this.folder = folder;
- this.Tag = folder;
- this.allowDrop = true;
- }
-
- public override ITreeNodeBase InternalNodeObject
- {
- get
- {
- return folder;
- }
- }
-
- public override AbstraX.ClientInterfaces.IBase BaseObject
- {
- get
- {
- return folder.BaseObject;
- }
-
- set
- {
- folder.BaseObject = value;
- }
- }
-
- public override void Expand()
- {
- if (!this.IsChildrenLoaded)
- {
- folder.ChildrenLoaded += new TreeBuilder.Contracts.ChildrenLoadedHandler(OnChildrenLoaded);
- folder.LoadChildren();
- }
-
- base.Expand();
- }
-
- public override string Text
- {
- get
- {
- return folder.Text;
- }
-
- set
- {
- folder.Text = value;
- }
- }
-
- public void AddMemberAsNode(object sender, RoutedEventArgs r)
- {
- var rootElement = (IElement)folder.FolderItemSource;
- var menu = (PopupMenuItem)sender;
-
- if (rootElement.Attributes.Any(a => a.Name == (string)menu.Tag))
- {
- var attribute = rootElement.Attributes.Single(a => a.Name == (string)menu.Tag);
- var createOperation = treeBuilderService.CreateAttributeNode(folder, attribute);
-
- createOperation.NodeCreated += (parent, e) =>
- {
- this.Nodes.Add(new TreeBuilderTreeNodeAttributeNode(treeBuilderService, treeView, createOperation.NewNode, this) { ChildOrdinal = this.Nodes.Count });
- base.Expand();
- };
- }
- else if (rootElement.ChildElements.Any(e => e.Name == (string)menu.Tag))
- {
- var element = rootElement.ChildElements.Single(a => a.Name == (string)menu.Tag);
- var createOperation = treeBuilderService.CreateElementNode(folder, element);
-
- createOperation.NodeCreated += (parent, e) =>
- {
- this.Nodes.Add(new TreeBuilderTreeNodeElementNode(treeBuilderService, treeView, createOperation.NewNode, this) { ChildOrdinal = this.Nodes.Count });
- base.Expand();
- };
- }
- }
-
- private List<IContextMenuItem> GetSubMenus()
- {
- List<IContextMenuItem> subMenus = new List<IContextMenuItem>();
-
- if (folder.FolderItemSource is IElement)
- {
- IElement element = (IElement)folder.FolderItemSource;
-
- foreach (var childElement in element.ChildElements)
- {
- subMenus.Add(new ContextMenuItem(null, childElement.Name, childElement.Name, AddMemberAsNode));
- }
-
- foreach (var childElement in element.ChildElements)
- {
- subMenus.Add(new ContextMenuItem(null, childElement.Name, childElement.Name, AddMemberAsNode));
- }
- }
-
- return subMenus;
- }
-
- public void AddFolder(object sender, RoutedEventArgs r)
- {
- var createOperation = treeBuilderService.CreateFolderNode(folder, folder.FolderItemSource);
-
- createOperation.NodeCreated += (parent, e) =>
- {
- this.Nodes.Add(new TreeBuilderTreeNodeFolder(treeBuilderService, treeView, createOperation.NewNode, this) { ChildOrdinal = this.Nodes.Count });
- base.Expand();
- };
- }
-
- public override ContextMenu ContextMenu
- {
- get
- {
- if (contextMenu == null)
- {
- contextMenu = new ContextMenu
- {
- Items = new List<IContextMenuItem>()
- {
- new ContextMenuItem
- {
- Text = "Add Member as Node",
- Items = GetSubMenus(),
- },
- new ContextMenuItem(null, "Add Folder", null, AddFolder),
- new ContextMenuItem(null, "Add Query", null, AddQuery),
- new ContextMenuItem(null, "Add Advanced Query...", null, AddAdvancedQuery),
- }
- };
- }
-
- return contextMenu;
- }
-
- set
- {
- contextMenu = value;
- }
- }
-
- public override bool? HasChildren
- {
- get { throw new NotImplementedException(); }
- }
-
- public override string ID
- {
- get
- {
- return folder.ID;
- }
- }
-
- public override void LoadChildren()
- {
- folder.ChildrenLoaded += new TreeBuilder.Contracts.ChildrenLoadedHandler(OnChildrenLoaded);
- folder.LoadChildren();
- }
-
- public override IEnumerable<ITreeNodeBase> Children
- {
- get
- {
- return folder.Children;
- }
- }
-
- public override void Remove()
- {
- folder.RemovedSuccessfully += (node, e) =>
- {
- this.parent.Nodes.Remove(this);
-
- var op = treeBuilderService.OrphansExist();
-
- op.Completed += (sender, e2) =>
- {
- if (op.Value)
- {
- MessageBox.Show("Orphans exist!");
- }
- };
- };
-
- folder.Remove();
- }
-
- public override bool AllowDrop
- {
- get
- {
- return allowDrop;
- }
- set
- {
- allowDrop = value;
- }
- }
-
- public override ITreeNode ShallowClone()
- {
- throw new NotImplementedException();
- }
- public override void OnSelect()
- {
- }
- public override ITreeNode DeepClone()
- {
- throw new NotImplementedException();
- }
-
- public override bool AllowRename
- {
- get
- {
- throw new NotImplementedException();
- }
- set
- {
- throw new NotImplementedException();
- }
- }
-
- public override bool HasLayoverImage<T>(out T image)
- {
- return folder.HasLayoverImage<T>(out image);
- }
-
- public override void AddNew(string shortCut)
- {
- }
-
- public override void DragEnter(object sender, UIObjects.DragDropInterfaces.DragEventArgs e)
- {
- }
-
- public override void DragLeave(object sender, UIObjects.DragDropInterfaces.DragEventArgs e)
- {
- }
-
- public override void DragOver(object sender, UIObjects.DragDropInterfaces.DragEventArgs e)
- {
- }
-
- public override void DragStarting(object sender, UIObjects.DragDropInterfaces.ItemDragEventArgs e)
- {
- }
-
- public override void DragCompleted(object sender, UIObjects.DragDropInterfaces.ItemDragEventArgs e)
- {
- }
-
- public override void ItemDropped(object sender, UIObjects.DragDropInterfaces.ItemDragEventArgs e, int insertionIndex)
- {
- }
-
- public override void GiveFeedback(object sender, UIObjects.DragDropInterfaces.GiveFeedbackEventArgs e)
- {
- }
-
- public override float ChildOrdinal
- {
- get
- {
- return folder.ChildOrdinal;
- }
- set
- {
- folder.ChildOrdinal = value;
- }
- }
- }
- }