Example usage for com.vaadin.ui Grid getColumn

List of usage examples for com.vaadin.ui Grid getColumn

Introduction

In this page you can find the example usage for com.vaadin.ui Grid getColumn.

Prototype

public Column<T, ?> getColumn(String columnId) 

Source Link

Document

Gets a Column of this grid by its identifying string.

Usage

From source file:annis.gui.admin.CorpusAdminPanel.java

License:Apache License

public CorpusAdminPanel() {
    corpusContainer.setBeanIdProperty("name");

    final Grid corporaGrid = new Grid(corpusContainer);
    corporaGrid.setSizeFull();/*from   www  . ja  va 2  s  .  co m*/
    corporaGrid.setSelectionMode(Grid.SelectionMode.MULTI);
    corporaGrid.setColumns("name", "textCount", "tokenCount", "sourcePath");

    corporaGrid.getColumn("textCount").setHeaderCaption("Texts");
    corporaGrid.getColumn("tokenCount").setHeaderCaption("Tokens");
    corporaGrid.getColumn("sourcePath").setHeaderCaption("Source Path");

    Button btDelete = new Button("Delete selected");
    btDelete.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Set<String> selection = new TreeSet<>();
            for (Object o : corporaGrid.getSelectedRows()) {
                selection.add((String) o);
            }
            corporaGrid.getSelectionModel().reset();
            if (!selection.isEmpty()) {

                for (CorpusListView.Listener l : listeners) {
                    l.deleteCorpora(selection);
                }
            }
        }
    });

    VerticalLayout layout = new VerticalLayout(btDelete, corporaGrid);
    layout.setSizeFull();
    layout.setExpandRatio(corporaGrid, 1.0f);
    layout.setSpacing(true);
    layout.setMargin(new MarginInfo(true, false, false, false));

    layout.setComponentAlignment(btDelete, Alignment.MIDDLE_CENTER);

    setContent(layout);
    setSizeFull();
}

From source file:ch.wscr.management.ui.view.MemberView.java

/**
 * Felder zum Bearbeiten der Daten im Grid anpassen
 *
 * @param grid das Grid fr die Mitgliederverwaltung
 *//*w ww  .  ja va  2  s.  c om*/
private void setEditorFields(final Grid grid) {
    grid.getColumn("driverLicense").getEditorField().setCaption("");
}

From source file:ch.wscr.management.ui.view.MemberView.java

/**
 * Die Spalten im Grid anpassen/*from  w ww .j  ava  2 s  .co  m*/
 *
 * @param grid das Grid fr die Mitgliederverwaltung
 */
private void setColumnHeaders(final Grid grid) {

    grid.setColumnOrder("memberId", "lastName", "firstName", "adrStreet", "adrPostalCode", "adrCity",
            "adrCountry", "birthDate", "driverLicense");

    grid.getColumn("memberId").setHeaderCaption("ID");
    grid.getColumn("firstName").setHeaderCaption("Vorname");
    grid.getColumn("lastName").setHeaderCaption("Nachname");
    grid.getColumn("adrStreet").setHeaderCaption("Strasse");
    grid.getColumn("adrPostalCode").setHeaderCaption("PLZ");
    grid.getColumn("adrCity").setHeaderCaption("Stadt");
    grid.getColumn("adrCountry").setHeaderCaption("Land");
    grid.getColumn("birthDate").setHeaderCaption("Geburtsdatum");
    grid.getColumn("driverLicense").setHeaderCaption("Bootsdriver");

    //        grid.setCellStyleGenerator(new Grid.CellStyleGenerator() {
    //            @Override
    //            public String getStyle(Grid.CellReference cellReference) {
    //                if (cellReference.getPropertyId().equals("memberId")) {
    //                    return GridUtil.ALIGN_CELL_RIGHT;
    //                }
    //                return null;
    //            }
    //        });
}

From source file:ch.wscr.management.ui.view.MemberView.java

/**
 * Die Darstellung der Daten im Grid mit Renderern anpassen
 *
 * @param grid das Grid fr die Mitgliederverwaltung
 *//*from ww w.  j  a va 2s  .  c o  m*/
private void setColumnRenderers(final Grid grid) {
    grid.getColumn("memberId").setRenderer(new EditDeleteButtonValueRenderer(
            new EditDeleteButtonValueRenderer.EditDeleteButtonClickListener() {
                @Override
                public void onEdit(ClickableRenderer.RendererClickEvent rendererClickEvent) {
                    grid.setEditorEnabled(true);
                    grid.editItem(rendererClickEvent.getItemId());
                }

                @Override
                public void onDelete(ClickableRenderer.RendererClickEvent rendererClickEvent) {

                }
            })).setWidth(120);

    grid.getColumn("driverLicense").setRenderer(new BooleanRenderer()).setWidth(120);
    grid.getColumn("birthDate").setRenderer(new DateRenderer(DateFormat.getDateInstance(DateFormat.SHORT)))
            .setWidth(120);
}

From source file:com.cerebro.cable.xforce.view.GestioneRazze.java

public GestioneRazze() {

    setMargin(true);// ww  w  . j ava 2  s.  c  om

    TableQuery racesTQ = new TableQuery("races", connPool);
    SQLContainer racesContainer = null;
    try {
        racesContainer = new SQLContainer(racesTQ);
    } catch (Exception ex) {
        logger.error("Errore nella tabella delle razze: " + ex.getMessage());
    }
    Grid racesTable = new Grid(racesContainer);
    racesTable.removeAllColumns();
    for (int i = 0; i < racesTabCols.length; i++) {
        racesTable.addColumn(racesTabCols[i][0]);
        Grid.Column col = racesTable.getColumn(racesTabCols[i][0]);
        col.setHeaderCaption(racesTabCols[i][1]);
    }
    racesTable.getColumn("image").setRenderer(new ImageRenderer(), new Converter<Resource, String>() {
        @Override
        public String convertToModel(Resource value, Class<? extends String> targetType, Locale locale)
                throws Converter.ConversionException {
            return "not needed";
        }

        @Override
        public Resource convertToPresentation(String value, Class<? extends Resource> targetType, Locale locale)
                throws Converter.ConversionException {
            return new FileResource(
                    new File(VaadinService.getCurrent().getBaseDirectory().getAbsolutePath() + value));
        }

        @Override
        public Class<String> getModelType() {
            return String.class;
        }

        @Override
        public Class<Resource> getPresentationType() {
            return Resource.class;
        }

    });

    FormLayout raceEditor = new FormLayout();

    addComponents(racesTable);
}

From source file:com.hack23.cia.web.impl.ui.application.views.common.gridfactory.impl.GridFactoryImpl.java

License:Apache License

/**
 * Creates the grid cell filter./*from   w w  w.  j  a  va  2 s .com*/
 *
 * @param columnOrder
 *            the column order
 * @param grid
 *            the grid
 */
private static void createGridCellFilter(final Object[] columnOrder, final Grid grid) {
    if (columnOrder != null) {
        final GridCellFilter gridCellFilter = new GridCellFilter(grid);

        for (final Object column : columnOrder) {
            if (grid.getColumn(column) != null) {
                gridCellFilter.setTextFilter(column.toString(), true, true);
            }
        }

    }
}

From source file:com.hack23.cia.web.impl.ui.application.views.common.gridfactory.impl.GridFactoryImpl.java

License:Apache License

/**
 * Sets the column converters./*from w ww .j a  va  2 s . c o  m*/
 *
 * @param collectionPropertyConverter
 *            the collection property converter
 * @param grid
 *            the grid
 */
private static void setColumnConverters(final ListPropertyConverter[] collectionPropertyConverter,
        final Grid grid) {
    if (collectionPropertyConverter != null) {
        for (final ListPropertyConverter converter : collectionPropertyConverter) {
            final Column column = grid.getColumn(converter.getColumn());
            column.setConverter(converter);
        }
    }
}

From source file:de.datenhahn.vaadin.componentrenderer.demo.ClassicGridTab.java

License:Apache License

private void init() {
    setSizeFull();//from  w ww  .j av  a2 s.com
    setMargin(true);
    setSpacing(true);

    addComponent(
            new Label("Look at the sourcecode to see the difference between the typed ComponentGrid and using"
                    + " the classic grid"));

    Grid grid = new Grid();
    ComponentCellKeyExtension.extend(grid);
    focusPreserveExtension = FocusPreserveExtension.extend(grid);
    DetailsKeysExtension.extend(grid);

    addComponent(ViewComponents.createEnableDisableCheckBox(grid));

    grid.setSizeFull();

    // Initialize Containers
    BeanItemContainer<Customer> bc = new BeanItemContainer<>(Customer.class);

    GeneratedPropertyContainer gpc = new GeneratedPropertyContainer(bc);
    grid.setContainerDataSource(gpc);

    // Load the data
    bc.addAll(CustomerProvider.createDummyData());

    // Initialize DetailsGenerator (Caution: the DetailsGenerator is set to null
    // when grid#setContainerDatasource is called, so make sure you call setDetailsGenerator
    // after setContainerDatasource
    grid.setDetailsGenerator(new CustomerDetailsGenerator());

    gpc.addGeneratedProperty(Customer.FOOD, new PropertyValueGenerator<Component>() {
        @Override
        public Component getValue(Item item, Object itemId, Object propertyId) {
            return ViewComponents.createClassicFoodSelector(grid, focusPreserveExtension, (Customer) itemId);
        }

        @Override
        public Class<Component> getType() {
            return Component.class;
        }

        // You must override getSortProperties to allow sorting by the values
        // underlying of the GeneratedValue. The default is that generated
        // property columns cannot be sorted (see PropertyValueGenerator default implementation)
        // if the generated column is not shadowing a real data column DO NOT overwrite this method
        // otherwise an exception is thrown when you sort it because the bean property cannot be found
        @Override
        public SortOrder[] getSortProperties(SortOrder order) {
            return new SortOrder[] { order };
        }
    });

    // Don't forget to set the ComponentRenderer AFTER adding the column
    grid.getColumn(Customer.FOOD).setRenderer(new ComponentRenderer());

    gpc.addGeneratedProperty(GENERATED_FOOD_ICON, new PropertyValueGenerator<Component>() {
        @Override
        public Component getValue(Item item, Object itemId, Object propertyId) {
            return ViewComponents.createFoodIcon((Customer) itemId);
        }

        @Override
        public Class<Component> getType() {
            return Component.class;
        }

        // You must override getSortProperties to allow sorting by the values
        // underlying of the GeneratedValue. The default is that generated
        // property columns cannot be sorted (see PropertyValueGenerator default implementation)
        // if the generated column is not shadowing a real data column DO NOT overwrite this method
        // otherwise an exception is thrown when you sort it because the bean property cannot be found
        @Override
        public SortOrder[] getSortProperties(SortOrder order) {
            return new SortOrder[] { order };
        }
    });

    // Don't forget to set the ComponentRenderer AFTER adding the column
    grid.getColumn(GENERATED_FOOD_ICON).setRenderer(new ComponentRenderer());

    gpc.addGeneratedProperty(GENERATED_RATING, new PropertyValueGenerator<Component>() {
        @Override
        public Component getValue(Item item, Object itemId, Object propertyId) {
            return ViewComponents.createRating((Customer) itemId);
        }

        @Override
        public Class<Component> getType() {
            return Component.class;
        }

    });

    // Don't forget to set the ComponentRenderer AFTER adding the column
    grid.getColumn(GENERATED_RATING).setRenderer(new ComponentRenderer());

    gpc.addGeneratedProperty(GENERATED_DELETE, new PropertyValueGenerator<Component>() {
        @Override
        public Component getValue(Item item, Object itemId, Object propertyId) {
            return ViewComponents.createClassicDeleteButton(grid, focusPreserveExtension, bc,
                    (Customer) itemId);
        }

        @Override
        public Class<Component> getType() {
            return Component.class;
        }

    });

    // Don't forget to set the ComponentRenderer AFTER adding the column
    grid.getColumn(GENERATED_DELETE).setRenderer(new ComponentRenderer());

    gpc.addGeneratedProperty(GENERATED_DETAILS_ICONS, new PropertyValueGenerator<Component>() {
        @Override
        public Component getValue(Item item, Object itemId, Object propertyId) {
            return ViewComponents.createDetailsIcons(grid, (Customer) itemId);
        }

        @Override
        public Class<Component> getType() {
            return Component.class;
        }

    });

    // Don't forget to set the ComponentRenderer AFTER adding the column
    grid.getColumn(GENERATED_DETAILS_ICONS).setRenderer(new ComponentRenderer());

    // always display the details column
    grid.setFrozenColumnCount(1);

    grid.setColumns(GENERATED_DETAILS_ICONS, Customer.ID, Customer.FIRST_NAME, Customer.LAST_NAME,
            Customer.FOOD, GENERATED_FOOD_ICON, GENERATED_RATING, GENERATED_DELETE);

    addComponent(grid);
    setExpandRatio(grid, 1.0f);
}

From source file:de.datenhahn.vaadin.componentrenderer.demo.ClassicGridWithStaticContainerTab.java

License:Apache License

private void init() {
    setSizeFull();/*from   w  w w  .j a va  2s.  c  om*/
    setMargin(true);
    setSpacing(true);

    addComponent(
            new Label("Look at the sourcecode to see the difference between the typed ComponentGrid and using"
                    + " the classic grid"));

    Grid grid = new Grid();
    ComponentCellKeyExtension.extend(grid);
    focusPreserveExtension = FocusPreserveExtension.extend(grid);
    DetailsKeysExtension.extend(grid);

    addComponent(ViewComponents.createEnableDisableCheckBox(grid));
    grid.setSelectionMode(Grid.SelectionMode.SINGLE);

    ((Grid.SingleSelectionModel) grid.getSelectionModel()).setDeselectAllowed(false);
    grid.setImmediate(true);

    grid.setSizeFull();

    // Initialize Containers
    BeanItemContainer<StaticCustomer> bc = new BeanItemContainer<>(StaticCustomer.class);

    grid.setContainerDataSource(bc);

    // Load the data
    bc.addAll(StaticCustomerProvider.createDummyData());

    // Initialize DetailsGenerator (Caution: the DetailsGenerator is set to null
    // when grid#setContainerDatasource is called, so make sure you call setDetailsGenerator
    // after setContainerDatasource
    grid.setDetailsGenerator(new StaticCustomerDetailsGenerator());

    // always display the details column
    grid.setFrozenColumnCount(1);

    grid.getColumn(Customer.FOOD).setRenderer(new ComponentRenderer());

    grid.setColumns(StaticCustomer.ID, StaticCustomer.FIRST_NAME, StaticCustomer.LAST_NAME,
            StaticCustomer.FOOD);

    addComponent(grid);
    setExpandRatio(grid, 1.0f);
}

From source file:de.kaiserpfalzEdv.vaadin.about.AboutViewImpl.java

License:Apache License

private void formatColumn(Grid grid, final String column, final String i18nBase, final int expandRatio) {
    grid.getColumn(column).setHeaderCaption(presenter.translate(i18nBase + "." + column + ".caption"));
    grid.getColumn(column).setExpandRatio(expandRatio);
}