use of com.vaadin.flow.component.treegrid.TreeGrid in project flow-components by vaadin.
the class GridSerializableTest method treeGridWithHierarchyColumnIsSerializable.
@Test
public void treeGridWithHierarchyColumnIsSerializable() throws IOException {
final TreeGrid<String> grid = new TreeGrid<>();
grid.addHierarchyColumn(String::toString);
new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(grid);
}
use of com.vaadin.flow.component.treegrid.TreeGrid in project flow-components by vaadin.
the class TreeComponentColumnsPage method addTreeGrid.
private void addTreeGrid(boolean addGridBefore) {
TreeGrid<String> grid = new TreeGrid<>();
if (addGridBefore) {
grid.setId("grid-then-comp");
add(grid);
}
ComponentRenderer<TextField, String> componentRenderer = new ComponentRenderer<>(TextField::new, (component, item) -> {
component.setReadOnly(true);
component.setValue(item);
});
grid.addComponentHierarchyColumn(this::createTextField).setHeader("Header A").setId("textfield");
grid.addColumn(componentRenderer).setHeader("Header B");
ComponentRenderer<Button, String> componentRendererBtn = new ComponentRenderer<>(() -> new Button("btn"), ((button, s) -> {
button.setText(s);
button.setThemeName(ButtonVariant.LUMO_ERROR.getVariantName());
}));
grid.addColumn(componentRendererBtn).setHeader("Header C");
TreeData<String> data = new TreeData<>();
final Map<String, String> parentPathMap = new HashMap<>();
addRootItems("Granddad", 3, data, parentPathMap).forEach(granddad -> addItems("Dad", 3, granddad, data, parentPathMap).forEach(dad -> addItems("Son", 100, dad, data, parentPathMap)));
grid.setDataProvider(new TreeDataProvider<>(data));
if (!addGridBefore) {
grid.setId("comp-then-grid");
add(grid);
}
}
use of com.vaadin.flow.component.treegrid.TreeGrid in project linkki by linkki-framework.
the class GridComponentCreatorTest method createTreeTableWithColumns.
private TreeGrid<?> createTreeTableWithColumns() {
CodeTablePmo containerPmo = new CodeTablePmo();
BindingContext bindingContext = new BindingContext();
TreeGrid<?> componentWrapper = (TreeGrid<?>) GridComponentCreator.createGrid(containerPmo, bindingContext);
return componentWrapper;
}
use of com.vaadin.flow.component.treegrid.TreeGrid in project ArchCNL by Mari-Wie.
the class FileSelectionComponent method createFileSelect.
@SuppressWarnings("unchecked")
private FileSelect createFileSelect(File rootFile) {
FileSelect newFileSelect = new FileSelect(rootFile, "adoc");
newFileSelect.getChildren().filter(TreeGrid.class::isInstance).map(TreeGrid.class::cast).forEach(treeGrid -> treeGrid.expand(treeGrid.getTreeData().getRootItems()));
newFileSelect.addValueChangeListener(event -> {
Optional<File> file = newFileSelect.getOptionalValue();
if (selectDirectory) {
handleDirectoryChange(file);
} else {
if (file.isPresent() && file.get().isFile()) {
selectedFile = file;
dialog.setConfirmButtonEnabled(true);
fileSelectErrorLabel.setVisible(false);
} else {
selectedFile = Optional.empty();
showErrorMessage("Please select a file.");
}
}
});
// or an empty directory is selected
if (selectDirectory) {
for (Component child : newFileSelect.getChildren().collect(Collectors.toList())) {
if (child instanceof TreeGrid) {
TreeGrid<File> grid = (TreeGrid<File>) child;
grid.addExpandListener(event -> {
File file = event.getItems().iterator().next();
handleDirectoryChange(Optional.of(file));
});
}
}
}
newFileSelect.setWidth("500px");
newFileSelect.setHeight("500px");
return newFileSelect;
}
use of com.vaadin.flow.component.treegrid.TreeGrid in project flow-components by vaadin.
the class GridBenchmark method setParameter.
@Override
public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
Location location = event.getLocation();
QueryParameters queryParameters = location.getQueryParameters();
Map<String, List<String>> parametersMap = queryParameters.getParameters();
if (!parametersMap.containsKey("variant") || !parametersMap.containsKey("metric")) {
add(new Text("Provide query parameters: variant and metric"));
return;
}
String metric = parametersMap.get("metric").get(0);
String variant = parametersMap.get("variant").get(0);
LoggerFactory.getLogger(GridBenchmark.class).info("Sample: " + variant + "-" + metric);
switch(variant) {
case "simple":
grid = getGrid();
addColumns(grid, 5, false);
break;
case "multicolumn":
grid = getGrid();
addColumns(grid, 50, false);
break;
case "componentrenderers":
grid = getGrid();
addColumns(grid, 5, true);
break;
case "detailsopened":
grid = getGrid();
addColumns(grid, 5, false);
grid.setItemDetailsRenderer(new ComponentRenderer<>(item -> new Text(item.toString())));
items.forEach(item -> grid.setDetailsVisible(item, true));
break;
case "tree":
grid = getTreeGrid();
((TreeGrid<String>) grid).addHierarchyColumn(i -> i);
addColumns(grid, 5, false);
break;
case "mixed":
grid = getTreeGrid();
((TreeGrid<String>) grid).addHierarchyColumn(i -> i);
addColumns(grid, 50, true);
grid.setItemDetailsRenderer(new ComponentRenderer<>(item -> new Text(item.toString())));
treeData.getRootItems().forEach(item -> grid.setDetailsVisible(item, true));
break;
default:
break;
}
switch(metric) {
case "verticalscrollframetime":
add(grid);
whenRendered(grid).then(v -> grid.getElement().executeJs("window.measureScrollFrameTime(this, false)"));
break;
case "horizontalscrollframetime":
add(grid);
whenRendered(grid).then(v -> grid.getElement().executeJs("window.measureScrollFrameTime(this, true)"));
break;
case "rendertime":
measureRendered(grid);
UI.getCurrent().getElement().executeJs("return window.startWhenReady()").then(v -> add(grid));
break;
case "expandtime":
add(grid);
startWhenRendered(grid).then(v -> {
measureRendered(grid);
TreeGrid<String> treeGrid = (TreeGrid<String>) grid;
TreeData<String> data = ((TreeDataProvider<String>) treeGrid.getDataProvider()).getTreeData();
treeGrid.expandRecursively(data.getRootItems(), 5);
});
break;
default:
break;
}
}
Aggregations