Wt examples 3.3.12
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, 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);
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
101WWidget *JWtHome::sourceViewer(const std::string &deployPath)
102{
103 return new ExampleSourceViewer(deployPath, jwtExamplePath_ + "/", "JAVA");
104}
105
106WWidget *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}
WApplication * createJWtHomeApplication(const WEnvironment &env, Wt::Dbo::SqlConnectionPool *blogDb)
Definition JWtHome.C:157
A simple widget to visualise a set of example source files.
Definition Home.h:68
void addLanguage(const Lang &l)
Definition Home.h:86
WTabWidget * examplesMenu_
Definition Home.h:89
void googleAnalyticsLogger()
Definition Home.C:426
void init()
Definition Home.C:62
WWidget * linkSourceBrowser(const std::string &examplePath)
Definition Home.C:200
WString tr(const char *key)
Definition Home.C:421
virtual WWidget * examples()
Definition JWtHome.C:43
WWidget * composerExample()
Definition JWtHome.C:129
WWidget * figtreeExample()
Definition JWtHome.C:139
WWidget * chartExample()
Definition JWtHome.C:119
virtual WWidget * createQuoteForm()
Definition JWtHome.C:92
WWidget * treeviewExample()
Definition JWtHome.C:124
virtual WWidget * sourceViewer(const std::string &deployPath)
Definition JWtHome.C:101
std::string jwtExamplePath_
Definition JWtHome.h:40
WWidget * wrapView(WWidget *(JWtHome::*createFunction)())
Definition JWtHome.C:152
WWidget * chatExample()
Definition JWtHome.C:134
WWidget * helloWorldExample()
Definition JWtHome.C:114
JWtHome(const WEnvironment &env, Wt::Dbo::SqlConnectionPool &blogDb)
Definition JWtHome.C:27
WWidget * example(const char *textKey, const std::string &sourceDir)
Definition JWtHome.C:106
WWidget * widgetGalleryExample()
Definition JWtHome.C:147
virtual Wt::Signals::connection connect(WObject *target, WObject::Method method)
virtual void addWidget(WWidget *widget)
virtual void setPathComponent(const std::string &path)
void setTransitionAnimation(const WAnimation &animation, bool autoReverse=false)
void setInternalPathEnabled(const std::string &basePath="")
WMenuItem * addTab(WWidget *child, const WString &label, LoadPolicy=LazyLoading)
Signal< int > & currentChanged()
WStackedWidget * contentsStack() const
void setInternalPathEncoding(bool enabled)
WApplication * createWidget(const WEnvironment &env, SimpleChatServer &server)
Definition simpleChat.C:145
Definition Home.h:23

Generated on Fri May 17 2024 for the C++ Web Toolkit (Wt) by doxygen 1.9.8