public static TreeItemType SwitchItems(ICanvas canvas,
                                               IDiagramCreator creator,
                                               ITreeItem oldItem,
                                               ITreeItem newItem,
                                               Action <DiagramProperties> setProperties)
        {
            if (newItem == null)
            {
                return(TreeItemType.None);
            }

            var oldItemType = GetTreeItemType(oldItem == null ? null : oldItem.GetUid());
            var newItemType = GetTreeItemType(newItem == null ? null : newItem.GetUid());

            if (oldItemType == TreeItemType.Diagram)
            {
                ModelEditor.Store(canvas, oldItem);
            }

            if (newItemType == TreeItemType.Diagram)
            {
                ModelEditor.Load(canvas, creator, newItem);

                if (setProperties != null)
                {
                    setProperties(canvas.GetProperties());
                }
            }

            return(newItemType);
        }
        public static void AddDiagram(ITreeItem project,
                                      bool select,
                                      Func <ITreeItem> createDiagram,
                                      IdCounter counter)
        {
            var diagram = CreateDiagramItem(null, createDiagram, counter);

            project.Add(diagram);

            ModelEditor.Store(null, diagram);

            if (select == true)
            {
                diagram.SetSelected(true);
            }
        }