com.freebox.engeneering.application.web.common.ApplicationLayout.java Source code

Java tutorial

Introduction

Here is the source code for com.freebox.engeneering.application.web.common.ApplicationLayout.java

Source

/*
 * Copyright 2012 Lexaden.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.freebox.engeneering.application.web.common;

import com.freebox.engeneering.application.view.state.StateLayout;
import com.lexaden.webflow.StateEvent;
import com.vaadin.server.Sizeable;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.VerticalLayout;

public class ApplicationLayout extends AbstractLayoutController<HorizontalLayout, ComponentContainer, Component> {

    private static final long serialVersionUID = -5252582678191884260L;

    /**
      * Initializes view layout when system enters 'initView' action state.
      *
      * @param event -  state event.
      */
    public void initView(@SuppressWarnings("rawtypes") StateEvent event) {
        final HorizontalLayout content = new HorizontalLayout();
        content.setSizeFull();
        content.setStyleName("main-view");

        final HorizontalSplitPanel leftSplitPanel = new HorizontalSplitPanel();
        leftSplitPanel.setSplitPosition(20, Sizeable.Unit.PERCENTAGE);

        final ComponentContainer leftSideBar = createPlaceholder(StateLayout.LEFT_SIDE_BAR);
        leftSideBar.setSizeFull();
        content.addComponent(leftSideBar, 0);

        final VerticalLayout verticalLayoutContent = new VerticalLayout();
        verticalLayoutContent.setStyleName("freebox-view");
        verticalLayoutContent.addComponent(createPlaceholder(StateLayout.HEADER));
        verticalLayoutContent.setSpacing(true);
        final ComponentContainer layoutContent = createPlaceholder(StateLayout.CONTENT);
        layoutContent.setSizeFull();
        verticalLayoutContent.addComponent(layoutContent);
        verticalLayoutContent.setSizeFull();
        //verticalLayoutContent.addComponent(createPlaceholder(StateLayout.FOOTER));

        verticalLayoutContent.setExpandRatio(layoutContent, 8f);

        content.addComponent(verticalLayoutContent, 1);
        content.setExpandRatio(leftSideBar, 1.0f);
        content.setExpandRatio(verticalLayoutContent, 9f);

        setView(content);
    }

    public void setCaption(String name) {
        getView().setCaption(name);
    }

    @Override
    public ComponentContainer onCreateContainer() {
        return new VerticalLayout();
    }

    @Override
    public void onPutControllerView(ComponentContainer container, Component content) {
        container.removeAllComponents();
        if (content != null) {
            container.addComponent(content);
            ((VerticalLayout) container).setComponentAlignment(content, Alignment.MIDDLE_CENTER);
        }
    }

    @Override
    public void onRemoveControllerView(ComponentContainer container) {
        container.removeAllComponents();
    }

}