]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCreaDevManagerTreeCtrl.cxx
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCreaDevManagerTreeCtrl.cxx
1 /*
2  * wxCreaDevManagerTreeCtrl.cpp
3  *
4  *  Created on: 19/10/2012
5  *      Author: daniel
6  */
7
8 #include "wxCreaDevManagerTreeCtrl.h"
9 #include "creaDevManagerIds.h"
10 #include <vector>
11
12 wxCreaDevManagerTreeCtrl::wxCreaDevManagerTreeCtrl(
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   Create(parent, id, pos, size, style, validator, name);
23 }
24
25 wxCreaDevManagerTreeCtrl::~wxCreaDevManagerTreeCtrl()
26 {
27 }
28
29 bool wxCreaDevManagerTreeCtrl::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 wxCreaDevManagerTreeCtrl::BuildTree(const ModelCreaDevManagerTree& projectsTree)
46 {
47   this->DeleteAllItems();
48   wxTreeItemId rootIndex = this-> AddRoot(_("Open Projects"));
49   for (int i = 0; i < projectsTree.projectRoots.size(); i++)
50   {
51       std::cout << "Building TreeCtrl for " << projectsTree.projectRoots[i].GetName() << std::endl;
52     wxTreeItemId parentIndex = this-> AppendItem(rootIndex, wxString(projectsTree.projectRoots[i].GetName().c_str(), wxConvUTF8));
53     this->BuildTree(projectsTree.projectRoots[i].GetChildren(), parentIndex);
54   }
55   this->Expand(rootIndex);
56
57   this->Update();
58 }
59
60 void wxCreaDevManagerTreeCtrl::BuildTree(const std::vector<ModelCreaDevManagerTreeNode>& projectsTree, wxTreeItemId parent)
61 {
62   for (int i = 0; i < projectsTree.size(); i++)
63   {
64     //cout << projectsTree[i].GetName() << endl;
65     wxTreeItemId parentNodeIndex;
66     wxString nodeName((projectsTree[i].GetName()).c_str(), wxConvUTF8);
67     parentNodeIndex = this->AppendItem(parent, nodeName);
68
69     std::vector<ModelCreaDevManagerTreeNode> innerChildren = projectsTree[i].GetChildren();
70     if(innerChildren.size() > 0)
71     {
72       this->BuildTree(innerChildren, parentNodeIndex);
73     }
74   }
75 }