Search in sources :

Example 1 with Grid

use of com.vaadin.ui.Grid in project GridFastNavigation by TatuLund.

the class DemoUI method init.

@Override
protected void init(VaadinRequest vaadinRequest) {
    final VerticalLayout layout = new VerticalLayout();
    initMessageTable();
    final Grid grid = new Grid();
    initGrid(grid);
    initNavigation(grid);
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.addComponent(grid);
    layout.addComponent(messageTable);
    layout.setSizeFull();
    setContent(layout);
}
Also used : Grid(com.vaadin.ui.Grid) VerticalLayout(com.vaadin.ui.VerticalLayout)

Example 2 with Grid

use of com.vaadin.ui.Grid in project VaadinUtils by rlsutton1.

the class ReportParameterTable method init.

protected void init(final String caption, final Class<T> tableClass, final SingularAttribute<T, String> displayField) {
    JpaBaseDao.getGenericDao(tableClass).flushCache();
    container = createContainer(tableClass, displayField);
    UI ui = UI.getCurrent();
    if (ui != null) {
        Runnable runner = new Runnable() {

            @Override
            public void run() {
                try (AutoCloseable closer = EntityManagerProvider.setThreadLocalEntityManagerTryWithResources()) {
                    ReportParameterTable.this.displayField = displayField;
                    layout.setSizeFull();
                    ReportParameterTable.this.caption = caption;
                    TextField searchText = new TextField();
                    searchText.setInputPrompt("Search");
                    searchText.setWidth("100%");
                    searchText.setImmediate(true);
                    searchText.setHeight("20");
                    searchText.addTextChangeListener(new TextChangeListener() {

                        private static final long serialVersionUID = 1315710313315289836L;

                        @Override
                        public void textChange(TextChangeEvent event) {
                            String value = event.getText();
                            removeAllContainerFilters();
                            if (value.length() > 0) {
                                container.addContainerFilter(new SimpleStringFilter(displayField.getName(), value, true, false));
                            }
                        }
                    });
                    grid = new Grid();
                    grid.setImmediate(true);
                    grid.setSizeFull();
                    // table.setHeight("150");
                    grid.setContainerDataSource(container);
                    // build lower case id's map, so we get the case of the
                    // id right
                    Map<String, String> idCaseMap = new HashMap<>();
                    for (Object id : container.getSortableContainerPropertyIds()) {
                        idCaseMap.put(((String) id).toLowerCase(), (String) id);
                    }
                    new GridHeadingPropertySet.Builder<T>().createColumn(caption, idCaseMap.get(displayField.getName().toLowerCase())).setLockedState(true).build().applyToGrid(grid);
                    if (idCaseMap.containsKey(displayField.getName().toLowerCase())) {
                        List<SortOrder> orders = new LinkedList<>();
                        orders.add(new SortOrder(idCaseMap.get(displayField.getName().toLowerCase()), SortDirection.ASCENDING));
                        grid.setSortOrder(orders);
                    }
                    final Label selectionCount = new Label("0 selected");
                    // removed for concertina
                    // layout.addComponent(new Label(caption));
                    layout.addComponent(searchText);
                    layout.addComponent(grid);
                    HorizontalLayout selectionLayout = new HorizontalLayout();
                    selectionLayout.setHeight("30");
                    selectionLayout.setWidth("100%");
                    selectionLayout.addComponent(selectionCount);
                    selectionLayout.setComponentAlignment(selectionCount, Alignment.MIDDLE_RIGHT);
                    layout.addComponent(selectionLayout);
                    grid.addSelectionListener(new SelectionListener() {

                        /**
                         */
                        private static final long serialVersionUID = 1L;

                        @Override
                        public void select(SelectionEvent event) {
                            validate();
                            selectionCount.setValue("" + event.getSelected().size() + " selected");
                        }
                    });
                    layout.setExpandRatio(grid, 1);
                    // layout.setComponentAlignment(selectAll,
                    // Alignment.BOTTOM_RIGHT);
                    loadContainerItems(container, tableClass);
                } catch (Exception e) {
                    ErrorWindow.showErrorWindow(e);
                }
            }
        };
        UI.getCurrent().accessSynchronously(runner);
    } else {
        logger.warn("No vaadin session available, not setting up UI");
    }
}
Also used : HashMap(java.util.HashMap) Grid(com.vaadin.ui.Grid) Label(com.vaadin.ui.Label) SortOrder(com.vaadin.data.sort.SortOrder) LinkedList(java.util.LinkedList) HorizontalLayout(com.vaadin.ui.HorizontalLayout) UI(com.vaadin.ui.UI) TextChangeEvent(com.vaadin.event.FieldEvents.TextChangeEvent) SelectionEvent(com.vaadin.event.SelectionEvent) TextField(com.vaadin.ui.TextField) TextChangeListener(com.vaadin.event.FieldEvents.TextChangeListener) SimpleStringFilter(com.vaadin.data.util.filter.SimpleStringFilter) SelectionListener(com.vaadin.event.SelectionEvent.SelectionListener)

Example 3 with Grid

use of com.vaadin.ui.Grid in project v-leaflet by mstahv.

the class MapInGridDetailsRow method getTestComponent.

@Override
public Component getTestComponent() {
    VerticalLayout vl = new VerticalLayout();
    vl.setSizeFull();
    final Grid<String> grid = new Grid<>();
    grid.setSizeFull();
    // Define some columns
    grid.addColumn(r -> r).setCaption("Name");
    grid.addColumn(r -> "").setCaption("Born");
    // Add some data rows
    grid.setItems("Nicolaus Copernicus", "Galileo Galilei", "Johannes Kepler");
    grid.setDetailsGenerator((DetailsGenerator<String>) s -> {
        final LMap leafletMap = new LMap();
        final LTileLayer baselayer = new LTileLayer();
        baselayer.setAttributionString("OpenStreetMap");
        baselayer.setUrl("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png");
        leafletMap.addLayer(baselayer);
        leafletMap.setWidth("100%");
        leafletMap.setHeight("100px");
        leafletMap.setZoomLevel(3);
        LMarker leafletMarker = new LMarker(-21.54, 30.76);
        leafletMap.addComponent(leafletMarker);
        leafletMap.zoomToContent();
        return leafletMap;
    });
    grid.addItemClickListener((ItemClickListener<String>) event -> grid.setDetailsVisible(event.getItem(), !grid.isDetailsVisible(event.getItem())));
    vl.addComponent(grid);
    return vl;
}
Also used : VerticalLayout(com.vaadin.ui.VerticalLayout) LMarker(org.vaadin.addon.leaflet.LMarker) LMap(org.vaadin.addon.leaflet.LMap) LTileLayer(org.vaadin.addon.leaflet.LTileLayer) AbstractTest(org.vaadin.addonhelpers.AbstractTest) DetailsGenerator(com.vaadin.ui.components.grid.DetailsGenerator) Component(com.vaadin.ui.Component) Grid(com.vaadin.ui.Grid) ItemClickListener(com.vaadin.ui.components.grid.ItemClickListener) LMap(org.vaadin.addon.leaflet.LMap) LTileLayer(org.vaadin.addon.leaflet.LTileLayer) Grid(com.vaadin.ui.Grid) VerticalLayout(com.vaadin.ui.VerticalLayout) LMarker(org.vaadin.addon.leaflet.LMarker)

Example 4 with Grid

use of com.vaadin.ui.Grid in project cuba by cuba-platform.

the class ComponentGridDecorator method initGpc.

/**
 * Replaces the current grid container with a {@link GeneratedPropertyContainer}
 * while preserving the {@link Grid.DetailsGenerator}.
 */
private void initGpc() {
    gpc = new GeneratedPropertyContainer(grid.getContainerDataSource());
    Grid.DetailsGenerator details = grid.getDetailsGenerator();
    grid.setContainerDataSource(gpc);
    grid.setDetailsGenerator(details);
}
Also used : GeneratedPropertyContainer(com.vaadin.data.util.GeneratedPropertyContainer) Grid(com.vaadin.ui.Grid)

Example 5 with Grid

use of com.vaadin.ui.Grid in project GridFastNavigation by TatuLund.

the class FastNavigation method setupFastNavigation.

private void setupFastNavigation(final Grid g, boolean changeColumnOnEnter, boolean dispatchEditEventOnBlur) {
    getState().changeColumnOnEnter = changeColumnOnEnter;
    getState().dispatchEditEventOnBlur = dispatchEditEventOnBlur;
    g.setEditorBuffered(false);
    g.setEditorEnabled(true);
    registerRpc(new FastNavigationServerRPC() {

        @Override
        public void rowUpdated(int rowIndex) {
            Object itemId = getItemIdByRowIndex(g, rowIndex);
            rowEditListeners.dispatch(new RowEditEvent(g, rowIndex, itemId));
        }

        private Object getItemIdByRowIndex(final Grid g, int rowIndex) {
            Indexed ds = g.getContainerDataSource();
            Object itemId = null;
            if (rowIndex >= 0 && (ds.size() > 0))
                itemId = ds.getIdByIndex(rowIndex);
            return itemId;
        }

        @Override
        public void cellUpdated(int rowIndex, int colIndex, String newData) {
            Object itemId = getItemIdByRowIndex(g, rowIndex);
            cellEditListeners.dispatch(new CellEditEvent(g, rowIndex, colIndex, newData, itemId));
        }

        @Override
        public void focusUpdated(int rowIndex, int colIndex) {
            Object itemId = getItemIdByRowIndex(g, rowIndex);
            if (hasRowFocusListener && rowIndex != lastFocusedRow) {
                rowFocusListeners.dispatch(new RowFocusEvent(g, rowIndex, itemId));
            }
            if (hasCellFocusListener && (rowIndex != lastFocusedRow || colIndex != lastFocusedCol)) {
                cellFocusListeners.dispatch(new CellFocusEvent(g, rowIndex, colIndex, lastFocusedRow == rowIndex, lastFocusedCol == colIndex, itemId));
            }
            lastFocusedRow = rowIndex;
            lastFocusedCol = colIndex;
        }

        @Override
        public void editorOpened(int rowIndex, int colIndex, int lockId) {
            Object itemId = getItemIdByRowIndex(g, rowIndex);
            EditorOpenEvent ev = new EditorOpenEvent(g, rowIndex, colIndex, itemId);
            editorOpenListeners.dispatch(ev);
            // Update disabled columns or readonly fields status if changed dynamically
            ArrayList<Integer> disabledColumns = new ArrayList<Integer>();
            for (int i = 0; i < g.getColumns().size(); i++) {
                if (!g.getColumns().get(i).isEditable()) {
                    disabledColumns.add(i);
                } else if ((g.getColumns().get(i).getEditorField() != null) && g.getColumns().get(i).getEditorField().isReadOnly()) {
                    disabledColumns.add(i);
                }
            }
            getRPC().setDisabledColumns(disabledColumns);
            getRPC().unlockEditor(lockId);
        }

        @Override
        public void ping() {
            getLogger().info("Received ping");
        }

        @Override
        public void editorClosed(int rowIndex, int colIndex, boolean wasCancelled) {
            editorCloseListeners.dispatch(new EditorCloseEvent(g, rowIndex, colIndex, wasCancelled));
        }

        @Override
        public void clickOut() {
            clickOutListeners.dispatch(new ClickOutEvent(g));
        }
    }, FastNavigationServerRPC.class);
    extend(g);
}
Also used : RowFocusEvent(org.vaadin.patrik.events.RowFocusEvent) ClickOutEvent(org.vaadin.patrik.events.ClickOutEvent) Grid(com.vaadin.ui.Grid) ArrayList(java.util.ArrayList) RowEditEvent(org.vaadin.patrik.events.RowEditEvent) CellEditEvent(org.vaadin.patrik.events.CellEditEvent) EditorCloseEvent(org.vaadin.patrik.events.EditorCloseEvent) EditorOpenEvent(org.vaadin.patrik.events.EditorOpenEvent) FastNavigationServerRPC(org.vaadin.patrik.shared.FastNavigationServerRPC) Indexed(com.vaadin.data.Container.Indexed) CellFocusEvent(org.vaadin.patrik.events.CellFocusEvent)

Aggregations

Grid (com.vaadin.ui.Grid)9 VerticalLayout (com.vaadin.ui.VerticalLayout)4 Label (com.vaadin.ui.Label)3 GeneratedPropertyContainer (com.vaadin.data.util.GeneratedPropertyContainer)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 TextField (com.vaadin.ui.TextField)2 ArrayList (java.util.ArrayList)2 SearchableGrid (au.com.vaadinutils.crud.SearchableGrid)1 Indexed (com.vaadin.data.Container.Indexed)1 InvalidValueException (com.vaadin.data.Validator.InvalidValueException)1 BeanFieldGroup (com.vaadin.data.fieldgroup.BeanFieldGroup)1 SortOrder (com.vaadin.data.sort.SortOrder)1 SimpleStringFilter (com.vaadin.data.util.filter.SimpleStringFilter)1 StringLengthValidator (com.vaadin.data.validator.StringLengthValidator)1 TextChangeEvent (com.vaadin.event.FieldEvents.TextChangeEvent)1 TextChangeListener (com.vaadin.event.FieldEvents.TextChangeListener)1 ItemClickEvent (com.vaadin.event.ItemClickEvent)1 ItemClickListener (com.vaadin.event.ItemClickEvent.ItemClickListener)1 SelectionEvent (com.vaadin.event.SelectionEvent)1 SelectionListener (com.vaadin.event.SelectionEvent.SelectionListener)1