TouchKit introduces a number of components special to mobile device user interfaces.

The NavigationView is a layout component that consists of a navigation bar and a content area. The content area is scrollable, so there is no need to use an inner panel component. In addition, there can be an optional toolbar component at the bottom of the view. A NavigationView is often used inside a NavigationManager to get view change animations.


NavigationView has a full size by default. The content area is expanding, so that it takes all the space left over from the navigation bar and toolbar.

A slot for an optional toolbar is located at the bottom of the NavigationView. The toolbar can be any component, but a Toolbar component made for this purpose is included in TouchKit. It is described in Section 19.4.2, “Toolbar. You could also use a HorizontalLayout or CssLayout.

You usually fill the tool bar with Button components with an icon and no textual caption. You set the toolbar with setToolbar().

The NavigationManager is a visual effect component that gives sliding animation when switching between views. You can register three components: the currently displayed component, the previous one on the left, and the next component on the right. You can set these components with setCurrentComponent(), setPreviousComponent(), and setNextComponent(), respectively.

The NavigationManager component is illustrated in Figure 19.2, “NavigationManager with Three NavigationViews”.


The navigation manager is important for responsiveness, because the previous and next components are cached and the slide animation started before server is contacted to load the new next or previous views.

Switching between the views is done programmatically according to user interaction; swipe gestures are not supported at the moment.

The NavigationButton is a special version of the regular Button designed for navigation inside a NavigationManager, as described in Section 19.4.3. Clicking the button will automatically navigate to the defined target view. The view change animation does not need to make a server request first, but starts immediately after clicking the button. If you leave the target view empty, an empty placeholder view is shown in the animation. The view is filled after it gets the content from the server.

You can give the target view either in the constructor or with setTargetView().

NavigationView view = new NavigationView("A View");
...
NavigationButton button = new NavigationButton("Click");
button.setTargetView(view);
...

Notice that the automatic navigation will only work if the button is inside a NavigationManager (in a view inside it). If you just want to use the button as a visual element, you can use it like a regular Button and handle the click events with a ClickListener.

Popover is much like a regular Vaadin sub-window, useful for quickly displaying some options or a small form related to an action. Unlike regular sub-windows, it does not support dragging or resizing by the user. It can have a caption, but usually does not. As sub-windows usually require a rather large screen size, the Popover is mainly applicable to tablet devices. When used on smaller devices, such as phones, the Popover automatically fills the entire screen.

In the following example, we extend Popover to use it. It is modal by default. Notice that the screen size is not available in the constructor, so we have to postpone using it to the attach() method.

Popover windows are added to an application-level Window object with addWindow(), just like sub-windows in a regular Vaadin application.

if (event.getButton() == emailButton) {
    ComposeView composeView = new ComposeView(smartphone);
    getWindow().addWindow(composeView);
    return;
}

The resulting user interface in a tablet device is shown in Figure 19.3, “Popover in a Tablet Device”.


Alternatively, you can call the showRelativeTo(), which displays the sub-window relative to an existing component in the user interface.

Popover popover = new Popover();
popover.setContent(mailboxHierarchyView);
popover.setClosable(true);
popover.showRelativeTo(showMailboxHierarchyButton);
popover.setHeight(getParent().getHeight() - 100, UNITS_PIXELS);

In this case, you should not call addWindow() explicitly.