7 #include <Wt/WApplication.h> 10 #include <Wt/WPushButton.h> 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>"));
37 makeTreeFile(
"<a href=\"IconPair.h\">IconPair.h</a>", wstateicon);
38 makeTreeFile(
"<a href=\"IconPair.C\">IconPair.C</a>", wstateicon);
40 makeTreeFile(
"<a href=\"TreeNode.h\">TreeNode.h</a>", wtreenode);
41 makeTreeFile(
"<a href=\"TreeNode.C\">TreeNode.C</a>", wtreenode);
43 makeTreeFile(
"<a href=\"DemoTreeList.h\">DemoTreeList.h</a>", demotreelist);
44 makeTreeFile(
"<a href=\"DemoTreeList.C\">DemoTreeList.C</a>", demotreelist);
52 (cpp14::make_unique<WText>(
"<p>Use the following buttons to change the tree " 56 = this->
addWidget(cpp14::make_unique<WPushButton>(
"Add folder"));
60 = this->
addWidget(cpp14::make_unique<WPushButton>(
"Remove folder"));
65 (cpp14::make_unique<WText>(
"<p>Remarks:" 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>" 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>" 114 if (numFolders > 0) {
115 int c = rand() % numFolders;
127 auto labelIcon = cpp14::make_unique<IconPair>(
128 "icons/yellow-folder-closed.png",
129 "icons/yellow-folder-open.png",
133 cpp14::make_unique<TreeNode>(name, TextFormat::Plain, std::move(labelIcon));
134 auto node_ = node.get();
142 auto labelIcon = cpp14::make_unique<IconPair>(
143 "icons/yellow-folder-closed.png",
144 "icons/yellow-folder-open.png",
147 cpp14::make_unique<TreeNode>(name, TextFormat::Plain, std::move(labelIcon));
156 = cpp14::make_unique<IconPair>(
"icons/document.png",
"icons/yellow-folder-open.png",
159 auto node = cpp14::make_unique<TreeNode>(name, TextFormat::XHTML, std::move(labelIcon));
160 auto node_ = node.get();
170 = cpp14::make_unique<IconPair>(
"icons/document.png",
"icons/yellow-folder-open.png",
173 cpp14::make_unique<TreeNode>(name, TextFormat::XHTML, std::move(labelIcon));
181 = cpp14::make_unique<WApplication>(env);
182 app->root()->addWidget(cpp14::make_unique<DemoTreeList>());
190 treeNodeLabelStyle.
font().
setFamily(FontFamily::Serif,
"Helvetica");
191 app->styleSheet().addRule(
".treenodelabel", treeNodeLabelStyle);
196 app->styleSheet().addRule(
".treenodechildcount",
197 "color:blue; font-family:Helvetica,serif;");
202 int main(
int argc,
char **argv)
WPushButton * removeFolderButton_
const std::vector< TreeNode * > & childNodes() const
Returns the list of children.
DemoTreeList()
Create a DemoTreeList.
Wt::Signals::connection connect(const F &function)
void addFolder()
Add a folder.
void setFamily(FontFamily genericFamily, const WString &specificFamilies=WString())
std::unique_ptr< WApplication > createApplication(const WEnvironment &env)
TreeNode * makeTreeFolder(const std::string name, TreeNode *parent)
Create a "folder" node, and insert in the given parent.
void removeChildNode(TreeNode *node, int index)
Removes a child node.
int main(int argc, char **argv)
void addChildNode(std::unique_ptr< TreeNode > node)
Adds a child node.
WPushButton * addFolderButton_
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.
void removeFolder()
Remove a folder.