nz.co.senanque.vaadinsupport.viewmanager.HelpLayout.java Source code

Java tutorial

Introduction

Here is the source code for nz.co.senanque.vaadinsupport.viewmanager.HelpLayout.java

Source

/*******************************************************************************
 * Copyright (c)2014 Prometheus Consulting
 *
 * 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 nz.co.senanque.vaadinsupport.viewmanager;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceAware;
import org.springframework.context.support.MessageSourceAccessor;

import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;

/**
 * This is a trivial help page which says very little. Notable because it uses
 * the view manager to pop back to the previous screen without us having to know
 * what it was.
 * 
 * @author Roger Parkinson
 * 
 */

public class HelpLayout extends VerticalLayout implements ViewManaged, InitializingBean, MessageSourceAware {
    private static final long serialVersionUID = 7507982480797356537L;
    private static final String HELP_HTML_SNIPPET = "This would show help if it were implemented.";
    private Button m_OKButton;
    private MessageSource m_messageSource;
    private ViewManager m_viewManager;

    public HelpLayout() {

    }

    private String getI18nHTML() {
        MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(m_messageSource);
        return messageSourceAccessor.getMessage("help.form.html", null, HELP_HTML_SNIPPET);
    }

    public void afterPropertiesSet() throws Exception {
        setSizeFull();
        Panel panel = new Panel();
        panel.setWidth("50%");
        panel.addComponent(new Label(getI18nHTML(), Label.CONTENT_XHTML));
        addComponent(panel);
        setComponentAlignment(panel, Alignment.MIDDLE_CENTER);
        m_OKButton = new Button("OK");
        panel.addComponent(m_OKButton);
        m_OKButton.addListener(new Button.ClickListener() {

            private static final long serialVersionUID = 1904763239654990140L;

            public void buttonClick(ClickEvent event) {
                getViewManager().popScreen();
                getViewManager().getMainWindow().requestRepaint();
            }
        });
    }

    public void switchedTo() {
        // TODO Auto-generated method stub

    }

    public void setMessageSource(MessageSource messageSource) {
        m_messageSource = messageSource;
    }

    public ViewManager getViewManager() {
        return m_viewManager;
    }

    public void setViewManager(ViewManager viewManager) {
        m_viewManager = viewManager;
    }
}