ALBA
albaGUITree.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: ALBA (Agile Library for Biomedical Applications)
4 Module: albaGUITree
5 Authors: Silvano Imboden
6
7 Copyright (c) BIC
8 All rights reserved. See Copyright.txt or
9
10
11 This software is distributed WITHOUT ANY WARRANTY; without even
12 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 PURPOSE. See the above copyright notice for more information.
14
15=========================================================================*/
16#ifndef __albaGUITree_H__
17#define __albaGUITree_H__
18//----------------------------------------------------------------------------
19// Include:
20//----------------------------------------------------------------------------
21#include <wx/laywin.h>
22#include <wx/image.h>
23#include <wx/imaglist.h>
24#include <wx/treectrl.h>
25#include <wx/hash.h>
26#include "albaEvent.h"
27#include "albaObserver.h"
28#include "albaGUINamedPanel.h"
29#include "albaServiceClient.h"
30#include "albaAbsLogicManager.h"
31
32//----------------------------------------------------------------------------
33// const :
34//----------------------------------------------------------------------------
35const int ID_TREE = 200;
36//----------------------------------------------------------------------------
37// albaGUITree :
38//----------------------------------------------------------------------------
96class ALBA_EXPORT albaGUITree: public albaGUINamedPanel, public albaServiceClient
97{
98public:
99 albaGUITree (wxWindow* parent, wxWindowID id=-1, bool CloseButton = false, bool HideTitle = false);
100 virtual ~albaGUITree();
101
103 void Reset();
104
108 bool AddNode(long long node_id, long long parent_id , wxString label, int icon = 0);
109
111 bool DeleteNode(long long node_id);
112
114 bool SetNodeLabel(long long node_id, wxString label);
115
117 wxString GetNodeLabel(long long node_id);
118
120 bool NodeHasChildren(long long node_id);
121
123 long long GetNodeParent(long long node_id);
124
126 bool SetNodeParent(long long node_id, long long parent_id );
127
129 bool SetNodeIcon(long long node_id, int icon);
130
132 int GetNodeIcon(long long node_id);
133
135 bool SelectNode(long long node_id);
136
145 void SetImageList(wxImageList *img);
146
149 void SortChildren(long long node_id =0);
150
152 void SetAutoSort(bool enable) {m_Autosort=enable;};
153
155 bool GetAutoSort() {return m_Autosort;};
156
158 void CollapseNode(long long node_id);
159
161 void ExpandNode(long long node_id);
162
163 bool IsNodeExpanded(long long node_id);
164
166 void SetListener(albaObserver *listener) {m_Listener=listener;};
167
169 wxTreeItemId ItemFromNode(long long node_id);
170
172 long long NodeFromItem(wxTreeItemId& item);
173
174
175 void SetTreeStyle(long style) {m_NodeTree->SetWindowStyle(style);};
176 long GetTreeStyle() {return m_NodeTree->GetWindowStyle();};
177
179 bool NodeExist(long long node_id);
180
181protected:
183 virtual void OnSelectionChanged(wxTreeEvent& event);
184
186 void OnSize(wxSizeEvent& event);
187
189 void DeleteNode2(long long node_id);
190
192 void SetNodeParent2(long long node_id, long long parent_id );
193
195 int CheckIconId(int icon);
196
197 bool IsRootHidden() {return (GetTreeStyle() & wxTR_HIDE_ROOT) != 0; };
198
201 long long m_NodeRoot;
202 wxTreeCtrl *m_NodeTree;
203 wxImageList *m_NodeImages;
204 wxHashTable *m_NodeTable;
206
207 //----------------------------------------------------------------------------
208 // albaGUITreeItemData :
210 //----------------------------------------------------------------------------
211 class albaGUITreeItemData: public wxTreeItemData{
212 public:
213 albaGUITreeItemData(long long node_id) {m_NodeId = node_id; };
214 long long GetNode() {return m_NodeId;};
215 protected:
216 long long m_NodeId;
217 };
218 //----------------------------------------------------------------------------
219 // albaGUITreeTableElement:
221 //----------------------------------------------------------------------------
222 class albaGUITreeTableElement: public wxObject
223 {
224 public:
225 albaGUITreeTableElement(wxTreeItemId item) {m_TreeItemId=item; };
226 wxTreeItemId GetItem() {return m_TreeItemId;};
227 void SetItem(wxTreeItemId item){m_TreeItemId=item; };
228 protected:
229 wxTreeItemId m_TreeItemId;
230 };
231
232DECLARE_EVENT_TABLE()
233}; // end of albaGUITree
234#endif
const int ID_TREE
Definition: albaGUITree.h:35
Class Name: albaGUINamedPanel.
Data to be attached to an item of albaGUITree, holds the reference to a node_id.
Definition: albaGUITree.h:211
albaGUITreeItemData(long long node_id)
Definition: albaGUITree.h:213
specialized HashTable element used in albaGUITree to store a reference to a wxTreeItemId
Definition: albaGUITree.h:223
albaGUITreeTableElement(wxTreeItemId item)
Definition: albaGUITree.h:225
void SetItem(wxTreeItemId item)
Definition: albaGUITree.h:227
albaGUITree allows a simplified and lot easier use of a wxWindows tree widget.
Definition: albaGUITree.h:97
bool DeleteNode(long long node_id)
Delete the specified node, and its subtree.
void SetListener(albaObserver *listener)
Set the Listener that will receive event-notification, the Listener can be changed any time
Definition: albaGUITree.h:166
int GetNodeIcon(long long node_id)
Return the icon index for the node 'node_id'.
wxHashTable * m_NodeTable
Definition: albaGUITree.h:204
wxTreeCtrl * m_NodeTree
Definition: albaGUITree.h:202
void CollapseNode(long long node_id)
collapse the children of node_id
void SetImageList(wxImageList *img)
Set the images to be used for the nodes.
bool SetNodeLabel(long long node_id, wxString label)
Set the label for the node.
void Reset()
Clears all items in the tree.
virtual ~albaGUITree()
bool SelectNode(long long node_id)
Select the node.
bool IsRootHidden()
Definition: albaGUITree.h:197
bool AddNode(long long node_id, long long parent_id, wxString label, int icon=0)
Create a new tree item with the specified parent,label and icon.
bool m_Autosort
Definition: albaGUITree.h:200
void SetNodeParent2(long long node_id, long long parent_id)
Move a node, and its subtree.
virtual void OnSelectionChanged(wxTreeEvent &event)
Private function that notify the Listener of node selection and deselection.
wxImageList * m_NodeImages
Definition: albaGUITree.h:203
bool NodeHasChildren(long long node_id)
Check if the node has children.
void DeleteNode2(long long node_id)
Delete recursively a node and its subtree.
long long m_NodeRoot
Definition: albaGUITree.h:201
bool SetNodeParent(long long node_id, long long parent_id)
Move a node, and its subtree.
wxString GetNodeLabel(long long node_id)
Get the label for the node.
bool IsNodeExpanded(long long node_id)
void SetTreeStyle(long style)
Definition: albaGUITree.h:175
long long NodeFromItem(wxTreeItemId &item)
Return node id from node item.
void ExpandNode(long long node_id)
expand the children of node_id
void OnSize(wxSizeEvent &event)
When tree is used on a wxNotebook m_NodeTree must be called on Sizing .
bool GetAutoSort()
Get the autosort flag.
Definition: albaGUITree.h:155
void SortChildren(long long node_id=0)
Sort the children of node_id.
wxTreeItemId ItemFromNode(long long node_id)
Return the node item from node id.
bool NodeExist(long long node_id)
Return true if node exist.
int CheckIconId(int icon)
Check that id is a valid index in the imagelist - return the (eventually clamped) value.
long long GetNodeParent(long long node_id)
Return the parent id of the node.
bool SetNodeIcon(long long node_id, int icon)
Set the icon for the node.
albaGUITree(wxWindow *parent, wxWindowID id=-1, bool CloseButton=false, bool HideTitle=false)
albaObserver * m_Listener
Definition: albaGUITree.h:205
long GetTreeStyle()
Definition: albaGUITree.h:176
bool m_PreventNotify
Definition: albaGUITree.h:199
void SetAutoSort(bool enable)
if autosort is on - the tree is always kept sorted
Definition: albaGUITree.h:152
Interface implementing the Observer of the Subject/Observer design pattern.
Definition: albaObserver.h:36