Example usage for com.vaadin.ui Layout iterator

List of usage examples for com.vaadin.ui Layout iterator

Introduction

In this page you can find the example usage for com.vaadin.ui Layout iterator.

Prototype

@Override
public Iterator<Component> iterator();

Source Link

Document

Gets an iterator to the collection of contained components.

Usage

From source file:com.ocs.dynamo.ui.composite.layout.LazyTabLayout.java

License:Apache License

/**
 * Constructs the lazy tab sheet by setting up empty dummy tabs
 * @param tabs//  w w  w  . j av a 2  s .  co m
 */
private void setupLazySheet(final TabSheet tabs) {

    // build up placeholder tabs that only contain an empty layout
    for (String caption : getTabCaptions()) {
        tabs.addTab(new DefaultVerticalLayout(false, false), caption);
    }

    // load the first tab
    ((Layout) tabs.getTab(0).getComponent()).addComponent(initTab(0));
    replacedTabs.add(tabs.getTab(0).getCaption());

    // respond to a tab change by actually loading the sheet
    tabs.addSelectedTabChangeListener(new TabSheet.SelectedTabChangeListener() {

        @Override
        public void selectedTabChange(SelectedTabChangeEvent event) {
            Component selectedTab = event.getTabSheet().getSelectedTab();
            Tab tab = event.getTabSheet().getTab(selectedTab);

            // lazily load a tab
            if (!replacedTabs.contains(tab.getCaption())) {
                replacedTabs.add(tab.getCaption());

                // look up the tab in the copies
                int index = 0;
                for (int i = 0; i < tabs.getComponentCount(); i++) {
                    Tab t = tabs.getTab(i);
                    if (t.getCaption().equals(tab.getCaption())) {
                        index = i;
                        break;
                    }
                }

                // paste the real tab into the placeholder
                Component realTab = initTab(index);
                ((Layout) selectedTab).addComponent(realTab);

            } else {
                // reload the tab if needed
                Layout layout = (Layout) selectedTab;
                Component next = layout.iterator().next();
                if (next instanceof Reloadable) {
                    ((Reloadable) next).reload();
                }
            }

        }
    });
}

From source file:de.unioninvestment.eai.portal.portlet.crud.mvp.views.DefaultTableView.java

License:Apache License

/**
 * {@inheritDoc}/*from  w w  w  .j av  a 2 s . co  m*/
 * 
 * @see de.unioninvestment.eai.portal.portlet.crud.mvp.views.TableView#initialize(de.unioninvestment.eai.portal.portlet.crud.mvp.views.TableView.Presenter,
 *      de.unioninvestment.eai.portal.portlet.crud.domain.model.DataContainer,
 *      de.unioninvestment.eai.portal.portlet.crud.domain.model.Table, int,
 *      double)
 */
@Override
public void initialize(TableView.Presenter presenter, DataContainer databaseContainer, Table tableModel,
        int pageLength, double cacheRate) {

    this.presenter = presenter;
    this.container = databaseContainer;
    this.tableModel = tableModel;

    // @since 1.45
    if (tableModel.getWidth() != null) {
        setWidth(tableModel.getWidth());
    }
    // @since 1.45
    if (tableModel.getHeight() != null) {
        setHeight(tableModel.getHeight());
    }

    table = new CrudTable(container, tableModel.getColumns(), tableModel.isSortingEnabled());
    table.disableContentRefreshing();
    table.setColumnCollapsingAllowed(true);
    table.setColumnReorderingAllowed(true);
    table.setSizeFull();
    table.setImmediate(true);
    table.setEditable(false);

    if (tableModel.getSelectionMode() == SelectionMode.MULTIPLE) {
        table.setSelectable(true);
        table.setNullSelectionAllowed(false);
        table.setMultiSelect(true);
        table.setMultiSelectMode(MultiSelectMode.DEFAULT);
    } else if (tableModel.getSelectionMode() == SelectionMode.SINGLE) {
        table.setSelectable(true);
        table.setNullSelectionAllowed(false);
    }

    if (!tableModel.isSortingEnabled()) {
        table.setSortEnabled(false);
    }

    table.addStyleName("crudViewMode");
    table.addStyleName("crudTable");

    Integer rowHeight = tableModel.getRowHeight();
    if (rowHeight != null) {
        table.addStyleName("rowheight" + rowHeight);
        String css = ".v-table-rowheight" + rowHeight + " .v-table-cell-content { height: " + rowHeight
                + "px; }";
        css += "div.crudTable td div.v-table-cell-wrapper { max-height: " + rowHeight + "px; }";
        Page.getCurrent().getStyles().add(css);
    }

    table.setPageLength(pageLength);
    table.setCacheRate(cacheRate);

    initializeTableFieldFactory();

    // since 1.45
    table.setHeight("100%");
    addComponent(table);
    setExpandRatio(table, 1);

    Layout buttonBar = initButtonBar();
    if (buttonBar.iterator().hasNext()) {
        addComponent(buttonBar);
    }

    renderTableHeader();

    updateColumnWidths();

    setColumnGenerator(table, rowHeight);

    updateVisibleColumns(false);

    initializeListener();

    setupErrorHandling();

    setTableStyleRenderer();

    presenter.doInitialize();

    if (tableModel.getMode() == Mode.EDIT) {
        switchToEditMode();
    }

    table.enableContentRefreshing(false);
}