|
Wt examples
3.3.5
|
A demonstration of the treelist. More...
#include <DemoTreeList.h>
Public Member Functions | |
| DemoTreeList (Wt::WContainerWidget *parent) | |
| Create a DemoTreeList. | |
Private Member Functions | |
| void | addMap () |
| Add a map. | |
| void | removeMap () |
| Remove a map. | |
| TreeNode * | makeTreeMap (const std::string name, TreeNode *parent) |
| Create a "map" node, and insert in the given parent. | |
| TreeNode * | makeTreeFile (const std::string name, TreeNode *parent) |
| Create a "file" node, and insert in the given parent. | |
Private Attributes | |
| TreeNode * | tree_ |
| TreeNode * | testMap_ |
| int | testCount_ |
| Wt::WPushButton * | addMapButton_ |
| Wt::WPushButton * | removeMapButton_ |
A demonstration of the treelist.
This is the main class for the treelist example.
Definition at line 27 of file DemoTreeList.h.
| DemoTreeList::DemoTreeList | ( | Wt::WContainerWidget * | parent | ) |
Create a DemoTreeList.
Definition at line 20 of file DemoTreeList.C.
: WContainerWidget(parent),
testCount_(0)
{
addWidget
(new WText("<h2>Wt Tree List example</h2>"
"<p>This is a simple demo of a treelist, implemented using"
" <a href='http://witty.sourceforge.net/'>Wt</a>.</p>"
"<p>The leafs of the tree contain the source code of the "
"tree-list in the classes <b>TreeNode</b> and "
"<b>IconPair</b>, as well as the implementation of this "
"demo itself in the class <b>DemoTreeList</b>.</p>"));
tree_ = makeTreeMap("Examples", 0);
addWidget(tree_);
TreeNode *treelist = makeTreeMap("Tree List", tree_);
TreeNode *wstateicon = makeTreeMap("class IconPair", treelist);
makeTreeFile("<a href=\"IconPair.h\">IconPair.h</a>", wstateicon);
makeTreeFile("<a href=\"IconPair.C\">IconPair.C</a>", wstateicon);
TreeNode *wtreenode = makeTreeMap("class TreeNode", treelist);
makeTreeFile("<a href=\"TreeNode.h\">TreeNode.h</a>", wtreenode);
makeTreeFile("<a href=\"TreeNode.C\">TreeNode.C</a>", wtreenode);
TreeNode *demotreelist = makeTreeMap("class DemoTreeList", treelist);
makeTreeFile("<a href=\"DemoTreeList.h\">DemoTreeList.h</a>", demotreelist);
makeTreeFile("<a href=\"DemoTreeList.C\">DemoTreeList.C</a>", demotreelist);
testMap_ = makeTreeMap("Test map", tree_);
/*
* Buttons to dynamically demonstrate changing the tree contents.
*/
addWidget
(new WText("<p>Use the following buttons to change the tree "
"contents:</p>"));
addMapButton_
= new WPushButton("Add map", this);
addMapButton_->clicked().connect(this, &DemoTreeList::addMap);
removeMapButton_
= new WPushButton("Remove map", this);
removeMapButton_->clicked().connect(this, &DemoTreeList::removeMap);
removeMapButton_->disable();
addWidget
(new WText("<p>Remarks:"
"<ul>"
"<li><p>This is not the instantiation of a pre-defined "
"tree list component, but the full implementation of such "
"a component, in about 350 lines of C++ code !</p> "
"<p>In comparison, the <a href='http://myfaces.apache.org'> "
"Apache MyFaces</a> JSF implementation of tree2, with similar "
"functionality, uses about 2400 lines of Java, and 140 lines "
"of JavaScript code.</p></li>"
"<li><p>Once loaded, the tree list does not require any "
"interaction with the server for handling the click events on "
"the <img src='icons/nav-plus-line-middle.gif' /> and "
"<img src='icons/nav-minus-line-middle.gif' /> icons, "
"because these events have been connected to slots using "
"STATIC connections. Such connections are converted to the "
"appropriate JavaScript code that is inserted into the page. "
"Still, the events are signaled to the server to update the "
"application state.</p></li>"
"<li><p>In contrast, the buttons for manipulating the tree "
"contents use DYNAMIC connections, and thus the update "
"is computed at server-side, and communicated back to the "
"browser (by default using AJAX).</p></li>"
"<li><p>When loading a page, only visible widgets (that are not "
"<b>setHidden(true)</b>) are transmitted. "
"The remaining widgets are loaded in the background after "
"rendering the page. "
"As a result the application is loaded as fast as possible.</p>"
"</li>"
"<li><p>The browser reload button is supported and behaves as "
"expected: the page is reloaded from the server. Again, "
"only visible widgets are transmitted immediately.</p> "
"<p>(For the curious, this is the way to see the actual "
"HTML/JavaScript code !)</p></li>"
"</ul></p>"));
}
| void DemoTreeList::addMap | ( | ) | [private] |
Add a map.
Definition at line 102 of file DemoTreeList.C.
{
TreeNode *node
= makeTreeMap("Map " + boost::lexical_cast<std::string>(++testCount_),
testMap_);
makeTreeFile("File " + boost::lexical_cast<std::string>(testCount_),
node);
removeMapButton_->enable();
}
| 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.
{
IconPair *labelIcon
= new IconPair("icons/document.png", "icons/yellow-folder-open.png",
false);
TreeNode *node = new TreeNode(name, XHTMLText, labelIcon, 0);
if (parent)
parent->addChildNode(node);
return node;
}
| 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.
{
IconPair *labelIcon
= new IconPair("icons/yellow-folder-closed.png",
"icons/yellow-folder-open.png",
false);
TreeNode *node = new TreeNode(name, PlainText, labelIcon, 0);
if (parent)
parent->addChildNode(node);
return node;
}
| void DemoTreeList::removeMap | ( | ) | [private] |
Remove a map.
Definition at line 113 of file DemoTreeList.C.
{
int numMaps = testMap_->childNodes().size();
if (numMaps > 0) {
int c = rand() % numMaps;
TreeNode *child = testMap_->childNodes()[c];
testMap_->removeChildNode(child);
delete child;
if (numMaps == 1)
removeMapButton_->disable();
}
}
Wt::WPushButton* DemoTreeList::addMapButton_ [private] |
Definition at line 39 of file DemoTreeList.h.
Wt::WPushButton* DemoTreeList::removeMapButton_ [private] |
Definition at line 40 of file DemoTreeList.h.
int DemoTreeList::testCount_ [private] |
Definition at line 37 of file DemoTreeList.h.
TreeNode* DemoTreeList::testMap_ [private] |
Definition at line 36 of file DemoTreeList.h.
TreeNode* DemoTreeList::tree_ [private] |
Definition at line 35 of file DemoTreeList.h.
1.7.6.1