我在我的应用程序中做了一些学校日程安排视图,所以我想我可以使用gwt日历小部件并自定义它(添加教授,一些课程信息等)。
例如http://www.smartclient.com/smartgwt/showcase/#custom_editing_calendar_category
但是如何将DataSource用于其他字段呢?
calendar.setEventEditorFields - 不接受DataSource
另外如果你知道一个更好的小部件来实现这个目标,那么告诉我更多关于它的信息会很好。
这个例子来自smartgwt展示区,区别在于我尝试扩展CalendarEvent所以我可以用例如新的字段"教授"
这就是我们尝试构建日历并尝试在数据源中添加新字段的方法。
package GwtApp.TechnicalUniversityApp.client.Schedule.Vertical;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceDateTimeField;
import com.smartgwt.client.data.fields.DataSourceSequenceField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.calendar.Calendar;
public class ScheduleLayoutVertical {
public static Canvas buildScheduleLayout(){
DataSource eventDS = new DataSource();
DataSourceSequenceField eventIdField = new DataSourceSequenceField("eventId");
eventIdField.setPrimaryKey(true);
DataSourceTextField nameField = new DataSourceTextField("name");
DataSourceTextField descField = new DataSourceTextField("description");
DataSourceDateTimeField startDateField = new DataSourceDateTimeField("startDate");
DataSourceDateTimeField endDateField = new DataSourceDateTimeField("endDate");
DataSourceTextField professorField = new DataSourceTextField("professor");
eventDS.setFields(eventIdField, nameField, descField, startDateField, endDateField,professorField);
eventDS.setClientOnly(true);
eventDS.setTestData(CalendarData.getRecords());
Calendar calendar = new Calendar();
calendar.setDataSource(eventDS);
calendar.setAutoFetchData(true);
return calendar;
}
}
这就是我们填充数据并使用扩展CalendarEvent
的地方 package GwtApp.TechnicalUniversityApp.client.Schedule.Vertical;
import java.util.Date;
public class CalendarData {
private static CalendarEvent[] records;
private static Date today = new Date();
private static int year = today.getYear();
private static int month = today.getMonth();
private static int start = today.getDate() - today.getDay();
public static CalendarEvent[] getRecords() {
if (records == null) {
records = getNewRecords();
}
return records;
}
public static CalendarEvent[] getNewRecords() {
return new CalendarEvent[]{
new CalendarEvent(1, "Meeting", "Shareholders meeting: monthly forecast report", new Date(year, month, start + 2, 9, 0, 0), new Date(year, month, start + 2, 14, 0, 0),"TestProff1"),
new CalendarEvent(2, "Realtor", "Breakfast with realtor to discuss moving plans", new Date(year, month, start + 3, 8, 0, 0), new Date(year, month, start + 3, 10, 0, 0),"TestProff2"),
new CalendarEvent(3, "Soccer", "Little league soccer finals", new Date(year, month, start + 4, 13, 0, 0), new Date(year, month, start + 4, 16, 0, 0),"TestProff1"),
new CalendarEvent(4, "Sleep", "Catch up on sleep", new Date(year, month, start + 4, 5, 0, 0), new Date(year, month, start + 4, 9, 0, 0),"TestProff2"),
new CalendarEvent(5, "Inspection", "Home inspector coming", new Date(year, month, start + 4, 10, 0, 0), new Date(year, month, start + 4, 12, 0, 0), false, "testStyle"),
new CalendarEvent(6, "Airport run", "Pick James up from the airport", new Date(year, month, start + 4, 1, 0, 0), new Date(year, month, start + 4, 3, 0, 0),"TestProff1"),
new CalendarEvent(7, "Dinner Party", "Prepare elaborate meal for friends", new Date(year, month, start + 4, 17, 0, 0), new Date(year, month, start + 4, 20, 0, 0),"TestProff1"),
new CalendarEvent(8, "Poker", "Poker at Steve's house", new Date(year, month, start + 4, 21, 0, 0), new Date(year, month, start + 4, 23, 0, 0),"TestProff2"),
new CalendarEvent(9, "Meeting", "Board of directors meeting: discussion of next months strategy", new Date(year, month, start + 5, 11, 0, 0), new Date(year, month, start + 5, 15, 0, 0),"TestProff1")
};
}
}
使用新构造函数扩展CalendarEvent
package GwtApp.TechnicalUniversityApp.client.Schedule.Vertical;
import java.util.Date;
public class CalendarEvent extends com.smartgwt.client.widgets.calendar.CalendarEvent {
String professor;
public CalendarEvent(int i, String string, String string2, Date date,
Date date2, String string3) {
super(i, string, string2, date, date2);
setProfessor(string3);
}
public CalendarEvent(int i, String string, String string2, Date date,
Date date2, boolean b, String string3) {
super(i, string, string2, date, date2, b);
setProfessor(string3);
}
public String getProfessor() {
return getAttributeAsString("professor");
}
public void setProfessor(String professor) {
setAttribute("professor", professor);
}
}
答案 0 :(得分:0)
其他(自定义)字段必须属于Calendar DataSource。