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);
}
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");
}
}
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;
}
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);
}
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);
}
Aggregations