GWTの2.1バージョンで導入されたMVPフレームワークに精通するために、非常に簡単なカレンダーアプリを構築しています。
私が達成したいのは、予定された予定のリストと利用可能な時間のリストを切り替えることができることです。
CalendarPlace、CalendarActivity、CalendarView、およびCalendarViewImplを作成しました。 私は私のカレンダーアプリで、私が呼び出しますので、私は、PlaceController.goTo(場所)を呼び出します別の場所に移動することを知っている:GWTの組み込みMVPフレームワークでURLに応答するにはどうすればよいですか?
clientFactory.getPlaceController.goTo(new CalendarPlace("freeTime");
をURLがindex.htmlに#のCalendarPlace次のようになります。リストのための空き時間自由時間または
clientFactory.getPlaceController.goTo(new CalendarPlace("appointments");
予定された予定のリスト。 URLはindex.html#CalendarPlace:appointments
ですが、問題はどこで異なるトークンに応答しますか?私はCalendarPlaceが適切な場所になると思うが、どうすればよいだろうか?
CalendarPlace:
public class CalendarPlace extends Place {
private String calendarName;
public CalendarPlace(String token) {
this.calendarName = token;
}
public String getCalendarName() {
return calendarName;
}
public static class Tokenizer implements PlaceTokenizer<CalendarPlace> {
@Override
public CalendarPlace getPlace(String token) {
return new CalendarPlace(token);
}
@Override
public String getToken(CalendarPlace place) {
return place.getCalendarName();
}
}
}
CalendarActivity:
public class CalendarActivity extends AbstractActivity
implements
CalendarView.Presenter {
private ClientFactory clientFactory;
private String name;
public CalendarActivity(CalendarPlace place, ClientFactory clientFactory) {
this.name = place.getCalendarName();
this.clientFactory = clientFactory;
}
@Override
public void goTo(Place place) {
clientFactory.getPlaceController().goTo(place);
}
@Override
public void start(AcceptsOneWidget containerWidget, EventBus eventBus) {
CalendarView calendarView = clientFactory.getCalendarView();
calendarView.setName(name);
calendarView.setPresenter(this);
containerWidget.setWidget(calendarView.asWidget());
}
}
CalendarViewImpl:
はここに私のソースコードである(私はチュートリアルhereから定型のほとんどを取って
public class CalendarViewImpl extends Composite implements CalendarView {
private VerticalPanel content;
private String name;
private Presenter presenter;
private OptionBox optionBox;
public CalendarViewImpl() {
//optionBox is used for navigation
//optionBox is where I call PlaceController.goTo() from
optionBox=new OptionBox();
RootPanel.get("bluebar").add(optionBox);
content=new VerticalPanel();
this.initWidget(content);
}
@Override
public void setPresenter(Presenter listener) {
this.presenter=listener;
}
@Override
public void setName(String calendarName) {
this.name = calendarName;
}
public void displayFreeTime() {
//called from somewhere to display the free time
}
public void getAppointments() {
//called from somewhere to display the appointments
}
}
私のためにそれを明確にしてくれてありがとう。 –