Wt examples
3.2.2
|
00001 /* 00002 * Copyright (C) 2009 Emweb bvba, Kessel-Lo, Belgium. 00003 * 00004 * See the LICENSE file for terms of use. 00005 */ 00006 00007 #include "JWtHome.h" 00008 00009 #ifdef WT_EMWEB_BUILD 00010 #include "QuoteForm.h" 00011 #endif // WT_EMWEB_BUILD 00012 00013 #include <Wt/WText> 00014 #include <Wt/WAnchor> 00015 #include <Wt/WStackedWidget> 00016 #include <Wt/WTreeNode> 00017 #include <Wt/WWidget> 00018 #include <Wt/WViewWidget> 00019 #include <Wt/WTabWidget> 00020 #include <Wt/WMenuItem> 00021 #include <Wt/WTable> 00022 #include <Wt/WEnvironment> 00023 #include <Wt/WLogger> 00024 00025 #include "ExampleSourceViewer.h" 00026 00027 JWtHome::JWtHome(const WEnvironment& env) 00028 : Home(env, 00029 "JWt, Java Web Toolkit", 00030 "jwt-home", "css/jwt") 00031 { 00032 addLanguage(Lang("en", "/", "en", "English")); 00033 00034 char* jwtExamplePath = getenv("JWT_EXAMPLE_PATH"); 00035 if (jwtExamplePath) 00036 jwtExamplePath_ = jwtExamplePath; 00037 else 00038 jwtExamplePath_ = "/home/pieter/projects/jwt/wt-port/java/examples/"; 00039 00040 init(); 00041 } 00042 00043 WWidget *JWtHome::examples() 00044 { 00045 WContainerWidget *result = new WContainerWidget(); 00046 00047 WText *intro = new WText(tr("home.examples")); 00048 intro->setInternalPathEncoding(true); 00049 result->addWidget(intro); 00050 00051 examplesMenu_ = new WTabWidget(result); 00052 WAnimation animation(WAnimation::SlideInFromRight, WAnimation::EaseIn); 00053 examplesMenu_->contentsStack()->setTransitionAnimation(animation, true); 00054 00055 /* 00056 * The following code is functionally equivalent to: 00057 * 00058 * examplesMenu_->addTab(helloWorldExample(), "Hello world"); 00059 * 00060 * However, we optimize here for memory consumption (it is a homepage 00061 * after all, and we hope to be slashdotted some day) 00062 * 00063 * Therefore, we wrap all the static content (including the tree 00064 * widgets), into WViewWidgets with static models. In this way the 00065 * widgets are not actually stored in memory on the server. 00066 */ 00067 00068 // The call ->setPathComponent() is to use "/examples/" instead of 00069 // "/examples/hello_world" as internal path 00070 examplesMenu_->addTab(wrapView(&JWtHome::helloWorldExample), 00071 tr("hello-world"))->setPathComponent(""); 00072 examplesMenu_->addTab(wrapView(&JWtHome::chartExample), 00073 tr("charts")); 00074 examplesMenu_->addTab(wrapView(&JWtHome::treeviewExample), 00075 tr("treeview")); 00076 examplesMenu_->addTab(wrapView(&JWtHome::composerExample), 00077 tr("mail-composer")); 00078 examplesMenu_->addTab(wrapView(&JWtHome::chatExample), 00079 tr("chat")); 00080 examplesMenu_->addTab(wrapView(&JWtHome::figtreeExample), 00081 tr("figtree")); 00082 examplesMenu_->addTab(wrapView(&JWtHome::widgetGalleryExample), 00083 tr("widget-gallery")); 00084 00085 // Enable internal paths for the example menu 00086 examplesMenu_->setInternalPathEnabled("/examples"); 00087 examplesMenu_->currentChanged().connect(this, &Home::googleAnalyticsLogger); 00088 00089 return result; 00090 } 00091 00092 WWidget *JWtHome::createQuoteForm() 00093 { 00094 #ifdef WT_EMWEB_BUILD 00095 return new QuoteForm(QuoteForm::JWt); 00096 #else 00097 return 0; 00098 #endif 00099 } 00100 00101 WWidget *JWtHome::sourceViewer(const std::string &deployPath) 00102 { 00103 return new ExampleSourceViewer(deployPath, jwtExamplePath_ + "/", "JAVA"); 00104 } 00105 00106 WWidget *JWtHome::example(const char *textKey, const std::string& sourceDir) 00107 { 00108 WContainerWidget *result = new WContainerWidget(); 00109 new WText(tr(textKey), result); 00110 result->addWidget(linkSourceBrowser(sourceDir)); 00111 return result; 00112 } 00113 00114 WWidget *JWtHome::helloWorldExample() 00115 { 00116 return example("home.examples.hello", "hello"); 00117 } 00118 00119 WWidget *JWtHome::chartExample() 00120 { 00121 return example("home.examples.chart", "charts"); 00122 } 00123 00124 WWidget *JWtHome::treeviewExample() 00125 { 00126 return example("home.examples.treeview", "treeviewdragdrop"); 00127 } 00128 00129 WWidget *JWtHome::composerExample() 00130 { 00131 return example("home.examples.composer", "composer"); 00132 } 00133 00134 WWidget *JWtHome::chatExample() 00135 { 00136 return example("home.examples.chat", "simplechat"); 00137 } 00138 00139 WWidget *JWtHome::figtreeExample() 00140 { 00141 WContainerWidget *result = new WContainerWidget(); 00142 WText *text = new WText(tr("home.examples.figtree"), result); 00143 text->setInternalPathEncoding(true); 00144 return result; 00145 } 00146 00147 WWidget *JWtHome::widgetGalleryExample() 00148 { 00149 return example("home.examples.widgetgallery", "widgetgallery"); 00150 } 00151 00152 WWidget *JWtHome::wrapView(WWidget *(JWtHome::*createWidget)()) 00153 { 00154 return makeStaticModel(boost::bind(createWidget, this)); 00155 } 00156 00157 WApplication *createJWtHomeApplication(const WEnvironment& env) 00158 { 00159 return new JWtHome(env); 00160 }