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的增加、修改、删除都有了。基本上自己就不用写什么代码来。
效果如图: