Skip to content

Commit

Permalink
Allowing to reset search facets by click.
Browse files Browse the repository at this point in the history
  • Loading branch information
tHerrmann committed Mar 28, 2019
1 parent 5a85fd3 commit 398f039
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions src/org/opencms/ui/apps/lists/CmsResultFacets.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.GridLayout;
import com.vaadin.v7.ui.Label;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.UI;
import com.vaadin.v7.ui.VerticalLayout;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ValoTheme;

/**
Expand All @@ -73,6 +73,9 @@ public class CmsResultFacets extends VerticalLayout {
/** The logger for this class. */
private static final Log LOG = CmsLog.getLog(CmsResultFacets.class.getName());

/** Style name indicating a facet is selected. */
private static final String SELECTED_STYLE = ValoTheme.LABEL_BOLD;

/** The serial version id. */
private static final long serialVersionUID = 7190928063356086124L;

Expand All @@ -97,6 +100,7 @@ public class CmsResultFacets extends VerticalLayout {
* @param manager the list manager instance
*/
public CmsResultFacets(CmsListManager manager) {

m_manager = manager;
m_selectedFieldFacets = new HashMap<String, List<String>>();
m_selectedRangeFacets = new HashMap<String, List<String>>();
Expand Down Expand Up @@ -159,6 +163,27 @@ protected Map<String, List<String>> getSelectedRangeFactes() {
return m_selectedRangeFacets;
}

/**
* Returns whether the given component is selected.<p>
*
* @param component the component
*
* @return <code>true</code> in case selected
*/
boolean isSelected(Component component) {

return component.getStyleName().contains(SELECTED_STYLE);
}

/**
* Resets the selected facets and triggers a new search.<p>
*/
void resetFacetsAndSearch() {

resetFacets();
m_manager.search(m_selectedFieldFacets, m_selectedRangeFacets);
}

/**
* Selects the given field facet.<p>
*
Expand Down Expand Up @@ -304,15 +329,19 @@ private Component prepareCategoryFacets(CmsSolrResultList solrResultList, CmsSea
cat.addStyleName(ValoTheme.BUTTON_BORDERLESS);
Boolean selected = facetController.getState().getIsChecked().get(value.getName());
if ((selected != null) && selected.booleanValue()) {
cat.addStyleName(ValoTheme.LABEL_BOLD);
cat.addStyleName(SELECTED_STYLE);
}
cat.addClickListener(new ClickListener() {

private static final long serialVersionUID = 1L;

public void buttonClick(ClickEvent event) {

selectFieldFacet(CmsListManager.FIELD_CATEGORIES, value.getName());
if (isSelected(event.getComponent())) {
resetFacetsAndSearch();
} else {
selectFieldFacet(CmsListManager.FIELD_CATEGORIES, value.getName());
}
}
});
catLayout.addComponent(cat);
Expand Down Expand Up @@ -362,15 +391,19 @@ private Component prepareDateFacets(CmsSolrResultList solrResultList, CmsSearchR
date.addStyleName(ValoTheme.BUTTON_BORDERLESS);
Boolean selected = facetController.getState().getIsChecked().get(value.getValue());
if ((selected != null) && selected.booleanValue()) {
date.addStyleName(ValoTheme.LABEL_BOLD);
date.addStyleName(SELECTED_STYLE);
}
date.addClickListener(new ClickListener() {

private static final long serialVersionUID = 1L;

public void buttonClick(ClickEvent event) {

selectRangeFacet(CmsListManager.FIELD_DATE_FACET_NAME, value.getValue());
if (isSelected(event.getComponent())) {
resetFacetsAndSearch();
} else {
selectRangeFacet(CmsListManager.FIELD_DATE_FACET_NAME, value.getValue());
}
}
});
int targetColumn;
Expand Down Expand Up @@ -414,15 +447,19 @@ private Component prepareFolderFacets(CmsSolrResultList solrResultList, CmsSearc
folder.addStyleName(ValoTheme.BUTTON_BORDERLESS);
Boolean selected = facetController.getState().getIsChecked().get(value.getName());
if ((selected != null) && selected.booleanValue()) {
folder.addStyleName(ValoTheme.LABEL_BOLD);
folder.addStyleName(SELECTED_STYLE);
}
folder.addClickListener(new ClickListener() {

private static final long serialVersionUID = 1L;

public void buttonClick(ClickEvent event) {

selectFieldFacet(CmsListManager.FIELD_PARENT_FOLDERS, value.getName());
if (isSelected(event.getComponent())) {
resetFacetsAndSearch();
} else {
selectFieldFacet(CmsListManager.FIELD_PARENT_FOLDERS, value.getName());
}
}
});
folderLayout.addComponent(folder);
Expand Down

0 comments on commit 398f039

Please sign in to comment.