com.antonjohansson.managementcenter.core.web.welcome.WelcomeView.java Source code

Java tutorial

Introduction

Here is the source code for com.antonjohansson.managementcenter.core.web.welcome.WelcomeView.java

Source

/**
 * Copyright (c) Anton Johansson <antoon.johansson@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.antonjohansson.managementcenter.core.web.welcome;

import com.antonjohansson.managementcenter.core.framework.view.View;

import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ValoTheme;

/**
 * The view for the welcome screen.
 *
 * @author Anton Johansson
 */
public class WelcomeView extends VerticalLayout implements View {
    ComboBox engine;
    Button create;

    public WelcomeView() {
        setSizeFull();

        Component connect = buildConnectForm();
        addComponent(connect);
        setComponentAlignment(connect, Alignment.MIDDLE_CENTER);
    }

    private Component buildConnectForm() {
        final VerticalLayout panel = new VerticalLayout();
        panel.setSizeUndefined();
        panel.setSpacing(true);

        panel.addComponent(getHeader());
        panel.addComponent(getExistingConnectionLayout());
        panel.addComponent(getNewConnectionLayout());
        return panel;
    }

    private Component getExistingConnectionLayout() {
        ComboBox connection = new ComboBox("Existing connection");
        connection.addItem("SQL Server 01");
        connection.addItem("Elasticsearch Server 01");
        connection.setWidth("400");
        connection.setNullSelectionAllowed(false);
        connection.setTextInputAllowed(false);

        Button connect = new Button("Connect");
        connect.addStyleName(ValoTheme.BUTTON_PRIMARY);
        connect.setClickShortcut(KeyCode.ENTER);
        connect.setWidth("120");

        HorizontalLayout layout = new HorizontalLayout();
        layout.setSpacing(true);
        layout.addComponents(connection, connect);
        layout.setComponentAlignment(connect, Alignment.BOTTOM_LEFT);
        return layout;
    }

    private Component getNewConnectionLayout() {
        engine = new ComboBox("New connection");
        engine.setWidth("400");
        engine.setNullSelectionAllowed(false);
        engine.setTextInputAllowed(false);

        create = new Button("Create");
        create.addStyleName(ValoTheme.BUTTON_PRIMARY);
        create.setClickShortcut(KeyCode.ENTER);
        create.setWidth("120");

        HorizontalLayout layout = new HorizontalLayout();
        layout.setSpacing(true);
        layout.addComponents(engine, create);
        layout.setComponentAlignment(create, Alignment.BOTTOM_LEFT);
        return layout;
    }

    private Component getHeader() {
        Label title = new Label("Management Center");
        title.setSizeUndefined();
        title.addStyleName(ValoTheme.LABEL_H3);
        title.addStyleName(ValoTheme.LABEL_LIGHT);
        return title;
    }
}