use of com.vaadin.flow.data.renderer.ComponentRenderer in project karnak by OsiriX-Foundation.
the class DicomWorkListSelectionDialog method buildDicomNodeRenderer.
private ComponentRenderer<Div, ConfigNode> buildDicomNodeRenderer() {
return new ComponentRenderer<Div, ConfigNode>(item -> {
Div div = new Div();
div.getStyle().set("line-height", "92%");
Span spanDescription = new Span(item.getName());
spanDescription.getStyle().set("font-weight", "500");
HtmlComponent htmlLineBreak = new HtmlComponent("BR");
Span spanOtherAttributes = new Span(item.getAet() + " | " + item.getHostname() + " | " + item.getPort());
spanOtherAttributes.getStyle().set("font-size", "75%");
div.add(spanDescription, htmlLineBreak, spanOtherAttributes);
return div;
});
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project aire-components by aire-ux.
the class ModuleGrid method populateGrid.
private Grid<Module> populateGrid() {
val grid = new Grid<Module>();
grid.addThemeVariants(GridVariant.LUMO_NO_BORDER);
grid.addItemClickListener(event -> {
setSelectedModule(event.getItem());
});
grid.setMultiSort(true);
grid.setAllRowsVisible(true);
grid.setColumnReorderingAllowed(true);
grid.addComponentColumn((ValueProvider<Module, ModuleLifecycleButtonBar>) module -> new ModuleLifecycleButtonBar(getModuleLifecycleDelegate(), getZephyr(), module)).setResizable(true).setHeader("Lifecycle");
grid.addColumn((ValueProvider<Module, String>) module -> module.getCoordinate().getGroup()).setSortable(true).setResizable(true).setHeader("Group");
grid.addColumn((ValueProvider<Module, String>) module -> module.getCoordinate().getName()).setSortable(true).setResizable(true).setHeader("Name");
grid.addColumn((ValueProvider<Module, String>) module -> module.getCoordinate().getVersion().toString()).setHeader("Version");
grid.addColumn(new ComponentRenderer<>(Span::new, new StatusComponentUpdater())).setHeader("Status");
grid.setItems(new ListDataProvider<>(getZephyr().getPlugins()));
grid.getStyle().set("overflow-y", "auto");
return grid;
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class Grid method addColumn.
/**
* Adds a new text column to this {@link Grid} with a template renderer,
* sorting properties and column factory provided. The values inside the
* renderer are converted to JSON values by using
* {@link JsonSerializer#toJson(Object)}.
* <p>
* <em>NOTE:</em> You can add component columns easily using the
* {@link #addComponentColumn(ValueProvider)}, but using
* {@link ComponentRenderer} is not as efficient as the built in renderers
* or using {@link TemplateRenderer}.
* <p>
* This constructor attempts to automatically configure both in-memory and
* backend sorting using the given sorting properties and matching those
* with the property names used in the given renderer.
* <p>
* <strong>Note:</strong> if a property of the renderer that is used as a
* sorting property does not extend Comparable, no in-memory sorting is
* configured for it.
*
* <p>
* Every added column sends data to the client side regardless of its
* visibility state. Don't add a new column at all or use
* {@link Grid#removeColumn(Column)} to avoid sending extra data.
* </p>
*
* @see #addColumn(Renderer, String...)
* @see #removeColumn(Column)
*
* @param renderer
* the renderer used to create the grid cell structure
* @param columnFactory
* the method that creates a new column instance for this
* {@link Grid} instance.
* @param sortingProperties
* the sorting properties to use for this column
* @return the created column
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected <C extends Column<T>> C addColumn(Renderer<T> renderer, BiFunction<Renderer<T>, String, C> columnFactory, String... sortingProperties) {
C column = addColumn(renderer, columnFactory);
Map<String, ValueProvider<T, ?>> valueProviders = renderer.getValueProviders();
Set<String> valueProvidersKeySet = valueProviders.keySet();
List<String> matchingSortingProperties = Arrays.stream(sortingProperties).filter(valueProvidersKeySet::contains).collect(Collectors.toList());
column.setSortProperty(matchingSortingProperties.toArray(new String[matchingSortingProperties.size()]));
Comparator<T> combinedComparator = (a, b) -> 0;
Comparator nullsLastComparator = Comparator.nullsLast(Comparator.naturalOrder());
for (String sortProperty : matchingSortingProperties) {
ValueProvider<T, ?> provider = valueProviders.get(sortProperty);
combinedComparator = combinedComparator.thenComparing((a, b) -> {
Object aa = provider.apply(a);
if (!(aa instanceof Comparable)) {
return 0;
}
Object bb = provider.apply(b);
return nullsLastComparator.compare(aa, bb);
});
}
return column;
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class LazyLoadingPage method createDataProviderWithCustomItemFilter.
private void createDataProviderWithCustomItemFilter() {
addTitle("ListDataProvider with custom item filter");
ComboBox<Person> comboBox = new ComboBox<>();
comboBox.setId("custom-filter");
List<Person> people = IntStream.range(0, 500).mapToObj(i -> new Person("Person", i)).collect(Collectors.toList());
ListDataProvider<Person> personDataProvider = new ListDataProvider<>(people);
comboBox.setRenderer(new ComponentRenderer<Div, Person>(person -> {
return new Div(new H4(person.getName()), new Label("Born: " + person.getBorn()));
}));
comboBox.setDataProvider((person, filter) -> String.valueOf(person.getBorn()).startsWith(filter), personDataProvider);
add(comboBox);
}
use of com.vaadin.flow.data.renderer.ComponentRenderer in project flow-components by vaadin.
the class GridViewUsingComponentsPage method createColumnComponentRenderer.
private void createColumnComponentRenderer() {
Grid<Person> grid = new Grid<>();
grid.setItems(createItems());
// Use the component constructor that accepts an item ->
// new PersonComponent(Person person)
grid.addComponentColumn(PersonComponent::new).setHeader("Person");
// Or you can use an ordinary function to setup the component
grid.addComponentColumn(item -> new NativeButton("Remove", evt -> {
ListDataProvider<Person> dataProvider = (ListDataProvider<Person>) grid.getDataProvider();
dataProvider.getItems().remove(item);
dataProvider.refreshAll();
})).setHeader("Actions");
// Item details can also use components
grid.setItemDetailsRenderer(new ComponentRenderer<>(PersonCard::new));
// When items are updated, new components are generated
TextField idField = new TextField("", "Person id");
TextField nameField = new TextField("", "New name");
NativeButton updateButton = new NativeButton("Update person", event -> {
String id = idField.getValue();
String name = nameField.getValue();
ListDataProvider<Person> dataProvider = (ListDataProvider<Person>) grid.getDataProvider();
dataProvider.getItems().stream().filter(person -> String.valueOf(person.getId()).equals(id)).findFirst().ifPresent(person -> {
person.setFirstName(name);
dataProvider.refreshItem(person);
});
});
grid.setSelectionMode(SelectionMode.NONE);
grid.setId("component-renderer");
idField.setId("component-renderer-id-field");
nameField.setId("component-renderer-name-field");
updateButton.setId("component-renderer-update-button");
addCard("Using components", "Grid with columns using component renderer", grid, idField, nameField, updateButton);
}
Aggregations