Example usage for com.vaadin.ui HorizontalLayout setExpandRatio

List of usage examples for com.vaadin.ui HorizontalLayout setExpandRatio

Introduction

In this page you can find the example usage for com.vaadin.ui HorizontalLayout setExpandRatio.

Prototype

public void setExpandRatio(Component component, float ratio) 

Source Link

Document

This method is used to control how excess space in layout is distributed among components.

Usage

From source file:com.peergreen.webconsole.scope.system.internal.bundle.BundleView.java

License:Open Source License

@PostConstruct
public void createView() {
    setMargin(true);/*from ww w .j a v a2  s.  c  om*/
    setSpacing(true);

    /*
    Page.Styles styles = Page.getCurrent().getStyles();
    styles.add(".no-padding {padding: 0em 0em 0em 0em !important; }");
    */

    HorizontalLayout header = new HorizontalLayout();
    //        header.setWidth("100%");
    header.setSpacing(true);
    header.setMargin(true);

    Label title = new Label("OSGi Bundles");
    title.addStyleName("h1");
    //        title.setSizeUndefined();
    header.addComponent(title);
    header.setComponentAlignment(title, Alignment.MIDDLE_LEFT);

    final TextField filter = new TextField();
    filter.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override
        public void textChange(final FieldEvents.TextChangeEvent event) {
            data.removeAllContainerFilters();
            String trimmed = event.getText().trim();
            Container.Filter or = new Or(new SimpleStringFilter(BUNDLE_ID_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(BUNDLE_NAME_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(BUNDLE_SYMBOLICNAME_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(VERSION_COLUMN, trimmed, true, false),
                    new SimpleStringFilter(PRETTY_STATE_COLUMN, trimmed, true, false));

            data.addContainerFilter(or);
        }
    });

    filter.setInputPrompt("Filter");
    filter.addShortcutListener(new ShortcutListener("Clear", ShortcutAction.KeyCode.ESCAPE, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            filter.setValue("");
            data.removeAllContainerFilters();
        }
    });
    header.addComponent(filter);
    header.setExpandRatio(filter, 1);
    header.setComponentAlignment(filter, Alignment.MIDDLE_LEFT);

    // Store the header in the vertical layout (this)
    addComponent(header);

    addComponent(tabSheet);

    table = new Table();
    table.setContainerDataSource(data);
    table.setSizeFull();
    table.setSortContainerPropertyId(BUNDLE_ID_COLUMN);
    table.setSortAscending(true);
    table.setImmediate(true);
    table.setColumnHeader(BUNDLE_ID_COLUMN, "Bundle ID");
    table.setColumnHeader(PRETTY_NAME_COLUMN, "Bundle Name");
    table.setColumnHeader(VERSION_COLUMN, "Version");
    table.setColumnHeader(PRETTY_STATE_COLUMN, "State");
    table.setColumnHeader("actions", "Actions");

    table.setColumnWidth(BUNDLE_ID_COLUMN, 100);

    table.setColumnAlignment(BUNDLE_ID_COLUMN, Table.Align.CENTER);
    table.setColumnAlignment(PRETTY_STATE_COLUMN, Table.Align.CENTER);
    table.setColumnAlignment(VERSION_COLUMN, Table.Align.CENTER);

    table.addGeneratedColumn("actions", new Table.ColumnGenerator() {
        @Override
        public Object generateCell(final Table source, final Object itemId, final Object columnId) {
            HorizontalLayout layout = new HorizontalLayout();
            BeanItem<BundleItem> item = (BeanItem<BundleItem>) source.getContainerDataSource().getItem(itemId);
            Bundle bundle = item.getBean().getBundle();
            if (BundleHelper.isState(bundle, Bundle.INSTALLED)
                    || BundleHelper.isState(bundle, Bundle.RESOLVED)) {
                Button changeState = new Button();
                changeState.addClickListener(new StartBundleClickListener(bundle, notifierService));
                //changeState.addStyleName("no-padding");
                changeState.setCaption("Start");
                //changeState.setIcon(new ClassResource(BundleViewer.class, "/images/go-next.png"));
                if (!securityManager.isUserInRole("admin")) {
                    changeState.setDisableOnClick(true);
                }
                layout.addComponent(changeState);
            }
            if (BundleHelper.isState(bundle, Bundle.ACTIVE)) {
                Button changeState = new Button();
                changeState.addClickListener(new StopBundleClickListener(bundle, notifierService));
                //changeState.addStyleName("no-padding");
                changeState.setCaption("Stop");
                if (!securityManager.isUserInRole("admin")) {
                    changeState.setDisableOnClick(true);
                }
                //changeState.setIcon(new ClassResource(BundleViewer.class, "/images/media-record.png"));
                layout.addComponent(changeState);
            }

            // Update
            Button update = new Button();
            update.addClickListener(new UpdateBundleClickListener(bundle, notifierService));
            //update.addStyleName("no-padding");
            update.setCaption("Update");
            if (!securityManager.isUserInRole("admin")) {
                update.setDisableOnClick(true);
            }
            //update.setIcon(new ClassResource(BundleViewer.class, "/images/view-refresh.png"));
            layout.addComponent(update);

            // Trash
            Button trash = new Button();
            trash.addClickListener(new UninstallBundleClickListener(bundle, notifierService));
            //trash.addStyleName("no-padding");
            trash.setCaption("Delete");
            if (!securityManager.isUserInRole("admin")) {
                trash.setDisableOnClick(true);
            }
            //trash.setIcon(new ClassResource(BundleViewer.class, "/images/user-trash-full.png"));
            layout.addComponent(trash);

            return layout;
        }
    });

    table.setVisibleColumns(BUNDLE_ID_COLUMN, PRETTY_NAME_COLUMN, VERSION_COLUMN, PRETTY_STATE_COLUMN,
            "actions");

    table.addItemClickListener(new ItemClickEvent.ItemClickListener() {
        @Override
        public void itemClick(final ItemClickEvent event) {
            if (event.isDoubleClick()) {
                BeanItem<BundleItem> item = (BeanItem<BundleItem>) table.getContainerDataSource()
                        .getItem(event.getItemId());
                Bundle bundle = item.getBean().getBundle();
                showBundle(bundle);
            }
        }
    });

    createBundleTracker();

    tabSheet.setSizeFull();
    selectedTabListener = new SelectedTabListener(uiContext.getViewNavigator());
    selectedTabListener.addLocation(table, uiContext.getViewNavigator().getLocation(this.getClass().getName()));
    tabSheet.addSelectedTabChangeListener(selectedTabListener);
    tabSheet.addTab(table, "Bundles", new ClassResource(BundleView.class, "/images/22x22/user-home.png"));
    setExpandRatio(tabSheet, 1.5f);

    tabSheet.setCloseHandler(new TabSheet.CloseHandler() {
        @Override
        public void onTabClose(TabSheet tabsheet, Component tabContent) {
            for (Map.Entry<Long, Component> tab : openTabs.entrySet()) {
                if (tabContent.equals(tab.getValue())) {
                    openTabs.remove(tab.getKey());
                }
            }
            tabsheet.removeComponent(tabContent);
            selectedTabListener.removeLocation(tabContent);
        }
    });
}

From source file:com.peergreen.webconsole.scope.system.internal.service.ServiceViewer.java

License:Open Source License

private void initHeader() {
    HorizontalLayout header = new HorizontalLayout();
    header.setWidth("100%");
    header.setSpacing(true);/*from w w w  .  jav  a2  s .c  o  m*/
    header.setMargin(true);

    Label title = new Label("OSGi Services");
    title.addStyleName("h1");
    title.setSizeUndefined();
    header.addComponent(title);
    header.setComponentAlignment(title, Alignment.MIDDLE_LEFT);

    final TextField filter = new TextField();
    filter.addTextChangeListener(new FieldEvents.TextChangeListener() {
        @Override
        public void textChange(final FieldEvents.TextChangeEvent event) {
            data.removeAllContainerFilters();
            String trimmed = event.getText().trim();
            Container.Filter or = new Or(new SimpleStringFilter(SERVICE_ID_COLUMN, trimmed, true, false),
                    new InterfacesFilter(trimmed), new BundleFilter(trimmed),
                    new ServicePropertiesFilter(trimmed));

            data.addContainerFilter(or);
        }
    });

    filter.setInputPrompt("Filter");
    filter.addShortcutListener(new ShortcutListener("Clear", ShortcutAction.KeyCode.ESCAPE, null) {
        @Override
        public void handleAction(Object sender, Object target) {
            filter.setValue("");
            data.removeAllContainerFilters();
        }
    });
    header.addComponent(filter);
    header.setExpandRatio(filter, 1);
    header.setComponentAlignment(filter, Alignment.MIDDLE_LEFT);

    // Store the header in the vertical layout (this)
    addComponent(header);
}

From source file:com.rdonasco.security.application.views.ApplicationListPanelView.java

License:Apache License

@Override
public void initWidget() throws WidgetInitalizeException {
    getAddButton().setCaption(I18NResource.localize("Add new"));
    getAddButton().setDescription(I18NResource.localize("Add new application"));
    getAddButton().setIcon(new ThemeResource(SecurityDefaultTheme.ICON_16x16_ADD));
    getAddButton().setWidth(100, UNITS_PERCENTAGE);
    getAddButton().addStyleName(SecurityDefaultTheme.CSS_SMALL);
    getRefreshButton().setCaption(I18NResource.localize("Refresh"));
    getRefreshButton().setIcon(new ThemeResource(SecurityDefaultTheme.ICON_16x16_REFRESH));
    getRefreshButton().addStyleName(SecurityDefaultTheme.CSS_SMALL);
    VerticalLayout content = ((VerticalLayout) getContent());
    content.setMargin(true);/*  w w  w .j  a  v  a 2 s. c  o  m*/
    content.setHeight(600, UNITS_PIXELS);
    content.removeAllComponents();
    if (null != getDataViewListTable()) {
        getDataViewListTable().setSizeFull();
        HorizontalLayout buttonLayout = new HorizontalLayout();
        buttonLayout.setSpacing(true);
        buttonLayout.setWidth(100F, UNITS_PERCENTAGE);
        buttonLayout.addComponent(getAddButton());
        buttonLayout.addComponent(getRefreshButton());
        buttonLayout.setExpandRatio(getAddButton(), 1);
        content.addComponent(buttonLayout);
        content.addComponent(getDataViewListTable());
        content.setExpandRatio(getDataViewListTable(), 1);
        content.setSpacing(true);
    }
}

From source file:com.rdonasco.security.group.views.GroupListPanelView.java

License:Apache License

@Override
public void initWidget() throws WidgetInitalizeException {
    setCaption(I18NResource.localize("Groups"));
    setStyleName(SecurityDefaultTheme.CSS_PANEL_BUBBLE);
    VerticalLayout content = (VerticalLayout) getContent();
    content.setMargin(true);//from  w w w.jav  a  2s  .  c  o m
    content.setHeight(600, UNITS_PIXELS);
    content.removeAllComponents();
    getGroupListTable().setSizeFull();
    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth(100F, UNITS_PERCENTAGE);
    buttonLayout.addComponent(getAddGroupButton());
    buttonLayout.addComponent(getRefreshButton());
    buttonLayout.setExpandRatio(getAddGroupButton(), 1);
    content.addComponent(buttonLayout);

    content.addComponent(getGroupListTable());
    content.setExpandRatio(getGroupListTable(), 1);
    content.setSpacing(true);

}

From source file:com.rdonasco.security.role.views.RoleListPanelView.java

License:Apache License

@Override
public void initWidget() throws WidgetInitalizeException {
    setCaption(I18NResource.localize("Roles"));
    setStyleName(SecurityDefaultTheme.CSS_PANEL_BUBBLE);
    VerticalLayout content = (VerticalLayout) getContent();
    content.setMargin(true);/* w  w  w  . j  a  va2s. com*/
    content.setHeight(600, UNITS_PIXELS);
    content.removeAllComponents();
    getRoleListTable().setSizeFull();
    HorizontalLayout buttonLayout = new HorizontalLayout();
    buttonLayout.setSpacing(true);
    buttonLayout.setWidth(100F, UNITS_PERCENTAGE);
    buttonLayout.addComponent(addRoleButton);
    buttonLayout.addComponent(refreshButton);
    buttonLayout.setExpandRatio(addRoleButton, 1);
    content.addComponent(buttonLayout);
    content.addComponent(getRoleListTable());
    content.setExpandRatio(getRoleListTable(), 1);
    content.setSpacing(true);
}

From source file:com.rdonasco.security.user.controllers.UserEditorViewController.java

License:Apache License

private void configureTabContentLayout(HorizontalLayout container, AbstractComponent leftContent,
        AbstractComponent rightContent) {
    container.setSpacing(true);/* w  ww  . ja  v a 2s .  c o m*/
    container.setMargin(true, true, true, true);

    container.addComponent(leftContent);
    container.addComponent(rightContent);
    leftContent.setWidth(100f, Sizeable.UNITS_PERCENTAGE);
    container.setExpandRatio(leftContent, 1f);
    container.setExpandRatio(rightContent, 0.25f);

    // fix the size of the panels
    float panelHeight = 300;
    leftContent.setHeight(panelHeight, Sizeable.UNITS_PIXELS);
    rightContent.setHeight(panelHeight, Sizeable.UNITS_PIXELS);
}

From source file:com.rdonasco.security.user.views.UserListPanelView.java

License:Apache License

@Override
public void initWidget() throws WidgetInitalizeException {
    getAddUserButton().setCaption(I18NResource.localize("Add new user"));
    getAddUserButton().setIcon(new ThemeResource(SecurityDefaultTheme.ICON_16x16_ADD));
    getAddUserButton().setWidth(100, UNITS_PERCENTAGE);
    getAddUserButton().addStyleName(SecurityDefaultTheme.CSS_SMALL);
    getRefreshButton().setCaption("Refresh");
    getRefreshButton().setIcon(new ThemeResource(SecurityDefaultTheme.ICON_16x16_REFRESH));
    getRefreshButton().addStyleName(SecurityDefaultTheme.CSS_SMALL);
    VerticalLayout content = ((VerticalLayout) getContent());
    content.setMargin(true);/*  w w w .j a v a2 s.  com*/
    content.setHeight(600, UNITS_PIXELS);
    content.removeAllComponents();
    if (null != getDataViewListTable()) {
        getDataViewListTable().setSizeFull();
        HorizontalLayout buttonLayout = new HorizontalLayout();
        buttonLayout.setSpacing(true);
        buttonLayout.setWidth(100F, UNITS_PERCENTAGE);
        buttonLayout.addComponent(getAddUserButton());
        buttonLayout.addComponent(getRefreshButton());
        buttonLayout.setExpandRatio(getAddUserButton(), 1);
        content.addComponent(buttonLayout);
        content.addComponent(getDataViewListTable());
        content.setExpandRatio(getDataViewListTable(), 1);
        content.setSpacing(true);
    }
}

From source file:com.save.bi.MaintenanceSummaryLineChart.java

public MaintenanceSummaryLineChart() {
    setSizeFull();//w ww  . ja v a  2s .c  o m

    HorizontalLayout h = new HorizontalLayout();
    h.setWidth("100%");
    h.setSpacing(true);

    ComboBox area = CommonComboBox.areas();
    area.setCaption(null);
    area.setInputPrompt("Select an Area.. ");
    area.setWidth("100px");
    h.addComponent(area);

    ComboBox year = CommonComboBox.yearList();
    year.setInputPrompt("Select a Year.. ");
    year.setWidth("100px");
    h.addComponent(year);

    Button button = new CommonButton("Generate Line Chart");
    button.setWidthUndefined();
    h.addComponent(button);
    h.setExpandRatio(button, 3);

    addComponent(h);
}

From source file:com.save.reports.maintenance.MaintenanceReportUI.java

public MaintenanceReportUI() {
    setSizeFull();//  w w w . j  ava2  s .  c  o m

    mrDataGrid.setFrozenColumnCount(2);
    addComponent(mrDataGrid);
    setExpandRatio(mrDataGrid, 1);

    HorizontalLayout h = new HorizontalLayout();
    h.setWidth("100%");
    h.setSpacing(true);
    h.setMargin(new MarginInfo(false, true, true, false));

    Button filter = new CommonButton("FILTER");
    filter.setWidth("200px");
    filter.addClickListener(this);
    h.addComponent(filter);
    h.setComponentAlignment(filter, Alignment.MIDDLE_RIGHT);
    h.setExpandRatio(filter, 1);

    Button exportToExcel = new CommonButton("EXPORT TO EXCEL");
    exportToExcel.setWidth("200px");
    exportToExcel.addClickListener(this);
    h.addComponent(exportToExcel);
    h.setComponentAlignment(exportToExcel, Alignment.MIDDLE_RIGHT);

    addComponent(h);
}

From source file:com.save.reports.promodeals.PromoDealReportUI.java

public PromoDealReportUI() {
    setSizeFull();/*from  www  .  ja  v  a2 s  . c  om*/

    addComponent(promoDealGrid);
    setExpandRatio(promoDealGrid, 1);

    HorizontalLayout h = new HorizontalLayout();
    h.setWidth("100%");
    h.setSpacing(true);
    h.setMargin(new MarginInfo(false, true, true, false));

    Button filter = new CommonButton("FILTER");
    filter.setWidth("200px");
    filter.addClickListener(this);
    h.addComponent(filter);
    h.setComponentAlignment(filter, Alignment.MIDDLE_RIGHT);
    h.setExpandRatio(filter, 1);

    Button exportToExcel = new CommonButton("EXPORT TO EXCEL");
    exportToExcel.setWidth("200px");
    exportToExcel.addClickListener(this);
    h.addComponent(exportToExcel);
    h.setComponentAlignment(exportToExcel, Alignment.MIDDLE_RIGHT);

    addComponent(h);
}