Layout Flashcards

(11 cards)

1
Q

App Layout . Navigation Bar

A

The navigation bar of AppLayout is a horizontal element that can contain any component, such as a header or a horizontal menu.
Setting content within header
private Component createHeaderContent() {
HorizontalLayout layout = new HorizontalLayout();

// Configure styling for the header
layout.setId("header");
layout.getThemeList().set("dark", true);
layout.setWidthFull();
layout.setSpacing(false);
layout.setAlignItems(FlexComponent.Alignment.CENTER);

// Have the drawer toggle button on the left
layout.add(new DrawerToggle());

// Placeholder for the title of the current view.
// The title will be set after navigation.
viewTitle = new H1();
layout.add(viewTitle);

// A user icon
layout.add(new Image("images/user.svg", "Avatar"));

return layout; }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

App Layout. Drawer

A

private Component createDrawerContent(Tabs menu) {
VerticalLayout layout = new VerticalLayout();

// Configure styling for the drawer
layout.setSizeFull();
layout.setPadding(false);
layout.setSpacing(false);
layout.getThemeList().set("spacing-s", true);
layout.setAlignItems(FlexComponent.Alignment.STRETCH);

// Have a drawer header with an application logo
HorizontalLayout logoLayout = new HorizontalLayout();
logoLayout.setId("logo");
logoLayout.setAlignItems(FlexComponent.Alignment.CENTER);
logoLayout.add(new Image("images/logo.png", "My Project logo"));
logoLayout.add(new H1("My Project"));

// Display the logo and the menu in the drawer
layout.add(logoLayout, menu);
return layout; }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

AppLayout.Drawer.VerticalMenu

A

The actual menu is a vertical Tabs component. It’s filled from a list of Tab components. Each tab contains a RouterLink to the corresponding view

private Tabs createMenu() {
final Tabs tabs = new Tabs();
tabs.setOrientation(Tabs.Orientation.VERTICAL);
tabs.addThemeVariants(TabsVariant.LUMO_MINIMAL);
tabs.setId(“tabs”);
tabs.add(createMenuItems());
return tabs;
}

private Component[] createMenuItems() {
return new Tab[] { createTab(“Hello World”, HelloWorldView.class),
createTab(“Card List”, CardListView.class),
createTab(“About”, AboutView.class) };
}

private static Tab createTab(String text,
Class<? extends Component> navigationTarget) {
final Tab tab = new Tab();
tab.add(new RouterLink(text, navigationTarget));
ComponentUtil.setData(tab, Class.class, navigationTarget);
return tab;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Handling Navigation

A

When the user navigates to a view, the tab for the view should be highlighted by setting it as selected. You can also set the view title in header.

You can do both these things by overriding afterNavigation() in AppLayout, as follows:

@Override
protected void afterNavigation() {
super.afterNavigation();

// Select the tab corresponding to currently shown view
getTabForComponent(getContent()).ifPresent(menu::setSelectedTab);

// Set the view title in the header
viewTitle.setText(getCurrentPageTitle()); }

Getting selected tab
private Optional<Tab> getTabForComponent(Component component) {
return menu.getChildren()
.filter(tab -> ComponentUtil.getData(tab, Class.class)
.equals(component.getClass()))
.findFirst().map(Tab.class::cast);
}</Tab>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Getting current page title

A

private String getCurrentPageTitle() {
return getContent().getClass().getAnnotation(PageTitle.class).value();
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Creating a view

A

Like any view, a view displayed in an AppLayout needs a route defined with the @Route annotation. The route needs to be linked to the main view by using the layout parameter to pass the class object of the main view.

@Route(value = “hello”, layout = MainView.class)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Page Title

A

@PageTitle(“Hello World”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Styling a View

A

You can define custom styling for the view with the @CssImport annotation.
@CssImport(“./styles/views/helloworld/hello-world-view.css”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Default View

A

Most applications need an entry point. You can define a view as the default view by defining the route of the main view with @RouteAlias. The value defining the route needs to be empty for the root route.
@RouteAlias(value = “”, layout = MainView.class)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Route and Views

A

Routing maps URLs to views or resources to navigate directly to the desired content or functionality. Typically, the root route / shows a main view, a route such as /users could show a sub-view that displays a list of users, and a route with the user ID as a parameter, such as /users/dadams, would show a specific user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly