Skip to content

Commit

Permalink
fix grid dataprovider not reloading on change
Browse files Browse the repository at this point in the history
use filter method when view is built
make grid use full height

Signed-off-by: Aleksandar Zivkovic <[email protected]>
  • Loading branch information
anywaywayany committed Feb 21, 2024
1 parent 6a6c48f commit 7074b88
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
14 changes: 14 additions & 0 deletions src/main/java/com/samic/samic/components/UIFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public static VerticalLayout rootComponentContainer(String heading, Component...
return container;
}

public static VerticalLayout rootComponentContainerFullHeight(String heading,
Component... containers) {
VerticalLayout container = rootComponentContainer(heading, containers);
container.setHeightFull();
return container;
}

public static HorizontalLayout childContainer(
FlexComponent.JustifyContentMode justifyContentMode, Component... components) {
// Create container
Expand All @@ -50,6 +57,13 @@ public static HorizontalLayout childContainer(
return childContainer;
}

public static HorizontalLayout childContainerFullHeight(
FlexComponent.JustifyContentMode justifyContentMode, Component... components) {
HorizontalLayout childContainer = childContainer(justifyContentMode, components);
childContainer.setHeightFull();
return childContainer;
}

///////////---------------------BUTTONS≈---------------------///////////
public static Button btnPrimary(
String text, ComponentEventListener<ClickEvent<Button>> listener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ private void initUI() {
.setAutoWidth(true).setFrozenToEnd(true);
grid.setItemDetailsRenderer(createStorageObjectDetailsRenderer());
grid.getStyle().setBorder("0px");
grid.setHeightFull();

setHeightFull();

filterStorage.setItemLabelGenerator(Storage::getName);
filterStorage.setItems(storageService.findAll().toList());
Expand All @@ -105,20 +108,8 @@ private void initUI() {
filterObjectType.setPlaceholder("Gerätetyp auswählen");
filterObjectType.setWidth("250px");

//GridListDataView<StorageObject> storageObjectList;

grid.setItems(storageObjectService.findFreeStorageObjects().toList());
/*listFilteredStorageObjects(searchField.getValue(), filterStorage.getValue()
.getId());*/
/* try {
storageObjectList = grid.setItems(listFilteredStorageObjects(searchField.getValue(), filterStorage.getValue()
.getId()));
} catch (SamicException e) {
storageObjectList = grid.setItems(List.of());
UIFactory.notificationError(e.getMessage()).open();
}*/
listFilteredStorageObjects("%", filterStorage.getValue().getId());

//GridListDataView<StorageObject> finalStorageObjectList = storageObjectList;
searchField.addValueChangeListener(
e -> listFilteredStorageObjects(e.getValue(), filterStorage.getValue()
.getId()));
Expand All @@ -133,8 +124,8 @@ private void initUI() {
filterStorage,
filterObjectType
)),
UIFactory.rootComponentContainer("",
UIFactory.childContainer(
UIFactory.rootComponentContainerFullHeight("",
UIFactory.childContainerFullHeight(
JustifyContentMode.START,
grid)),
reservationDialog);
Expand Down Expand Up @@ -165,6 +156,7 @@ private void reserve() {
reservationDialog.close();

UIFactory.notificationSuccess("Reservierung erfolgreich durchgeführt").open();
grid.getDataProvider().refreshAll();
}

private ComponentRenderer<StorageObjectDetailsForm, StorageObject> createStorageObjectDetailsRenderer() {
Expand All @@ -186,6 +178,7 @@ private void addToUser(StorageObject item) {

storageObjectService.saveStorageObject(item);
UIFactory.notificationSuccess("Lagerobjekt erfolgreich deinem Lager hinzugefügt").open();
grid.getDataProvider().refreshAll();
}


Expand Down

0 comments on commit 7074b88

Please sign in to comment.