Wt examples  4.0.2
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 ()
 Create a DemoTreeList. More...
 

Private Member Functions

void addFolder ()
 Add a folder. More...
 
void removeFolder ()
 Remove a folder. More...
 
TreeNodemakeTreeFolder (const std::string name, TreeNode *parent)
 Create a "folder" node, and insert in the given parent. More...
 
std::unique_ptr< TreeNodemakeTreeFolder (const std::string name)
 Create a "folder" root. More...
 
TreeNodemakeTreeFile (const std::string name, TreeNode *parent)
 Create a "file" node, and insert in the given parent. More...
 
std::unique_ptr< TreeNodemakeTreeFile (const std::string name)
 Create a "file" root. More...
 

Private Attributes

TreeNodetree_
 
TreeNodetestFolder_
 
int testCount_
 
WPushButton * addFolderButton_
 
WPushButton * removeFolderButton_
 

Detailed Description

A demonstration of the treelist.

This is the main class for the treelist example.

Definition at line 29 of file DemoTreeList.h.

Constructor & Destructor Documentation

◆ DemoTreeList()

DemoTreeList::DemoTreeList ( )

Create a DemoTreeList.

Definition at line 19 of file DemoTreeList.C.

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

Member Function Documentation

◆ addFolder()

void DemoTreeList::addFolder ( )
private

Add a folder.

Definition at line 101 of file DemoTreeList.C.

102 {
103  TreeNode *node
104  = makeTreeFolder("Folder " + std::to_string(++testCount_), testFolder_);
105  makeTreeFile("File " + std::to_string(testCount_), node);
106 
107  removeFolderButton_->enable();
108 }
WPushButton * removeFolderButton_
Definition: DemoTreeList.h:42
TreeNode * makeTreeFolder(const std::string name, TreeNode *parent)
Create a "folder" node, and insert in the given parent.
Definition: DemoTreeList.C:125
TreeNode * testFolder_
Definition: DemoTreeList.h:38
TreeNode * makeTreeFile(const std::string name, TreeNode *parent)
Create a "file" node, and insert in the given parent.
Definition: DemoTreeList.C:152
Example implementation of a single tree list node.
Definition: TreeNode.h:57

◆ makeTreeFile() [1/2]

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

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

Definition at line 152 of file DemoTreeList.C.

154 {
155  auto labelIcon
156  = cpp14::make_unique<IconPair>("icons/document.png", "icons/yellow-folder-open.png",
157  false);
158 
159  auto node = cpp14::make_unique<TreeNode>(name, TextFormat::XHTML, std::move(labelIcon));
160  auto node_ = node.get();
161  if (parent)
162  parent->addChildNode(std::move(node));
163 
164  return node_;
165 }
void addChildNode(std::unique_ptr< TreeNode > node)
Adds a child node.
Definition: TreeNode.C:96

◆ makeTreeFile() [2/2]

std::unique_ptr< TreeNode > DemoTreeList::makeTreeFile ( const std::string  name)
private

Create a "file" root.

Definition at line 167 of file DemoTreeList.C.

168 {
169  auto labelIcon
170  = cpp14::make_unique<IconPair>("icons/document.png", "icons/yellow-folder-open.png",
171  false);
172  auto node =
173  cpp14::make_unique<TreeNode>(name, TextFormat::XHTML, std::move(labelIcon));
174 
175  return node;
176 }

◆ makeTreeFolder() [1/2]

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

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

Definition at line 125 of file DemoTreeList.C.

126 {
127  auto labelIcon = cpp14::make_unique<IconPair>(
128  "icons/yellow-folder-closed.png",
129  "icons/yellow-folder-open.png",
130  false);
131 
132  auto node =
133  cpp14::make_unique<TreeNode>(name, TextFormat::Plain, std::move(labelIcon));
134  auto node_ = node.get();
135  parent->addChildNode(std::move(node));
136 
137  return node_;
138 }
void addChildNode(std::unique_ptr< TreeNode > node)
Adds a child node.
Definition: TreeNode.C:96

◆ makeTreeFolder() [2/2]

std::unique_ptr< TreeNode > DemoTreeList::makeTreeFolder ( const std::string  name)
private

Create a "folder" root.

Definition at line 140 of file DemoTreeList.C.

141 {
142  auto labelIcon = cpp14::make_unique<IconPair>(
143  "icons/yellow-folder-closed.png",
144  "icons/yellow-folder-open.png",
145  false);
146  auto node =
147  cpp14::make_unique<TreeNode>(name, TextFormat::Plain, std::move(labelIcon));
148 
149  return node;
150 }

◆ removeFolder()

void DemoTreeList::removeFolder ( )
private

Remove a folder.

Definition at line 110 of file DemoTreeList.C.

111 {
112  int numFolders = testFolder_->childNodes().size();
113 
114  if (numFolders > 0) {
115  int c = rand() % numFolders;
116 
117  TreeNode *child = testFolder_->childNodes()[c];
118  testFolder_->removeChildNode(child, c);
119 
120  if (numFolders == 1)
121  removeFolderButton_->disable();
122  }
123 }
WPushButton * removeFolderButton_
Definition: DemoTreeList.h:42
void removeChildNode(TreeNode *node, int index)
Removes a child node.
Definition: TreeNode.C:106
const std::vector< TreeNode * > & childNodes() const
Returns the list of children.
Definition: TreeNode.h:84
TreeNode * testFolder_
Definition: DemoTreeList.h:38
Example implementation of a single tree list node.
Definition: TreeNode.h:57

Member Data Documentation

◆ addFolderButton_

WPushButton* DemoTreeList::addFolderButton_
private

Definition at line 41 of file DemoTreeList.h.

◆ removeFolderButton_

WPushButton* DemoTreeList::removeFolderButton_
private

Definition at line 42 of file DemoTreeList.h.

◆ testCount_

int DemoTreeList::testCount_
private

Definition at line 39 of file DemoTreeList.h.

◆ testFolder_

TreeNode* DemoTreeList::testFolder_
private

Definition at line 38 of file DemoTreeList.h.

◆ tree_

TreeNode* DemoTreeList::tree_
private

Definition at line 37 of file DemoTreeList.h.


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

Generated on Thu Mar 15 2018 for the C++ Web Toolkit (Wt) by doxygen 1.8.14