ç§ã¯åå¿è ã®Javaããã°ã©ããŒã§ãããGWTã§æ¬æ Œçãªã¢ããªã±ãŒã·ã§ã³ãéçºããããšããèªåã®ãã£ãªã¢ãå§ããŸããã ããã«ã¯GWTãããã¯ã«é¢ããéåžžã«å€ãã®èšäºããããŸãããäœããã®çç±ã§ããã°ãããGWT-Platformãã¬ãŒã ã¯ãŒã¯ã«é¢ããæ å ±ã¯ãŸã£ãããããŸããã ãã®ãã¬ãŒã ã¯ãŒã¯ã®è©³çŽ°ã«ã€ããŠã¯ ã ãã¡ããã芧ãã ãã ãç°¡åãªã¢ããªã±ãŒã·ã§ã³ã®äŸã§äœæ¥ããéã®åºæ¬ã«ã€ããŠç°¡åã«èª¬æããŸãã
ãã®ã¢ããªã±ãŒã·ã§ã³ã«ã¯ãçŸåšã®ãã¥ãŒãåãæ¿ããããã®ãã¿ã³ãé 眮ãããããã²ãŒã·ã§ã³ããã«ãå«ãŸããŸãã ç¶æ³ã«å¿ããŠç®çã®ã³ã³ãã³ããæ¿å ¥ãã2ã€ã®åããããŸãã ããããããããããã«2ã€ã®åãäœæããŸããã å®éã«ã¯ããã¡ãã1ã€ãå¿ èŠã«ãªããŸãã
ããã²ãŒã·ã§ã³ããŒã®ãã¿ã³ãã¯ãªãã¯ãããšãã¢ããªã±ãŒã·ã§ã³ã®å·ŠåŽãéãããæå³ã®ãªãããã¹ãã®ããå³åŽãéããŸãã
ããã©ã«ãã§ã¯ãå·ŠåŽã®åãéããååãšå§ãå ¥åããããã®ãã€ã¢ãã°ããã¯ã¹ãéãããã®ãã¿ã³ããããŸãã 確èªãã¿ã³ãæŒããšããã®ããŒã¿ãå³ã®åã«è»¢éãããŠè¡šç€ºãããŸãã
ãããã£ãŠããŸãæåã«ãIDEã§GWTãããžã§ã¯ããäœæããå¿ èŠããããŸãã GWTPã䜿çšããã«ã¯ããããžã§ã¯ãã«ã©ã€ãã©ãªguice-2.0.jarãguice-3.0.jarãgwtp-all-1.0.jarãaopalliance.jarãguice-assistedinject-3.0.jarãè¿œå ããå¿ èŠããããŸãã ãŸããgwt-bootstrap-2.2.2.0-SNAPSHOT.jarãè¿œå ããŠãã¢ããªã±ãŒã·ã§ã³ã«ãçŸããè¿œå ããŸããã
Eclipseã«gwt-platformãã©ã°ã€ã³ãã€ã³ã¹ããŒã«ã§ããŸãã ããã¯äººçã倧ãã«ä¿é²ããŸãã ãã®å©ããåããŠãæ°ãããããžã§ã¯ããšãã¬ãŒã³ããŒã·ã§ã³ãã¬ãŒã³ããŒã·ã§ã³ãã³ãã«ã®äž¡æ¹ãäœæã§ããŸãã ãã®ãªã³ã¯ããããŠã³ããŒãïŒ plugin.gwt-platform.googlecode.com/hg/update
ç¶è¡ïŒ
ã¯ã©ã€ã¢ã³ãã¢ãžã¥ãŒã«ãšGinjectorãäœæããå¿ èŠããããŸãã ãã©ã°ã€ã³ã䜿çšããŠã¢ããªã±ãŒã·ã§ã³ãäœæãããšãèªåçã«äœæãããŸãã
configureïŒïŒã¡ãœããã§ã¯ããã¬ãŒã³ã¿ãŒãã€ã³ã¿ãŒãã§ã€ã¹ã«ãã€ã³ãããŠå®è£ ããŸãã
public class ClientModule extends AbstractPresenterModule { @Override protected void configure() { install(new DefaultModule(ClientPlaceManager.class)); bindPresenter(MainPagePresenter.class, MainPagePresenter.MyView.class, MainPageView.class, MainPagePresenter.MyProxy.class); bindConstant().annotatedWith(DefaultPlace.class).to(NameTokens.main); } }
@GinModules({ DispatchAsyncModule.class, ClientModule.class }) public interface ClientGinjector extends Ginjector { EventBus getEventBus(); PlaceManager getPlaceManager(); Provider<MainPagePresenter> getMainPagePresenter(); }
次ã¯ãšã³ããªãã€ã³ãã§ããããã§ã¯ããã¬ãŒã¹ãããŒãžã£ã«çŸåšã®ããŒãžïŒå ŽæïŒã«ç§»åããããã«æ瀺ããŸãã ã€ãŸãããã©ãŠã¶ã®ã¢ãã¬ã¹ããŒã«å¿ èŠãªå Žæã決å®ããããŒã¯ã³ãå ¥åããå Žåãããã«å°éããŸãã ãã¡ãããã¢ã¯ã»ã¹æš©ãããã°æäŸãããŸãã ïŒããšãã°ãGateKeeperããããæ åœããå ŽåããããŸãïŒã
public class HabraTest implements EntryPoint { private final ClientGinjector ginjector = GWT.create(ClientGinjector.class); @Override public void onModuleLoad() { DelayedBindRegistry.bind(ginjector); ginjector.getPlaceManager().revealCurrentPlace(); } }
ç§ã¯å Žæã§ã®äœæ¥ã«éäžããŸããã ãã§ã«ããã«ã¯ãGWTã«é¢ããå€ãã®æ³šç®ãã¹ãèšäºããããŸããã ããšãã°ã ãã ã
å Žæã䜿çšããã«ïŒããæ£ç¢ºã«ã¯ã1ã€ã®å Žæã§ïŒå°ããªGWTã¢ããªã±ãŒã·ã§ã³ãäœæããæ¹æ³ã瀺ããŸãã
ãŸããã¢ããªã±ãŒã·ã§ã³ã®ã¡ã€ã³ãã¬ãŒã³ã¿ãŒãäœæããŸãã
public class MainPagePresenter extends Presenter<MainPagePresenter.MyView, MainPagePresenter.MyProxy> implements MainPageUiHandlers, FirstPageEvent.Handler{ public interface MyView extends View, HasUiHandlers<MainPageUiHandlers> { } // public final static Object SLOT_FIRST_PAGE = new Object(); public final static Object SLOT_SECOND_PAGE = new Object(); // private FirstPagePresenter firstPagePresenter; private SecondPagePresenter secondPagePresenter; @ProxyStandard @NameToken(NameTokens.main) public interface MyProxy extends ProxyPlace<MainPagePresenter> { } private EventBus eventBus; private final PlaceManager placeManager; // @Inject public MainPagePresenter(final EventBus eventBus, final MyView view, FirstPagePresenter firstPagePresenter, SecondPagePresenter secondPagePresenter, final MyProxy proxy, final PlaceManager placeManager) { super(eventBus, view, proxy); this.placeManager = placeManager; this.firstPagePresenter = firstPagePresenter; this.secondPagePresenter = secondPagePresenter; this.eventBus = eventBus; // getView().setUiHandlers(this); eventBus.addHandler(FirstPageEvent.getType(), this); } // @Override protected void revealInParent() { RevealRootContentEvent.fire(this, this); } @Override protected void onBind() { super.onBind(); // getView().setInSlot(SLOT_FIRST_PAGE, firstPagePresenter); } // MainPageView @Override public void onRightBtnClicked() { showRightContent(); MainPageEvent mainPageEvent = new MainPageEvent( MainPageEvent.Action.SHOW_LOREM_IPSUM); eventBus.fireEvent(mainPageEvent); } // @Override public void onLeftBtnClicked() { showLeftContent(); } public void showLeftContent() { removeFromSlot(SLOT_SECOND_PAGE, secondPagePresenter); getView().setInSlot(SLOT_FIRST_PAGE, firstPagePresenter); } public void showRightContent() { removeFromSlot(SLOT_FIRST_PAGE, firstPagePresenter); getView().setInSlot(SLOT_SECOND_PAGE, secondPagePresenter); } @Override public void onFirstPageEvent(FirstPageEvent event) { // , showRightContent(); MainPageEvent mainPageEvent = new MainPageEvent( MainPageEvent.Action.SHOW_FORM_RESULT, event.getFirstName(), event.getLastName()); eventBus.fireEvent(mainPageEvent); } }
FirstPagePresenter firstPagePresenterãSecondPagePresenter secondPagePresenterã®ã³ã³ã¹ãã©ã¯ã¿ãŒã«æ³šå ¥ããããšã«æ³šæããŠãã ããã
ãããã¯ãã¬ãŒã³ã¿ãŒã«ãªããŸã-ã¢ããªã±ãŒã·ã§ã³ã®å·Šéšåãšå³éšåãè¡šããŠã£ãžã§ããïŒã€ãŸããçè«çã«ã¯åå¥ã®ããŒãžïŒã
GWTPã«ã¯ãäž»ã«3çš®é¡ã®ãã¬ãŒã³ã¿ãŒããããŸãã
- ãŸãé 眮ãããŠãããã©ã³ã¹ãã³ããŒ
- ãã©ã³ã¹ãã³ããŒãŠã£ãžã§ããïŒPresenterWidgetïŒ
- ãããã¢ãããŠã£ã³ããŠãè¡šããã¬ãŒã³ã¿ãŒãŠã£ãžã§ãã
ãã¬ãŒã³ã¿ãŒãã¬ãŒã¹ã¯ãã¢ããªã±ãŒã·ã§ã³ã®åå¥ã®ããŒãžãäœæãããã©ãŠã¶ã®ã¢ãã¬ã¹ããŒã«è¿œå ãããããããããŒã¯ã³ã䜿çšããŠããã²ãŒãããããã«äœ¿çšãããŸãã
ãã®ãããªåãã¬ãŒã³ã¿ãŒã«ã¯ããã¬ãŒã³ã¿ãŒã«æ·»ä»ãããŠããããŒã¯ã³ã瀺ã泚éãå«ãŸããŠããå¿ èŠããããŸãã
ãã®å Žåããã®ãããªãã¬ãŒã³ã¿ãŒã¯1ã€ã ã䜿çšããŸãã
ãããŒãžããå€æŽããã«ã¯ãã¹ãããã®ã·ã¹ãã ãšã¹ãããã«é 眮ããããã¬ãŒã³ã¿ãŒãŠã£ãžã§ããã䜿çšããŸãã
ãã¬ãŒã³ã¿ãŒãŠã£ãžã§ããã¯ãå¿ ãããã·ã³ã°ã«ãã³ã§ã¯ãªããã¬ãŒã³ã¿ãŒã§ãã å€ãã®ç¬ç«ããã€ã³ã¹ã¿ã³ã¹ãæã€ããšãã§ããŸãã
ã¹ãããã·ã¹ãã ã®ãããã§ãä»ã®ãã¬ãŒã³ã¿ãŒå ã§ãã¬ãŒã³ã¿ãŒãç¡éã«ãã¬ãŒã³ã§ããŸãã ãã¬ãŒã³ã¿ãŒãŠã£ãžã§ãããå¥ã®ãã¬ãŒã³ã¿ãŒã«é 眮ããã«ã¯ã芪ãã¬ãŒã³ã¿ãŒã§ã¹ããããå®çŸ©ãã芪ãã¬ãŒã³ã¿ãŒã®ãã¥ãŒã§setInSlotïŒïŒã¡ãœããããªãŒããŒã©ã€ãããå¿ èŠããããŸãã
MainPagePresenterã¯ã©ã¹ã¯ãã¹ããããåãªããªããžã§ã¯ãã§ããããšã瀺ããŠããŸãã
public final static Object SLOT_FIRST_PAGE = new Object(); public final static Object SLOT_SECOND_PAGE = new Object();
察å¿ãããã¥ãŒã§ããã¬ãŒã³ã¿ãŒãã¹ãããã«æ¿å ¥ããããã®ã«ãŒã«ãå®çŸ©ããŸãã
public class MainPageView extends ViewWithUiHandlers<MainPageUiHandlers> implements MainPagePresenter.MyView { // @UiField HTMLPanel main; // @UiField ResponsiveNavbar navbar; // @UiField Button firstPageBtn, secondPageBtn; private static MainPageViewUiBinder uiBinder = GWT .create(MainPageViewUiBinder.class); interface MainPageViewUiBinder extends UiBinder<Widget, MainPageView> { } // @UiField Column leftColumn, rightColumn; @Inject public MainPageView() { uiBinder.createAndBindUi(this); navbar.setInverse(true); // firstPageBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { getUiHandlers().onLeftBtnClicked(); } }); secondPageBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { getUiHandlers().onRightBtnClicked(); } }); } @Override public Widget asWidget() { return main; } // @Override public void setInSlot(Object slot, IsWidget content) { if(slot == MainPagePresenter.SLOT_FIRST_PAGE ) { leftColumn.add(content); } else if(slot == MainPagePresenter.SLOT_SECOND_PAGE ){ rightColumn.add(content); } else { super.setInSlot(slot, content); } } // @Override public void removeFromSlot(Object slot, IsWidget content) { if(slot == MainPagePresenter.SLOT_FIRST_PAGE ) { leftColumn.remove(content); } else if(slot == MainPagePresenter.SLOT_SECOND_PAGE ){ rightColumn.remove(content); } else { super.removeFromSlot(slot, content); } } }
ãã¹ãŠãéåžžã«ç°¡åã§ããsetInSlotïŒïŒã¯ãã¬ãŒã³ã¿ãŒãšããã«å¯Ÿå¿ããã¹ããããåãå ¥ããŸãã
ãã®ãã¬ãŒã³ã¿ãŒãé 眮ãããŠã£ãžã§ãããæå®ããã ãã§ãã ãã®å Žåããããã¯2ã€ã®ããŒãã¹ãã©ããåleftColumnãšrightColumnã§ãã
ãã®å Žåãç¹°ãè¿ããŸãããããŒãžã®ééãã·ãã¥ã¬ãŒãããã«ã¯ããã¹ãŠã1ã€ã®åã«å ¥ããæ¹ãé©åã§ãã
ããã«ããã¬ãŒã³ã¿ãŒãŠã£ãžã§ãããšãã®ãã¥ãŒïŒ
public class FirstPagePresenter extends PresenterWidget<FirstPagePresenter.MyView> implements FirstPageUiHandlers, PopupEvent.Handler{ public interface MyView extends View, HasUiHandlers<FirstPageUiHandlers> { } // FirstPagePopupPresenter firstPagePopupPresenter; EventBus eventBus; @Inject public FirstPagePresenter(final EventBus eventBus, final MyView view, FirstPagePopupPresenter firstPagePopupPresenter ) { super(eventBus, view); this.firstPagePopupPresenter = firstPagePopupPresenter; this.eventBus = eventBus; getView().setUiHandlers(this); // PopupEvent eventBus.addHandler(PopupEvent.getType(), this); } @Override public void onShowFormBtnClicked() { // showForm(true); } private void showForm(boolean show) { if(show){ addToPopupSlot(firstPagePopupPresenter, true); firstPagePopupPresenter.getView().show(); } else { removeFromPopupSlot(firstPagePopupPresenter); } } @Override public void onPopupEvent(PopupEvent event) { showForm(false); eventBus.fireEvent(new FirstPageEvent(event.getFirstName(), event.getLastName())); } }
ç¹å®ã®FirstPagePopupPresenter firstPagePopupPresenterãæ¿å ¥ããããšã«æ³šæããŠãã ããïŒã³ãŒãã¯ä»¥äžã«ãªããŸãïŒã ããã¯ãã©ãŒã ã®ãããã¢ããã§ãã åæ§ã«ãä»»æã®ãã¬ãŒã³ã¿ãŒãŠã£ãžã§ãããä»»æã®éã§ãä»»æã®ãã¹ãã§æ¿å ¥ã§ããŸãã äž»ãªããšã¯ãéå±€ãå£ããªãããšã§ãã
public class FirstPageView extends ViewWithUiHandlers<FirstPageUiHandlers> implements FirstPagePresenter.MyView { private final Widget widget; @UiField Button showFormBtn; public interface Binder extends UiBinder<Widget, FirstPageView> { } @Inject public FirstPageView(final Binder binder) { widget = binder.createAndBindUi(this); showFormBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { getUiHandlers().onShowFormBtnClicked(); } }); } @Override public Widget asWidget() { return widget; } }
ãã¥ãŒã¯ãåæå®ãããViewWithUiHandlersã¯ã©ã¹ãç¶æ¿ããããšãé€ããŠãç¹å¥ãªãã®ã§ã¯ãããŸããã
ç§ãã¡ã¯MVPã®ååã«éåããããªãããããã¥ãŒãããã¬ãŒã³ã¿ãŒã«çŽæ¥ã¢ã¯ã»ã¹ããããšã¯ã§ããŸããïŒéã«ãã§ããŸãïŒã ãã®ããã«ãã€ã³ã¿ãŒãã§ã€ã¹ã䜿çšããŸãã getUiHandlersïŒïŒã䜿çšããŠãã¿ã³ã®ã¯ãªãã¯ã«ã€ããŠéç¥ããŸãOnShowFormBtnClickedïŒïŒ;
public interface FirstPageUiHandlers extends UiHandlers{ void onShowFormBtnClicked(); }
getUiHandlersïŒïŒã¯ã察å¿ãããã¬ãŒã³ã¿ãŒã«å®è£ ããã¡ãœãããæå®ããFirstPageUiHandlersã€ã³ã¿ãŒãã§ã€ã¹ãè¿ããŸãã åœç¶ããã¬ãŒã³ã¿ãŒã¯ãã®ã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ããå¿ èŠããããããã«åã蟌ãŸããMyViewã€ã³ã¿ãŒãã§ã€ã¹ã¯HasUiHandlersåã€ã³ã¿ãŒãã§ã€ã¹ãç¶æ¿ããå¿ èŠããããŸãã ãããŠãäž»ãªããšã¯ããã¬ãŒã³ã¿ãŒã§èªåããã¥ãŒã€ãã³ãã®ãã³ãã©ãŒãšããŠå²ãåœãŠãããšãå¿ããªãããšã§ã-getViewïŒïŒãSetUiHandlersïŒthisïŒ;
次ã«ããã¬ãŒã³ã¿ãŒãš2çªç®ã®ããŒãžã®å¯Ÿå¿ãããã¥ãŒïŒ
public class SecondPagePresenter extends PresenterWidget<SecondPagePresenter.MyView> implements MainPageEvent.Handler { public interface MyView extends View { void showLoremIpsum(); void showFormInfo(String firstName, String lastName); } EventBus eventBus; @Inject public SecondPagePresenter(final EventBus eventBus, final MyView view) { super(eventBus, view); this.eventBus = eventBus; eventBus.addHandler(MainPageEvent.getType(), this); } @Override public void onMainPageEvent(MainPageEvent event) { switch(event.getAction()) { case SHOW_FORM_RESULT: showFormInfoWidget(event.getFirstName(), event.getLastName()); break; case SHOW_LOREM_IPSUM: showLoremIpsumWidget(); break; default: break; } } private void showLoremIpsumWidget() { getView().showLoremIpsum(); } private void showFormInfoWidget(String firstName, String lastName) { getView().showFormInfo( firstName, lastName); }
public class SecondPageView extends ViewImpl implements SecondPagePresenter.MyView { private final Widget widget; @UiField FlowPanel contentPanel; public interface Binder extends UiBinder<Widget, SecondPageView> { } @Inject public SecondPageView(final Binder binder) { widget = binder.createAndBindUi(this); } @Override public Widget asWidget() { return widget; } @Override public void showLoremIpsum() { contentPanel.clear(); contentPanel.add(new LoremIpsumWidget()); } @Override public void showFormInfo(String firstName, String lastName) { contentPanel.clear(); contentPanel.add(new FormInfoWidget(firstName, lastName)); } }
GWTã®éçºè ã«ãšã£ãŠç¹ã«é¢çœããŠæ°ãããã®ã¯ãããŸããã ãã¬ãŒã³ã¿ãŒéã®éä¿¡ã¯ãæšæºã€ãã³ãïŒGwtEventïŒãä»ããŠè¡ãããŸãã
æåŸã«ããã©ãŒã ã§ãããã¢ããããŸãïŒ
public class FirstPagePopupPresenter extends PresenterWidget<FirstPagePopupPresenter.MyView> implements PopupUiHandlers { public interface MyView extends PopupView , HasUiHandlers<PopupUiHandlers>{ } EventBus eventBus; @Inject public FirstPagePopupPresenter(final EventBus eventBus, final MyView view) { super(eventBus, view); this.eventBus = eventBus; getView().setUiHandlers(this); } @Override public void onSubmitBtnClicked(String firstName, String lastName) { eventBus.fireEvent(new PopupEvent(firstName, lastName)); } }
public class FirstPagePopupView extends PopupViewWithUiHandlers<PopupUiHandlers> implements FirstPagePopupPresenter.MyView { @UiField PopupPanel main; @UiField Button submitBtn; @UiField TextBox firstName, lastName; public interface Binder extends UiBinder<Widget, FirstPagePopupView> { } @Inject public FirstPagePopupView(final EventBus eventBus, final Binder binder) { super(eventBus); binder.createAndBindUi(this); main.setAnimationEnabled(true); main.setModal(true); main.setGlassEnabled(true); submitBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { getUiHandlers().onSubmitBtnClicked(firstName.getValue(), lastName.getValue()); } }); } @Override public Widget asWidget() { return main; } }
ã芧ã®ãšãããpopupã¯ãã¬ãŒã³ã¿ãŒãŠã£ãžã§ããã§ããããŸããããã®ãã¥ãŒã€ã³ã¿ãŒãã§ã€ã¹ã¯PopupViewãç¶æ¿ããå¿ èŠããããŸãã ãŸããã¡ã€ã³ãã¥ãŒããã«ã¯PopupPanelããŸãã¯ãã®ã¯ã©ã¹ã®çžç¶äººã§ãªããã°ãªããŸããã åŸæ¥ã®ãã¬ãŒã³ã¿ãŒãŠã£ãžã§ãããšã®ãã1ã€ã®éãã¯ãããŒãžã«ãããã¢ããã衚瀺ããããã«ã¹ããããšæ¿å ¥ããã«ãå¿ èŠãªãããšã§ãã addToPopupSlotïŒïŒã¡ãœããã䜿çšããã ãã§ååã§ãã
ãŸãããã¹ãŠã®ãã³ãã«ã§ããã¬ãŒã³ããŒã·ã§ã³ãã¬ãŒã³ããŒã·ã§ã³ã¯uibinderã䜿çšããŸããã 察å¿ãã* ui.xmlãã¡ã€ã«ãã¢ããããŒãããŸããã ããã§ã¯ãååãšããŠãGWTéçºè ã«ãšã£ãŠèå³æ·±ããã®ã¯äœããããŸããã
ãããžã§ã¯ãèªäœã¯ã ãã®ã¢ãã¬ã¹ã§ãã°ããå©çšå¯èœã«ãªããŸãã
ããã§ããããžã§ã¯ãã«ã€ããŠèª¬æããäœãèµ·ãã£ãŠããã®ãããã¬ãŒã³ã¿ãŒãã©ã®ããã«é¢ä¿ããŠããã®ãã説æããŸãã
ãªãŒããŒã©ã€ããããonBindïŒïŒã¡ãœããã§MainPagePresenterãããŒããããšãããã«æåã®ããŒãžãã¹ãããã«é 眮ãããŸãã
@Override protected void onBind() { super.onBind(); getView().setInSlot(SLOT_FIRST_PAGE, firstPagePresenter); }
ïŒãã¬ãŒã³ã¿ãŒãšã¡ãœããonBindïŒïŒãonUnbindãonRevealïŒïŒãonResetïŒïŒãonHideïŒïŒã®ã©ã€ããµã€ã¯ã«ã«ã€ããŠã¯ã次ã®èšäºã§èª¬æããŸããïŒ
ãããã£ãŠãFirstPagePresenter'aãã¥ãŒã¯ç»é¢ã®å·ŠåŽã«è¡šç€ºãããŸãã ãã¿ã³ãã¯ãªãã¯ãããšãFirstPageUiHandlersã€ã³ã¿ãŒãã§ã€ã¹ã§èª¬æãããŠããFirstPagePresenterã®onShowFormBtnClickedïŒïŒã¡ãœããã®å®è£ ãåŒã³åºããŸãã
åŒã³åºãïŒ
showFormBtn.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { getUiHandlers().onShowFormBtnClicked(); } });
FirstPagePresenter 'eã§ã¯ã次ã®ããšãèµ·ãããŸãã
addToPopupSlot(firstPagePopupPresenter, true);
ã¹ãããã«ãããã¢ãããã¬ãŒã³ã¿ãŒãèšå®ããŸãã ãã§ã«è¿°ã¹ãããã«ããããã¢ããã®å Žåãã¹ããããå®çŸ©ããå¿ èŠã¯ãããŸããã å¯äžã®æ¡ä»¶ã¯ããããã¢ãããåŒã³åºããããã¬ãŒã³ã¿ãŒèªäœã芪ã®ã¹ãããã«ååšããå¿ èŠãããããšãªã©ã§ãã addToPopupSlotïŒïŒã¡ãœããã®2çªç®ã®ãã©ã¡ãŒã¿ãŒã¯ããããã¢ãããã¢ããªã±ãŒã·ã§ã³ãŠã£ã³ããŠã®äžå€®ã«é 眮ãããã©ããã瀺ããŸãïŒã¡ãœããã«ã¯ããã€ãã®ãªãŒããŒããŒããããããã®ãã©ã¡ãŒã¿ãŒã¯éåžžãªãã·ã§ã³ã§ãïŒã
ãŠã£ã³ããŠã«ãããã¢ããã衚瀺ãããããããã«ããŒã¿ãå ¥åããŠç¢ºèªãã¿ã³ãæŒããŸãã ããã«ãåæ§ã®ã¹ããŒã ã«ããã°ãgetUiHandlersïŒïŒãä»ããŠãããã¢ããããã®ãã¬ãŒã³ã¿ãŒã®ãã³ãã©ãŒãåŒã³åºãããããã€ãã³ããã¹ããŒããŸãã ïŒ
@Override public void onPopupEvent(PopupEvent event) { showForm(false); eventBus.fireEvent(new FirstPageEvent(event.getFirstName(), event.getLastName())); }
æåã«ãshowFormïŒïŒã¡ãœããã§ãã¹ããããããããã¢ãããåé€ããŸãã
removeFromPopupSlot(firstPagePopupPresenter);
次ã«ãæ°ããã€ãã³ãïŒçŸåšã¯FirstPageEventïŒãããã«ã¹ããŒããŸãã MainPagePresenterã¯ããã«ãµãã¹ã¯ã©ã€ããããŠããŸãã
@Override public void onFirstPageEvent(FirstPageEvent event) { // , showRightContent(); MainPageEvent mainPageEvent = new MainPageEvent( MainPageEvent.Action.SHOW_FORM_RESULT, event.getFirstName(), event.getLastName()); eventBus.fireEvent(mainPageEvent); }
MainPagePresenterã¯ãããåä¿¡ãããšãã¹ãããããæåã®ããŒãžãåé€ãã2çªç®ã®ããŒãžãæ¿å ¥ããŸãã
public void showRightContent() { removeFromSlot(SLOT_FIRST_PAGE, firstPagePresenter); getView().setInSlot(SLOT_SECOND_PAGE, secondPagePresenter); }
ããã«åœŒã¯ãã§ã«MainPageEventãããã«é£ã¶ã ååãšå§ã ãã§ãªããã¢ã¯ã·ã§ã³ãæå¥ãèšã£ãŠããŸãã
onMainPageEventïŒïŒã¡ãœããã§ã€ãã³ããåãåã£ãSecondPagePresenterã¯ãããŒãžã«è¡šç€ºãããã®ã決å®ããŸãã ãã®å Žåããããã¯ãã¬ãŒã³ã¿ãŒã®ãªãéåžžã®ãŠã£ãžã§ããã§ãã
@Override public void onMainPageEvent(MainPageEvent event) { switch(event.getAction()) { case SHOW_FORM_RESULT: showFormInfoWidget(event.getFirstName(), event.getLastName()); break; case SHOW_LOREM_IPSUM: showLoremIpsumWidget(); break; default: break; } }
ããã ãã§ãã ãã®ãããªåçŽãªã¢ã¯ã·ã§ã³ã«ã¯ã³ãŒããå€ãããããã«æãããããããŸãããã次ã®ãšããã§ãã
- ç§ãã¡ã¯MVPã®ååã«éåããŸãã-ãã¥ãŒã¯ãã¬ãŒã³ã¿ãŒã«ã€ããŠäœãç¥ããªãã¯ãã§ã
- ã¢ããªã±ãŒã·ã§ã³ãã¢ãžã¥ãŒã«ã«åå²ããããšã«ãããã³ãŒãã¯åå©çšå¯èœãã€æè»ã«ãªããŸãã
ãŸããããã€ãã¯ããããæ¿æããã§ããã-ãªãã€ãã³ãã®äŒéã®ãã®ãããªé·ãé£éïŒ ãã ããã€ãã³ããåä¿¡ããåŸããã¬ãŒã³ã¿ãŒã¯æ¬¡ã®ã€ãã³ããéä¿¡ããåã«äœããã®æäœãè¡ãããšã«æ°ä»ããããããŸããã ããšãã°ãäžå¿ èŠãªãã¬ãŒã³ã¿ãŒãåé€ããããåä¿¡ããããŒã¿ãäœããã®æ¹æ³ã§åŠçãããããŸãã
äžè¬çã«ããã®èšäºã誰ãã«ãšã£ãŠæçšã§ããã圌ãGWT-Platformã«ç®ãåããããšãé¡ã£ãŠããŸãã
PSïŒç©èªãšèãããã誀ãã®æ··ä¹±ããaã³ããŸãã ããã¯ç§ã®æåã®ITæçš¿ã§ãã åççãªæ¹å€ãšã¢ããã€ã¹ã¯å€§æè¿ã§ãã