Example usage for com.vaadin.ui Grid addColumn

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

Introduction

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

Prototype

public <V> Column<T, V> addColumn(ValueProvider<T, V> valueProvider) 

Source Link

Document

Adds a new text column to this Grid with a value provider.

Usage

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

public GestioneRazze() {

    setMargin(true);//www  .j  av a 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.scipionyx.butterflyeffect.frontend.configuration.ui.view.AboutView.java

License:Apache License

/**
 * //from w  w  w  .j a  va 2  s  . co m
 * @param instancesBackend
 * @param justclean
 */
private void loadClusterInformation(List<ServiceInstance> instancesBackend, GridLayout layout,
        boolean justclean) {

    layout.removeAllComponents();

    int i = 0;
    for (ServiceInstance instance : instancesBackend) {

        Grid<GridProperty<?>> tableCluster = new Grid<>("Node [" + i + "]");
        tableCluster.addStyleName(ValoTheme.TABLE_COMPACT);
        tableCluster.setSizeFull();

        tableCluster.addColumn(GridProperty::getName).setCaption("Property");
        tableCluster.addColumn(GridProperty::getValue).setCaption("Value");

        List<GridProperty<?>> list = new ArrayList<>();
        list.add(new GridProperty<>("Host", instance.getHost()));
        list.add(new GridProperty<>("Service Id", instance.getServiceId()));
        list.add(new GridProperty<>("Port", instance.getPort()));
        list.add(new GridProperty<>("Uri", instance.getUri()));

        for (String key : instance.getMetadata().keySet()) {
            list.add(new GridProperty<>("Metadata[" + key + "]", instance.getMetadata().get(key)));
        }

        tableCluster.setItems(list);

        layout.addComponent(tableCluster);

        i++;

    }

}

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

License:Apache License

private void init() {
    setSizeFull();/*from www. j a va 2  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();
    grid.addColumn("foo");
    grid.addRow("1");
    grid.addRow("2");
    grid.addRow("3");
    grid.addRow("4");
    ComponentGridDecorator componentGridDecorator = new ComponentGridDecorator<>(grid, null);
    addComponent(ViewComponents.createEnableDisableCheckBox(grid));

    grid.setSizeFull();

    // 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());

    componentGridDecorator.addComponentColumn("Just some", e -> new Label("some" + e));

    grid.setColumns("Just some");

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

From source file:dhbw.clippinggorilla.userinterface.views.AboutUsView.java

public AboutUsView() {
    setMargin(true);//from   w w  w.j  a va 2 s.c o  m
    setWidth("55%");

    Label aboutUsHeader = new Label();
    Language.set(Word.ABOUT_US, aboutUsHeader);
    aboutUsHeader.setStyleName(ValoTheme.LABEL_H1);
    addComponent(aboutUsHeader);

    Label aboutUsGroupHeadline = new Label();
    Language.set(Word.GROUP_PROJECT_OF_GROUP_4, aboutUsGroupHeadline);
    aboutUsGroupHeadline.setStyleName(ValoTheme.LABEL_H2);
    addComponent(aboutUsGroupHeadline);

    Label aboutUsText = new Label();
    Language.set(Word.GROUP_PROJECT_BODY, aboutUsText);
    aboutUsText.setWidth("100%");
    aboutUsText.setContentMode(com.vaadin.shared.ui.ContentMode.HTML);
    addComponent(aboutUsText);

    Label theTeamHeader = new Label();
    Language.set(Word.OUR_TEAM, theTeamHeader);
    theTeamHeader.setStyleName(ValoTheme.LABEL_H2);
    addComponent(theTeamHeader);

    Grid<Person> theTeamGrid = new Grid<>();
    List<Person> persons = Arrays.asList(new Person("Dan-Pierre", "Drehlich", Person.Function.TEAMLEADER),
            new Person("Stefan", "Schmid", Person.Function.RESPONSIBLE_FOR_RESEARCH),
            new Person("Jan", "Striegel", Person.Function.TECHNICAL_ASSISTANT),
            new Person("Lisa", "Hartung",
                    Person.Function.RESPONSIBLE_FOR_MODELING_QUALITY_ASSURANCE_AND_DOCUMENTATION),
            new Person("Tim", "Heinzelmann", Person.Function.RESPONSIBLE_FOR_TESTS),
            new Person("Josua", "Frank", Person.Function.RESPONSIBLE_FOR_IMPLEMENTATION));
    Grid.Column c1 = theTeamGrid.addColumn(p -> p.getFirstName());
    Language.setCustom(Word.FIRST_NAME, s -> c1.setCaption(s));
    Grid.Column c2 = theTeamGrid.addColumn(p -> p.getLastName());
    Language.setCustom(Word.LAST_NAME, s -> c2.setCaption(s));
    Grid.Column c3 = theTeamGrid.addColumn(p -> p.getResposibility());
    Language.setCustom(Word.RESPONSIBILITY, s -> {
        c3.setCaption(s);
        theTeamGrid.getDataProvider().refreshAll();
    });
    theTeamGrid.setItems(persons);
    theTeamGrid.setWidth("100%");
    theTeamGrid.setHeightByRows(6);
    addComponent(theTeamGrid);
    SESSIONS.put(VaadinSession.getCurrent(), this);
}

From source file:dhbw.clippinggorilla.userinterface.views.ArchiveView.java

public ArchiveView() {
    HorizontalLayout optionsLayout = new HorizontalLayout();
    optionsLayout.setWidth("100%");

    Grid<Clipping> gridClippings = new Grid<>();
    Set<Clipping> clippings = ClippingUtils.getUserClippings(UserUtils.getCurrent(),
            LocalDate.now(ZoneId.of("Europe/Berlin")));
    gridClippings.setItems(clippings);/*from  w  w w.  ja  v a2 s  .  com*/

    InlineDateTimeField datePicker = new InlineDateTimeField();
    datePicker.setValue(LocalDateTime.now(ZoneId.of("Europe/Berlin")));
    datePicker.setLocale(Locale.GERMANY);
    datePicker.setResolution(DateTimeResolution.DAY);
    datePicker.addValueChangeListener(date -> {
        Set<Clipping> clippingsOfDate = ClippingUtils.getUserClippings(UserUtils.getCurrent(),
                date.getValue().toLocalDate());
        gridClippings.setItems(clippingsOfDate);
        gridClippings.getDataProvider().refreshAll();
    });

    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM);
    formatter.withZone(ZoneId.of("Europe/Berlin"));
    Column columnTime = gridClippings.addColumn(c -> {
        return c.getDate().format(formatter);
    });
    Language.setCustom(Word.TIME, s -> columnTime.setCaption(s));
    Column columnAmountArticles = gridClippings.addColumn(c -> {
        long amountArticles = c.getArticles().values().stream().flatMap(l -> l.stream()).count();
        amountArticles += c.getArticlesFromGroup().values().stream().flatMap(l -> l.stream()).count();
        if (amountArticles != 1) {
            return amountArticles + " " + Language.get(Word.ARTICLES);
        } else {
            return amountArticles + " " + Language.get(Word.ARTICLE);
        }
    });
    Language.setCustom(Word.ARTICLES, s -> {
        columnAmountArticles.setCaption(s);
        gridClippings.getDataProvider().refreshAll();
    });

    gridClippings.setHeight("100%");
    gridClippings.setSelectionMode(Grid.SelectionMode.SINGLE);
    gridClippings.addSelectionListener(c -> {
        if (c.getFirstSelectedItem().isPresent()) {
            currentClipping = c.getFirstSelectedItem().get();
            showClippingBy(currentClipping, currentSort);
        }
    });

    optionsLayout.addComponents(datePicker, gridClippings);
    optionsLayout.setComponentAlignment(datePicker, Alignment.BOTTOM_CENTER);
    optionsLayout.setComponentAlignment(gridClippings, Alignment.BOTTOM_RIGHT);
    optionsLayout.setExpandRatio(gridClippings, 5);

    VerticalLayout sortLayout = new VerticalLayout();

    comboBoxSortOptions = new ComboBox<>(Language.get(Word.SORT_BY));
    Language.setCustom(Word.SORT_BY, s -> {
        comboBoxSortOptions.setCaption(s);
        comboBoxSortOptions.getDataProvider().refreshAll();
    });
    comboBoxSortOptions.setItems(EnumSet.allOf(ClippingView.SortOptions.class));
    comboBoxSortOptions.setItemCaptionGenerator(s -> s.getName());
    comboBoxSortOptions.setItemIconGenerator(s -> s.getIcon());
    comboBoxSortOptions.setValue(currentSort);
    comboBoxSortOptions.setTextInputAllowed(false);
    comboBoxSortOptions.setEmptySelectionAllowed(false);
    comboBoxSortOptions.addStyleName("comboboxsort");
    comboBoxSortOptions.addValueChangeListener(e -> {
        currentSort = e.getValue();
        showClippingBy(currentClipping, currentSort);
    });
    comboBoxSortOptions.setVisible(false);

    sortLayout.setMargin(false);
    sortLayout.setSpacing(false);
    sortLayout.addComponent(comboBoxSortOptions);

    clippingArticlesLayout = new VerticalLayout();
    clippingArticlesLayout.setSpacing(true);
    clippingArticlesLayout.setMargin(false);
    clippingArticlesLayout.setSizeFull();

    addComponents(optionsLayout, sortLayout, clippingArticlesLayout);
}

From source file:dhbw.clippinggorilla.userinterface.views.ImpressumView.java

public ImpressumView() {
    setMargin(true);//from www.  jav a  2 s  .c o  m
    setWidth("55%");

    Label impressumHeader = new Label();
    Language.set(Word.IMPRESSUM, impressumHeader);
    impressumHeader.setStyleName(ValoTheme.LABEL_H1);
    addComponent(impressumHeader);

    Label impressumText = new Label();
    Language.set(Word.IMPRESSUM_BODY, impressumText);
    impressumText.setWidth("100%");
    impressumText.setContentMode(com.vaadin.shared.ui.ContentMode.HTML);
    addComponent(impressumText);

    Grid<Person> studentsGrid = new Grid<>();
    List<Person> persons = Arrays.asList(new Person("Dan-Pierre", "Drehlich", Person.Function.TEAMLEADER),
            new Person("Stefan", "Schmid", Person.Function.RESPONSIBLE_FOR_RESEARCH),
            new Person("Jan", "Striegel", Person.Function.TECHNICAL_ASSISTANT),
            new Person("Lisa", "Hartung",
                    Person.Function.RESPONSIBLE_FOR_MODELING_QUALITY_ASSURANCE_AND_DOCUMENTATION),
            new Person("Tim", "Heinzelmann", Person.Function.RESPONSIBLE_FOR_TESTS),
            new Person("Josua", "Frank", Person.Function.RESPONSIBLE_FOR_IMPLEMENTATION));
    Column c1 = studentsGrid.addColumn(p -> p.getFirstName());
    Language.setCustom(Word.FIRST_NAME, s -> c1.setCaption(s));
    Column c2 = studentsGrid.addColumn(p -> p.getLastName());
    Language.setCustom(Word.LAST_NAME, s -> c2.setCaption(s));
    Column c3 = studentsGrid.addColumn(p -> p.getResposibility());
    Language.setCustom(Word.RESPONSIBILITY, s -> {
        c3.setCaption(s);
        studentsGrid.getDataProvider().refreshAll();
    });

    studentsGrid.setItems(persons);
    studentsGrid.setWidth("100%");
    studentsGrid.setHeightByRows(6);
    addComponent(studentsGrid);

    Label liabilityHeadline = new Label();
    Language.set(Word.LIABILITY, liabilityHeadline);
    liabilityHeadline.setStyleName(ValoTheme.LABEL_H1);
    addComponent(liabilityHeadline);

    Label liabilityContentHeadline = new Label();
    Language.set(Word.LIABILITY_CONTENT, liabilityContentHeadline);
    liabilityContentHeadline.setStyleName(ValoTheme.LABEL_H2);
    addComponent(liabilityContentHeadline);

    Label liabilityContentText = new Label();
    Language.set(Word.LIABILITY_CONTENT_BODY, liabilityContentText);
    liabilityContentText.setWidth("100%");
    addComponent(liabilityContentText);

    Label liabilityLinksHeadline = new Label();
    Language.set(Word.LIABILITY_LINKS, liabilityLinksHeadline);
    liabilityLinksHeadline.setStyleName(ValoTheme.LABEL_H2);
    addComponent(liabilityLinksHeadline);

    Label liabilityLinksText = new Label();
    Language.set(Word.LIABILITY_LINKS_BODY, liabilityLinksText);
    liabilityLinksText.setWidth("100%");
    addComponent(liabilityLinksText);

    Label copyrightHeadline = new Label();
    Language.set(Word.COPYRIGHT, copyrightHeadline);
    copyrightHeadline.setStyleName(ValoTheme.LABEL_H2);
    addComponent(copyrightHeadline);

    Label copyrightText = new Label();
    Language.set(Word.COPYRIGHT_BODY, copyrightText);
    copyrightText.setWidth("100%");
    addComponent(copyrightText);

    Label dataProtectionHeadline = new Label();
    Language.set(Word.DATAPROTECTION, dataProtectionHeadline);
    dataProtectionHeadline.setStyleName(ValoTheme.LABEL_H2);
    addComponent(dataProtectionHeadline);

    Label dataProtectionText = new Label();
    Language.set(Word.DATAPROTECTION_BODY, dataProtectionText);
    dataProtectionText.setWidth("100%");
    addComponent(dataProtectionText);
    SESSIONS.put(VaadinSession.getCurrent(), this);
}

From source file:fi.jasoft.dragdroplayouts.demo.DemoUI.java

License:Apache License

private Grid<DemoView> createViewSelection() {

    Grid<DemoView> select = new Grid<>();

    select.addColumn(view -> view.getCaption());
    select.setWidth("200px");
    select.setHeight("100%");
    select.addSelectionListener((change) -> {
        navigator.navigateTo(change.getFirstSelectedItem().get().getName());
    });//from w  w  w. ja va 2s .  co m

    select.setItems(views);
    return select;
}

From source file:org.jpos.qi.eeuser.ConsumersView.java

License:Open Source License

@Override
public void setGridGetters() {
    Grid<Consumer> g = getGrid();
    g.addColumn(Consumer::getId).setId("id");
    g.addColumn(consumer -> consumer.getRolesAsString()).setId("roles");
    g.addColumn(Consumer::getStartDate).setId("startDate");
    g.addColumn(Consumer::getEndDate).setId("endDate");
    g.addColumn(consumer -> consumer.getUser().getNickAndId()).setId("user");
    g.addColumn(Consumer::isActive).setId("active");
    g.addColumn(Consumer::isDeleted).setId("deleted");

    //select first item on user combobox
    userComboBox.setValue(userComboBox.getDataProvider().fetch(new Query<>()).findFirst().orElse(null));
}

From source file:org.jpos.qi.eeuser.RolesView.java

License:Open Source License

@Override
public void setGridGetters() {
    Grid<Role> g = this.getGrid();
    g.addColumn(Role::getId).setId("id");
    g.addColumn(Role::getName).setId("name");
    g.addColumn(Role::getPermissions).setId("permissions");
}

From source file:org.jpos.qi.eeuser.UsersView.java

License:Open Source License

@Override
public void setGridGetters() {
    Grid<User> g = getGrid();
    g.addColumn(User::getId).setId("id");
    g.addColumn(User::getName).setId("name");
    g.addColumn(User::getNick).setId("nick");
    g.addColumn(User::getEmail).setId("email");
    g.addColumn(User::isActive).setId("active");
    g.addColumn(User::isDeleted).setId("deleted");
    g.addColumn(User::isVerified).setId("verified");
    g.addColumn(User::getStartDate).setId("startDate");
    g.addColumn(User::getEndDate).setId("endDate");
    g.addColumn(User::isForcePasswordChange).setId("forcePasswordChange");
    g.addColumn(User::getLastLogin).setId("lastLogin");
    g.addColumn(User::getPasswordChanged).setId("passwordChanged");
    g.addColumn(User::getLoginAttempts).setId("loginAttempts");

}