Я создаю очень простое приложение-календарь, чтобы познакомиться с MVP-фреймворком, представленным в версии 2.1 GWT.
Чего я хочу добиться, так это возможности переключаться между списком запланированных встреч и списком доступного времени.
Я создал CalendarPlace, CalendarActivity, CalendarView и CalendarViewImpl.
Я знаю, что для перехода в другое место я бы назвал PlaceController.goTo (Place), поэтому в моем приложении календаря я бы назвал:
clientFactory.getPlaceController.goTo(new CalendarPlace("freeTime");
URL-адрес будет index.html # CalendarPlace: freeTime для списка свободного времени или
clientFactory.getPlaceController.goTo(new CalendarPlace("appointments");
для списка запланированных встреч. URL-адрес будет index.html # CalendarPlace: встречи
Но вопрос в том, где мне ответить на разные токены? Я думаю, что 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:
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
}
}