高级SmartGWT教程,第1部分

贾斯汀(Justin),帕特(Pat)和我已经开始着手一个需要用户界面进行管理和管理的副项目。 在与SmartGWT和GWT共同工作了一段时间之后,我们决定使用SmartGWT创建接口。 我们非常喜欢视觉组件(请查看SmartGWT展示柜 )以及它有助于快速开发的事实。

在本教程中,我将向您展示如何在短短几个小时内为用户界面创建原型。 该界面在很大程度上受Drools Guvnor应用程序的影响。 我们在许多项目中都使用了Drools,并且有Guvnor来创建业务规则。 我们只是喜欢用户界面,它既美观又实用。 查看一些Guvnor屏幕截图 。

让我们开始吧。 我假设您已经安装了GWT SDK和Eclipse的Google插件 。 SmartGWT与GWT 1.5.3,GWT 1.6.4,GWT 1.7.x和GWT 2.0.x兼容。 当前,我正在使用GWT 2.1.0 SDK和SmartGWT 2.2版本。 从本质上讲,这是有关SmartGWT的更高级的教程,因此您可能必须检查一下我的介绍性文章“ SmartGWT入门以获取出色的GWT接口”教程。 此外,另一个有用的资源是“布局用户界面”教程,我们曾用来启动我们自己的界面的开发。

首先,我们在Eclipse中创建一个新的“ Web应用程序项目”。 我选择“ AwesomeSmartGWTUIProject”作为项目名称,选择“ com.javacodegeeks.smartgwt.appui”作为程序包名称。

接下来,将提取的ZIP中的“ smartgwt.jar”文件添加到项目的类路径中。 请注意,该文件也应添加到“ war / WEB-INF / lib”目录中。

然后编辑模块xml文件(名为“ AwesomeSmartGWTUIProject.gwt.xml”),并在标准“继承”声明之后添加以下行:

<inherits name="com.smartgwt.SmartGwt"/>

另外,注释掉声明GWT主题用法的现有部分:

<!--<inherits name='com.google.gwt.user.theme.standard.Standard'/> -->

这是模块XML文件的外观:

<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='awesomesmartgwtuiproject'><!-- Inherit the core Web Toolkit stuff.                        --><inherits name='com.google.gwt.user.User'/><!-- Inherit the default GWT style sheet.  You can change       --><!-- the theme of your GWT application by uncommenting          --><!-- any one of the following lines.                            --><!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/>  --><!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> --><!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>     --><!-- Other module inherits                                      --><inherits name="com.smartgwt.SmartGwt"/><!-- Specify the app entry point class.                         --><entry-point class='com.javacodegeeks.smartgwt.appui.client.AwesomeSmartGWTUIProject'/><!-- Specify the paths for translatable code                    --><source path='client'/><source path='shared'/></module>

下一步是删除“ AwesomeSmartGWTUIProject.html”文件中存在的一些自动生成的代码,尤其是H1和Table标记。 这是您应该得到的:

<!doctype html>
<!-- The DOCTYPE declaration above will set the    -->
<!-- browser's rendering engine into               -->
<!-- "Standards Mode". Replacing this declaration  -->
<!-- with a "Quirks Mode" doctype may lead to some -->
<!-- differences in layout.                        --><html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><!--                                                               --><!-- Consider inlining CSS to reduce the number of requested files --><!--                                                               --><link type="text/css" rel="stylesheet" href="AwesomeSmartGWTUIProject.css"><!--                                           --><!-- Any title is fine                         --><!--                                           --><title>Web Application Starter Project</title><!--                                           --><!-- This script loads your compiled module.   --><!-- If you add any GWT meta tags, they must   --><!-- be added before this line.                --><!--                                           --><script type="text/javascript" language="javascript" src="awesomesmartgwtuiproject/awesomesmartgwtuiproject.nocache.js"></script></head><!--                                           --><!-- The body can have arbitrary html, or      --><!-- you can leave the body empty if you want  --><!-- to create a completely dynamic UI.        --><!--                                           --><body><!-- OPTIONAL: include this if you want history support --><iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe><!-- RECOMMENDED if your web app will not function without JavaScript enabled --><noscript><div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">Your web browser must have JavaScript enabledin order for this application to display correctly.</div></noscript></body>
</html>

同样,删除所有存在于EntryPoint类中的名为“ AwesomeSmartGWTUIProject”的代码,并仅保留一个空的onModuleLoad方法,如下所示:

package com.javacodegeeks.smartgwt.appui.client;import com.google.gwt.core.client.EntryPoint;public class AwesomeSmartGWTUIProject implements EntryPoint {public void onModuleLoad() {}}

现在,我们准备开始编写SmartGWT代码,因此请确保已为SmartGWT Javadocs添加了书签。 在构建接口时,我们将继续使用两个非常重要的类。

  • HLayout :这是一个与布局相关的类,沿水平轴应用大小调整策略,即,其所有内部组件将以水平方式放置。
  • VLayout :这是一个与布局相关的类,沿垂直轴应用大小调整策略,即,所有内部组件都将以垂直方式放置。

这些类都从父Layout扩展,因此它们继承了addMember方法,该方法允许它们添加其他Canvas对象或Widget 。

使用各种布局对象,我们会将整个屏幕区域分解为特定的子区域(北,南,东,西和主区域)。 让我们看看入口点类的第一个版本如何:

package com.javacodegeeks.smartgwt.appui.client;import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.javacodegeeks.smartgwt.appui.client.ui.ApplicationMenu;
import com.javacodegeeks.smartgwt.appui.client.ui.HeaderArea;
import com.javacodegeeks.smartgwt.appui.client.ui.MainArea;
import com.javacodegeeks.smartgwt.appui.client.ui.NavigationArea;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;public class AwesomeSmartGWTUIProject implements EntryPoint {private static final int HEADER_HEIGHT = 85;private VLayout mainLayout;private HLayout northLayout;private HLayout southLayout;private VLayout eastLayout;private HLayout westLayout;public void onModuleLoad() {Window.enableScrolling(false);Window.setMargin("0px");// main layout occupies the whole areamainLayout = new VLayout();mainLayout.setWidth100();mainLayout.setHeight100();northLayout = new HLayout();northLayout.setHeight(HEADER_HEIGHT);VLayout vLayout = new VLayout();vLayout.addMember(new HeaderArea());vLayout.addMember(new ApplicationMenu());northLayout.addMember(vLayout);westLayout = new NavigationArea();westLayout.setWidth("15%");eastLayout = new MainArea();eastLayout.setWidth("85%");southLayout = new HLayout();southLayout.setMembers(westLayout, eastLayout);mainLayout.addMember(northLayout);mainLayout.addMember(southLayout);// add the main layout container to GWT's root panelRootLayoutPanel.get().add(mainLayout);}}

不用担心编译错误,我们稍后将创建必要的类。 如您所见,我们将整个屏幕区域划分为较小的块,并使用SmartGWT API将所有组件连接在一起。 请注意使用setWidth100和setHeight100方法,它们方便地允许特定组件占据整个可用区域。 最后, RootLayoutPanel是GWT类,它使我们可以访问屏幕的根面板。 现在让我们创建各种组件。

* ApplicationMenu:

package com.javacodegeeks.smartgwt.appui.client.ui;import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.layout.HLayout;public class ApplicationMenu extends HLayout {private static final int APPLICATION_MENU_HEIGHT = 27;private Label label;public ApplicationMenu() {super();this.setHeight(APPLICATION_MENU_HEIGHT);label = new Label();label.setContents("Application Menu");label.setAlign(Alignment.CENTER);label.setOverflow(Overflow.HIDDEN);this.addMember(label);}}

这里没什么特别的,我们只是在布局中添加了一个Label并将Alignment设置为居中。

*标头区域:

package com.javacodegeeks.smartgwt.appui.client.ui;import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.layout.HLayout;public class HeaderArea extends HLayout {private static final int HEADER_AREA_HEIGHT = 60;public HeaderArea() {super();this.setHeight(HEADER_AREA_HEIGHT);Img logo = new Img("jcg_logo.png", 282, 60);Label name = new Label();name.setOverflow(Overflow.HIDDEN);  name.setContents("Java 2 Java Developers Resource Center"); HLayout westLayout = new HLayout();westLayout.setHeight(HEADER_AREA_HEIGHT);    westLayout.setWidth("70%");westLayout.addMember(logo);westLayout.addMember(name);Label signedInUser = new Label();signedInUser.setContents("Fabrizio Chami ");   HLayout eastLayout = new HLayout();eastLayout.setAlign(Alignment.RIGHT);  eastLayout.setHeight(HEADER_AREA_HEIGHT);eastLayout.setWidth("30%");eastLayout.addMember(signedInUser);this.addMember(westLayout);      this.addMember(eastLayout);}}

同样,很简单。 我们使用Img类添加了图像,并提供了文件名。 请注意,图像URL自动位于“ images”文件夹下,因此基本上“ jcg_logo.png”文件必须位于“ war / images”文件夹中。

*导航区域:

package com.javacodegeeks.smartgwt.appui.client;import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.VisibilityMode;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.SectionStack;
import com.smartgwt.client.widgets.layout.SectionStackSection;public class NavigationArea extends HLayout {public NavigationArea() {super();this.setMembersMargin(20);  this.setOverflow(Overflow.HIDDEN);this.setShowResizeBar(true);final SectionStack sectionStack = new SectionStack();  sectionStack.setVisibilityMode(VisibilityMode.MULTIPLE);sectionStack.setShowExpandControls(true);sectionStack.setAnimateSections(true);sectionStack.setVisibilityMode(VisibilityMode.MUTEX);sectionStack.setOverflow(Overflow.HIDDEN);SectionStackSection section1 = new SectionStackSection("Section 1");section1.setExpanded(true);Label label1 = new Label();label1.setContents("Label1");section1.addItem(label1);SectionStackSection section2 = new SectionStackSection("Section 2");section2.setExpanded(false);Label label2 = new Label();label2.setContents("Label2");label2.setOverflow(Overflow.AUTO);label2.setPadding(10);section2.addItem(label2);SectionStackSection section3 = new SectionStackSection("Section 3");section3.setExpanded(false);Label label3 = new Label();label3.setContents("Label3");label3.setOverflow(Overflow.AUTO);label3.setPadding(10);section3.addItem(label3);sectionStack.addSection(section1);sectionStack.addSection(section2);sectionStack.addSection(section3);this.addMember(sectionStack);}}

对于导航区域,我们需要类似手风琴的组件。 这是在SmartGWT中通过我们向其中添加SectionStackSection实例的SectionStack类实现的。 我们可以向这些项目添加任意的小部件,但是为了简单起见,现在我们仅添加一些Label 。 请注意setShowResizeBar方法的使用,该方法允许我们在布局中的该成员之后显示调整大小的条,以允许调整其大小。

*主要区域:

package com.javacodegeeks.smartgwt.appui.client.ui;import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.Label;
import com.smartgwt.client.widgets.layout.VLayout;public class MainArea extends VLayout {private Label label;public MainArea() {super();label = new Label();label.setContents("Main Area");label.setAlign(Alignment.CENTER);label.setOverflow(Overflow.HIDDEN);this.addMember(label);}}

主要区域将托管我们界面的大部分小部件,但目前仅包括标签。

好的,让我们看看到目前为止我们做了什么。 启动Eclipse配置(作为Web应用程序项目),然后将浏览器指向提供的URL:

http://127.0.0.1:8888/AwesomeSmartGWTUIProject.html?gwt.codesvr=127.0.0.1:9997

这是您应该看到的图像:

几分钟的代码还不错。 不必弄乱CSS,HTML和JavaScript,我们已经创建了UI的框架,其中包括严格定义的子区域。 剩下的就是通过使用各种精美的小部件填充区域来增强它。

在本教程的下一部分中,我将向您介绍一些最高级的组件(例如树和选项卡)。 现在,您可以在此处找到到目前为止创建的Eclipse项目。 请注意,我删除了一些SmartGWT特定的内容(图像等),因为它们使档案过大。 这些应该由新项目自动创建。 “ gwt-servlet.jar”也已从“ war \ WEB-INF \ lib”目录中删除。

UI编码愉快!

更新:我还发布了本教程的第二部分 。

相关文章 :
  • SmartGWT入门,提供出色的GWT界面
  • 将JSON功能添加到您的GWT应用程序中
  • 建立自己的GWT Spring Maven原型
  • 将CAPTCHA添加到您的GWT应用程序
  • GWT Spring和Hibernate进入数据网格世界
  • GWT 2 Spring 3 JPA 2 Hibernate 3.5教程

翻译自: https://www.javacodegeeks.com/2011/01/advanced-smartgwt-tutorial-part-1.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/374738.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

git 技巧

将某个文件回退到某个版本 git co d359624286d9c1f022b8b3b6f2d3fe3b6524188b build.sh 查看某个文件在某个版本时的内容 git show d359624286d9c1f022b8b3b6f2d3fe3b6524188b:build.sh 如果想把这个文件重命名保存 git show d359624286d9c1f022b8b3b6f2d3fe3b6524188b:build.s…

机会

民生电商的机会.地点在成都. 联系 &#xff1a;iskall0 at 163.com 待遇 &#xff1a;和BAT差不多. H5方向&#xff1a; 前端功底扎实.对H5有较深的理解和造诣.大数据方向1&#xff1a; SSH玩的熟.linux玩的熟.熟悉云计算架构和SOA.MySQL玩的熟,PostgreSQL加分 : ]熟Hadoop、St…

力扣验证回文串

给定一个字符串&#xff0c;验证它是否是回文串&#xff0c;只考虑字母和数字字符&#xff0c;可以忽略字母的大小写 代码思路&#xff1a;将s中的每个字符用for循环取出&#xff0c;判断一下&#xff0c;如果是字母或者数字&#xff0c;插入到StringBuffer类型sgood中&#xf…

Spring MVC3 Hibernate CRUD示例应用程序

学习从HelloWorld应用程序开始的任何Web框架都是一个好主意。 一旦我们熟悉了框架配置&#xff0c;最好做一个CRUD&#xff08;创建&#xff0c;读取&#xff0c;更新&#xff0c;删除&#xff09;应用程序&#xff0c;该应用程序涵盖Web框架的各个方面&#xff0c;例如验证&am…

Linux Mint---ATI显卡驱动安装篇

显卡驱动可谓是至关重要&#xff0c;当时折腾debian驱动的时候可是弄了好几天才搞定的&#xff0c;现在却非常容易就是装上&#xff0c; 详见这篇博客&#xff1a;http://www.yyearth.com/article/14-03/amd13.html 在此表示感谢&#xff01; 我的話&#xff0c;全在圖形界面下…

百度云推送的简单集成

1.在百度云推送的应用管理页面&#xff0c;创建自己的应用&#xff0c;创建应用时&#xff0c;需要提供两个证书&#xff0c;开发环境的推送证书和正式环境的推送证书。证书的格式是pem格式的&#xff0c;需要先在apple 开发者中心配置好推送证书&#xff0c;安装到mac上&#…

高级SmartGWT教程,第2部分

这是我的教程的第二部分&#xff0c;有关使用SmartGWT快速进行UI开发。 在本教程的第一部分中 &#xff0c;我们创建了基本的界面布局并添加了一些基本组件。 现在是时候解决这个问题&#xff0c;并使用SmartGWT的真正功能了。 在继续之前&#xff0c;让我们记住到目前为止我们…

有感而发,生活

我们每一个人都是独一无二的&#xff0c;当然我们每一个人的路子也是不尽相同的&#xff0c;不能因为一时的失意而放弃了自己儿时的梦想&#xff0c;路是一步一步走的&#xff0c;未来需要努力&#xff0c;我相信 我们每一个人都可以做到自己心中的样子&#xff0c;安逸的生活是…

力扣反转字符串中的元音字母

给你一个字符串 s &#xff0c;仅反转字符串中的所有元音字母&#xff0c;并返回结果字符串。 元音字母包括 ‘a’、‘e’、‘i’、‘o’、‘u’&#xff0c;且可能以大小写两种形式出现。 代码思路&#xff1a; 1.将字符串转换为字符数组 2.设置碰撞指针&#xff0c;从两头寻…

使用 SqlDataSource 插入、更新和删除数据49

简介 正如在 数据插入、更新和删除概述 中讨论的那样&#xff0c;GridView 控件提供内置的更新和删除功能&#xff0c;而DetailsView 和 FormView 控件则包含对插入、编辑和删除功能的支持。这些数据修改功能无需编写任何代码&#xff0c;可直接嵌入数据源控件。 数据插入、更新…

Solaris是出色的Java开发平台的原因

几天前&#xff0c;我发布了“ OpenSolaris的死亡&#xff1a;为Java开发人员选择操作系统 ”&#xff0c;其中我说Solaris是Java开发人员的绝佳平台。 这篇文章的重点只是想知道自OpenSolaris淘汰以来我将使用哪个Solaris版本。 正如Neil的评论使我意识到的那样&#xff0c;该…

python , angular js 学习记录【2】

1.不同scope之间的通信 &#xff08;1&#xff09;无父子关系的scope通信&#xff1a; 在需要操作的scope里面定义一个事件&#xff0c;名称为delete_host&#xff0c;参数为data $rootScope.$on(delete_host, function(event,data) {angular.forEach($scope.hosts, function (…

【转】phpize学习

为什么使用phpize? 比如刚开始安装的时候使用 ./configure --prefix/usr/local/php7 --exec-prefix/usr/local/php7 --bindir/usr/local/php7/bin --sbindir/usr/local/php7/sbin --includedir/usr/local/php7/include --libdir/usr/local/php7/lib/php --mandir/usr/local/ph…

GWT 2 Spring 3 JPA 2 Hibernate 3.5教程– Eclipse和Maven 2展示

不久前&#xff0c;我的一个朋友和同事向我飞过&#xff0c;说“世界上只有一半在使用Maven ”。 当我意识到最受欢迎的文章&#xff08;到目前为止&#xff09; GWT 2 Spring 3 JPA 2 Hibernate 3.5 Tutorial提出了一种基于Google的Web Toolkit&#xff08; GWT &#xff09; …

Android的WiFi开启与关闭

注意&#xff1a;要首先注册开启和关闭WiFi的权限&#xff0c; <?xml version"1.0" encoding"utf-8"?> <manifest xmlns:android"http://schemas.android.com/apk/res/android"package"com.wyl.wifi"android:versionCode&q…

awk用法小结(作者总结)

http://www.chinaunix.net/old_jh/24/691456.htmlhttp://wenku.baidu.com/view/ebac4fc658f5f61fb736664d.htmlawk 用法&#xff1a;awk pattern {action} 变量名 含义 ARGC 命令行变元个数 ARGV 命令行变元数组 FILENAME 当前输入文件名 FNR 当前文件中的记录号 FS 输入域分…

力扣盛最多水的容器

给你 n 个非负整数 a1&#xff0c;a2&#xff0c;…&#xff0c;an&#xff0c;每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线&#xff0c;垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0) 。找出其中的两条线&#xff0c;使得它们与 x 轴共同构成的容器可以容纳最多…

Java最佳实践–多线程环境中的DateFormat

这是有关使用Java编程语言时的拟议实践的系列文章的第一篇。 所有讨论的主题均基于用例&#xff0c;这些用例来自于电信行业的关键任务超高性能生产系统的开发。 在阅读本文的每个部分之前&#xff0c;强烈建议您参考相关的Java API文档以获取详细信息和代码示例。 所有测试…

IntentDemo

Intent通信示例&#xff1a; 两个Button&#xff0c;一个startBrowser, 一个startPhone. 其中&#xff0c;OnClickListener()是类View的一个interface&#xff0c;需要实现其中的onClick()函数。 startActivity()开启另一个Activity&#xff0c;本示例中开启Browser或Phone. In…

JBoss 4.2.x Spring 3 JPA Hibernate教程

在花了许多时间在网上搜索之后&#xff0c;尝试找到对几个项目使用Spring&#xff0c;JPA和Hibenate的最有效方法&#xff0c;我们得出了将在下面介绍的配置的结论。 将Spring与JPA和Hibernate集成包括几个步骤&#xff1a; Spring容器的配置 JPA ORM层的配置 Hibernate Sec…