Java 类com.vaadin.ui.components.grid.HeaderRow 实例源码

项目:Persephone    文件:TracePage.java   
private Grid<HeaderGridRow> formatHeaders(String title, Map<String, List<String>> headers) {
    Grid<HeaderGridRow> grid = new Grid<>(HeaderGridRow.class);

    grid.removeAllColumns();

    Column<HeaderGridRow, String> headerColumn = grid.addColumn(HeaderGridRow::getHeader)
            .setCaption("Header")
            .setExpandRatio(1);
    Column<HeaderGridRow, String> valuesColumn = grid.addColumn(HeaderGridRow::getValues)
            .setCaption("Values")
            .setDescriptionGenerator(HeaderGridRow::getValues)
            .setExpandRatio(1);

    grid.setItems(headers.entrySet().stream().map(HeaderGridRow::new));
    grid.sort(headerColumn);

    HeaderRow titleRow = grid.prependHeaderRow();
    titleRow.join(headerColumn, valuesColumn).setHtml(title);

    return grid;
}
项目:Persephone    文件:MetricsPage.java   
private Grid<MetricsGridRow> getAllMetricsGrid(Map<String, Number> metrics) {
    allMetricsRows = metrics.entrySet().stream()
                            .map(MetricsGridRow::new)
                            .collect(Collectors.toList());

    Grid<MetricsGridRow> grid = new Grid<>(MetricsGridRow.class);
    grid.removeAllColumns();
    Column<MetricsGridRow, String> nameColumn = grid.addColumn(MetricsGridRow::getName)
                                                            .setCaption("Name")
                                                            .setExpandRatio(1);
    grid.addColumn(MetricsGridRow::getValue).setCaption("Value");

    grid.setItems(allMetricsRows);
    grid.sort(nameColumn);
    grid.setSizeFull();
    grid.setRowHeight(40);

    TextField filterInput = new TextField();
    filterInput.setPlaceholder("filter by metric...");
    filterInput.addValueChangeListener(e -> updateMetrics(e.getValue()));
    filterInput.setValueChangeMode(ValueChangeMode.LAZY);
    filterInput.setSizeFull();

    // Header row
    HeaderRow filterRow = grid.addHeaderRowAt(grid.getHeaderRowCount());
    filterRow.getCell(nameColumn).setComponent(filterInput);

    return grid;
}
项目:Persephone    文件:ApplicationsPage.java   
private void initFilterRow(Column<Application, String> appColumn, Column<Application, String> envColumn, Column<Application, String> urlColumn) {
    TextField filterApp = new TextField();
    TextField filterEnv = new TextField();
    TextField filterUrl = new TextField();

    filterApp.setPlaceholder("filter by application...");
    filterApp.addValueChangeListener(e -> updateApplications(e.getValue(), filterEnv.getValue(), filterUrl.getValue()));
    filterApp.setValueChangeMode(ValueChangeMode.LAZY);
    filterApp.focus();
    filterApp.setSizeFull();

    filterEnv.setPlaceholder("filter by environment...");
    filterEnv.addValueChangeListener(e -> updateApplications(filterApp.getValue(), e.getValue(), filterUrl.getValue()));
    filterEnv.setValueChangeMode(ValueChangeMode.LAZY);
    filterEnv.setSizeFull();

    filterUrl.setPlaceholder("filter by URL...");
    filterUrl.addValueChangeListener(e -> updateApplications(filterApp.getValue(), filterEnv.getValue(), e.getValue()));
    filterUrl.setValueChangeMode(ValueChangeMode.LAZY);
    filterUrl.setSizeFull();

    // Header row
    HeaderRow filterRow = grid.addHeaderRowAt(grid.getHeaderRowCount());
    filterRow.getCell(appColumn).setComponent(filterApp);
    filterRow.getCell(envColumn).setComponent(filterEnv);
    filterRow.getCell(urlColumn).setComponent(filterUrl);
}
项目:vaadin-excel-exporter    文件:ExportToExcel.java   
@SuppressWarnings({ "rawtypes", "unchecked" })
private int addHeaderFooterRow(Sheet sheet, int rowNum,
        final ExportExcelComponentConfiguration<BEANTYPE> componentConfiguration,
        AbstractComponentHeaderFooterConfiguration headerFooterConfig) {
    int tmpRowNum = rowNum;

    Row myRow = sheet.createRow(tmpRowNum);

    int startMerge = -999;
    for (int columns = 0; columns < componentConfiguration.getVisibleProperties().length; columns++) {
        Cell myCell = myRow.createCell(columns, XSSFCell.CELL_TYPE_STRING);
        String columnId = componentConfiguration.getVisibleProperties()[columns];
        if (headerFooterConfig.getMergedCells() != null) {
            startMerge = addMergedCell( sheet, tmpRowNum, componentConfiguration, headerFooterConfig, startMerge,
                                        columns, myCell);
        } else if (headerFooterConfig.getRow() != null) {
            if (headerFooterConfig.getRow() instanceof HeaderRow) {
                ExcelStyleUtil.addGenericGridHeaderRow( ((HeaderRow) headerFooterConfig.getRow()).getCell(columnId),
                                                        myCell);
            } else if (headerFooterConfig.getRow() instanceof FooterRow) {
                ExcelStyleUtil.addGenericGridFooterRow( ((FooterRow) headerFooterConfig.getRow()).getCell(columnId),
                                                        myCell);
            }
        } else if (headerFooterConfig.getColumnKeys() != null) {
            myCell.setCellValue(headerFooterConfig.getColumnKeys()[columns]);
        }
        myCell.setCellStyle(componentConfiguration.getHeaderStyleFunction()
            .apply(this.workbook, columnId));
    }

    if (headerFooterConfig instanceof ComponentHeaderConfiguration
            && ((ComponentHeaderConfiguration) headerFooterConfig).isAutoFilter()) {
        sheet.setAutoFilter(new CellRangeAddress(tmpRowNum, tmpRowNum, 0,
                componentConfiguration.getVisibleProperties().length - 1));
    }

    tmpRowNum++;
    return tmpRowNum;
}
项目:Persephone    文件:PropertiesPage.java   
private void initGrid() {
    this.grid = new Grid<>(PropertyItem.class);

    this.grid.removeAllColumns();
    Column<PropertyItem, String> propertyColumn = this.grid.addColumn(PropertyItem::getKey)
                                                            .setCaption("Property")
                                                            .setExpandRatio(1);
    Column<PropertyItem, String> valueColumn = this.grid.addColumn(PropertyItem::getValue)
                                                            .setCaption("Value")
                                                            .setExpandRatio(1);
    Column<PropertyItem, String> originColumn = this.grid.addColumn(PropertyItem::getOrigin).setCaption("Origin");

    this.grid.sort(propertyColumn);
    this.grid.setSizeFull();
    this.grid.setRowHeight(40);

    // distinct origin
    List<String> origins = this.currentEnv.getProperties().stream()
                                                .map(PropertyItem::getOrigin)
                                                .distinct()
                                                .sorted(String::compareTo)
                                                .collect(Collectors.toList());

    // Filters
    TextField filterProperty = new TextField();
    TextField filterValue = new TextField();
    NativeSelect<String> filterOrigin = new NativeSelect<>(null, origins);

    filterProperty.setPlaceholder("filter by key...");
    filterProperty.addValueChangeListener(e -> updateProperties(e.getValue(), filterValue.getValue(), filterOrigin.getValue()));
    filterProperty.setValueChangeMode(ValueChangeMode.LAZY);
    filterProperty.focus();
    filterProperty.setSizeFull();

    filterValue.setPlaceholder("filter by value...");
    filterValue.addValueChangeListener(e -> updateProperties(filterProperty.getValue(), e.getValue(), filterOrigin.getValue()));
    filterValue.setValueChangeMode(ValueChangeMode.LAZY);
    filterValue.setSizeFull();

    filterOrigin.addValueChangeListener(e -> updateProperties(filterProperty.getValue(), filterValue.getValue(), e.getValue()));
    filterOrigin.setSizeFull();

    // Header row
    HeaderRow filterRow = grid.addHeaderRowAt(grid.getHeaderRowCount());
    filterRow.getCell(propertyColumn).setComponent(filterProperty);
    filterRow.getCell(valueColumn).setComponent(filterValue);
    filterRow.getCell(originColumn).setComponent(filterOrigin);
}
项目:Persephone    文件:LoggersPage.java   
@Override
public void enter(ViewChangeEvent event) {
    pageHelper.setErrorHandler(this);

    this.removeAllComponents();

    // Get application
    int appId = Integer.parseInt(event.getParameters());
    Application app = pageHelper.getApp(appId);

    // Get loggers config
    Optional<Loggers> loggers = getLoggers(app);

    if(loggers.isPresent()) {

        // Display loggers in a grid
        grid = new Grid<>(LoggerGridRow.class);

        grid.removeAllColumns();

        Column<LoggerGridRow, String> nameColumn = grid.addColumn(LoggerGridRow::getName)
                                                                .setCaption("Name")
                                                                .setExpandRatio(2);
        grid.addComponentColumn(logger -> {
            NativeSelect<String> levelsDropdown = new NativeSelect<>(null, loggers.get().getLevels());

            levelsDropdown.setEmptySelectionAllowed(false);
            levelsDropdown.setSelectedItem(logger.getLevel());

            // on selected level
            levelsDropdown.addValueChangeListener(value -> {

                // change logger level
                loggersService.changeLevel(app, logger.getName(), value.getValue());

                // refresh data in grid (several loggers might have been impacted)
                updateLoggers(app);

                Notification.show(
                        String.format("Logger %s level changed to %s", logger.getName(), value.getValue())
                        , Notification.Type.TRAY_NOTIFICATION);
            });

            return levelsDropdown;
        })  .setCaption("Level")
            .setExpandRatio(1);

        grid.setSizeFull();
        grid.setRowHeight(40);

        grid.setItems(loggersRows);
        grid.sort(nameColumn);

        // Filter grid by logger name
        filterInput = new TextField();
        filterInput.setPlaceholder("filter by logger name...");
        filterInput.addValueChangeListener(e -> filterLoggers(e.getValue()));
        filterInput.setValueChangeMode(ValueChangeMode.LAZY);
        filterInput.focus();
        filterInput.setSizeFull();

        // Header row
        HeaderRow filterRow = grid.addHeaderRowAt(grid.getHeaderRowCount());
        filterRow.getCell(nameColumn).setComponent(filterInput);

        this.addComponent(new PageHeader(app, "Loggers"));
        this.addComponent(new Label("Changing a level will update one/many logger(s) level(s)"));
        this.addComponent(grid);
    } else {
        this.addComponent(new PageHeader(app, "Loggers"));
        this.addComponent(new Label(String.format("Failed to call %s<br />This endpoint is available since Spring Boot 1.5", app.endpoints().loggers()), ContentMode.HTML));
    }
}
项目:holon-vaadin    文件:AbstractGridItemListingBuilder.java   
public HeaderRowWrapper(HeaderRow row, Function<P, String> converter) {
    super();
    this.row = row;
    this.converter = converter;
}
项目:dungeonstory-java    文件:WeaponTypeGrid.java   
public WeaponTypeGrid() {
    super();
    //        withProperties("name", "proficiencyType", "handleType", "usageType", "oneHandBaseDamage",
    //                "twoHandBaseDamage", "damageType", "isReach", "isFinesse", "isLoading");
    //        withColumnHeaders("Nom", "Maitrise", "Manipulation", "Usage", "1 main", "2 mains",
    //                "Type de dommage", "Allonge", "Finesse", "Load");
    //
    //        Grid.Column reach = getColumn("isReach");
    //        reach.setRenderer(new HtmlRenderer(),
    //                new StringToBooleanConverter(FontAwesome.CHECK_CIRCLE_O.getHtml(), FontAwesome.CIRCLE_O.getHtml()));
    //
    //        Grid.Column finesse = getColumn("isFinesse");
    //        finesse.setRenderer(new HtmlRenderer(),
    //                new StringToBooleanConverter(FontAwesome.CHECK_CIRCLE_O.getHtml(), FontAwesome.CIRCLE_O.getHtml()));
    //
    //        Grid.Column loading = getColumn("isLoading");
    //        loading.setRenderer(new HtmlRenderer(),
    //                new StringToBooleanConverter(FontAwesome.CHECK_CIRCLE_O.getHtml(), FontAwesome.CIRCLE_O.getHtml()));
    //
    //        Grid.HeaderRow groupingHeader = prependHeaderRow();
    //        Grid.HeaderCell namesCell = groupingHeader.join(groupingHeader.getCell("oneHandBaseDamage"),
    //                groupingHeader.getCell("twoHandBaseDamage"));
    //        namesCell.setText("Dommage");

    StringToBooleanConverter converter = new StringToBooleanConverter("", VaadinIcons.CHECK_CIRCLE_O.getHtml(),
            VaadinIcons.CIRCLE_THIN.getHtml());
    addColumn(WeaponType::getName).setCaption("Nom").setId("name");
    addColumn(WeaponType::getProficiencyType).setCaption("Maitrise").setId("proficiencyType");
    addColumn(WeaponType::getHandleType).setCaption("Manipulation").setId("handleType");
    addColumn(WeaponType::getUsageType).setCaption("Usage").setId("usage");
    addColumn(WeaponType::getOneHandBaseDamage).setCaption("1 main").setId("oneHandBaseDamage");
    addColumn(WeaponType::getTwoHandBaseDamage).setCaption("2 mains").setId("twoHandBaseDamage");
    addColumn(WeaponType::getDamageType).setCaption("Type de dommage").setId("damageType");
    addColumn(weaponType -> converter.convertToPresentation(weaponType.getIsReach(), new ValueContext()), new HtmlRenderer())
            .setCaption("Allonge");
    addColumn(weaponType -> converter.convertToPresentation(weaponType.getIsFinesse(), new ValueContext()), new HtmlRenderer())
            .setCaption("Finesse");
    addColumn(weaponType -> converter.convertToPresentation(weaponType.getIsLoading(), new ValueContext()), new HtmlRenderer())
            .setCaption("Recharge");

    HeaderRow groupingHeader = prependHeaderRow();
    HeaderCell namesCell = groupingHeader.join(groupingHeader.getCell("oneHandBaseDamage"), groupingHeader.getCell("twoHandBaseDamage"));
    namesCell.setText("Dommage");

}
项目:vaadin-excel-exporter    文件:DemoUI.java   
@Override
protected void init(final VaadinRequest request) {

    // Creating the Export Tool Bar
    MenuBar exportToolBar = createToolBar();

    final VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();

    // Adding the Export Tool Bar to the Layout
    layout.addComponent(exportToolBar);

    /*********
     * Adding Components to the Layout namely Tables, Grids and Tree Table
     *******/
    this.gridDefault = new Grid<>(DataModel.class);
    this.gridDefault.setDataProvider(new ListDataProvider<>(DataModelGenerator.generate(20)));
    this.gridDefault.setSizeFull();
    this.gridDefault.setColumns(this.visibleColumns);

    this.gridMergedCells = new Grid<>(DataModel.class);
    this.gridMergedCells.setDataProvider(new ListDataProvider<>(DataModelGenerator.generate(20)));
    this.gridMergedCells.setColumns(this.visibleColumns);
    this.gridMergedCells.setSizeFull();
    HeaderRow headerRow = this.gridMergedCells.addHeaderRowAt(0);
    HeaderCell joinHeaderColumns1 = headerRow.join("country", "productType");
    joinHeaderColumns1.setText("mergedCell");
    HeaderCell joinHeaderColumns2 = headerRow.join("cheapest", "contractor");
    joinHeaderColumns2.setText("mergedCell");
    FooterRow footerRow1 = this.gridMergedCells.addFooterRowAt(0);
    FooterCell joinFooterColumns1 = footerRow1.join("country", "productType");
    joinFooterColumns1.setText("mergedCell");
    FooterCell joinFooterColumns2 = footerRow1.join("cheapest", "contractor");
    joinFooterColumns2.setText("mergedCell");
    FooterRow footerRow2 = this.gridMergedCells.addFooterRowAt(0);
    for (int i = 0; i < this.visibleColumns.length; i++) {
        footerRow2.getCell(this.visibleColumns[i])
            .setText(this.columnHeaders[i]);
    }

    this.gridFrozenColumns = new Grid<>(DataModel.class);
    this.gridFrozenColumns.setDataProvider(new ListDataProvider<>(DataModelGenerator.generate(20)));
    this.gridFrozenColumns.setColumns(this.visibleColumns);
    this.gridFrozenColumns.getColumn("country")
        .setWidth(300);
    this.gridFrozenColumns.getColumn("productType")
        .setWidth(300);
    this.gridFrozenColumns.getColumn("catalogue")
        .setWidth(300);
    this.gridFrozenColumns.setSizeFull();
    this.gridFrozenColumns.setFrozenColumnCount(3);

    TabSheet tabSheet = new TabSheet();
    tabSheet.setSizeFull();
    tabSheet.addTab(this.gridDefault, "Grid (Default)");
    tabSheet.addTab(this.gridMergedCells, "Grid (Merged Cells)");
    tabSheet.addTab(this.gridFrozenColumns, "Grid (Frozen Columns&Rows)");
    layout.addComponent(tabSheet);
    layout.setExpandRatio(tabSheet, 1);

    /*********
     * Adding Components to the Layout namely Tables, Grids and Tree Table
     *******/

    /*********
     * Adding the above data to the containers or components
     *******/

    setContent(layout);
}
项目:GridExtensionPack    文件:HeaderWrapExtensionLayout.java   
public HeaderWrapExtensionLayout() {

        setMargin(true);

        final SelectGrid<RowData> grid = new SelectGrid<>();
        final WrappingGrid wrap = WrappingGrid.extend(grid);

        TableSelectionModel<RowData> selectionModel = new TableSelectionModel<>();
        selectionModel.setMode(TableSelectionMode.SHIFT);
        grid.setSelectionModel(selectionModel);

        generateData(grid, 5, 100);

        HeaderRow headerRow = grid.prependHeaderRow();
        headerRow.join(grid.getColumns().get(1), grid.getColumns().get(2));

        HeaderRow headerRow1 = grid.appendHeaderRow();
        headerRow1.join(grid.getColumns().get(2), grid.getColumns().get(3));

        grid.setWidth("100%");
        grid.setHeight("100%");

        final Button button = new Button(BUTTON_WRAPPING_DISABLED_TEXT);
        button.addClickListener(new Button.ClickListener() {
            int state = 0;

            public void buttonClick(ClickEvent event) {
                state = (state + 1) % 2;
                switch (state) {
                case 0:
                    // Disable wrapping, attempt to restore original behavior
                    wrap.setWrapping(false);
                    button.setCaption(BUTTON_WRAPPING_DISABLED_TEXT);
                    break;
                case 1:
                    // Apply wrapping rules
                    wrap.setWrapping(true);
                    button.setCaption(BUTTON_WRAPPING_ENABLED_TEXT);
                    break;
                }
            }
        });

        addComponent(button);
        addComponent(grid);

        CacheStrategyExtension.extend(grid, 5, 0.2d);

    }
项目:vaadin-fluent-api    文件:FluentGrid.java   
/**
 * Sets the default row of the header. The default row is a special header
 * row that displays column captions and sort indicators. By default Grid
 * has a single row which is also the default row. When a header row is set
 * as the default row, any existing cell content is replaced by the column
 * captions.
 *
 * @param row
 *            the new default row, or null for no default row
 * @return this for method chaining
 * @see Grid#setDefaultHeaderRow(HeaderRow)
 *
 * @throws IllegalArgumentException
 *             if the header does not contain the row
 */
@SuppressWarnings("unchecked")
public default THIS withDefaultHeaderRow(HeaderRow row) {
    ((Grid<ITEM>) this).setDefaultHeaderRow(row);
    return (THIS) this;
}
项目:vaadin-grid-util    文件:GridCellFilter.java   
/**
 * generated HeaderRow
 *
 * @return added HeaderRow during intialization
 */
public HeaderRow getFilterRow() {
    return filterHeaderRow;
}