Wt examples  3.3.0
JWtHome.C
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Emweb bvba, Kessel-Lo, Belgium.
3  *
4  * See the LICENSE file for terms of use.
5  */
6 
7 #include "JWtHome.h"
8 
9 #ifdef WT_EMWEB_BUILD
10 #include "QuoteForm.h"
11 #endif // WT_EMWEB_BUILD
12 
13 #include <Wt/WText>
14 #include <Wt/WAnchor>
15 #include <Wt/WStackedWidget>
16 #include <Wt/WTreeNode>
17 #include <Wt/WWidget>
18 #include <Wt/WViewWidget>
19 #include <Wt/WTabWidget>
20 #include <Wt/WMenuItem>
21 #include <Wt/WTable>
22 #include <Wt/WEnvironment>
23 #include <Wt/WLogger>
24 
25 #include "ExampleSourceViewer.h"
26 
28  : Home(env,
29  "JWt, Java Web Toolkit",
30  "jwt-home", "css/jwt")
31 {
32  addLanguage(Lang("en", "/", "en", "English"));
33 
34  char* jwtExamplePath = getenv("JWT_EXAMPLE_PATH");
35  if (jwtExamplePath)
36  jwtExamplePath_ = jwtExamplePath;
37  else
38  jwtExamplePath_ = "/home/pieter/projects/jwt/wt-port/java/examples/";
39 
40  init();
41 }
42 
44 {
45  WContainerWidget *result = new WContainerWidget();
46 
47  WText *intro = new WText(tr("home.examples"));
48  intro->setInternalPathEncoding(true);
49  result->addWidget(intro);
50 
51  examplesMenu_ = new WTabWidget(result);
52  WAnimation animation(WAnimation::SlideInFromRight, WAnimation::EaseIn);
54 
55  /*
56  * The following code is functionally equivalent to:
57  *
58  * examplesMenu_->addTab(helloWorldExample(), "Hello world");
59  *
60  * However, we optimize here for memory consumption (it is a homepage
61  * after all, and we hope to be slashdotted some day)
62  *
63  * Therefore, we wrap all the static content (including the tree
64  * widgets), into WViewWidgets with static models. In this way the
65  * widgets are not actually stored in memory on the server.
66  */
67 
68  // The call ->setPathComponent() is to use "/examples/" instead of
69  // "/examples/hello_world" as internal path
71  tr("hello-world"))->setPathComponent("");
73  tr("charts"));
75  tr("treeview"));
77  tr("mail-composer"));
79  tr("chat"));
81  tr("figtree"));
83  tr("widget-gallery"));
84 
85  // Enable internal paths for the example menu
88 
89  return result;
90 }
91 
93 {
94 #ifdef WT_EMWEB_BUILD
95  return new QuoteForm(QuoteForm::JWt);
96 #else
97  return 0;
98 #endif
99 }
100 
101 WWidget *JWtHome::sourceViewer(const std::string &deployPath)
102 {
103  return new ExampleSourceViewer(deployPath, jwtExamplePath_ + "/", "JAVA");
104 }
105 
106 WWidget *JWtHome::example(const char *textKey, const std::string& sourceDir)
107 {
108  WContainerWidget *result = new WContainerWidget();
109  new WText(tr(textKey), result);
110  result->addWidget(linkSourceBrowser(sourceDir));
111  return result;
112 }
113 
115 {
116  return example("home.examples.hello", "hello");
117 }
118 
120 {
121  return example("home.examples.chart", "charts");
122 }
123 
125 {
126  return example("home.examples.treeview", "treeviewdragdrop");
127 }
128 
130 {
131  return example("home.examples.composer", "composer");
132 }
133 
135 {
136  return example("home.examples.chat", "simplechat");
137 }
138 
140 {
141  WContainerWidget *result = new WContainerWidget();
142  WText *text = new WText(tr("home.examples.figtree"), result);
143  text->setInternalPathEncoding(true);
144  return result;
145 }
146 
148 {
149  return example("home.examples.widgetgallery", "widgetgallery");
150 }
151 
153 {
154  return makeStaticModel(boost::bind(createWidget, this));
155 }
156 
158 {
159  return new JWtHome(env);
160 }

Generated on Fri May 31 2013 for the C++ Web Toolkit (Wt) by doxygen 1.8.3.1