diff --git a/src/main/java/com/databasepreservation/common/client/common/dialogs/DatabaseSelectDialog.java b/src/main/java/com/databasepreservation/common/client/common/dialogs/DatabaseSelectDialog.java index ba00f866..39bb1c53 100644 --- a/src/main/java/com/databasepreservation/common/client/common/dialogs/DatabaseSelectDialog.java +++ b/src/main/java/com/databasepreservation/common/client/common/dialogs/DatabaseSelectDialog.java @@ -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; @@ -48,10 +49,6 @@ public class DatabaseSelectDialog extends DialogBox { private SearchWrapper databasesSearchWrapper; private SearchPanelWithSearchAll parentSearchPanel; private Filter defaultFilter; - private String listId; - - // private Collection selectedUUIDs; - // private long totalSelectedObjects; private long notLoaded; private long notSearchable; @@ -85,19 +82,21 @@ public void init(Filter defaultFilter, String allFilter, ClientMessages messages description.add(new SimplePanel(new Label(messages.manageDatabaseSearchAllContactInfo()))); ListBuilder 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; @@ -193,9 +192,7 @@ private void cancelHandler() { } private void clearHandler() { - this.clearSelectedObjectsInLocalStorage(); - this.doParentSearch(); - this.hide(); + this.list.setSelected(new HashSet<>()); } private void doParentSearch() { diff --git a/src/main/java/com/databasepreservation/common/client/common/lists/DatabaseSelectList.java b/src/main/java/com/databasepreservation/common/client/common/lists/DatabaseSelectList.java index 2ca97726..043c908f 100644 --- a/src/main/java/com/databasepreservation/common/client/common/lists/DatabaseSelectList.java +++ b/src/main/java/com/databasepreservation/common/client/common/lists/DatabaseSelectList.java @@ -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 diff --git a/src/main/java/com/databasepreservation/common/client/common/lists/utils/AsyncTableCell.java b/src/main/java/com/databasepreservation/common/client/common/lists/utils/AsyncTableCell.java index 513cdcca..1b84dd84 100644 --- a/src/main/java/com/databasepreservation/common/client/common/lists/utils/AsyncTableCell.java +++ b/src/main/java/com/databasepreservation/common/client/common/lists/utils/AsyncTableCell.java @@ -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; @@ -109,6 +110,8 @@ protected enum TextAlign { private Column selectColumn; private Set selected = new HashSet(); + private boolean persistSelections = false; + private Set persistedSelectedUUIDs = new HashSet<>(); private final List> listeners = new ArrayList>(); private Filter filter; @@ -312,15 +315,25 @@ private void configure(final CellTable display) { selectColumn = new Column(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 @@ -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 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; @@ -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(); } @@ -628,8 +666,12 @@ public SelectedItems getSelected() { } else { List 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(ids, selectedClass.getName()); @@ -638,18 +680,18 @@ public SelectedItems getSelected() { return ret; } - public Set getSelectedObjects() { - return selected; - } - public void setSelected(Set newSelected) { selected.clear(); selected.addAll(newSelected); + persistedSelectedUUIDs.clear(); + for (T selectedObject : newSelected) { + persistedSelectedUUIDs.add(selectedObject.getUuid()); + } redraw(); fireOnCheckboxSelectionChanged(); } - public void setSelectedByUUIDs(Iterable databaseUUIDs) { + public void setSelectedByUUIDs(Collection databaseUUIDs) { this.selected.clear(); HashMap resultsMap = new HashMap<>(); for (T resultsObject : this.result.getResults()) { @@ -660,12 +702,15 @@ public void setSelectedByUUIDs(Iterable 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(); } @@ -983,4 +1028,8 @@ public IndexResult getResult() { public void setResult(IndexResult result) { this.result = result; } + + public void setPersistSelections(boolean persistSelections) { + this.persistSelections = persistSelections; + } }