public void ChangeNodeType(String ToType)
        {
            if (treeView1.SelectedItem == null)
            {
                return;
            }
            treeView1.SelectedItem.EndEdit();
            String FromType = treeView1.SelectedItem.NodeData.DataItem.NodeType;

            NodeDataObject nodeDataObject = treeView1.SelectedItem.NodeData;

            if (nodeDataObject.DataItem.NodeType == ToType)
            {
                MessageBox.Show(String.Format("本节点己经是{0}型的了。", ToType));
                return;
            }
            if (NodeTypeChanger.CanChangeTo(FromType, ToType) == false)
            {
                MessageBox.Show(string.Format("不能完成从{0}到{1}类型的转换。", FromType, ToType));
                return;
            }

            NodeDataObject detailTextNodeDataObject = NodeTypeChanger.GetNodeChanger(FromType, ToType).ChangeTo(nodeDataObject, DALConfig.getEFConnectionString(dbInfoObject.DatabaseFilePath));

            if (detailTextNodeDataObject != null)
            {
                treeView1.SelectedItem.NodeData = detailTextNodeDataObject;
                ChangeNodeIcon(treeView1.SelectedItem, detailTextNodeDataObject.DataItem.SelectedIcon);
                LoadDataAndShowInUI(treeView1.SelectedItem);
                SaveTreeToDB();
            }
        }
Beispiel #2
0
        /// <summary>
        /// 依据节点类型创建"空白"的数据信息对象,其HasBeenLoadFromStorage属性为false
        /// (无需数据存储的节点,如OnlyText例此,其HasBeenLoadFromStorage始终为true)
        /// </summary>
        /// <param name="treeNodeType"></param>
        /// <returns></returns>
        public static NodeDataObject CreateDataInfoNode(String treeNodeType, String EFConnectionString)
        {
            NodeDataObject nodeDataObject = new NodeDataObject();

            if (treeNodeType == "InfoNode")
            {
                InfoNodeDataInfo info = new InfoNodeDataInfo()
                {
                    MainWindow = _mainWindow
                };
                InfoNodeAccess access = new InfoNodeAccess(EFConnectionString);
                info.SetRootControlDataAccessObj(access);

                nodeDataObject.DataItem = info;
                //设置数据未装入标记
                nodeDataObject.DataItem.HasBeenLoadFromStorage = false;

                nodeDataObject.AccessObject = access;
            }
            if (treeNodeType == "LabelNode")
            {
                LabelNodeDataInfo info = new LabelNodeDataInfo()
                {
                    MainWindow = _mainWindow
                };
                LabelNodeAccess accessObj = new LabelNodeAccess(EFConnectionString);
                info.SetRootControlDataAccessObj(accessObj);
                nodeDataObject.DataItem = info;
                //设置数据未装入标记
                nodeDataObject.DataItem.HasBeenLoadFromStorage = false;
                nodeDataObject.AccessObject = accessObj;
            }
            return(nodeDataObject);
        }
 /// <summary>
 /// 添加兄弟节点,如果参数中有为null或空串的,或者当前TreeView中没有选中的节点,返回null
 /// </summary>
 /// <param name="nodeText"></param>
 /// <param name="nodeIcon"></param>
 /// <returns></returns>
 public TreeViewIconsItem AddSibling(String nodeText, NodeDataObject nodeDataObject)
 {
     if (String.IsNullOrEmpty(nodeText) || tree.SelectedItem == null)
     {
         return(null);
     }
     return(addNode(AddNodeCategory.AddSibling, tree.SelectedItem as TreeViewIconsItem, nodeText, nodeDataObject));
 }
 /// <summary>
 /// 添加根节点,如果参数中有为null或空串的,返回null
 /// </summary>
 /// <param name="nodeText"></param>
 /// <param name="nodeIcon"></param>
 /// <returns></returns>
 public TreeViewIconsItem AddRoot(String nodeText, NodeDataObject nodeDataObject)
 {
     if (String.IsNullOrEmpty(nodeText))
     {
         return(null);
     }
     return(addNode(AddNodeCategory.AddRoot, null, nodeText, nodeDataObject));
 }
        public NodeDataObject ChangeTo(NodeDataObject sourceObject, String EFConnectionString)
        {
            NodeDataObject dataObject = NodeFactory.CreateDataInfoNode("DetailText", EFConnectionString);

            dataObject.DataItem.Path = sourceObject.DataItem.Path;
            //在数据库中创建对象
            dataObject.AccessObject.Create(dataObject.DataItem);
            return(dataObject);
        }
        public NodeDataObject ChangeTo(NodeDataObject sourceObject, String EFConnectionString)
        {
            NodeDataObject dataObject = NodeFactory.CreateDataInfoNode("OnlyText", EFConnectionString);

            dataObject.DataItem.Path = sourceObject.DataItem.Path;
            //在数据库中删除记录
            sourceObject.AccessObject.DeleteDataInfoObject(sourceObject.DataItem);
            return(dataObject);
        }
Beispiel #7
0
        public InterfaceLibrary.NodeDataObject ChangeTo(InterfaceLibrary.NodeDataObject sourceObject, String EFConnectionString)
        {
            NodeDataObject dataObject = NodeFactory.CreateDataInfoNode("Folder", EFConnectionString);

            dataObject.DataItem.Path = sourceObject.DataItem.Path;
            //在数据库中创建对象
            dataObject.AccessObject.Create(dataObject.DataItem);
            return(dataObject);
        }
Beispiel #8
0
        /// <summary>
        /// 再标签节点中显示信息节点内容
        /// </summary>
        /// <param name="newSelectedNode"></param>
        private void LoadDataAndShowInLabelNodeUI(TreeViewIconsItem newSelectedNode)
        {
            NodeDataObject dataInfoObject = newSelectedNode.NodeData;

            //正确地设置可视化界面所关联的数据存取对象
            dataInfoObject.DataItem.SetRootControlDataAccessObj(dataInfoObject.AccessObject);

            //检查一下数据是否己被装入
            if (!dataInfoObject.DataItem.HasBeenLoadFromStorage)
            {
                //装入数据
                IDataInfo dataObj = dataInfoObject.AccessObject.GetDataInfoObjectByPath(newSelectedNode.Path);

                if (dataObj != null)
                {
                    //给将己装入数据的对象添加对主窗体的引用
                    if (NodeFactory._mainWindow != null)
                    {
                        dataObj.MainWindow = NodeFactory._mainWindow;
                    }
                    //把节点数据对象挂到节点上
                    newSelectedNode.NodeData.DataItem = dataObj;
                }
            }

            if (dataInfoObject.DataItem.ShouldEmbedInHostWorkingBench)
            {
                if (dataInfoObject.DataItem.RootControl.Parent != null)
                {
                    (dataInfoObject.DataItem.RootControl.Parent as ContentControl).Content = null;
                }

                (NodeUIContainer.Content as LabelNodeControl).InnerContainer.Content = dataInfoObject.DataItem.RootControl;


                if (dataInfoObject.DataItem.RootControl is InfoNodeControl)
                {
                    (dataInfoObject.DataItem.RootControl as InfoNodeControl).InnerSuperRichTextBox.EditorTool = EditorTool;
                }


                //根节点不显示内容
                if (newSelectedNode.Parent is TreeView)
                {
                    NodeUIContainer.Content = null;
                }
            }
            //显示最新的数据
            dataInfoObject.DataItem.BindToRootControl();
            dataInfoObject.DataItem.RefreshDisplay();
        }
Beispiel #9
0
        /// <summary>
        /// 依据数据库连接字串(EntityFramework格式)创建合适的IDataAcess对象
        /// </summary>
        /// <param name="treeNodeType"></param>
        /// <param name="EFConnectionString"></param>
        /// <returns></returns>
        public static IDataAccess CreateNodeAccessObject(String treeNodeType, String EFConnectionString)
        {
            NodeDataObject nodeDataObject = new NodeDataObject();

            if (treeNodeType == "InfoNode")
            {
                return(new InfoNodeAccess(EFConnectionString));
            }
            if (treeNodeType == "LabelNode")
            {
                return(new LabelNodeAccess(EFConnectionString));
            }
            return(null);
        }
        public InterfaceLibrary.NodeDataObject ChangeTo(InterfaceLibrary.NodeDataObject sourceObject, String EFConnectionString)
        {
            FolderInfo     folderInfo = sourceObject.DataItem as FolderInfo;
            NodeDataObject dataObject = NodeFactory.CreateDataInfoNode("DetailText", EFConnectionString);
            DetailTextInfo detailInfo = dataObject.DataItem as DetailTextInfo;

            detailInfo.Path    = sourceObject.DataItem.Path;
            detailInfo.Text    = folderInfo.Text;
            detailInfo.RTFText = folderInfo.RTFText;
            //在数据库中删除记录
            sourceObject.AccessObject.DeleteDataInfoObject(folderInfo);
            //在数据库中创建对象
            dataObject.AccessObject.Create(detailInfo);
            return(dataObject);
        }
        public TreeViewIconsItem(SuperTreeView tree, NodeDataObject dataObject)
        {
            belongToTreeView = tree;
            _dataObject      = dataObject;

            //以下处理UI控件
            headerContainer = new StackPanel();


            //  设置StackPanel中的内容水平排列
            headerContainer.Orientation = Orientation.Horizontal;
            //将Header设置为StackPanel
            Header = headerContainer;
            //设置正常状态下的显示控件
            _iconImageControl = new Image();
            _iconImageControl.VerticalAlignment = VerticalAlignment.Center;
            _iconImageControl.Margin            = new Thickness(0, 0, 4, 0);
            _iconImageControl.Source            = _icon;
            //  向StackPanel对象中添加一个图标对象
            headerContainer.Children.Add(_iconImageControl);

            //  创建用于添加文本信息的TextBlock对象
            textBlock                   = new TextBlock();
            textBlock.FontSize          = TreeNodeDefaultFontSize;
            textBlock.VerticalAlignment = VerticalAlignment.Center;
            //  向StackPanel对象中添加文本信息
            headerContainer.Children.Add(textBlock);

            //实例化文本框控件,准备用于编辑
            edtText          = new TextBox();
            edtText.FontSize = TreeNodeDefaultFontSize;
            edtText.MinWidth = 100;
            //对事件进行响应
            edtText.KeyDown   += edtText_KeyDown;
            edtText.LostFocus += edtText_LostFocus;
            //由于默认情况下WPF的TextBox的Cut存在BUG:即完成复制工作但却不删除选中的文字,因此不得不用自己的代码取代默认的命令响应代码
            CommandBinding bind = new CommandBinding();

            bind.Command     = ApplicationCommands.Cut;
            bind.Executed   += bind_Executed;
            bind.CanExecute += bind_CanExecute;
            edtText.CommandBindings.Add(bind);
            //使用当前时间作为本Item的ID
            id = TimerUtils.getHighPrecisionCurrentTime();
        }
        /// <summary>
        /// 依据数据库连接字串(EntityFramework格式)创建合适的IDataAcess对象
        /// </summary>
        /// <param name="NodeType"></param>
        /// <param name="EFConnectionString"></param>
        /// <returns></returns>
        public static IDataAccess CreateNodeAccessObject(String NodeType, String EFConnectionString)
        {
            NodeDataObject nodeDataObject = new NodeDataObject();

            if (NodeType == "OnlyText")
            {
                return(null);
            }
            if (NodeType == "Folder")
            {
                return(new FolderAccess(EFConnectionString));
            }
            if (NodeType == "DetailText")
            {
                return(new DetailTextAccess(EFConnectionString));
            }
            return(null);
        }
        /// <summary>
        /// 依据节点类型创建"空白"的数据信息对象,其HasBeenLoadFromStorage属性为false
        /// (无需数据存储的节点,如OnlyText例此,其HasBeenLoadFromStorage始终为true)
        /// </summary>
        /// <param name="NodeType"></param>
        /// <returns></returns>
        public static NodeDataObject CreateDataInfoNode(String NodeType, String EFConnectionString)
        {
            NodeDataObject nodeDataObject = new NodeDataObject();

            if (NodeType == "OnlyText")
            {
                nodeDataObject.DataItem = new OnlyTextInfo()
                {
                    MainWindow = _mainWindow
                };
                nodeDataObject.AccessObject = null;
            }
            if (NodeType == "Folder")
            {
                FolderInfo info = new FolderInfo()
                {
                    MainWindow = _mainWindow
                };
                FolderAccess access = new FolderAccess(EFConnectionString);
                info.SetRootControlDataAccessObj(access);

                nodeDataObject.DataItem = info;
                //设置数据未装入标记
                nodeDataObject.DataItem.HasBeenLoadFromStorage = false;

                nodeDataObject.AccessObject = access;
            }
            if (NodeType == "DetailText")
            {
                DetailTextInfo info = new DetailTextInfo()
                {
                    MainWindow = _mainWindow
                };
                DetailTextAccess accessObj = new DetailTextAccess(EFConnectionString);

                info.SetRootControlDataAccessObj(accessObj);
                nodeDataObject.DataItem = info;
                //设置数据未装入标记
                nodeDataObject.DataItem.HasBeenLoadFromStorage = false;

                nodeDataObject.AccessObject = accessObj;
            }
            return(nodeDataObject);
        }
        /// <summary>
        /// 为新节点提取数据并显示
        /// </summary>
        /// <param name="newSelectedNode"></param>
        private void LoadDataAndShowInUI(TreeViewIconsItem newSelectedNode)
        {
            if (newSelectedNode.NodeData.DataItem.NodeType == "OnlyText")
            {
                NodeUIContainer.Content = null;
                newSelectedNode.NodeData.DataItem.RefreshDisplay();
                return;
            }
            NodeDataObject dataInfoObject = newSelectedNode.NodeData;

            //正确地设置可视化界面所关联的数据存取对象
            dataInfoObject.DataItem.SetRootControlDataAccessObj(dataInfoObject.AccessObject);

            //检查一下数据是否己被装入
            if (!dataInfoObject.DataItem.HasBeenLoadFromStorage)
            {
                //装入数据
                IDataInfo dataObj = dataInfoObject.AccessObject.GetDataInfoObjectByPath(newSelectedNode.Path);

                if (dataObj != null)
                {
                    //给将己装入数据的对象添加对主窗体的引用
                    if (NodeFactory._mainWindow != null)
                    {
                        dataObj.MainWindow = NodeFactory._mainWindow;
                    }
                    //把节点数据对象挂到节点上
                    newSelectedNode.NodeData.DataItem = dataObj;
                }
            }

            if (dataInfoObject.DataItem.ShouldEmbedInHostWorkingBench)
            {
                if (dataInfoObject.DataItem.RootControl.Parent != null)
                {
                    (dataInfoObject.DataItem.RootControl.Parent as ContentControl).Content = null;
                }
                NodeUIContainer.Content = dataInfoObject.DataItem.RootControl;
            }
            //显示最新的数据
            dataInfoObject.DataItem.BindToRootControl();
            dataInfoObject.DataItem.RefreshDisplay();
        }
        // <summary>
        /// 从XElement中创建TreeViewIconsItem对象,不理会其子节点
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        private TreeViewIconsItem CreateTreeViewNodeFromXElement(XElement element)
        {
            if (element == null)
            {
                return(null);
            }
            NodeDataObject    nodeDataObject = NodeFactory.CreateDataInfoNode(element.Attribute("NodeType").Value, EFConnectionString);
            TreeViewIconsItem node           = new TreeViewIconsItem(this, nodeDataObject);

            node.HeaderText = element.Attribute("Title").Value;
            if (element.Attribute("Foreground") != null)
            {
                String color = element.Attribute("Foreground").Value;

                node.MyForeground = new SolidColorBrush((Color)ColorConverter.ConvertFromString(color));
            }
            else
            {
                //默认为黑色
                node.Foreground = Brushes.Black;
            }

            if (element.Attribute("FontWeight") != null)
            {
                String FontWeight = element.Attribute("FontWeight").Value;
                if (FontWeight != "Normal")
                {
                    node.FontWeight = FontWeights.ExtraBold;
                }
                else
                {
                    node.FontWeight = FontWeights.Normal;
                }
            }
            node.Icon = nodeDataObject.DataItem.NormalIcon;
            return(node);
        }
Beispiel #16
0
        private void AddNode(AddNodeCategory category)
        {
            string treeNodeType = labeltree.TreeNodeType;
            //为新节点生成默认文本
            String NodeText = MainWin.getDefaultNodeText(treeNodeType) + (labeltree.NodeCount + 1);
            //尝试从剪贴板中提取文本
            String textFromClipboard = StringUtils.getFirstLineOfString(Clipboard.GetText());

            if (String.IsNullOrEmpty(textFromClipboard) == false && textFromClipboard != LastPasteNodeText && textFromClipboard.IndexOf("/") == -1)
            {
                //检测一下从剪贴板中获取的文本是否有效(即不会导致重名的节点出现)
                String newNodeText = textFromClipboard;
                bool   nodeExisted = labeltree.IsNodeExisted(MainWin.getNewNodePath(category, newNodeText));
                //如果不存在同名的路径
                if (nodeExisted == false)
                {
                    NodeText          = newNodeText;
                    LastPasteNodeText = NodeText;
                }
            }
            //如果还有重复路径的,则循环使用随机数,务必保证路径不会相同
            while (labeltree.IsNodeExisted(MainWin.getNewNodePath(category, NodeText)))
            {
                NodeText = MainWin.getDefaultNodeText(treeNodeType) + new Random().Next() as string;
            }

            //创建默认的节点数据对象
            NodeDataObject dataobject = NodeFactory.CreateDataInfoNode(treeNodeType, DALConfig.getEFConnectionString(curDbInfoTab.dbInfoObject.DatabaseFilePath));

            TreeViewIconsItem newNode = null;

            //在树中添加节点
            switch (category)
            {
            case AddNodeCategory.AddRoot:
                newNode = labeltree.AddRoot(NodeText, dataobject);
                curDbInfoTab.LabelViewObj.SuperTree.AddRoot(NodeText, dataobject);
                break;

            case AddNodeCategory.AddChild:
                newNode = labeltree.AddChild(NodeText, dataobject);
                curDbInfoTab.LabelViewObj.SuperTree.AddChild(NodeText, dataobject);
                break;

            case AddNodeCategory.AddSibling:
                newNode = labeltree.AddSibling(NodeText, dataobject);
                curDbInfoTab.LabelViewObj.SuperTree.AddSibling(NodeText, dataobject);
                break;

            default:
                break;
            }
            if (newNode == null)
            {
                return;
            }
            //新节点,默认不是粗体的
            newNode.FontWeight = FontWeights.Normal;
            //在数据库中创建记录
            if (dataobject.AccessObject != null)
            {
                dataobject.AccessObject.Create(dataobject.DataItem);
            }
            //保存树结构
            curDbInfoTab.SaveTreeToDB(labeltree);
            //自动进入编辑状态
            newNode.BeginEdit();
        }
        public TreeViewIconsItem(SuperTreeView tree, NodeDataObject dataObject, string iconType)
        {
            belongToTreeView = tree;
            _dataObject      = dataObject;

            //以下处理UI控件
            headerContainer = new StackPanel();


            //  设置StackPanel中的内容水平排列
            headerContainer.Orientation = Orientation.Horizontal;
            //将Header设置为StackPanel
            Header = headerContainer;
            //设置正常状态下的显示控件
            _iconImageControl = new Image();
            _iconImageControl.VerticalAlignment = VerticalAlignment.Center;
            _iconImageControl.Margin            = new Thickness(0, 0, 4, 0);


            _iconImageControl.Source = _icon;
            //  向StackPanel对象中添加一个图标对象
            headerContainer.Children.Add(_iconImageControl);

            //  创建用于添加文本信息的TextBlock对象
            textBlock                   = new TextBlock();
            textBlock.FontSize          = TreeNodeDefaultFontSize;
            textBlock.VerticalAlignment = VerticalAlignment.Center;
            //  向StackPanel对象中添加文本信息
            headerContainer.Children.Add(textBlock);

            //实例化文本框控件,准备用于编辑
            edtText          = new TextBox();
            edtText.FontSize = TreeNodeDefaultFontSize;
            edtText.MinWidth = 100;
            //对事件进行响应
            edtText.KeyDown   += edtText_KeyDown;
            edtText.LostFocus += edtText_LostFocus;
            //由于默认情况下WPF的TextBox的Cut存在BUG:即完成复制工作但却不删除选中的文字,因此不得不用自己的代码取代默认的命令响应代码
            CommandBinding bind = new CommandBinding();

            bind.Command     = ApplicationCommands.Cut;
            bind.Executed   += bind_Executed;
            bind.CanExecute += bind_CanExecute;
            edtText.CommandBindings.Add(bind);
            //使用当前时间作为本Item的ID
            id = TimerUtils.getHighPrecisionCurrentTime();

            //给节点添加样式,直接在xaml文件中添加,貌似只能添加第一层的样式
            //TabItem样式绑定的几种方式
            //item.SetValue(TabItem.StyleProperty, Application.Current.Resources["TabItemStyle1"] );
            //item.Style = Resources["TabItemStyle1"] as Style;
            //item.Style = (Style)this.FindResource("TabItemStyle1.2");

            this.Style = (Style)this.FindResource("TreeViewItem1");


            IconType = iconType;
            if (IconType == "FileIcon")
            {
                Icon = ImageUtils.GetBitmapSourceFromImageFileName("pack://application:,,,/WPFSuperTreeView;component/Images/FileIcon.png", UriKind.Absolute);
            }
            else if (IconType == "LabelNode")
            {
                Icon = ImageUtils.GetBitmapSourceFromImageFileName("pack://application:,,,/WPFSuperTreeView;component/Images/LabelNode.png", UriKind.Absolute);
            }
            else
            {
                Icon = ImageUtils.GetBitmapSourceFromImageFileName("pack://application:,,,/WPFSuperTreeView;component/Images/InfoNode.png", UriKind.Absolute);
            }
        }
        /// <summary>
        /// 添加节点
        /// 成功返回新节点,不成功,返回null
        /// 新节点自动展开且选中
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="nodeText"></param>
        /// <param name="nodeIcon"></param>
        /// <returns></returns>
        private TreeViewIconsItem addNode(AddNodeCategory addType, TreeViewIconsItem selectedNode, String nodeText, NodeDataObject nodeDataObject)
        {
            if (selectedNode != null)
            {
                selectedNode.IsExpanded = true;
            }
            ShouldRaiseSelectedItemChangedEvent = true;

            TreeViewIconsItem treeNode = new TreeViewIconsItem(this, nodeDataObject);

            treeNode.HeaderText = nodeText;
            treeNode.Icon       = nodeDataObject.DataItem.NormalIcon;
            //自动展开
            treeNode.IsExpanded = true;
            switch (addType)
            {
            case AddNodeCategory.AddRoot:
                treeNode.Path = "/" + nodeText + "/";
                nodeDataObject.DataItem.Path = treeNode.Path;
                tree.Items.Add(treeNode);
                nodesManager.nodes.Add(treeNode);
                break;

            case AddNodeCategory.AddChild:
                if (selectedNode != null)
                {
                    treeNode.Path = selectedNode.Path + nodeText + "/";
                    nodeDataObject.DataItem.Path = treeNode.Path;
                    selectedNode.Items.Add(treeNode);
                    nodesManager.nodes.Add(treeNode);
                }
                else
                {
                    return(null);
                }
                break;

            case AddNodeCategory.AddSibling:
                if (selectedNode != null && selectedNode.Parent != null)
                {
                    //如果选中节点是顶层节点
                    if (selectedNode.Parent == tree)
                    {
                        treeNode.Path = "/" + nodeText + "/";
                        nodeDataObject.DataItem.Path = treeNode.Path;
                        tree.Items.Add(treeNode);
                    }
                    else
                    {
                        //不是顶层节点
                        TreeViewIconsItem parent = selectedNode.Parent as TreeViewIconsItem;
                        treeNode.Path = parent.Path + nodeText + "/";
                        nodeDataObject.DataItem.Path = treeNode.Path;
                        parent.Items.Add(treeNode);
                    }
                    nodesManager.nodes.Add(treeNode);
                }
                else      //当前没有选中节点或选中节点没有父亲
                {
                    return(null);
                }

                break;

            default:
                break;
            }
            if (_autoSelectNewNode)
            {
                treeNode.IsSelected = true;
            }

            //更新树的存储
            String treeXml = saveToXmlString();

            if (_repository != null)
            {
                _repository.SaveTree(treeXml);
            }


            return(treeNode);
        }