com.freebox.engeneering.application.web.layout.RightSideBarController.java Source code

Java tutorial

Introduction

Here is the source code for com.freebox.engeneering.application.web.layout.RightSideBarController.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.layout;

import com.freebox.engeneering.application.view.state.StateConstants;
import com.freebox.engeneering.application.web.common.AbstractController;
import com.lexaden.webflow.StateEvent;
import com.lexaden.webflow.annotation.OnEnterState;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Accordion;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

/**
 * This class is responsible for UI components collaborations on right side bar part of the screen.
 *
 * @author Aliaksei Papou
 */
@SuppressWarnings("serial")
public class RightSideBarController extends AbstractController<Accordion> {

    /**
     * Initializes view when system enters 'initView' action state.
     *
     * @param event -  state event.
     */
    @Override
    public void initView(StateEvent event) {
        final Accordion content = new Accordion();
        content.setSizeFull();
        setView(content);
    }

    /**
     * This method is called every time system enters any profile state
     *
     * @param stateEvent -state event.
     */
    @OnEnterState(StateConstants.PROFILE)
    public void buildRightSideBarView(StateEvent stateEvent) {
        clearView(stateEvent);

        final Accordion accordion = super.getView();

        final VerticalLayout verticalLayout = new VerticalLayout();
        accordion.addTab(verticalLayout, "Right Side Bar");

        final VerticalLayout contentLayout = new VerticalLayout();
        contentLayout.setMargin(true);
        contentLayout.setSpacing(true);

        contentLayout.addComponent(new Label("www.lexaden.com<br/>contact@lexaden.com", ContentMode.HTML));
        verticalLayout.addComponent(contentLayout);
    }

    public void clearView(StateEvent stateEvent) {
        Accordion content = super.getView();
        if (content != null) {
            content.removeAllComponents();
        }
    }
}