Example usage for com.vaadin.ui Grid Grid

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

Introduction

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

Prototype

public Grid(DataProvider<T, ?> dataProvider) 

Source Link

Document

Creates a new Grid using the given DataProvider .

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   w  w w .  j av  a  2 s . com
    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:annis.gui.admin.UserManagementPanel.java

License:Apache License

public UserManagementPanel() {

    userContainer = new BeanContainer<>(User.class);
    userContainer.setBeanIdProperty("name");

    progress = new ProgressBar();
    progress.setCaption("Loading user list");
    progress.setIndeterminate(true);//w w  w  .  j  av  a  2  s  . c om
    progress.setVisible(false);

    GeneratedPropertyContainer generated = new GeneratedPropertyContainer(userContainer);
    generated.addGeneratedProperty("edit", new PropertyValueGenerator<String>() {

        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            return "Edit";
        }

        @Override
        public Class<String> getType() {
            return String.class;
        }
    });
    generated.addGeneratedProperty("changePassword", new PropertyValueGenerator<String>() {

        @Override
        public String getValue(Item item, Object itemId, Object propertyId) {
            return "Change password";
        }

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

    userList = new Grid(generated);
    userList.setSizeFull();
    userList.setSelectionMode(Grid.SelectionMode.MULTI);
    userList.setColumns("name", "edit", "changePassword", "expires", "groups", "permissions");

    HeaderRow filterRow = userList.appendHeaderRow();
    TextField userFilterField = new TextField();
    userFilterField.setInputPrompt("Filter");
    userFilterField.addTextChangeListener(new FieldEvents.TextChangeListener() {

        @Override
        public void textChange(FieldEvents.TextChangeEvent event) {
            userContainer.removeContainerFilters("name");
            if (!event.getText().isEmpty()) {
                userContainer.addContainerFilter(new SimpleStringFilter("name", event.getText(), true, false));
            }
        }
    });
    filterRow.getCell("name").setComponent(userFilterField);

    CheckBox expiredFilterField = new CheckBox("has expired");
    expiredFilterField.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            userContainer.removeContainerFilters("expires");
            if ((Boolean) event.getProperty().getValue() == true) {
                userContainer.addContainerFilter(new ExpiredUserFilter("expires"));
            }
        }
    });
    filterRow.getCell("expires").setComponent(expiredFilterField);

    TextField groupFilterField = new TextField();
    groupFilterField.setInputPrompt("Filter by groups");
    groupFilterField.addTextChangeListener(new FieldEvents.TextChangeListener() {

        @Override
        public void textChange(FieldEvents.TextChangeEvent event) {
            userContainer.removeContainerFilters("groups");
            if (!event.getText().isEmpty()) {
                userContainer.addContainerFilter(
                        new GroupManagementPanel.StringPatternInSetFilter("groups", event.getText()));
            }
        }
    });
    filterRow.getCell("groups").setComponent(groupFilterField);

    Grid.Column editColum = userList.getColumn("edit");
    editColum.setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() {

        @Override
        public void click(ClickableRenderer.RendererClickEvent event) {

            User u = userContainer.getItem(event.getItemId()).getBean();

            FieldGroup group = new FieldGroup(userContainer.getItem(event.getItemId()));
            group.addCommitHandler(new UserCommitHandler(u.getName()));

            EditSingleUser edit = new EditSingleUser(group, groupsContainer, permissionsContainer);

            Window w = new Window("Edit user \"" + u.getName() + "\"");
            w.setContent(edit);
            w.setModal(true);
            w.setWidth("500px");
            w.setHeight("400px");
            UI.getCurrent().addWindow(w);
        }
    }));
    editColum.setHeaderCaption("");
    editColum.setExpandRatio(0);

    Grid.Column passwordColumn = userList.getColumn("changePassword");
    passwordColumn.setRenderer(new ButtonRenderer(new ClickableRenderer.RendererClickListener() {

        @Override
        public void click(ClickableRenderer.RendererClickEvent event) {
            UserManagementPanel.this.askForPasswordChange((String) event.getItemId());
        }
    }));
    passwordColumn.setHeaderCaption("");
    passwordColumn.setExpandRatio(0);

    userList.getColumn("name").setHeaderCaption("Username");

    Grid.Column groupsColumm = userList.getColumn("groups");
    groupsColumm.setHeaderCaption("Groups");
    groupsColumm.setConverter(new CommaSeperatedStringConverterSet());
    groupsColumm.setExpandRatio(1);

    Grid.Column permissionsColumn = userList.getColumn("permissions");
    permissionsColumn.setHeaderCaption("Additional permissions");
    permissionsColumn.setConverter(new CommaSeperatedStringConverterSet());

    Grid.Column expiresColumn = userList.getColumn("expires");
    expiresColumn.setHeaderCaption("Expiration Date");
    expiresColumn.setConverter(new DateTimeStringConverter());

    txtUserName = new TextField();
    txtUserName.setInputPrompt("New user name");

    Button btAddNewUser = new Button("Add new user");
    btAddNewUser.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            handleAdd();
        }
    });
    btAddNewUser.addStyleName(ChameleonTheme.BUTTON_DEFAULT);

    Button btDeleteUser = new Button("Delete selected user(s)");
    btDeleteUser.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            // get selected users
            Set<String> selectedUsers = new TreeSet<>();
            for (Object id : userList.getSelectedRows()) {
                selectedUsers.add((String) id);
            }
            userList.getSelectionModel().reset();
            for (UserListView.Listener l : listeners) {
                l.deleteUsers(selectedUsers);
            }
        }
    });

    actionLayout = new HorizontalLayout(txtUserName, btAddNewUser, btDeleteUser);

    layout = new VerticalLayout(actionLayout, progress, userList);
    layout.setSizeFull();
    layout.setExpandRatio(userList, 1.0f);
    layout.setExpandRatio(progress, 1.0f);
    layout.setSpacing(true);
    layout.setMargin(new MarginInfo(true, false, false, false));

    layout.setComponentAlignment(actionLayout, Alignment.MIDDLE_CENTER);
    layout.setComponentAlignment(progress, Alignment.TOP_CENTER);

    setContent(layout);
    setSizeFull();

    addActionHandler(new AddUserHandler(txtUserName));

}

From source file:annis.gui.ShareSingleMatchGenerator.java

License:Apache License

public ShareSingleMatchGenerator(List<ResolverEntry> visualizers, Match match, PagedResultQuery query,
        String segmentation, PluginSystem ps) {
    this.match = match;
    this.query = query;
    this.segmentation = segmentation;
    this.ps = ps;

    setResizeLazy(true);/*from   ww w  . ja  v  a  2 s .c o m*/

    directURL = new ObjectProperty<>("");
    iframeCode = new ObjectProperty<>("");

    visContainer = new BeanItemContainer<>(ResolverEntry.class);
    visContainer.addAll(visualizers);

    txtDirectURL = new TextArea(directURL);
    txtDirectURL.setCaption("Link for publications");
    txtDirectURL.setWidth("100%");
    txtDirectURL.setHeight("-1px");
    txtDirectURL.addStyleName(ValoTheme.TEXTFIELD_LARGE);
    txtDirectURL.addStyleName("shared-text");
    txtDirectURL.setWordwrap(true);
    txtDirectURL.setReadOnly(true);

    txtIFrameCode = new TextArea(iframeCode);
    txtIFrameCode.setCaption("Code for embedding visualization into web page");
    txtIFrameCode.setWidth("100%");
    txtIFrameCode.setHeight("-1px");
    txtIFrameCode.addStyleName(ValoTheme.TEXTFIELD_LARGE);
    txtIFrameCode.addStyleName("shared-text");
    txtIFrameCode.setWordwrap(true);
    txtIFrameCode.setReadOnly(true);

    preview = new BrowserFrame();
    preview.setCaption("Preview");
    preview.addStyleName("shared-text");
    preview.setSizeFull();

    generatedLinks = new VerticalLayout(txtDirectURL, txtIFrameCode, preview);
    generatedLinks.setComponentAlignment(txtDirectURL, Alignment.TOP_LEFT);
    generatedLinks.setComponentAlignment(txtIFrameCode, Alignment.TOP_LEFT);
    generatedLinks.setExpandRatio(preview, 1.0f);

    visSelector = new Grid(visContainer);
    visSelector.setCaption("Select visualization");
    visSelector.setHeight("100%");
    visSelector.setColumns("displayName");
    visSelector.setSelectionMode(Grid.SelectionMode.SINGLE);
    visSelector.addSelectionListener(ShareSingleMatchGenerator.this);
    visSelector.select(visContainer.getIdByIndex(0));
    visSelector.setWidth("300px");
    visSelector.getColumn("displayName").setSortable(false);

    generatedLinks.setSizeFull();

    Label infoText = new Label(
            "<p style=\"font-size: 18px\" >" + "<strong>Share your match:</strong>&nbsp;"
                    + "1.&nbsp;Choose the visualization to share. 2.&nbsp;Copy the generated link or code. "
                    + "3.&nbsp;Share this link with your peers or include the code in your website. " + "</p>",
            ContentMode.HTML);

    HorizontalLayout hLayout = new HorizontalLayout(visSelector, generatedLinks);
    hLayout.setSizeFull();
    hLayout.setSpacing(true);
    hLayout.setExpandRatio(generatedLinks, 1.0f);

    Button btClose = new Button("Close");
    btClose.setSizeUndefined();
    btClose.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            getUI().removeWindow(ShareSingleMatchGenerator.this);
        }
    });

    layout = new VerticalLayout(infoText, hLayout, btClose);
    layout.setSizeFull();
    layout.setExpandRatio(hLayout, 1.0f);
    layout.setComponentAlignment(btClose, Alignment.MIDDLE_CENTER);

    setContent(layout);
}

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

public GestioneRazze() {

    setMargin(true);/* ww w.j a  v  a  2s.  c o m*/

    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.cxplonka.feature.ui.vaadin.DataTableView.java

public DataTableView() {
    this.grid = new Grid(Customer.class);
}

From source file:com.github.carljmosca.ui.EventsView.java

@PostConstruct
private void init() {
    sdf = new SimpleDateFormat("MM/dd/yy HH:mm");
    setCaption("Events");
    grid = new Grid<>(Events.class);
    grid.addColumn(p -> p.getName() + ": " + sdf.format(p.getStartTime()) + " " + p.getCause())
            .setCaption("Name/Start").setId("nameAndStart");
    grid.setColumns("nameAndStart");
    grid.setHeightMode(HeightMode.ROW);//from w w  w.j a  v  a 2  s . c om
    grid.setHeightByRows(10.0d);
    grid.setSelectionMode(Grid.SelectionMode.SINGLE);
    grid.addSelectionListener((SelectionEvent<Events> event) -> {
        DemoUI demoUI = (DemoUI) UI.getCurrent();
        demoUI.setEventId(grid.getSelectedItems().stream().findFirst().get().getEventsPK().getId());
        getNavigationManager().navigateTo(framesView);
    });
    grid.setSizeUndefined();
    VerticalLayout gridLayout = new VerticalLayout(grid);
    gridLayout.setSizeFull();
    SimpleDateFormat dtf = new SimpleDateFormat("yy-MM-dd hh:mm");
    setContent(gridLayout);
}

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

License:Apache License

@Override
public void createBasicBeanItemNestedPropertiesGrid(final AbstractOrderedLayout panelContent,
        final Indexed datasource, final String caption, final String[] nestedProperties,
        final Object[] columnOrder, final Object[] hideColumns,
        final AbstractPageItemRendererClickListener<?> listener, final String actionId,
        final ListPropertyConverter[] collectionPropertyConverters) {
    final Grid grid = new Grid(datasource);

    grid.setCaption(caption);/*from  w  w w  . ja  v  a2s  .com*/
    grid.setSelectionMode(SelectionMode.SINGLE);

    createNestedProperties(datasource, nestedProperties);

    configureColumnOrdersAndHiddenFields(columnOrder, hideColumns, grid);

    configureListeners(listener, grid);

    setColumnConverters(collectionPropertyConverters, grid);

    grid.setSizeFull();

    grid.setStyleName("Level2Header");

    grid.setImmediate(true);
    grid.setReadOnly(true);

    createGridCellFilter(columnOrder, grid);

    panelContent.addComponent(grid);
    panelContent.setExpandRatio(grid, ContentRatio.GRID);
}

From source file:com.mycompany.controller.cartGrid.java

public Grid getCartGrid() {

    grid = new Grid("Kosr"); //nv
    grid.setSelectionMode(Grid.SelectionMode.MULTI); //tbb cella kijellse
    grid.setStyleName("cart"); //stlus
    grid.addColumn("Nap", String.class); //oszloptpusok
    grid.addColumn("tel", String.class);
    grid.addColumn("?r", Integer.class);
    grid.addColumn("Mennyisg", Integer.class);
    grid.getColumn("Nap").setSortable(false); //rendezs tilts

    grid.setWidth(100, Unit.PERCENTAGE); //mretezs
    grid.setHeight("645px");
    return grid;//from w  w  w. j a v a2s .  c  o  m

}

From source file:com.rex.components.valo.Tables.java

License:Apache License

public Tables() {
    setMargin(true);//ww w  . j  a va2 s  . co  m
    setSpacing(true);

    Label h1 = new Label("Tables & Grids");
    h1.addStyleName("h1");
    addComponent(h1);

    Label disclaimer = new Label(
            "<p>Note that most of the toggles only affect the Table component. The Grid component supports footers, expand ratios, row indexes/captions/icons and cell renderers, but those have not been implemented here.</p>",
            ContentMode.HTML);
    disclaimer.setCaption("Toggle features/styles");
    addComponent(disclaimer);
    disclaimer.addStyleName(ValoTheme.LABEL_SMALL);

    HorizontalLayout wrap = new HorizontalLayout();
    wrap.addStyleName("wrapping");
    wrap.setSpacing(true);
    addComponent(wrap);

    wrap.addComponents(hierarchical, footer, sized, expandRatios, stripes, verticalLines, horizontalLines,
            borderless, headers, compact, small, rowIndex, rowCaption, rowIcon, componentsInCells);

    ValueChangeListener update = new ValueChangeListener() {
        @Override
        public void valueChange(ValueChangeEvent event) {
            if (table == null) {
                table = new Table("Table component");
                table.setContainerDataSource(normalContainer);
                addComponent(table);
            }
            if (grid == null) {
                grid = new Grid("Grid component");
                grid.setContainerDataSource(gridContainer);
                addComponent(grid);
            }
            if (hierarchical.getValue() && table instanceof Table) {
                removeComponent(table);
                table = new TreeTable();
                table.setContainerDataSource(hierarchicalContainer);
                addComponent(table);
                removeComponent(grid);
            } else if (!hierarchical.getValue() && table instanceof TreeTable) {
                removeComponent(table);
                table = new Table();
                table.setContainerDataSource(normalContainer);
                addComponent(table);
                addComponent(grid);
            }

            configure(table, grid, footer.getValue(), sized.getValue(), expandRatios.getValue(),
                    stripes.getValue(), verticalLines.getValue(), horizontalLines.getValue(),
                    borderless.getValue(), headers.getValue(), compact.getValue(), small.getValue(),
                    rowIndex.getValue(), rowCaption.getValue(), rowIcon.getValue(),
                    componentsInCells.getValue());
        }
    };

    hierarchical.addValueChangeListener(update);
    footer.addValueChangeListener(update);
    sized.addValueChangeListener(update);
    expandRatios.addValueChangeListener(update);
    stripes.addValueChangeListener(update);
    verticalLines.addValueChangeListener(update);
    horizontalLines.addValueChangeListener(update);
    borderless.addValueChangeListener(update);
    headers.addValueChangeListener(update);
    compact.addValueChangeListener(update);
    small.addValueChangeListener(update);
    rowIndex.addValueChangeListener(update);
    rowCaption.addValueChangeListener(update);
    rowIcon.addValueChangeListener(update);
    componentsInCells.addValueChangeListener(update);

    footer.setValue(false);

}

From source file:com.scipionyx.butterflyeffect.frontend.configuration.ui.view.AboutView.java

License:Apache License

/**
 * //from w ww.  j  a v a 2  s.c  om
 */
@Override
public void doBuildWorkArea(VerticalLayout workAreaPanel) throws Exception {

    //
    tableFrontEndInformation = new Grid<>("Frontend Information");
    tableFrontEndInformation.addColumn(GridProperty::getName).setCaption("Property");
    tableFrontEndInformation.addColumn(GridProperty::getValue).setCaption("Value");
    tableFrontEndInformation.addColumn(GridProperty::getDescription).setCaption("Description");

    workAreaPanel.addComponent(tableFrontEndInformation);

    //
    backendLayout = createClusterInformation("Backend", workAreaPanel);
    frontendLayout = createClusterInformation("Frontend", workAreaPanel);

    addButton(ValoTheme.BUTTON_FRIENDLY, new Button("Refresh", event -> doEnter(null)));

}