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 09f25642..e3fd42c5 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 @@ -1,5 +1,6 @@ package com.databasepreservation.common.client.common.dialogs; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -20,6 +21,7 @@ import com.databasepreservation.common.client.index.filter.OneOfManyFilterParameter; import com.databasepreservation.common.client.index.filter.SimpleFilterParameter; import com.databasepreservation.common.client.index.select.SelectedItems; +import com.databasepreservation.common.client.index.select.SelectedItemsFilter; import com.databasepreservation.common.client.index.select.SelectedItemsList; import com.databasepreservation.common.client.index.sort.Sorter; import com.databasepreservation.common.client.models.structure.ViewerDatabase; @@ -92,7 +94,6 @@ public void init(Filter defaultFilter, String allFilter, ClientMessages messages } }); this.list = metadataDatabaseList; - metadataDatabaseList.addSelectedResetListener(this::doParentSearch); return metadataDatabaseList; }, new AsyncTableCellOptions<>(ViewerDatabase.class, "DatabaseList_metadata")); @@ -156,7 +157,7 @@ public void resetExcludedInfo() { public void updateExcludedInfo() { this.exludedInfo .setWidget(new HTML(SafeHtmlUtils.fromSafeConstant(messages.manageDatabaseSearchAllExcludedLoaded(this.notLoaded) - + messages.manageDatabaseSearchAllExcludedPrivacy(this.notSearchable)))); + + " " + messages.manageDatabaseSearchAllExcludedPrivacy(this.notSearchable)))); } public void writeSelectedObjectsToLocalStorage() { @@ -166,9 +167,10 @@ public void writeSelectedObjectsToLocalStorage() { if (selectedItems instanceof SelectedItemsList) { localStorage.setItem(ViewerConstants.LOCAL_STORAGE_SEARCHALL_SELECTION, String.join(",", ((SelectedItemsList) selectedItems).getIds())); + } else if (selectedItems instanceof SelectedItemsFilter) { + localStorage.setItem(ViewerConstants.LOCAL_STORAGE_SEARCHALL_SELECTION, ViewerConstants.SEARCHALL_SELECTEDALL); } } - this.list.resetSelected(); } public void clearSelectedObjectsInLocalStorage() { @@ -176,11 +178,11 @@ public void clearSelectedObjectsInLocalStorage() { if (localStorage != null) { localStorage.removeItem(ViewerConstants.LOCAL_STORAGE_SEARCHALL_SELECTION); } - this.list.resetSelected(); } private void confirmHandler() { this.writeSelectedObjectsToLocalStorage(); + this.doParentSearch(); this.hide(); } @@ -190,23 +192,44 @@ private void cancelHandler() { private void clearHandler() { this.clearSelectedObjectsInLocalStorage(); + this.doParentSearch(); this.hide(); } - private void doParentSearch(List selectedUUIDs) { + private void doParentSearch() { + Storage localStorage = Storage.getLocalStorageIfSupported(); + List selectedUUIDs = null; + boolean selectedAll = false; + if (localStorage != null) { + String uuidsString = localStorage.getItem(ViewerConstants.LOCAL_STORAGE_SEARCHALL_SELECTION); + if (uuidsString != null) { + if (uuidsString.equals(ViewerConstants.SEARCHALL_SELECTEDALL)) { + selectedAll = true; + } else { + selectedUUIDs = new ArrayList<>(); + if (!uuidsString.isEmpty()) { + Collections.addAll(selectedUUIDs, uuidsString.split(",")); + } + } + } + } if (selectedUUIDs != null) { Filter newFilter = new Filter(this.defaultFilter); newFilter.add(new OneOfManyFilterParameter(ViewerConstants.SOLR_ROWS_DATABASE_UUID, selectedUUIDs)); this.parentSearchPanel.setSearchAllTotalDatabases((long) selectedUUIDs.size()); this.parentSearchPanel.setDefaultFilter(newFilter); this.parentSearchPanel.doSearch(); + } else if (selectedAll || ClientConfigurationManager + .getStringWithDefault(ViewerConstants.SEARCHALL_SELECTEDALL, ViewerConstants.PROPERTY_SEARCHALL_DEFAULTSELECTION) + .equals(ViewerConstants.SEARCHALL_SELECTEDALL)) { + this.parentSearchPanel.setSearchAllTotalDatabases(this.list.getResult().getTotalCount()); + this.parentSearchPanel.setDefaultFilter(defaultFilter); + this.parentSearchPanel.doSearch(); } else { - if (ClientConfigurationManager.getStringWithDefault(ViewerConstants.SEARCHALL_SELECTEDALL, - ViewerConstants.PROPERTY_SEARCHALL_DEFAULTSELECTION).equals(ViewerConstants.SEARCHALL_SELECTEDALL)) { - this.parentSearchPanel.setSearchAllTotalDatabases(this.list.getResult().getTotalCount()); - this.parentSearchPanel.setDefaultFilter(defaultFilter); - this.parentSearchPanel.doSearch(); - } + this.parentSearchPanel.setSearchAllTotalDatabases(0L); + this.parentSearchPanel.setDefaultFilter(defaultFilter); + this.parentSearchPanel.doSearch(); + } } } 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 e8ca9e9e..2ca97726 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 @@ -7,10 +7,7 @@ */ package com.databasepreservation.common.client.common.lists; -import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; @@ -28,8 +25,6 @@ import com.databasepreservation.common.client.index.IndexResult; import com.databasepreservation.common.client.index.facets.Facets; import com.databasepreservation.common.client.index.filter.Filter; -import com.databasepreservation.common.client.index.select.SelectedItems; -import com.databasepreservation.common.client.index.select.SelectedItemsList; import com.databasepreservation.common.client.index.sort.Sorter; import com.databasepreservation.common.client.models.structure.ViewerDatabase; import com.databasepreservation.common.client.models.user.User; @@ -40,7 +35,6 @@ import com.google.gwt.i18n.client.LocaleInfo; import com.google.gwt.safehtml.shared.SafeHtml; import com.google.gwt.safehtml.shared.SafeHtmlUtils; -import com.google.gwt.storage.client.Storage; import com.google.gwt.user.cellview.client.CellTable; import com.google.gwt.user.cellview.client.Column; import com.google.gwt.user.cellview.client.ColumnSortList; @@ -58,31 +52,12 @@ public class DatabaseSelectList extends BasicAsyncTableCell { private static final String OPEN_VALIDATED_SPAN = ""; private static final String OPEN_NOT_VALIDATED_SPAN = ""; - private String localStorageSelectedId; - private Collection savedSelectedUUIDs; - private List selectedResetListeners; - public DatabaseSelectList() { this(new Filter(), null, null, false, false); } public DatabaseSelectList(Filter filter, Facets facets, String summary, boolean selectable, boolean exportable) { super(filter, facets, summary, selectable, exportable, 15, 15); - this.localStorageSelectedId = localStorageSelectedId; - loadSavedSelectedUUIDsFromLocalStorage(); - addValueChangeHandler(event -> resetSelected()); - this.selectedResetListeners = new ArrayList<>(); - } - - private void loadSavedSelectedUUIDsFromLocalStorage() { - this.savedSelectedUUIDs = new ArrayList<>(); - Storage storage = Storage.getLocalStorageIfSupported(); - String storageString = storage.getItem(ViewerConstants.LOCAL_STORAGE_SEARCHALL_SELECTION); - if (storageString != null) { - this.savedSelectedUUIDs.addAll(List.of(storageString.split(","))); - } else { - this.savedSelectedUUIDs = null; - } } @Override @@ -196,41 +171,4 @@ protected void getData(Sublist sublist, ColumnSortList columnSortList, public void exportClickHandler() { // do nothing } - - public void resetSelected() { - loadSavedSelectedUUIDsFromLocalStorage(); - if (this.savedSelectedUUIDs != null) { - setSelectedByUUIDs(this.savedSelectedUUIDs); - } else { - setSelected(new HashSet<>()); - redraw(); - fireOnCheckboxSelectionChanged(); - } - SelectedItems selectedItems = getSelected(); - List selectedUUIDs; - if (this.savedSelectedUUIDs != null && selectedItems instanceof SelectedItemsList) { - selectedUUIDs = new ArrayList<>(((SelectedItemsList) selectedItems).getIds()); - } else { - selectedUUIDs = null; - } - for (SelectedResetListener listener : this.selectedResetListeners) { - listener.onSelectionChange(selectedUUIDs); - } - } - - @Override - public void refresh() { - super.refresh(); - resetSelected(); - } - - // LISTENER - - public interface SelectedResetListener { - void onSelectionChange(List selected); - } - - public void addSelectedResetListener(SelectedResetListener listener) { - this.selectedResetListeners.add(listener); - } } 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 64b0b81b..513cdcca 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 @@ -664,10 +664,6 @@ public void setSelectedByUUIDs(Iterable databaseUUIDs) { fireOnCheckboxSelectionChanged(); } - public void setSelectedAll() { - this.selectAllCheckBox.setValue(true); - } - public void clearSelected() { selected.clear(); redraw(); diff --git a/src/main/java/com/databasepreservation/common/client/common/search/SearchAllButtonWrapper.java b/src/main/java/com/databasepreservation/common/client/common/search/SearchAllButtonWrapper.java index 416d74f2..0c25d5f5 100644 --- a/src/main/java/com/databasepreservation/common/client/common/search/SearchAllButtonWrapper.java +++ b/src/main/java/com/databasepreservation/common/client/common/search/SearchAllButtonWrapper.java @@ -28,6 +28,7 @@ public void init(Filter defaultFilter, String allFilter, ClientMessages messages this.messages = messages; this.button = new Button(); this.button.addStyleName("btn-link-info btn btn-searchall-dialog"); + setTotalSelectedDatabases(0L); this.databaseSelectDialog = new DatabaseSelectDialog(defaultFilter, allFilter, messages, parentSearchPanel); this.button.addClickHandler(event -> { this.databaseSelectDialog.center(); diff --git a/src/main/java/com/databasepreservation/common/client/common/search/SearchWrapper.java b/src/main/java/com/databasepreservation/common/client/common/search/SearchWrapper.java index 0b25444f..c7c5416c 100644 --- a/src/main/java/com/databasepreservation/common/client/common/search/SearchWrapper.java +++ b/src/main/java/com/databasepreservation/common/client/common/search/SearchWrapper.java @@ -145,8 +145,9 @@ private void attachComponents(String objectClassSimpleName rootPanel.clear(); rootPanel.add(searchPanel); + if (!(searchPanel instanceof SearchPanelWithSearchAll) - || !((SearchPanelWithSearchAll) searchPanel).getTotalSelected().equals("0")) { + || ((SearchPanelWithSearchAll) searchPanel).getTotalSelected() != 0) { if (scrollPanelCssClasses != null) { ScrollPanel scrollPanel = new ScrollPanel(list); scrollPanel.addStyleName(scrollPanelCssClasses);