PageRenderTime 64ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/DeveloperBranches/Ken/Previous/TreeBuilder/ViewModels/TreeBuilderTreeNodeMenuItem.cs

#
C# | 372 lines | 311 code | 58 blank | 3 comment | 10 complexity | 44339d1550fc1656384a3b88fe20fea1 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UIObjects.TreeViewInterfaces;
  6. using AbstraX.ClientInterfaces;
  7. using System.Collections.ObjectModel;
  8. using TreeBuilder.Contracts;
  9. using MvvmTreeView;
  10. using System.Windows.Controls;
  11. using System.Diagnostics;
  12. using SL4PopupMenu;
  13. using System.Windows;
  14. namespace TreeBuilder.ViewModels
  15. {
  16. public class TreeBuilderTreeNodeMenuItem : TreeBuilderTreeNodeImageNode
  17. {
  18. private ITreeNodeMenuItem menuItem;
  19. private bool allowDrop;
  20. public TreeBuilderTreeNodeMenuItem(ITreeBuilderService treeBuilderService, ITreeView treeView, ITreeNodeMenuItem menuItem, ITreeNode parent) : base(treeBuilderService, treeView, parent)
  21. {
  22. this.menuItem = menuItem;
  23. this.Tag = menuItem;
  24. this.allowDrop = true;
  25. this.menuItem.ImageAvailable += new ImageNodeImageAvailableHandler(NotifyImageAvailable);
  26. }
  27. public override ITreeNodeImage TreeNodeImage
  28. {
  29. get
  30. {
  31. return this.menuItem.TreeNodeImage;
  32. }
  33. set
  34. {
  35. this.menuItem.TreeNodeImage = value;
  36. }
  37. }
  38. public override ITreeNodeBase InternalNodeObject
  39. {
  40. get
  41. {
  42. return menuItem;
  43. }
  44. }
  45. public override IBase BaseObject
  46. {
  47. get
  48. {
  49. return menuItem.MenuSource;
  50. }
  51. set
  52. {
  53. menuItem.MenuSource = value;
  54. }
  55. }
  56. public override void Expand()
  57. {
  58. if (!this.IsChildrenLoaded)
  59. {
  60. menuItem.ChildrenLoaded += new TreeBuilder.Contracts.ChildrenLoadedHandler(OnChildrenLoaded);
  61. menuItem.LoadChildren();
  62. }
  63. base.Expand();
  64. }
  65. public override string Text
  66. {
  67. get
  68. {
  69. return menuItem.Text;
  70. }
  71. set
  72. {
  73. menuItem.Text = value;
  74. }
  75. }
  76. public void AddSubMenu(object sender, RoutedEventArgs r)
  77. {
  78. var createOperation = treeBuilderService.CreateMenuItem(menuItem, this.BaseObject);
  79. createOperation.NodeCreated += (parent, e) =>
  80. {
  81. this.Nodes.Add(new TreeBuilderTreeNodeMenuItem(treeBuilderService, treeView, createOperation.NewNode, this) { ChildOrdinal = this.Nodes.Count });
  82. base.Expand();
  83. };
  84. }
  85. public void AddOperationMenu(IOperation operation)
  86. {
  87. var createOperation = treeBuilderService.CreateMenuItem(menuItem, this.BaseObject, operation);
  88. createOperation.NodeCreated += (parent, e) =>
  89. {
  90. this.Nodes.Add(new TreeBuilderTreeNodeMenuItem(treeBuilderService, treeView, createOperation.NewNode, this) { ChildOrdinal = this.Nodes.Count });
  91. base.Expand();
  92. };
  93. }
  94. public void AddStockActionMenu(TreeNodeMenuItemStockAction stockAction, StockActionMenuAttribute stockActionMenuAttribute)
  95. {
  96. var createOperation = treeBuilderService.CreateMenuItem(menuItem, this.BaseObject, stockAction);
  97. createOperation.NodeCreated += (parent, e) =>
  98. {
  99. this.Nodes.Add(new TreeBuilderTreeNodeMenuItem(treeBuilderService, treeView, createOperation.NewNode, this) { ChildOrdinal = this.Nodes.Count });
  100. base.Expand();
  101. if (stockActionMenuAttribute.SpecialStockActionMenu != null)
  102. {
  103. Debugger.Break();
  104. }
  105. };
  106. }
  107. private List<IContextMenuItem> GetStockActionMenus()
  108. {
  109. var subMenus = new List<IContextMenuItem>();
  110. foreach (var field in typeof(TreeNodeMenuItemStockAction).GetFields())
  111. {
  112. if ((field.Attributes & System.Reflection.FieldAttributes.Static) > 0)
  113. {
  114. var stockActionMenuAttribute = (StockActionMenuAttribute)field.GetCustomAttributes(typeof(StockActionMenuAttribute), true).Single();
  115. var stockAction = (TreeNodeMenuItemStockAction)field.GetValue(null);
  116. subMenus.Add(new ContextMenuItem(null, stockActionMenuAttribute.DisplayText, stockActionMenuAttribute.ToString(), (sender, e) =>
  117. {
  118. AddStockActionMenu(stockAction, stockActionMenuAttribute);
  119. }));
  120. }
  121. }
  122. return subMenus;
  123. }
  124. private List<IContextMenuItem> GetMenuItemSourceSubMenus()
  125. {
  126. List<IContextMenuItem> subMenus = new List<IContextMenuItem>();
  127. if (this.BaseObject is IElement)
  128. {
  129. IElement element = (IElement)this.BaseObject;
  130. foreach (var childElement in element.ChildElements)
  131. {
  132. if (childElement.DataType.IsCollectionType)
  133. {
  134. var bindElement = childElement;
  135. subMenus.Add(new ContextMenuItem(null, bindElement.Name, bindElement.Name, (sender, e) =>
  136. {
  137. //AddNodePropertyBinding(TreeNodePropertyType.Children, bindElement);
  138. }));
  139. }
  140. }
  141. }
  142. subMenus.Add(new ContextMenuItem(null, "Query...", "CreateQueryChildrenValue", (sender, e) =>
  143. {
  144. //AddNodePropertyBinding(TreeNodePropertyType.Children, TreeNodePropertyStockBinding.FromQuery);
  145. }));
  146. subMenus.Add(new ContextMenuItem(null, "Advanced Query...", "CreateQueryChildrenValue", (sender, e) =>
  147. {
  148. //AddNodePropertyBinding(TreeNodePropertyType.Children, TreeNodePropertyStockBinding.FromQuery);
  149. }));
  150. return subMenus;
  151. }
  152. private List<IContextMenuItem> GetOperationMenus()
  153. {
  154. List<IContextMenuItem> subMenus = new List<IContextMenuItem>();
  155. if (menuItem.MenuSource is IElement)
  156. {
  157. IElement element = (IElement)menuItem.MenuSource;
  158. foreach (var operation in element.Operations)
  159. {
  160. subMenus.Add(new ContextMenuItem(null, operation.Name, operation.Name, (sender, e) =>
  161. {
  162. AddOperationMenu(operation);
  163. }));
  164. }
  165. }
  166. subMenus.Add(new ContextMenuItem(null, "Query", null, AddQuery));
  167. subMenus.Add(new ContextMenuItem(null, "Advanced Query...", null, AddAdvancedQuery));
  168. return subMenus;
  169. }
  170. public override ContextMenu ContextMenu
  171. {
  172. get
  173. {
  174. if (contextMenu == null)
  175. {
  176. contextMenu = new ContextMenu
  177. {
  178. Items = new List<IContextMenuItem>()
  179. {
  180. new ContextMenuItem(null, "Add Sub Menu", null, AddSubMenu),
  181. new ContextMenuItem
  182. {
  183. Text = "Add Stock Menu",
  184. Items = GetStockActionMenus()
  185. },
  186. new ContextMenuItem
  187. {
  188. Text = "Add Menu Bound To",
  189. Items = GetOperationMenus()
  190. },
  191. new ContextMenuItem
  192. {
  193. Text = "Add Menu Item Source From",
  194. Items = GetMenuItemSourceSubMenus()
  195. }
  196. }
  197. };
  198. }
  199. return contextMenu;
  200. }
  201. set
  202. {
  203. contextMenu = value;
  204. }
  205. }
  206. public override bool? HasChildren
  207. {
  208. get { throw new NotImplementedException(); }
  209. }
  210. public override string ID
  211. {
  212. get
  213. {
  214. return menuItem.ID;
  215. }
  216. }
  217. public override void LoadChildren()
  218. {
  219. menuItem.ChildrenLoaded += new TreeBuilder.Contracts.ChildrenLoadedHandler(OnChildrenLoaded);
  220. menuItem.LoadChildren();
  221. }
  222. public override IEnumerable<ITreeNodeBase> Children
  223. {
  224. get
  225. {
  226. return menuItem.Children;
  227. }
  228. }
  229. public override void Remove()
  230. {
  231. menuItem.RemovedSuccessfully += (node, e) =>
  232. {
  233. this.parent.Nodes.Remove(this);
  234. var op = treeBuilderService.OrphansExist();
  235. op.Completed += (sender, e2) =>
  236. {
  237. if (op.Value)
  238. {
  239. MessageBox.Show("Orphans exist!");
  240. }
  241. };
  242. };
  243. menuItem.Remove();
  244. }
  245. public override bool AllowDrop
  246. {
  247. get
  248. {
  249. return allowDrop;
  250. }
  251. set
  252. {
  253. allowDrop = value;
  254. }
  255. }
  256. public override ITreeNode ShallowClone()
  257. {
  258. throw new NotImplementedException();
  259. }
  260. public override void OnSelect()
  261. {
  262. }
  263. public override ITreeNode DeepClone()
  264. {
  265. throw new NotImplementedException();
  266. }
  267. public override bool AllowRename
  268. {
  269. get
  270. {
  271. throw new NotImplementedException();
  272. }
  273. set
  274. {
  275. throw new NotImplementedException();
  276. }
  277. }
  278. public override void AddNew(string shortCut)
  279. {
  280. }
  281. public override void DragEnter(object sender, UIObjects.DragDropInterfaces.DragEventArgs e)
  282. {
  283. }
  284. public override void DragLeave(object sender, UIObjects.DragDropInterfaces.DragEventArgs e)
  285. {
  286. }
  287. public override void DragOver(object sender, UIObjects.DragDropInterfaces.DragEventArgs e)
  288. {
  289. }
  290. public override void DragStarting(object sender, UIObjects.DragDropInterfaces.ItemDragEventArgs e)
  291. {
  292. }
  293. public override void DragCompleted(object sender, UIObjects.DragDropInterfaces.ItemDragEventArgs e)
  294. {
  295. }
  296. public override void ItemDropped(object sender, UIObjects.DragDropInterfaces.ItemDragEventArgs e, int insertionIndex)
  297. {
  298. }
  299. public override void GiveFeedback(object sender, UIObjects.DragDropInterfaces.GiveFeedbackEventArgs e)
  300. {
  301. }
  302. public override float ChildOrdinal
  303. {
  304. get
  305. {
  306. return menuItem.ChildOrdinal;
  307. }
  308. set
  309. {
  310. menuItem.ChildOrdinal = value;
  311. }
  312. }
  313. }
  314. }