Beispiel #1
0
 public TreeNode FindNode(TreeNode node, NodeTag tag)
 {
     // check with node itself
     if (null != node)
     {
         NodeTag tagNode = node.Tag as NodeTag;
         if (null != tagNode && tagNode.Equals(tag))
             return node;
     }
     // check with child nodes
     TreeNodeCollection tnCollection = null == node ? Nodes : node.Nodes;
     foreach (TreeNode tn in tnCollection)
     {
         TreeNode tnResult = FindNode(tn, tag);
         if (null != tnResult)
             return tnResult;
     }
     return null;
 }
Beispiel #2
0
 public void PopulateAndSelectNode(NodeTag tag)
 {
     TreeNode nodeSelected = FindNode(null, tag);
     BeginUpdate();  // this disables redrawing of tree
     if (null == nodeSelected)
     {
         _log.Error(string.Format("Failed to retrieve valid node from NodeTag {0}", tag.ToString()));
         // retrieve db node
         Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext();
         Pic.DAL.SQLite.TreeNode tn = Pic.DAL.SQLite.TreeNode.GetById(db, tag.TreeNode);
         // insert all needed parents and node
         nodeSelected = InsertNodeAndParents(tn, db);
         if (null == nodeSelected)
         {
             _log.Error(string.Format("Failed to retrieve valid node from NodeTag {0}", tag.ToString()));
             return; // -> complete failure
         }
     }
     if (null != nodeSelected)
     {
         _preventEventTriggering = true;
         // ################## --> needed to update tree
         nodeSelected.Expand();
         // ################## --> needed to update tree
         SelectedNode = nodeSelected;
         EndUpdate(); // enables the redrawing of the treeview
         _preventEventTriggering = false;
         SelectedNode = nodeSelected;
     }
     else
         EndUpdate(); // enables the redrawing of the treeview
 }
Beispiel #3
0
 public NodeEventArgs(int treeNodeId, NodeTag.NodeType type) { _treeNodeId = treeNodeId; _type = type; }
Beispiel #4
0
 public void SelectNode(NodeTag tag)
 {
     SelectedNode = FindNode(null, tag);
     if (null != SelectedNode)
         SelectedNode.EnsureVisible();
 }
Beispiel #5
0
        private void insertNewDocumentLabel_Click(object sender, EventArgs e)
        {
            try
            {
                Pic.DAL.SQLite.PPDataContext db = new Pic.DAL.SQLite.PPDataContext();

                NodeTag tag = GetCurrentTag();
                if (null == tag || tag.IsDocument)
                    throw new Exception("Invalid TreeNode tag");
                Pic.DAL.SQLite.TreeNode treeNode = Pic.DAL.SQLite.TreeNode.GetById(db, tag.TreeNode);

                // force creation of a profile if no profile exist
                Pic.DAL.SQLite.CardboardProfile[] cardboardProfiles = Pic.DAL.SQLite.CardboardProfile.GetAll(db);
                if (cardboardProfiles.Length == 0)
                {
                    FormEditProfiles dlgProfile = new FormEditProfiles();
                    dlgProfile.ShowDialog();
                }
                cardboardProfiles = Pic.DAL.SQLite.CardboardProfile.GetAll(db);
                if (cardboardProfiles.Length == 0)
                    return;

                // show dialog
                FormCreateDocument dlg = new FormCreateDocument();
                dlg.TreeNode = tag;
                if (DialogResult.OK == dlg.ShowDialog())
                {
                    // insert document in treeview
                    List<Pic.DAL.SQLite.TreeNode> tnodes = Pic.DAL.SQLite.TreeNode.GetByDocumentId(db, dlg.DocumentID);
                    // (re)populate parent node
                    PopulateChildren(SelectedNode);
                    if (dlg.OpenInsertedDocument)
                    {
                        // select current node
                        NodeTag newDocTag = new NodeTag(NodeTag.NodeType.NT_DOCUMENT, tnodes[0].ID);
                        SelectedNode = FindNode(null, newDocTag);  // <- for some reasons, this does not work
                        // however, we can force document opening with the following line
                        SelectionChanged(this, new NodeEventArgs(newDocTag.TreeNode, newDocTag.Type), newDocTag.Name);
                    }
                }
            }
            catch (System.Exception ex)
            {
                Debug.Fail(ex.ToString());
                _log.Error(ex.ToString());
            }
        }