SmartGWT 之 Calendar 真简单

使用 SmartGWT 的 Calendar 还是很简单的,而且还比较好用。

首先看SmartGWT 的 ShowCase,里面用的DataSource 都是 client only的,

这个当然不是我所需要的。于是首先按照 CalendarEvent 类的构造函数,搞了一个

server 端的 Bean,当然是受 hibernate 管理的那种了。

 

@Entity
@Indexed 
@ClassBridge( impl = AllFieldSearchableClassBridge.class)
public class MyCalendarEvent implements Searchable {
    @Id @GeneratedValue( strategy = GenerationType.AUTO)
    private Long eventId;
    @Field( index=Index.TOKENIZED, store=Store.YES)
    private String name;
    @Field( index=Index.TOKENIZED, store=Store.YES)
    private String description;
    private Date startDate;
    private Date endDate;
    private boolean canEdit=true;
    private String eventWindowStyle;
    ...
}

 然后,创建一个 data source:

<DataSource
    ID="MyCalendarEvent"
    serverType="hibernate"
    beanClassName="org.simon.pim8.server.calendar.MyCalendarEvent"
>
    <fields>
        <field name="eventId"      type="sequence" hidden="true"       primaryKey="true"/>
        <field name="name"         type="text" title="事件名称" required="true"/>
        <field name="description"  type="text"     title="描述" hidden="true"         length="2048"/>
        <field name="startDate"    type="datetime"     title="开始时间"         length="128"/>
        <field name="endDate"      type="datetime"     title="结束时间"         length="128"/>
        <field name="canEdit"      type="boolean"     title="可以编辑"         length="128"/>
        <field name="eventWindowStyle"      type="text"     title="窗口样式"   hidden="true"      length="128"/>
    </fields>
</DataSource>

 

这里, startDate 和 endDate 一定要是 datetime 类型的,不然就会只记录日期,没有时间。

 

最后,client端的类就非常简单了。

 

        Calendar cal = new Calendar();
        DataSource ds = DataSource.get( "MyCalendarEvent");
        cal.setDataSource( ds);
        cal.setAutoFetchData( true);
        cal.setEventAutoArrange( true);
        cal.setEventOverlapPercent( 50);
        cal.setEventOverlap( true);
        cal.setScrollToWorkday( true);
        addMember( cal);

 

这样一来, Calendar的增加、修改、删除都有了。基本上自己就不用写什么代码来。

 效果如图:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值