org.ikasan.dashboard.ui.mappingconfiguration.panel.MappingConfigurationView.java Source code

Java tutorial

Introduction

Here is the source code for org.ikasan.dashboard.ui.mappingconfiguration.panel.MappingConfigurationView.java

Source

/*
* $Id$
* $URL$
*
* ====================================================================
* Ikasan Enterprise Integration Platform
*
* Distributed under the Modified BSD License.
* Copyright notice: The copyright for this software and a full listing
* of individual contributors are as shown in the packaged copyright.txt
* file.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of source code must retain the above copyright notice,
*    this list of conditions and the following disclaimer.
*
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this list of conditions and the following disclaimer in the documentation
*    and/or other materials provided with the distribution.
*
*  - Neither the name of the ORGANIZATION nor the names of its contributors may
*    be used to endorse or promote products derived from this software without
*    specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
package org.ikasan.dashboard.ui.mappingconfiguration.panel;

import org.ikasan.dashboard.ui.framework.display.ViewComponentContainer;
import org.vaadin.teemu.VaadinIcons;

import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalSplitPanel;
import com.vaadin.ui.themes.ValoTheme;

/**
 * 
 * 
 * @author Ikasan Development Team
 *
 */
public class MappingConfigurationView extends Panel implements View {
    private static final long serialVersionUID = -4759498822589839343L;
    private MappingConfigurationSearchPanel searchPanel;
    private MappingConfigurationSearchResultsPanel searchResultsPanel;
    private ViewComponentContainer viewComponentContainer;
    private VerticalSplitPanel verticalSplitPanel;

    private float splitPosition;
    private Unit splitUnit;

    /**
     * Constructor
     * 
     * @param searchPanel
     * @param searchResultsPanel
     * @param viewComponentContainer
     * @param newActionsPanel
     */
    public MappingConfigurationView(MappingConfigurationSearchPanel searchPanel,
            MappingConfigurationSearchResultsPanel searchResultsPanel,
            ViewComponentContainer viewComponentContainer) {
        this.searchPanel = searchPanel;
        this.searchResultsPanel = searchResultsPanel;
        this.viewComponentContainer = viewComponentContainer;

        this.init();
    }

    /**
     * Helper method to initialise this object.
     */
    protected void init() {
        this.setSizeFull();

        HorizontalLayout topContainer = new HorizontalLayout();
        topContainer.setSizeFull();
        topContainer.setMargin(true);
        topContainer.addComponent(this.searchPanel);
        HorizontalLayout bottomContainer = new HorizontalLayout();
        bottomContainer.setMargin(true);
        bottomContainer.setSizeFull();
        bottomContainer.addComponent(this.viewComponentContainer);

        final Button hideFilterButton = new Button();
        hideFilterButton.setIcon(VaadinIcons.MINUS);
        hideFilterButton.setCaption("Hide Filter");
        hideFilterButton.setStyleName(ValoTheme.BUTTON_LINK);
        hideFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);

        final Button showFilterButton = new Button();
        showFilterButton.setIcon(VaadinIcons.PLUS);
        showFilterButton.setCaption("Show Filter");
        showFilterButton.addStyleName(ValoTheme.BUTTON_LINK);
        showFilterButton.addStyleName(ValoTheme.BUTTON_SMALL);
        showFilterButton.setVisible(false);

        hideFilterButton.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                hideFilterButton.setVisible(false);
                showFilterButton.setVisible(true);
                splitPosition = verticalSplitPanel.getSplitPosition();
                splitUnit = verticalSplitPanel.getSplitPositionUnit();
                verticalSplitPanel.setSplitPosition(0, Unit.PIXELS);
            }
        });

        showFilterButton.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                hideFilterButton.setVisible(true);
                showFilterButton.setVisible(false);
                verticalSplitPanel.setSplitPosition(splitPosition, splitUnit);
            }
        });

        GridLayout filterButtonLayout = new GridLayout(2, 1);
        filterButtonLayout.setHeight(25, Unit.PIXELS);
        filterButtonLayout.addComponent(hideFilterButton, 0, 0);
        filterButtonLayout.addComponent(showFilterButton, 1, 0);

        this.verticalSplitPanel = new VerticalSplitPanel(topContainer, bottomContainer);
        this.verticalSplitPanel.addStyleName(ValoTheme.SPLITPANEL_LARGE);
        this.verticalSplitPanel.setSizeFull();
        this.verticalSplitPanel.setSplitPosition(260, Unit.PIXELS);

        GridLayout wrapper = new GridLayout(1, 2);
        wrapper.setRowExpandRatio(0, .01f);
        wrapper.setRowExpandRatio(1, .99f);
        wrapper.setSizeFull();
        wrapper.addComponent(filterButtonLayout);
        wrapper.setComponentAlignment(filterButtonLayout, Alignment.MIDDLE_RIGHT);
        wrapper.addComponent(verticalSplitPanel);

        this.setContent(wrapper);
    }

    @Override
    public void enter(ViewChangeEvent event) {
        this.searchPanel.enter(event);
        this.searchResultsPanel.enter(event);
    }
}