Wt examples  4.9.1
Loading...
Searching...
No Matches
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.h>
14#include <Wt/WAnchor.h>
15#include <Wt/WStackedWidget.h>
16#include <Wt/WTreeNode.h>
17#include <Wt/WWidget.h>
18#include <Wt/WViewWidget.h>
19#include <Wt/WTabWidget.h>
20#include <Wt/WMenuItem.h>
21#include <Wt/WTable.h>
22#include <Wt/WEnvironment.h>
23#include <Wt/WLogger.h>
24
25#include "ExampleSourceViewer.h"
26
27JWtHome::JWtHome(const WEnvironment& env, Dbo::SqlConnectionPool& blogDb)
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
43std::unique_ptr<WWidget> JWtHome::examples()
44{
45 std::unique_ptr<WContainerWidget> result(std::make_unique<WContainerWidget>());
46
47 std::unique_ptr<WText> intro(std::make_unique<WText>(tr("home.examples")));
48 intro->setInternalPathEncoding(true);
49 result->addWidget(std::move(intro));
50
51 examplesMenu_ = result->addWidget(std::make_unique<WTabWidget>());
52 WAnimation animation(AnimationEffect::SlideInFromRight, TimingFunction::EaseIn);
53 examplesMenu_->contentsStack()->setTransitionAnimation(animation, true);
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"));
74 examplesMenu_->addTab(std::move(wrapView(&JWtHome::chartExample)),
75 tr("charts"));
77 tr("treeview"));
79 tr("mail-composer"));
80 examplesMenu_->addTab(std::move(wrapView(&JWtHome::chatExample)),
81 tr("chat"));
83 tr("figtree"));
84
85 // Enable internal paths for the example menu
86 examplesMenu_->setInternalPathEnabled("/examples");
87 examplesMenu_->currentChanged().connect(this, &Home::googleAnalyticsLogger);
88
89 return std::move(result);
90}
91
92std::unique_ptr<WWidget> JWtHome::createQuoteForm()
93{
94#ifdef WT_EMWEB_BUILD
95 return std::make_unique<QuoteForm>(QuoteForm::JWt);
96#else
97 return nullptr;
98#endif
99}
100
101std::unique_ptr<WWidget> JWtHome::sourceViewer(const std::string &deployPath)
102{
103 return std::make_unique<ExampleSourceViewer>(deployPath, jwtExamplePath_ + "/", "JAVA");
104}
105
106std::unique_ptr<WWidget> JWtHome::example(const char *textKey, const std::string& sourceDir)
107{
108 std::unique_ptr<WContainerWidget> result = std::make_unique<WContainerWidget>();
109 result->addWidget(std::make_unique<WText>(tr(textKey)));
110 result->addWidget(linkSourceBrowser(sourceDir));
111 return std::move(result);
112}
113
114std::unique_ptr<WWidget> JWtHome::helloWorldExample()
115{
116 return std::move(example("home.examples.hello", "hello"));
117}
118
119std::unique_ptr<WWidget> JWtHome::chartExample()
120{
121 return std::move(example("home.examples.chart", "charts"));
122}
123
124std::unique_ptr<WWidget> JWtHome::treeviewExample()
125{
126 return std::move(example("home.examples.treeview", "treeviewdragdrop"));
127}
128
129std::unique_ptr<WWidget> JWtHome::composerExample()
130{
131 return std::move(example("home.examples.composer", "composer"));
132}
133
134std::unique_ptr<WWidget> JWtHome::chatExample()
135{
136 return std::move(example("home.examples.chat", "simplechat"));
137}
138
139std::unique_ptr<WWidget> JWtHome::figtreeExample()
140{
141 std::unique_ptr<WContainerWidget> result(std::make_unique<WContainerWidget>());
142 WText *text = result->addWidget(std::make_unique<WText>(tr("home.examples.figtree")));
143 text->setInternalPathEncoding(true);
144 return std::move(result);
145}
146
147std::unique_ptr<WWidget> JWtHome::widgetGalleryExample()
148{
149 return std::move(example("home.examples.widgetgallery", "widgetgallery"));
150}
151
152std::unique_ptr<WWidget> JWtHome::wrapView(std::unique_ptr<WWidget> (JWtHome::*createWidget)())
153{
154 return makeStaticModel(std::bind(createWidget, this));
155}
156
157std::unique_ptr<WApplication> createJWtHomeApplication(const WEnvironment& env,
158 Dbo::SqlConnectionPool *blogDb)
159{
160 return std::make_unique<JWtHome>(env, *blogDb);
161}
std::unique_ptr< WApplication > createJWtHomeApplication(const WEnvironment &env, Dbo::SqlConnectionPool *blogDb)
Definition: JWtHome.C:157
Definition: Home.h:68
std::unique_ptr< WWidget > linkSourceBrowser(const std::string &examplePath)
Definition: Home.C:202
void addLanguage(const Lang &l)
Definition: Home.h:86
WTabWidget * examplesMenu_
Definition: Home.h:89
void googleAnalyticsLogger()
Definition: Home.C:430
void init()
Definition: Home.C:63
WString tr(const char *key)
Definition: Home.C:425
std::unique_ptr< WWidget > helloWorldExample()
Definition: JWtHome.C:114
std::unique_ptr< WWidget > figtreeExample()
Definition: JWtHome.C:139
virtual std::unique_ptr< WWidget > sourceViewer(const std::string &deployPath)
Definition: JWtHome.C:101
std::unique_ptr< WWidget > chartExample()
Definition: JWtHome.C:119
std::unique_ptr< WWidget > example(const char *textKey, const std::string &sourceDir)
Definition: JWtHome.C:106
JWtHome(const WEnvironment &env, Dbo::SqlConnectionPool &blogDb)
Definition: JWtHome.C:27
std::string jwtExamplePath_
Definition: JWtHome.h:40
std::unique_ptr< WWidget > chatExample()
Definition: JWtHome.C:134
virtual std::unique_ptr< WWidget > examples()
Definition: JWtHome.C:43
std::unique_ptr< WWidget > treeviewExample()
Definition: JWtHome.C:124
std::unique_ptr< WWidget > widgetGalleryExample()
Definition: JWtHome.C:147
std::unique_ptr< WWidget > wrapView(std::unique_ptr< WWidget >(JWtHome::*createFunction)())
Definition: JWtHome.C:152
virtual std::unique_ptr< WWidget > createQuoteForm()
Definition: JWtHome.C:92
std::unique_ptr< WWidget > composerExample()
Definition: JWtHome.C:129
std::unique_ptr< Wt::WApplication > createWidget(const Wt::WEnvironment &env, SimpleChatServer &server)
Definition: simpleChat.C:148
Definition: Home.h:23