]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMProjectsTreeCtrl.cxx
cda1e60dccf58dc231138199a0bad7d1adb6afee
[crea.git] / lib / creaDevManagerLib / wxCDMProjectsTreeCtrl.cxx
1 /*
2  * wxCreaDevManagerTreeCtrl.cpp
3  *
4  *  Created on: 19/10/2012
5  *      Author: daniel
6  */
7
8 #include "wxCDMProjectsTreeCtrl.h"
9 #include "creaDevManagerIds.h"
10 #include <vector>
11
12 wxCDMProjectsTreeCtrl::wxCDMProjectsTreeCtrl(
13     wxWindow *parent,
14     wxWindowID id,
15     const wxPoint &pos,
16     const wxSize &size,
17     long style,
18     const wxValidator &validator,
19     const wxString &name
20 )
21 {
22   wxCDMProjectsTreeCtrl::Create(parent, id, pos, size, style, validator, name);
23 }
24
25 wxCDMProjectsTreeCtrl::~wxCDMProjectsTreeCtrl()
26 {
27 }
28
29 bool wxCDMProjectsTreeCtrl::Create(
30     wxWindow* parent,
31     wxWindowID id,
32     const wxPoint &pos,
33     const wxSize &size,
34     long style,
35     const wxValidator &validator,
36     const wxString &name
37 )
38 {
39   wxTreeCtrl::Create (parent, id, pos, size, style, validator, name);
40   wxTreeItemId rootIndex = this-> AddRoot(_("Open Projects"));
41   this->Update();
42   return TRUE;
43 }
44
45 void wxCDMProjectsTreeCtrl::BuildTree(const modelCDMProjectsTree& projectsTree)
46 {
47   this->DeleteAllItems();
48   wxTreeItemId rootIndex = this-> AddRoot(_("Open Projects"));
49   std::cout << "Building TreeCtrl for " << projectsTree.projectRoot.GetName() << std::endl;
50   wxTreeItemId parentIndex = this-> AppendItem(rootIndex, wxString(projectsTree.projectRoot.GetName().c_str(), wxConvUTF8));
51   this->BuildTree(projectsTree.projectRoot.GetChildren(), parentIndex);
52
53   this->Expand(rootIndex);
54
55   this->Update();
56 }
57
58 void wxCDMProjectsTreeCtrl::BuildTree(const std::vector<modelCDMProjectsTreeNode>& projectsTree, wxTreeItemId parent)
59 {
60   for (int i = 0; i < projectsTree.size(); i++)
61   {
62     //cout << projectsTree[i].GetName() << endl;
63     wxTreeItemId parentNodeIndex;
64     wxString nodeName((projectsTree[i].GetName()).c_str(), wxConvUTF8);
65     parentNodeIndex = this->AppendItem(parent, nodeName);
66
67     std::vector<modelCDMProjectsTreeNode> innerChildren = projectsTree[i].GetChildren();
68     if(innerChildren.size() > 0)
69     {
70       this->BuildTree(innerChildren, parentNodeIndex);
71     }
72   }
73 }