Wt examples
3.2.2
Main Page
Modules
Namespaces
Classes
Files
File List
File Members
build
buildd
witty-3.2.2-p1
examples
wt-homepage
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
27
JWtHome::JWtHome
(
const
WEnvironment
& env)
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
43
WWidget
*
JWtHome::examples
()
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);
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
70
examplesMenu_
->
addTab
(
wrapView
(&
JWtHome::helloWorldExample
),
71
tr
(
"hello-world"
))->
setPathComponent
(
""
);
72
examplesMenu_
->
addTab
(
wrapView
(&
JWtHome::chartExample
),
73
tr
(
"charts"
));
74
examplesMenu_
->
addTab
(
wrapView
(&
JWtHome::treeviewExample
),
75
tr
(
"treeview"
));
76
examplesMenu_
->
addTab
(
wrapView
(&
JWtHome::composerExample
),
77
tr
(
"mail-composer"
));
78
examplesMenu_
->
addTab
(
wrapView
(&
JWtHome::chatExample
),
79
tr
(
"chat"
));
80
examplesMenu_
->
addTab
(
wrapView
(&
JWtHome::figtreeExample
),
81
tr
(
"figtree"
));
82
examplesMenu_
->
addTab
(
wrapView
(&
JWtHome::widgetGalleryExample
),
83
tr
(
"widget-gallery"
));
84
85
// Enable internal paths for the example menu
86
examplesMenu_
->
setInternalPathEnabled
(
"/examples"
);
87
examplesMenu_
->
currentChanged
().
connect
(
this
, &
Home::googleAnalyticsLogger
);
88
89
return
result;
90
}
91
92
WWidget
*
JWtHome::createQuoteForm
()
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
114
WWidget
*
JWtHome::helloWorldExample
()
115
{
116
return
example
(
"home.examples.hello"
,
"hello"
);
117
}
118
119
WWidget
*
JWtHome::chartExample
()
120
{
121
return
example
(
"home.examples.chart"
,
"charts"
);
122
}
123
124
WWidget
*
JWtHome::treeviewExample
()
125
{
126
return
example
(
"home.examples.treeview"
,
"treeviewdragdrop"
);
127
}
128
129
WWidget
*
JWtHome::composerExample
()
130
{
131
return
example
(
"home.examples.composer"
,
"composer"
);
132
}
133
134
WWidget
*
JWtHome::chatExample
()
135
{
136
return
example
(
"home.examples.chat"
,
"simplechat"
);
137
}
138
139
WWidget
*
JWtHome::figtreeExample
()
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
147
WWidget
*
JWtHome::widgetGalleryExample
()
148
{
149
return
example
(
"home.examples.widgetgallery"
,
"widgetgallery"
);
150
}
151
152
WWidget
*
JWtHome::wrapView
(
WWidget
*(
JWtHome
::*
createWidget
)())
153
{
154
return
makeStaticModel(boost::bind(createWidget,
this
));
155
}
156
157
WApplication
*
createJWtHomeApplication
(
const
WEnvironment
& env)
158
{
159
return
new
JWtHome
(env);
160
}
Generated on Tue Oct 30 2012 for
the C++ Web Toolkit (Wt)
by
1.8.1.2