Search in sources :

Example 1 with MenuStore

use of com.iluwatar.flux.store.MenuStore in project java-design-patterns by iluwatar.

the class App method main.

/**
   * Program entry point
   * 
   * @param args command line args
   */
public static void main(String[] args) {
    // initialize and wire the system
    MenuStore menuStore = new MenuStore();
    Dispatcher.getInstance().registerStore(menuStore);
    ContentStore contentStore = new ContentStore();
    Dispatcher.getInstance().registerStore(contentStore);
    MenuView menuView = new MenuView();
    menuStore.registerView(menuView);
    ContentView contentView = new ContentView();
    contentStore.registerView(contentView);
    // render initial view
    menuView.render();
    contentView.render();
    // user clicks another menu item
    // this triggers action dispatching and eventually causes views to render with new content
    menuView.itemClicked(MenuItem.COMPANY);
}
Also used : ContentView(com.iluwatar.flux.view.ContentView) MenuStore(com.iluwatar.flux.store.MenuStore) MenuView(com.iluwatar.flux.view.MenuView) ContentStore(com.iluwatar.flux.store.ContentStore)

Example 2 with MenuStore

use of com.iluwatar.flux.store.MenuStore in project java-design-patterns by iluwatar.

the class MenuViewTest method testStoreChanged.

@Test
public void testStoreChanged() throws Exception {
    final MenuStore store = mock(MenuStore.class);
    when(store.getSelected()).thenReturn(MenuItem.HOME);
    final MenuView view = new MenuView();
    view.storeChanged(store);
    verify(store, times(1)).getSelected();
    verifyNoMoreInteractions(store);
}
Also used : MenuStore(com.iluwatar.flux.store.MenuStore) Test(org.junit.Test)

Example 3 with MenuStore

use of com.iluwatar.flux.store.MenuStore in project java-design-patterns by iluwatar.

the class MenuView method storeChanged.

@Override
public void storeChanged(Store store) {
    MenuStore menuStore = (MenuStore) store;
    selected = menuStore.getSelected();
    render();
}
Also used : MenuStore(com.iluwatar.flux.store.MenuStore)

Aggregations

MenuStore (com.iluwatar.flux.store.MenuStore)3 ContentStore (com.iluwatar.flux.store.ContentStore)1 ContentView (com.iluwatar.flux.view.ContentView)1 MenuView (com.iluwatar.flux.view.MenuView)1 Test (org.junit.Test)1