]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/wxCDMProjectsTreeCtrl.cxx
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMProjectsTreeCtrl.cxx
diff --git a/lib/creaDevManagerLib/wxCDMProjectsTreeCtrl.cxx b/lib/creaDevManagerLib/wxCDMProjectsTreeCtrl.cxx
new file mode 100755 (executable)
index 0000000..cda1e60
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * wxCreaDevManagerTreeCtrl.cpp
+ *
+ *  Created on: 19/10/2012
+ *      Author: daniel
+ */
+
+#include "wxCDMProjectsTreeCtrl.h"
+#include "creaDevManagerIds.h"
+#include <vector>
+
+wxCDMProjectsTreeCtrl::wxCDMProjectsTreeCtrl(
+    wxWindow *parent,
+    wxWindowID id,
+    const wxPoint &pos,
+    const wxSize &size,
+    long style,
+    const wxValidator &validator,
+    const wxString &name
+)
+{
+  wxCDMProjectsTreeCtrl::Create(parent, id, pos, size, style, validator, name);
+}
+
+wxCDMProjectsTreeCtrl::~wxCDMProjectsTreeCtrl()
+{
+}
+
+bool wxCDMProjectsTreeCtrl::Create(
+    wxWindow* parent,
+    wxWindowID id,
+    const wxPoint &pos,
+    const wxSize &size,
+    long style,
+    const wxValidator &validator,
+    const wxString &name
+)
+{
+  wxTreeCtrl::Create (parent, id, pos, size, style, validator, name);
+  wxTreeItemId rootIndex = this-> AddRoot(_("Open Projects"));
+  this->Update();
+  return TRUE;
+}
+
+void wxCDMProjectsTreeCtrl::BuildTree(const modelCDMProjectsTree& projectsTree)
+{
+  this->DeleteAllItems();
+  wxTreeItemId rootIndex = this-> AddRoot(_("Open Projects"));
+  std::cout << "Building TreeCtrl for " << projectsTree.projectRoot.GetName() << std::endl;
+  wxTreeItemId parentIndex = this-> AppendItem(rootIndex, wxString(projectsTree.projectRoot.GetName().c_str(), wxConvUTF8));
+  this->BuildTree(projectsTree.projectRoot.GetChildren(), parentIndex);
+
+  this->Expand(rootIndex);
+
+  this->Update();
+}
+
+void wxCDMProjectsTreeCtrl::BuildTree(const std::vector<modelCDMProjectsTreeNode>& projectsTree, wxTreeItemId parent)
+{
+  for (int i = 0; i < projectsTree.size(); i++)
+  {
+    //cout << projectsTree[i].GetName() << endl;
+    wxTreeItemId parentNodeIndex;
+    wxString nodeName((projectsTree[i].GetName()).c_str(), wxConvUTF8);
+    parentNodeIndex = this->AppendItem(parent, nodeName);
+
+    std::vector<modelCDMProjectsTreeNode> innerChildren = projectsTree[i].GetChildren();
+    if(innerChildren.size() > 0)
+    {
+      this->BuildTree(innerChildren, parentNodeIndex);
+    }
+  }
+}