Wt examples  3.3.6
Public Member Functions | Private Member Functions | Private Attributes | List of all members
DemoTreeList Class Reference

A demonstration of the treelist. More...

#include <DemoTreeList.h>

Inheritance diagram for DemoTreeList:
Inheritance graph
[legend]

Public Member Functions

 DemoTreeList (Wt::WContainerWidget *parent)
 Create a DemoTreeList. More...
 

Private Member Functions

void addMap ()
 Add a map. More...
 
void removeMap ()
 Remove a map. More...
 
TreeNodemakeTreeMap (const std::string name, TreeNode *parent)
 Create a "map" node, and insert in the given parent. More...
 
TreeNodemakeTreeFile (const std::string name, TreeNode *parent)
 Create a "file" node, and insert in the given parent. More...
 

Private Attributes

TreeNodetree_
 
TreeNodetestMap_
 
int testCount_
 
Wt::WPushButton * addMapButton_
 
Wt::WPushButton * removeMapButton_
 

Detailed Description

A demonstration of the treelist.

This is the main class for the treelist example.

Definition at line 27 of file DemoTreeList.h.

Constructor & Destructor Documentation

§ DemoTreeList()

DemoTreeList::DemoTreeList ( Wt::WContainerWidget *  parent)

Create a DemoTreeList.

Definition at line 20 of file DemoTreeList.C.

21  : WContainerWidget(parent),
22  testCount_(0)
23 {
24  addWidget
25  (new WText("<h2>Wt Tree List example</h2>"
26  "<p>This is a simple demo of a treelist, implemented using"
27  " <a href='http://witty.sourceforge.net/'>Wt</a>.</p>"
28  "<p>The leafs of the tree contain the source code of the "
29  "tree-list in the classes <b>TreeNode</b> and "
30  "<b>IconPair</b>, as well as the implementation of this "
31  "demo itself in the class <b>DemoTreeList</b>.</p>"));
32 
33  tree_ = makeTreeMap("Examples", 0);
34  addWidget(tree_);
35 
36  TreeNode *treelist = makeTreeMap("Tree List", tree_);
37  TreeNode *wstateicon = makeTreeMap("class IconPair", treelist);
38  makeTreeFile("<a href=\"IconPair.h\">IconPair.h</a>", wstateicon);
39  makeTreeFile("<a href=\"IconPair.C\">IconPair.C</a>", wstateicon);
40  TreeNode *wtreenode = makeTreeMap("class TreeNode", treelist);
41  makeTreeFile("<a href=\"TreeNode.h\">TreeNode.h</a>", wtreenode);
42  makeTreeFile("<a href=\"TreeNode.C\">TreeNode.C</a>", wtreenode);
43  TreeNode *demotreelist = makeTreeMap("class DemoTreeList", treelist);
44  makeTreeFile("<a href=\"DemoTreeList.h\">DemoTreeList.h</a>", demotreelist);
45  makeTreeFile("<a href=\"DemoTreeList.C\">DemoTreeList.C</a>", demotreelist);
46 
47  testMap_ = makeTreeMap("Test map", tree_);
48 
49  /*
50  * Buttons to dynamically demonstrate changing the tree contents.
51  */
52  addWidget
53  (new WText("<p>Use the following buttons to change the tree "
54  "contents:</p>"));
55 
57  = new WPushButton("Add map", this);
58  addMapButton_->clicked().connect(this, &DemoTreeList::addMap);
59 
61  = new WPushButton("Remove map", this);
62  removeMapButton_->clicked().connect(this, &DemoTreeList::removeMap);
63  removeMapButton_->disable();
64 
65  addWidget
66  (new WText("<p>Remarks:"
67  "<ul>"
68  "<li><p>This is not the instantiation of a pre-defined "
69  "tree list component, but the full implementation of such "
70  "a component, in about 350 lines of C++ code !</p> "
71  "<p>In comparison, the <a href='http://myfaces.apache.org'> "
72  "Apache MyFaces</a> JSF implementation of tree2, with similar "
73  "functionality, uses about 2400 lines of Java, and 140 lines "
74  "of JavaScript code.</p></li>"
75  "<li><p>Once loaded, the tree list does not require any "
76  "interaction with the server for handling the click events on "
77  "the <img src='icons/nav-plus-line-middle.gif' /> and "
78  "<img src='icons/nav-minus-line-middle.gif' /> icons, "
79  "because these events have been connected to slots using "
80  "STATIC connections. Such connections are converted to the "
81  "appropriate JavaScript code that is inserted into the page. "
82  "Still, the events are signaled to the server to update the "
83  "application state.</p></li>"
84  "<li><p>In contrast, the buttons for manipulating the tree "
85  "contents use DYNAMIC connections, and thus the update "
86  "is computed at server-side, and communicated back to the "
87  "browser (by default using AJAX).</p></li>"
88  "<li><p>When loading a page, only visible widgets (that are not "
89  "<b>setHidden(true)</b>) are transmitted. "
90  "The remaining widgets are loaded in the background after "
91  "rendering the page. "
92  "As a result the application is loaded as fast as possible.</p>"
93  "</li>"
94  "<li><p>The browser reload button is supported and behaves as "
95  "expected: the page is reloaded from the server. Again, "
96  "only visible widgets are transmitted immediately.</p> "
97  "<p>(For the curious, this is the way to see the actual "
98  "HTML/JavaScript code !)</p></li>"
99  "</ul></p>"));
100 }
Wt::WPushButton * addMapButton_
Definition: DemoTreeList.h:39
TreeNode * makeTreeMap(const std::string name, TreeNode *parent)
Create a "map" node, and insert in the given parent.
Definition: DemoTreeList.C:129
Wt::WPushButton * removeMapButton_
Definition: DemoTreeList.h:40
TreeNode * testMap_
Definition: DemoTreeList.h:36
void removeMap()
Remove a map.
Definition: DemoTreeList.C:113
void addMap()
Add a map.
Definition: DemoTreeList.C:102
TreeNode * tree_
Definition: DemoTreeList.h:35
TreeNode * makeTreeFile(const std::string name, TreeNode *parent)
Create a "file" node, and insert in the given parent.
Definition: DemoTreeList.C:143
Example implementation of a single tree list node.
Definition: TreeNode.h:55

Member Function Documentation

§ addMap()

void DemoTreeList::addMap ( )
private

Add a map.

Definition at line 102 of file DemoTreeList.C.

103 {
104  TreeNode *node
105  = makeTreeMap("Map " + boost::lexical_cast<std::string>(++testCount_),
106  testMap_);
107  makeTreeFile("File " + boost::lexical_cast<std::string>(testCount_),
108  node);
109 
110  removeMapButton_->enable();
111 }
TreeNode * makeTreeMap(const std::string name, TreeNode *parent)
Create a "map" node, and insert in the given parent.
Definition: DemoTreeList.C:129
Wt::WPushButton * removeMapButton_
Definition: DemoTreeList.h:40
TreeNode * testMap_
Definition: DemoTreeList.h:36
TreeNode * makeTreeFile(const std::string name, TreeNode *parent)
Create a "file" node, and insert in the given parent.
Definition: DemoTreeList.C:143
Example implementation of a single tree list node.
Definition: TreeNode.h:55

§ makeTreeFile()

TreeNode * DemoTreeList::makeTreeFile ( const std::string  name,
TreeNode parent 
)
private

Create a "file" node, and insert in the given parent.

Definition at line 143 of file DemoTreeList.C.

145 {
146  IconPair *labelIcon
147  = new IconPair("icons/document.png", "icons/yellow-folder-open.png",
148  false);
149 
150  TreeNode *node = new TreeNode(name, XHTMLText, labelIcon, 0);
151  if (parent)
152  parent->addChildNode(node);
153 
154  return node;
155 }
An icon pair (identical to WIconPair)
Definition: IconPair.h:34
void addChildNode(TreeNode *node)
Adds a child node.
Definition: TreeNode.C:86
Example implementation of a single tree list node.
Definition: TreeNode.h:55

§ makeTreeMap()

TreeNode * DemoTreeList::makeTreeMap ( const std::string  name,
TreeNode parent 
)
private

Create a "map" node, and insert in the given parent.

Definition at line 129 of file DemoTreeList.C.

130 {
131  IconPair *labelIcon
132  = new IconPair("icons/yellow-folder-closed.png",
133  "icons/yellow-folder-open.png",
134  false);
135 
136  TreeNode *node = new TreeNode(name, PlainText, labelIcon, 0);
137  if (parent)
138  parent->addChildNode(node);
139 
140  return node;
141 }
An icon pair (identical to WIconPair)
Definition: IconPair.h:34
void addChildNode(TreeNode *node)
Adds a child node.
Definition: TreeNode.C:86
Example implementation of a single tree list node.
Definition: TreeNode.h:55

§ removeMap()

void DemoTreeList::removeMap ( )
private

Remove a map.

Definition at line 113 of file DemoTreeList.C.

114 {
115  int numMaps = testMap_->childNodes().size();
116 
117  if (numMaps > 0) {
118  int c = rand() % numMaps;
119 
120  TreeNode *child = testMap_->childNodes()[c];
121  testMap_->removeChildNode(child);
122  delete child;
123 
124  if (numMaps == 1)
125  removeMapButton_->disable();
126  }
127 }
Wt::WPushButton * removeMapButton_
Definition: DemoTreeList.h:40
TreeNode * testMap_
Definition: DemoTreeList.h:36
const std::vector< TreeNode * > & childNodes() const
Returns the list of children.
Definition: TreeNode.h:82
void removeChildNode(TreeNode *node)
Removes a child node.
Definition: TreeNode.C:96
Example implementation of a single tree list node.
Definition: TreeNode.h:55

Member Data Documentation

§ addMapButton_

Wt::WPushButton* DemoTreeList::addMapButton_
private

Definition at line 39 of file DemoTreeList.h.

§ removeMapButton_

Wt::WPushButton* DemoTreeList::removeMapButton_
private

Definition at line 40 of file DemoTreeList.h.

§ testCount_

int DemoTreeList::testCount_
private

Definition at line 37 of file DemoTreeList.h.

§ testMap_

TreeNode* DemoTreeList::testMap_
private

Definition at line 36 of file DemoTreeList.h.

§ tree_

TreeNode* DemoTreeList::tree_
private

Definition at line 35 of file DemoTreeList.h.


The documentation for this class was generated from the following files:

Generated on Thu Jan 12 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.12