GWT interface的使用例子

一、定义一个接口类

public interface TicketViewModuleListener {
void fieldsChanged();

void positionReceived(double latitude, double longitude);
}

二、定义widget类并实现TicketViewModuleListener接口

public class TicketViewWidget extends VOverlay implements OfflineMode,
TicketViewModuleListener {

private InformationLayout informationLayout;

@Override
public void fieldsChanged() {
if (validateFields) {
validateFields();
}
if (listener != null && isApplicationOnline()) {
listener.updateState(getTicket());
}

fieldsChanged = true;
CacheManifestStatusIndicator.setConfirmationRequired(true);
saveTicketButton.setEnabled(true);
}

private boolean isApplicationOnline() {
return OfflineModeEntrypoint.get().getNetworkStatus().isAppOnline();
}

private boolean validateFields() {
resetValidations();

boolean valid = true;
if (!informationLayout.validateFields()) {
valid = false;
}
return valid;
}

private Widget buildSectionWrapper(final Widget content,
final String captionString, final String styleName) {
VCssLayout layout = new VCssLayout();
layout.addStyleName(styleName);

Label caption = new Label(captionString);
caption.addStyleName("sectioncaption");
layout.add(caption);

layout.add(content);

return layout;
}

@Override
public void positionReceived(final double latitude, final double longitude) {
if (listener != null) {
listener.positionReceived(latitude, longitude);
}
}

}

三、定义组件类并调用接口

public class InformationLayout extends VerticalComponentGroupWidget {

private final TicketViewModuleListener listener;

private void requestUserPosition() {
Geolocation geolocation = Geolocation.getIfSupported();
if (geolocation == null) {
useCurrentLocationSwitch.setValue(false);
} else {
geolocation
.getCurrentPosition(new Callback<com.google.gwt.geolocation.client.Position, PositionError>() {
@Override
public void onSuccess(
final com.google.gwt.geolocation.client.Position result) {
currentPosition = result;
if (listener != null) {
listener.positionReceived(result
.getCoordinates().getLatitude(), result
.getCoordinates().getLongitude());
}
}

@Override
public void onFailure(final PositionError reason) {
useCurrentLocationSwitch.setValue(false, true);
remove(useCurrentLocationSwitch);
}
});
}
}

}

四、应用情况

widget类实现listener接口,并调用组件类,组件类产生事件后调用widget类,达到参数传递的目的。

原文地址:https://www.cnblogs.com/wuzg/p/9606111.html

时间: 2024-08-07 17:00:55

GWT interface的使用例子的相关文章

SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-010-Introduction为类增加新方法

一. 1.Introduction的作用是给类动态的增加方法 When Spring discovers a bean annotated with @Aspect , it will automatically create a proxy that delegates calls to either the proxied bean or to the introduction implementation, depending on whether the method called be

20145335郝昊《java程序设计》第4周学习总结

20145335郝昊 <Java程序设计>第4周学习总结 教材学习内容总结 第六章 何谓继承: 概念: 面向对象中,为避免多个类间重复定义共同行为.(简单说就是将相同的程序代码提升为父类.) 特点: 这里接触到了新的关键词,extends,在java语言中用estends来继承父类的行为. is-a原则,在java中子类只能继承一个父类.要开始理解多态,必须先知道操作的对象是“哪一种”. 多态,使用单一接口操作多种类型的对象. 在继承父类之后,定义与父类中相同的方法部署,但执行内容不同,称为重

什么是接口(入门篇)

上学的时候,学校的老师,总会用一些简单的例子来解释什么是接口(interface) 这些例子可能像是这样 /// <summary> /// 一个表示动物的接口 /// </summary> public interface IAnimal { /// <summary> /// 所有的动物都要吃东西 /// </summary> void Eat(); } 然后再随便上一个小动物,比如像这样的 public class Cat : IAnimal { pu

《JavaScript设计模式》笔记之第一、二章

第一章 创建一个类 方法一: var Anim = function() { ... }; Anim.prototype.start = function() { ... }; Anim.prototype.stop = function() { ... }; 方法二: var Anim = function() { ... }; Anim.prototype = { start: function() { ... }, stop: function() { ... } }; 方法三: Func

hibernate 注解annotation

转自jpa&hibernate注解 物理连接:http://www.blogjava.net/oxidy/archive/2013/06/06/400266.html @Entity(name="EntityName") 必须,name为可选,对应数据库中一的个表 2.@Table(name="",catalog="",schema="") 可选,通常和@Entity配合使用,只能标注在实体的class定义处,表示实体

AUTOSAR-软件规范文档阅读

基于AUTOSAR_SWS_CANDriver.pdf,Specification of CAN Driver AUTOSAR CP Release 4.3.1 AUTOSAR所有软件规范文档(SWS)的目录结构都是一样的,如下: 特点及优点如下: a. 结构化程度高,所有文档结构一致,易于查找: b. 内容详实,包括所有API/数据结构的列表: c. 采用多种说明方法,如表格.UML图,易于理解. 1 Introduction and functional overview 第一章做简单的功能

Rxjava、Retrofit返回json数据解析异常处理

每个App都避免不了要进行网络请求,从最开始的用谷歌封装的volley到再到android-async-http再到OKHttpUtils再到现在的Retrofit和RxJava,从我自己用后的体验来看,用了retrofit和RxJava真的回不去了,回不去了,不去了,去了,了-(哈哈,本来还想分析下这四个的区别,网上这样的文章很多,我就没必要多添乱了-.-).不多逼逼,下面开始正文. 1.Rxjava和Retrofit依赖导入: compile 'io.reactivex:rxandroid:

漫谈golang之fmt格式化模块

fmt 漫谈 Go Walkthrough: fmt fmt常用的格式化字符串 %v 是个通用的占位符.它会自动将变量转换为默认格式的字符串,这在打印字符串或数字等原语时非常有用,而且不需要特定的选项 %#v 根据go语法打印.尤其在打印struct和切片时特别直观 package main import ( "fmt" ) //1 var brand = "ALIENWARE" type computer struct { name string price fl

LWIP network interface 网卡 初始化 以 STM32 为例子 后面会有 用 2G 或者4G 模块 用 PPP拨号的 形式 虚拟出网卡 所以先以 这个为 前提

LWIP   network interface   网卡 初始化    以  STM32  为例子  后面会有 用  2G 或者4G 模块 用 PPP拨号的 形式  虚拟出网卡  所以先以 这个为  前提 LWIP   有 一个 结构体 是 描述 物理 接口 的  即  netif Struct, 大神朱工 对这个 有个 详细的 解释 :http://blog.csdn.net/zhzht19861011/article/details/6690534 LWIP  官网  对 这个  结构体