Skip to content

Commit

Permalink
Address DNA issues (persist selections, new clear button functionality)
Browse files Browse the repository at this point in the history
  • Loading branch information
SugaryLump committed Dec 4, 2024
1 parent 4283ac2 commit 512913c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;

import org.roda.core.data.v2.index.sublist.Sublist;
Expand Down Expand Up @@ -48,10 +49,6 @@ public class DatabaseSelectDialog extends DialogBox {
private SearchWrapper databasesSearchWrapper;
private SearchPanelWithSearchAll parentSearchPanel;
private Filter defaultFilter;
private String listId;

// private Collection<String> selectedUUIDs;
// private long totalSelectedObjects;

private long notLoaded;
private long notSearchable;
Expand Down Expand Up @@ -85,19 +82,21 @@ public void init(Filter defaultFilter, String allFilter, ClientMessages messages
description.add(new SimplePanel(new Label(messages.manageDatabaseSearchAllContactInfo())));

ListBuilder<ViewerDatabase> databaseMetadataList = new ListBuilder<>(() -> {
DatabaseSelectList metadataDatabaseList = new DatabaseSelectList(new Filter(), null, null, true, false);
Filter available = new Filter();
available
.add(new SimpleFilterParameter(ViewerConstants.SOLR_DATABASES_STATUS, ViewerDatabaseStatus.AVAILABLE.name()));
DatabaseSelectList metadataDatabaseList = new DatabaseSelectList(available, null, null, true, false);
metadataDatabaseList.getSelectionModel().addSelectionChangeHandler(event -> {
ViewerDatabase selected = metadataDatabaseList.getSelectionModel().getSelectedObject();
if (selected != null) {
HistoryManager.gotoSIARDInfo(selected.getUuid());
metadataDatabaseList.getSelectionModel().clear();
}
list = metadataDatabaseList;
});
this.list = metadataDatabaseList;

return metadataDatabaseList;
}, new AsyncTableCellOptions<>(ViewerDatabase.class, "DatabaseList_metadata"));
this.listId = databaseMetadataList.getOptions().getListId();
this.parentSearchPanel = parentSearchPanel;
this.defaultFilter = defaultFilter;
this.messages = messages;
Expand Down Expand Up @@ -193,9 +192,7 @@ private void cancelHandler() {
}

private void clearHandler() {
this.clearSelectedObjectsInLocalStorage();
this.doParentSearch();
this.hide();
this.list.setSelected(new HashSet<>());
}

private void doParentSearch() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public DatabaseSelectList() {

public DatabaseSelectList(Filter filter, Facets facets, String summary, boolean selectable, boolean exportable) {
super(filter, facets, summary, selectable, exportable, 15, 15);
setPersistSelections(true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.databasepreservation.common.client.common.lists.utils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -109,6 +110,8 @@ protected enum TextAlign {

private Column<T, Boolean> selectColumn;
private Set<T> selected = new HashSet<T>();
private boolean persistSelections = false;
private Set<String> persistedSelectedUUIDs = new HashSet<>();
private final List<CheckboxSelectionListener<T>> listeners = new ArrayList<AsyncTableCell.CheckboxSelectionListener<T>>();

private Filter filter;
Expand Down Expand Up @@ -312,15 +315,25 @@ private void configure(final CellTable<T> display) {
selectColumn = new Column<T, Boolean>(new CheckboxCell(true, false)) {
@Override
public Boolean getValue(T object) {
return selected.contains(object);
if (persistSelections) {
if (object == null) {
return false;
} else {
return persistedSelectedUUIDs.contains(object.getUuid());
}
} else {
return selected.contains(object);
}
}
};

selectColumn.setFieldUpdater((index, object, isSelected) -> {
if (isSelected) {
selected.add(object);
persistedSelectedUUIDs.add(object.getUuid());
} else {
selected.remove(object);
persistedSelectedUUIDs.remove(object.getUuid());
}

// update header
Expand All @@ -334,15 +347,34 @@ public Boolean getValue(T object) {
public Boolean getValue() {
Boolean ret;

if (selected.isEmpty()) {
ret = false;
} else if (selected.containsAll(getVisibleItems())) {
ret = true;
showSelectAllPanel();
if (!persistSelections) {
if (selected.isEmpty()) {
ret = false;
} else if (selected.containsAll(getVisibleItems())) {
ret = true;
showSelectAllPanel();
} else {
// some are selected
ret = false;
hideSelectAllPanel();
}
} else {
// some are selected
ret = false;
hideSelectAllPanel();
Collection<String> visibleUUIDs = new ArrayList<>();
for (T item : getVisibleItems()) {
if (item != null) {
visibleUUIDs.add(item.getUuid());
}
}
if (persistedSelectedUUIDs.isEmpty()) {
ret = false;
} else if (persistedSelectedUUIDs.containsAll(visibleUUIDs)) {
ret = true;
showSelectAllPanel();
} else {
// some are selected
ret = false;
hideSelectAllPanel();
}
}

return ret;
Expand All @@ -351,9 +383,15 @@ public Boolean getValue() {

selectHeader.setUpdater(value -> {
if (value) {
for (T item : getVisibleItems()) {
persistedSelectedUUIDs.add(item.getUuid());
}
selected.addAll(getVisibleItems());
showSelectAllPanel();
} else {
for (T item : getVisibleItems()) {
persistedSelectedUUIDs.remove(item.getUuid());
}
selected.clear();
hideSelectAllPanel();
}
Expand Down Expand Up @@ -628,8 +666,12 @@ public SelectedItems<T> getSelected() {
} else {
List<String> ids = new ArrayList<>();

for (T item : selected) {
ids.add(item.getUuid());
if (!persistSelections) {
for (T item : selected) {
ids.add(item.getUuid());
}
} else {
ids.addAll(persistedSelectedUUIDs);
}

ret = new SelectedItemsList<T>(ids, selectedClass.getName());
Expand All @@ -638,18 +680,18 @@ public SelectedItems<T> getSelected() {
return ret;
}

public Set<T> getSelectedObjects() {
return selected;
}

public void setSelected(Set<T> newSelected) {
selected.clear();
selected.addAll(newSelected);
persistedSelectedUUIDs.clear();
for (T selectedObject : newSelected) {
persistedSelectedUUIDs.add(selectedObject.getUuid());
}
redraw();
fireOnCheckboxSelectionChanged();
}

public void setSelectedByUUIDs(Iterable<String> databaseUUIDs) {
public void setSelectedByUUIDs(Collection<String> databaseUUIDs) {
this.selected.clear();
HashMap<String, T> resultsMap = new HashMap<>();
for (T resultsObject : this.result.getResults()) {
Expand All @@ -660,12 +702,15 @@ public void setSelectedByUUIDs(Iterable<String> databaseUUIDs) {
this.selected.add(resultsMap.get(databaseUUID));
}
}
this.persistedSelectedUUIDs.clear();
this.persistedSelectedUUIDs.addAll(databaseUUIDs);
redraw();
fireOnCheckboxSelectionChanged();
}

public void clearSelected() {
selected.clear();
persistedSelectedUUIDs.clear();
redraw();
fireOnCheckboxSelectionChanged();
}
Expand Down Expand Up @@ -983,4 +1028,8 @@ public IndexResult<T> getResult() {
public void setResult(IndexResult<T> result) {
this.result = result;
}

public void setPersistSelections(boolean persistSelections) {
this.persistSelections = persistSelections;
}
}

0 comments on commit 512913c

Please sign in to comment.