Example usage for com.vaadin.ui HorizontalSplitPanel setMaxSplitPosition

List of usage examples for com.vaadin.ui HorizontalSplitPanel setMaxSplitPosition

Introduction

In this page you can find the example usage for com.vaadin.ui HorizontalSplitPanel setMaxSplitPosition.

Prototype

public void setMaxSplitPosition(float pos, Unit unit) 

Source Link

Document

Sets the maximum split position to the given position and unit.

Usage

From source file:org.sensorhub.ui.AdminUI.java

License:Mozilla Public License

@Override
protected void init(VaadinRequest request) {
    String configClass = null;//  w ww .jav a  2s  . c o  m
    moduleConfigLists.clear();

    // retrieve module config
    try {
        Properties initParams = request.getService().getDeploymentConfiguration().getInitParameters();
        String moduleID = initParams.getProperty(AdminUIModule.SERVLET_PARAM_MODULE_ID);
        uiConfig = (AdminUIConfig) SensorHub.getInstance().getModuleRegistry().getModuleById(moduleID)
                .getConfiguration();
    } catch (Exception e) {
        throw new RuntimeException("Cannot get UI module configuration", e);
    }

    try {
        // load default form builders
        customForms.put(HttpServerConfig.class.getCanonicalName(), HttpServerConfigForm.class);
        customForms.put(StreamStorageConfig.class.getCanonicalName(), GenericStorageConfigForm.class);
        customForms.put(CommConfig.class.getCanonicalName(), CommConfigForm.class);
        customForms.put(SOSConfigForm.SOS_PACKAGE + "SOSServiceConfig", SOSConfigForm.class);
        customForms.put(SOSConfigForm.SOS_PACKAGE + "SOSProviderConfig", SOSConfigForm.class);

        // load custom form builders defined in config
        for (CustomUIConfig customForm : uiConfig.customForms) {
            configClass = customForm.configClass;
            Class<?> clazz = Class.forName(customForm.uiClass);
            customForms.put(configClass, (Class<IModuleConfigForm>) clazz);
            log.debug("Loaded custom form for " + configClass);
        }
    } catch (Exception e) {
        log.error("Error while instantiating form builder for config class " + configClass, e);
    }

    try {
        // load default panel builders
        customPanels.put(SensorConfig.class.getCanonicalName(), SensorAdminPanel.class);
        customPanels.put(StorageConfig.class.getCanonicalName(), StorageAdminPanel.class);

        // load custom panel builders defined in config
        for (CustomUIConfig customPanel : uiConfig.customPanels) {
            configClass = customPanel.configClass;
            Class<?> clazz = Class.forName(customPanel.uiClass);
            customPanels.put(configClass, (Class<IModuleAdminPanel<?>>) clazz);
            log.debug("Loaded custom panel for " + configClass);
        }
    } catch (Exception e) {
        log.error("Error while instantiating panel builder for config class " + configClass, e);
    }

    // register new field converter for interger numbers
    @SuppressWarnings("serial")
    ConverterFactory converterFactory = new DefaultConverterFactory() {
        @Override
        protected <PRESENTATION, MODEL> Converter<PRESENTATION, MODEL> findConverter(
                Class<PRESENTATION> presentationType, Class<MODEL> modelType) {
            // Handle String <-> Integer/Short/Long
            if (presentationType == String.class
                    && (modelType == Long.class || modelType == Integer.class || modelType == Short.class)) {
                return (Converter<PRESENTATION, MODEL>) new StringToIntegerConverter() {
                    @Override
                    protected NumberFormat getFormat(Locale locale) {
                        NumberFormat format = super.getFormat(Locale.US);
                        format.setGroupingUsed(false);
                        return format;
                    }
                };
            }
            // Let default factory handle the rest
            return super.findConverter(presentationType, modelType);
        }
    };
    VaadinSession.getCurrent().setConverterFactory(converterFactory);

    // init main panels
    HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
    splitPanel.setMinSplitPosition(300.0f, Unit.PIXELS);
    splitPanel.setMaxSplitPosition(30.0f, Unit.PERCENTAGE);
    splitPanel.setSplitPosition(350.0f, Unit.PIXELS);
    setContent(splitPanel);

    // build left pane
    VerticalLayout leftPane = new VerticalLayout();
    leftPane.setSizeFull();

    // header image and title
    Component header = buildHeader();
    leftPane.addComponent(header);
    leftPane.setExpandRatio(header, 0);

    // toolbar
    Component toolbar = buildToolbar();
    leftPane.addComponent(toolbar);
    leftPane.setExpandRatio(toolbar, 0);

    // accordion with several sections
    Accordion stack = new Accordion();
    stack.setSizeFull();
    VerticalLayout layout;
    Tab tab;

    layout = new VerticalLayout();
    tab = stack.addTab(layout, "Sensors");
    tab.setIcon(ACC_TAB_ICON);
    buildModuleList(layout, SensorConfig.class);

    layout = new VerticalLayout();
    tab = stack.addTab(layout, "Storage");
    tab.setIcon(ACC_TAB_ICON);
    buildModuleList(layout, StorageConfig.class);

    layout = new VerticalLayout();
    tab = stack.addTab(layout, "Processing");
    tab.setIcon(ACC_TAB_ICON);
    buildModuleList(layout, ProcessConfig.class);

    layout = new VerticalLayout();
    tab = stack.addTab(layout, "Services");
    tab.setIcon(ACC_TAB_ICON);
    buildModuleList(layout, ServiceConfig.class);

    layout = new VerticalLayout();
    tab = stack.addTab(layout, "Clients");
    tab.setIcon(ACC_TAB_ICON);
    buildModuleList(layout, ClientConfig.class);

    layout = new VerticalLayout();
    tab = stack.addTab(layout, "Network");
    tab.setIcon(ACC_TAB_ICON);
    buildNetworkConfig(layout);

    leftPane.addComponent(stack);
    leftPane.setExpandRatio(stack, 1);
    splitPanel.addComponent(leftPane);

    // init config area
    configArea = new VerticalLayout();
    configArea.setMargin(true);
    splitPanel.addComponent(configArea);
}