6 #include <boost/lexical_cast.hpp> 8 #include <Wt/WApplication> 11 #include <Wt/WPushButton> 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>"));
38 makeTreeFile(
"<a href=\"IconPair.h\">IconPair.h</a>", wstateicon);
39 makeTreeFile(
"<a href=\"IconPair.C\">IconPair.C</a>", wstateicon);
41 makeTreeFile(
"<a href=\"TreeNode.h\">TreeNode.h</a>", wtreenode);
42 makeTreeFile(
"<a href=\"TreeNode.C\">TreeNode.C</a>", wtreenode);
44 makeTreeFile(
"<a href=\"DemoTreeList.h\">DemoTreeList.h</a>", demotreelist);
45 makeTreeFile(
"<a href=\"DemoTreeList.C\">DemoTreeList.C</a>", demotreelist);
53 (
new WText(
"<p>Use the following buttons to change the tree " 66 (
new WText(
"<p>Remarks:" 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>" 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>" 118 int c = rand() % numMaps;
132 =
new IconPair(
"icons/yellow-folder-closed.png",
133 "icons/yellow-folder-open.png",
147 =
new IconPair(
"icons/document.png",
"icons/yellow-folder-open.png",
168 treeNodeLabelStyle.
font().
setFamily(WFont::Serif,
"Helvetica");
175 "color:blue; font-family:Helvetica,serif;");
180 int main(
int argc,
char **argv)
Wt::WPushButton * addMapButton_
An icon pair (identical to WIconPair)
TreeNode * makeTreeMap(const std::string name, TreeNode *parent)
Create a "map" node, and insert in the given parent.
Wt::WPushButton * removeMapButton_
void removeMap()
Remove a map.
DemoTreeList(Wt::WContainerWidget *parent)
Create a DemoTreeList.
WContainerWidget * root() const
void addChildNode(TreeNode *node)
Adds a child node.
WApplication * createApplication(const WEnvironment &env)
void setFamily(FontFamily genericFamily, const WString &specificFamilies=WString())
WCssTextRule * addRule(const std::string &selector, const WString &declarations, const std::string &ruleName=std::string())
const std::vector< TreeNode * > & childNodes() const
Returns the list of children.
int main(int argc, char **argv)
void removeChildNode(TreeNode *node)
Removes a child node.
WCssStyleSheet & styleSheet()
TreeNode * makeTreeFile(const std::string name, TreeNode *parent)
Create a "file" node, and insert in the given parent.
Example implementation of a single tree list node.