Wt examples  3.7.1
JWtHome.C
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Emweb bv, Herent, 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, blogDb,
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("widget-gallery"));
75  tr("charts"));
77  tr("treeview"));
79  tr("mail-composer"));
81  tr("chat"));
83  tr("figtree"));
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 
159 {
160  return new JWtHome(env, *blogDb);
161 }
A simple widget to visualise a set of example source files.
WMenuItem * addTab(std::unique_ptr< WWidget > child, const WString &label, ContentLoading loadPolicy=ContentLoading::Lazy)
WWidget * linkSourceBrowser(const std::string &examplePath)
Definition: Home.C:200
WWidget * chartExample()
Definition: JWtHome.C:119
JWtHome(const WEnvironment &env, Wt::Dbo::SqlConnectionPool &blogDb)
Definition: JWtHome.C:27
WWidget * composerExample()
Definition: JWtHome.C:129
Signal< int > & currentChanged()
WWidget * example(const char *textKey, const std::string &sourceDir)
Definition: JWtHome.C:106
void setTransitionAnimation(const WAnimation &animation, bool autoReverse=false)
Definition: Home.h:23
WString tr(const char *key)
Definition: Home.C:421
WWidget * widgetGalleryExample()
Definition: JWtHome.C:147
Definition: Home.h:67
std::string jwtExamplePath_
Definition: JWtHome.h:40
WApplication * createJWtHomeApplication(const WEnvironment &env, Wt::Dbo::SqlConnectionPool *blogDb)
Definition: JWtHome.C:157
void setInternalPathEnabled(const std::string &basePath="")
WWidget * figtreeExample()
Definition: JWtHome.C:139
WStackedWidget * contentsStack() const
virtual WWidget * createQuoteForm()
Definition: JWtHome.C:92
void init()
Definition: Home.C:62
virtual WWidget * sourceViewer(const std::string &deployPath)
Definition: JWtHome.C:101
void setInternalPathEncoding(bool enabled)
WWidget * wrapView(WWidget *(JWtHome::*createFunction)())
Definition: JWtHome.C:152
WTabWidget * examplesMenu_
Definition: Home.h:89
WWidget * helloWorldExample()
Definition: JWtHome.C:114
WApplication * createWidget(const WEnvironment &env, SimpleChatServer &server)
Definition: simpleChat.C:145
virtual WWidget * examples()
Definition: JWtHome.C:43
WWidget * treeviewExample()
Definition: JWtHome.C:124
virtual void setPathComponent(const std::string &path)
WWidget * chatExample()
Definition: JWtHome.C:134
void addLanguage(const Lang &l)
Definition: Home.h:86
virtual Wt::Signals::connection connect(WObject *target, WObject::Method method) override
virtual void addWidget(std::unique_ptr< WWidget > widget)
void googleAnalyticsLogger()
Definition: Home.C:426

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13