com.vaadin.ui.Grid Java Examples

The following examples show how to use com.vaadin.ui.Grid. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebTree.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void setSelectionMode(SelectionMode selectionMode) {
    this.selectionMode = selectionMode;
    switch (selectionMode) {
        case SINGLE:
            component.setGridSelectionModel(new CubaSingleSelectionModel<>());
            break;
        case MULTI:
            component.setGridSelectionModel(new CubaMultiSelectionModel<>());
            break;
        case NONE:
            component.setSelectionMode(Grid.SelectionMode.NONE);
            return;
    }

    // Every time we change selection mode, the new selection model is set,
    // so we need to add selection listener again.
    component.addSelectionListener(this::onSelectionChange);
}
 
Example #2
Source File: AbstractMetadataPopupLayout.java    From hawkbit with Eclipse Public License 1.0 6 votes vote down vote up
protected Grid createMetadataGrid() {
    final Grid metadataGrid = new Grid();
    metadataGrid.addStyleName(SPUIStyleDefinitions.METADATA_GRID);
    metadataGrid.setImmediate(true);
    metadataGrid.setHeight("100%");
    metadataGrid.setWidth("100%");
    metadataGrid.setId(UIComponentIdProvider.METDATA_TABLE_ID);
    metadataGrid.setSelectionMode(SelectionMode.SINGLE);
    metadataGrid.setColumnReorderingAllowed(true);
    metadataGrid.setContainerDataSource(getMetadataContainer());
    metadataGrid.getColumn(KEY).setHeaderCaption(i18n.getMessage("header.key"));
    metadataGrid.getColumn(VALUE).setHeaderCaption(i18n.getMessage("header.value"));
    metadataGrid.getColumn(VALUE).setHidden(true);
    metadataGrid.addSelectionListener(this::onRowClick);
    metadataGrid.getColumn(DELETE_BUTTON).setHeaderCaption("");
    metadataGrid.getColumn(DELETE_BUTTON).setRenderer(new HtmlButtonRenderer(this::onDelete));
    metadataGrid.getColumn(DELETE_BUTTON).setWidth(50);
    metadataGrid.getColumn(KEY).setExpandRatio(1);
    return metadataGrid;
}
 
Example #3
Source File: AttributesLocationCompanion.java    From cuba with Apache License 2.0 6 votes vote down vote up
protected void removeFromSourceGrid(Grid currentSourceGrid, boolean isAttributesSourceGrid, AbstractComponent dropComponent, int dropIndex) {
    if (!droppedSuccessful || draggedItem == null) {
        return;
    }

    //noinspection unchecked
    List<CategoryAttribute> items = (List<CategoryAttribute>) ((ListDataProvider) currentSourceGrid.getDataProvider()).getItems();
    if (currentSourceGrid.equals(dropComponent) && dropIndex >= 0) {
        int removeIndex = items.indexOf(draggedItem) == dropIndex
                ? items.lastIndexOf(draggedItem)
                : items.indexOf(draggedItem);
        if (removeIndex >= 0 && removeIndex != dropIndex) {
            items.remove(removeIndex);
        }
    } else {
        items.remove(draggedItem);
    }

    if (isAttributesSourceGrid && AttributesLocationFrame.EMPTY_ATTRIBUTE_NAME.equals(draggedItem.getName())) {
        attributesSourceDataContainer.add(createEmptyAttribute());
    }

    currentSourceGrid.getDataProvider().refreshAll();
}
 
Example #4
Source File: HeaderWrapExtensionLayout.java    From GridExtensionPack with Apache License 2.0 6 votes vote down vote up
private void generateData(Grid<RowData> g, int cols, int rows) {
	g.addColumn(RowData::getRowNumber).setCaption("#");
	for (int x = 0; x < cols; ++x) {
		int row = x;
		g.addColumn(t -> row < t.getValues().length ? t.getValues()[row] : "Empty")
				.setCaption("Yet another dummy column with extremely long and pointless title " + (x + 1));
	}

	List<RowData> data = new ArrayList<>();
	Random r = new Random();
	for (int y = 0; y < rows; ++y) {
		String[] values = new String[cols];
		for (int x = 0; x < cols; ++x) {
			values[x] = "" + r.nextInt() + " babies born last year";
		}
		data.add(new RowData(y, values));
	}
	g.setItems(data);
}
 
Example #5
Source File: PageItemPropertyClickListenerTest.java    From cia with Apache License 2.0 6 votes vote down vote up
/**
 * Check correct page id click success test.
 */
@Test
public void checkCorrectPageIdClickSuccessTest() {
	final PageItemPropertyClickListener pageItemPropertyClickListener = new PageItemPropertyClickListener(UserViews.POLITICIAN_VIEW_NAME,"personId");

	final String personIdValue = "personId";
	final ViewRiksdagenPolitician riksdagenPolitician = new ViewRiksdagenPolitician().withPersonId(personIdValue);
	final String pageId = pageItemPropertyClickListener.getPageId(riksdagenPolitician);

	assertEquals(personIdValue, pageId);
	
	final UI uiMock = Mockito.mock(UI.class);
	UI.setCurrent(uiMock);
	
	final Navigator navigatorMock = Mockito.mock(Navigator.class);
	Mockito.when(uiMock.getNavigator()).thenReturn(navigatorMock);		
			
	pageItemPropertyClickListener.click(new RendererClickEvent(new Grid(), riksdagenPolitician, null, null) {

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;});
	
	Mockito.verify(navigatorMock, times(1)).navigateTo(UserViews.POLITICIAN_VIEW_NAME + "/personId");
}
 
Example #6
Source File: CubaEditorImpl.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
protected void doEdit(T bean) {
    Objects.requireNonNull(bean, "Editor can't edit null");
    if (!isEnabled()) {
        throw new IllegalStateException(
                "Editing is not allowed when Editor is disabled.");
    }

    edited = bean;

    getParent().select(edited); // ItemPropertyChangedEvent is sent only if a row is selected

    getParent().getColumns().stream().filter(Grid.Column::isEditable)
            .forEach(c -> {
                CubaEditorField<?> editorField = getEnhancedGrid().getColumnEditorField(bean, c);
                configureField(editorField);
                addComponentToGrid(editorField);
                columnFields.put(c, editorField);
                getState().columnFields.put(getInternalIdForColumn(c), editorField.getConnectorId());
            });

    eventRouter.fireEvent(new CubaEditorOpenEvent<>(this, edited, Collections.unmodifiableMap(columnFields)));
}
 
Example #7
Source File: MGrid.java    From viritin with Apache License 2.0 5 votes vote down vote up
public MGrid<T> withColumnHeaders(String... properties) {
    List<Column<T, ?>> columns = getColumns();
    for (int i = 0; i < columns.size(); i++) {
        Grid.Column<T, ? extends Object> c = columns.get(i);
        c.setCaption(properties[i]);
    }
    return this;
}
 
Example #8
Source File: SwMetadataPopupLayout.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected Grid createMetadataGrid() {
    final Grid metadataGrid = super.createMetadataGrid();
    metadataGrid.getContainerDataSource().addContainerProperty(TARGET_VISIBLE, Boolean.class, Boolean.FALSE);
    metadataGrid.getColumn(TARGET_VISIBLE).setHeaderCaption(i18n.getMessage("metadata.targetvisible"));
    metadataGrid.getColumn(TARGET_VISIBLE).setHidden(true);
    return metadataGrid;
}
 
Example #9
Source File: UploadProgressInfoWindow.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
private Grid createGrid() {
    final Grid statusGrid = new Grid(uploads);
    statusGrid.addStyleName(SPUIStyleDefinitions.UPLOAD_STATUS_GRID);
    statusGrid.setId(UIComponentIdProvider.UPLOAD_STATUS_POPUP_GRID);
    statusGrid.setSelectionMode(SelectionMode.NONE);
    statusGrid.setHeaderVisible(true);
    statusGrid.setImmediate(true);
    statusGrid.setSizeFull();
    return statusGrid;
}
 
Example #10
Source File: WebTreeDataGrid.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void onColumnReorder(Grid.ColumnReorderEvent e) {
    super.onColumnReorder(e);

    String[] columnOrder = getColumnOrder();
    // if the hierarchy column isn't set explicitly,
    // we set the first column as the hierarchy column
    if (getHierarchyColumn() == null
            && columnOrder.length > 0) {
        String columnId = columnOrder[0];

        Grid.Column<E, ?> newHierarchyColumn = component.getColumn(columnId);
        setHierarchyColumnInternal(newHierarchyColumn);
    }
}
 
Example #11
Source File: GridContextMenu.java    From cuba with Apache License 2.0 5 votes vote down vote up
private void addGridSectionContextMenuListener(final Section section,
        final GridContextMenuOpenListener<T> listener) {
    addContextMenuOpenListener((final ContextMenuOpenEvent event) -> {
        if (event
                .getContextClickEvent() instanceof Grid.GridContextClickEvent) {
            @SuppressWarnings("unchecked")
            GridContextClickEvent<T> gridEvent = (GridContextClickEvent<T>) event
                    .getContextClickEvent();
            if (gridEvent.getSection() == section) {
                listener.onContextMenuOpen(new GridContextMenuOpenListener.GridContextMenuOpenEvent<>(
                        GridContextMenu.this, gridEvent));
            }
        }
    });
}
 
Example #12
Source File: SidebarMenuExtension.java    From GridExtensionPack with Apache License 2.0 5 votes vote down vote up
protected SidebarMenuExtension(Grid<?> grid) {
	registerRpc(new SidebarMenuExtensionServerRpc() {

		@Override
		public void click(Integer id) {
			Command command = idToCommandMap.get(id);
			if (command != null) {
				command.trigger();
			}
		}
	});
	rpcProxy = getRpcProxy(SidebarMenuExtensionClientRpc.class);
	extend(grid);

}
 
Example #13
Source File: CubaTree.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected Grid.SelectionMode getSelectionMode() {
    SelectionModel<T> selectionModel = getSelectionModel();
    Grid.SelectionMode mode = null;
    if (selectionModel instanceof SingleSelectionModel) {
        mode = Grid.SelectionMode.SINGLE;
    } else if (selectionModel instanceof MultiSelectionModel) {
        mode = Grid.SelectionMode.MULTI;
    } else if (selectionModel instanceof NoSelectionModel) {
        mode = Grid.SelectionMode.NONE;
    }
    return mode;
}
 
Example #14
Source File: SidebarMenuExtensionLayout.java    From GridExtensionPack with Apache License 2.0 5 votes vote down vote up
private void addGrid() {
	final Grid<TestFile> grid = new Grid<>("Attachment grid");
	grid.addColumn(TestFile::getFileName).setCaption("File Name");
	grid.addColumn(TestFile::isOpen).setHidable(true).setCaption("Is Open");
	grid.addColumn(TestFile::createOpenLink, new HtmlRenderer()).setHidable(true).setCaption("Download");
	grid.setColumnReorderingAllowed(true);
	addComponent(grid);
	extension = SidebarMenuExtension.create(grid);

	grid.setItems(Stream.of("Test file 1", "Test file 2").map(TestFile::new));
}
 
Example #15
Source File: WebTreeDataGrid.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void initComponent(Grid<E> component) {
    super.initComponent(component);

    CubaTreeGrid<E> treeGrid = (CubaTreeGrid<E>) component;
    treeGrid.setItemCollapseAllowedProvider(itemCollapseAllowedProvider::test);
}
 
Example #16
Source File: GridFactoryImpl.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Configure column orders and hidden fields.
 *
 * @param columnOrder
 *            the column order
 * @param hideColumns
 *            the hide columns
 * @param grid
 *            the grid
 */
private static void configureColumnOrdersAndHiddenFields(final String[] columnOrder, final String[] hideColumns,
		final Grid grid) {
	if (columnOrder != null) {
		grid.setColumnOrder(columnOrder);
	}

	if (hideColumns != null) {
		for (final String o : hideColumns) {
			grid.removeColumn(o);
		}
	}
}
 
Example #17
Source File: GridFactoryImpl.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the grid cell filter.
 *
 * @param columnOrder
 *            the column order
 * @param grid
 *            the grid
 * @param dataType
 *            the data type
 */
private static void createGridCellFilter(final String[] columnOrder, final Grid grid, final Class dataType) {
	if (columnOrder != null) {
		final GridCellFilter filter = new GridCellFilter(grid, dataType);
		for (final String column : columnOrder) {
			if (grid.getColumn(column) != null) {
				filter.setTextFilter(column, true, true);
			}
		}
	}
}
 
Example #18
Source File: GridFactoryImpl.java    From cia with Apache License 2.0 5 votes vote down vote up
private static <T extends Serializable> void createNestedProperties(final Grid<T> grid,
		final String[] nestedProperties) {
	if (nestedProperties != null) {
		for (final String property : nestedProperties) {
			final Column<T, ?> addColumn = grid.addColumn(new BeanNestedPropertyValueProvider<T>(property));
			addColumn.setId(property);
		}
	}
}
 
Example #19
Source File: GridFactoryImpl.java    From cia with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the column converters.
 *
 * @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) {
			grid.removeColumn(converter.getColumn());
			final Column column = grid.addColumn(converter);
			column.setCaption(WordUtils.capitalize(converter.getColumn()));
			column.setId(converter.getColumn());
		}
	}
}
 
Example #20
Source File: WebTreeDataGrid.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void setHierarchyColumn(Column<E> column) {
    checkNotNullArgument(column);

    this.hierarchyColumn = column;

    Grid.Column<E, ?> newHierarchyColumn = ((ColumnImpl<E>) column).getGridColumn();
    setHierarchyColumnInternal(newHierarchyColumn);
}
 
Example #21
Source File: CubaGridColumn.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public Grid.Column<T, V> setEditable(boolean editable) {
    // Removed check that editorBinding is not null,
    // because we don't use Vaadin binding.
    getState().editable = editable;
    return this;
}
 
Example #22
Source File: CubaEditorImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected String generateErrorMessage(Map<Component, Grid.Column<T, ?>> fieldToColumn,
                                      Map<Component, ValidationResult> errors) {
    return errors.entrySet().stream()
            .filter(entry ->
                    !Strings.isNullOrEmpty(entry.getValue().getErrorMessage())
                            && fieldToColumn.containsKey(entry.getKey()))
            .map(entry ->
                    fieldToColumn.get(entry.getKey()).getCaption() + ": " +
                            entry.getValue().getErrorMessage())
            .collect(Collectors.joining("; "));
}
 
Example #23
Source File: CubaEditorImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected Map<String, Object> generatePropertiesMap() {
    Map<String, Object> properties = new HashMap<>();
    for (Map.Entry<Grid.Column<T, ?>, Component> entry : columnFields.entrySet()) {
        properties.put(entry.getKey().getId(), ((CubaEditorField<?>) entry.getValue()).getValue());
    }
    return properties;
}
 
Example #24
Source File: PhoneBookEntryForm.java    From jpa-addressbook with The Unlicense 5 votes vote down vote up
public PhoneBookEntryForm() {
    super(PhoneBookEntry.class);
    groupsGrid.setColumns("name");
    groupsGrid.setHeaderVisible(false);
    groupsGrid.setSelectionMode(Grid.SelectionMode.MULTI);
    groups = groupsGrid.asMultiSelect();
}
 
Example #25
Source File: CubaEditorImpl.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
protected void doCancel(boolean afterBeingSaved) {
    // CAUTION copied from parent with changes
    T editedBean = edited;
    // As columnFields is cleared in doClose, we need to make a copy of it
    Map<Grid.Column<T, ?>, Component> usedColumnFields = ImmutableMap.copyOf(columnFields);
    doClose();
    if (!afterBeingSaved) {
        eventRouter.fireEvent(
                new CubaEditorCancelEvent<>(this, editedBean, usedColumnFields));
    }
}
 
Example #26
Source File: WebTreeDataGrid.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void setHierarchyColumnInternal(Grid.Column<E, ?> newHierarchyColumn) {
    Grid.Column<E, ?> prevHierarchyColumn = component.getHierarchyColumn();
    component.setHierarchyColumn(newHierarchyColumn);

    // Due to Vaadin bug, we need to reset column's
    // collapsible state after changing the hierarchy column
    if (prevHierarchyColumn != null
            && !newHierarchyColumn.equals(prevHierarchyColumn)) {
        updateColumnCollapsible(prevHierarchyColumn);
    }
}
 
Example #27
Source File: GridContextMenu.java    From context-menu with Apache License 2.0 5 votes vote down vote up
private void addGridSectionContextMenuListener(final Section section,
        final GridContextMenuOpenListener<T> listener) {
    addContextMenuOpenListener((final ContextMenuOpenEvent event) -> {
        if (event
                .getContextClickEvent() instanceof Grid.GridContextClickEvent) {
            @SuppressWarnings("unchecked")
            GridContextClickEvent<T> gridEvent = (GridContextClickEvent<T>) event
                    .getContextClickEvent();
            if (gridEvent.getSection() == section) {
                listener.onContextMenuOpen(new GridContextMenuOpenEvent<>(
                        GridContextMenu.this, gridEvent));
            }
        }
    });
}
 
Example #28
Source File: GridGanttLayout.java    From gantt with Apache License 2.0 5 votes vote down vote up
private Grid<Step> createGridForGantt() {

        dataProvider = new ListDataProvider<>(new ArrayList<>(gantt.getSteps()));
        Grid<Step> grid = new Grid<>(dataProvider);
        grid.setWidth(400, Unit.PIXELS);
        grid.setHeight(100, Unit.PERCENTAGE);

        Column<Step, ?> c = grid.addColumn(Step::getCaption);
        c.setSortable(false);
        c.setResizable(false);

        gantt.setVerticalScrollDelegateTarget(grid);

        return grid;
    }
 
Example #29
Source File: CacheStrategyExtension.java    From GridExtensionPack with Apache License 2.0 4 votes vote down vote up
protected CacheStrategyExtension(Grid grid, int minSize, double pageMultiplier) {
	getState().minSize = minSize;
	getState().pageMultiplier = pageMultiplier;
	extend(grid);
}
 
Example #30
Source File: GridContextMenu.java    From context-menu with Apache License 2.0 4 votes vote down vote up
public GridContextMenu(Grid<T> parentComponent) {
    super(parentComponent, true);
}