Changeset 4924


Ignore:
Timestamp:
04/08/14 15:34:30 (10 years ago)
Author:
Twan Goosen
Message:

Created 'single facet panel' from collection panel in faceted search page so that it can be reused more easily

Location:
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/pages/FacetedSearchPage.java

    r4913 r4924  
    11package eu.clarin.cmdi.vlo.wicket.pages;
    22
     3import eu.clarin.cmdi.vlo.wicket.panels.SingleFacetPanel;
    34import eu.clarin.cmdi.vlo.config.VloConfig;
    4 import eu.clarin.cmdi.vlo.pojo.ExpansionState;
    55import eu.clarin.cmdi.vlo.wicket.panels.search.FacetsPanel;
    66import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
     
    1010import eu.clarin.cmdi.vlo.wicket.components.SearchForm;
    1111import eu.clarin.cmdi.vlo.wicket.panels.search.SearchResultsPanel;
    12 import eu.clarin.cmdi.vlo.wicket.model.FacetFieldModel;
    1312import eu.clarin.cmdi.vlo.wicket.model.FacetFieldsModel;
    14 import eu.clarin.cmdi.vlo.wicket.model.FacetSelectionModel;
    1513import eu.clarin.cmdi.vlo.wicket.panels.BreadCrumbPanel;
    1614import eu.clarin.cmdi.vlo.wicket.panels.search.FacetValuesPanel;
     
    3432
    3533    private static final long serialVersionUID = 1L;
    36    
     34
    3735    @SpringBean
    3836    private FacetFieldsService facetFieldsService;
     
    105103
    106104    private Panel createCollectionsPanel(final String id) {
    107         final IModel<QueryFacetsSelection> queryModel = getModel();
    108         final FacetFieldModel collectionFacetFieldModel = new FacetFieldModel(facetFieldsService, vloConfig.getCollectionFacet(), queryModel, FacetValuesPanel.MAX_NUMBER_OF_FACETS_TO_SHOW);
    109         final FacetSelectionModel collectionSelectionModel = new FacetSelectionModel(collectionFacetFieldModel, queryModel);
    110         final FacetPanel panel = new FacetPanel(id, collectionSelectionModel, new Model<ExpansionState>(ExpansionState.COLLAPSED)) {
     105        final FacetPanel panel = new SingleFacetPanel(id, getModel(), vloConfig.getCollectionFacet(), facetFieldsService) {
    111106
    112107            @Override
    113108            protected void selectionChanged(AjaxRequestTarget target) {
    114109                updateSelection(target);
    115             }
    116 
    117             @Override
    118             protected boolean isHideIfNoValues() {
    119                 // collections facets should always be visible, even if no
    120                 // values are present (due to no search results)
    121                 return false;
    122110            }
    123111
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/FacetPanel.java

    r4872 r4924  
    2929import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxFallbackLink;
    3030import org.apache.wicket.markup.html.basic.Label;
    31 import org.apache.wicket.markup.html.panel.Panel;
     31import org.apache.wicket.markup.html.panel.GenericPanel;
    3232import org.apache.wicket.model.AbstractReadOnlyModel;
    3333import org.apache.wicket.model.IModel;
     
    4242 * @author twagoo
    4343 */
    44 public abstract class FacetPanel extends Panel {
    45 
    46     private final IModel<FacetSelection> selectionModel;
     44public abstract class FacetPanel extends GenericPanel<FacetSelection> {
     45
    4746    private final IModel<ExpansionState> expansionStateModel;
    4847
     
    5352        super(id, selectionModel);
    5453
    55         this.selectionModel = selectionModel;
    5654        this.expansionStateModel = expansionState;
    5755
     
    8987
    9088        // Facet name becomes title
    91         titleLink.add(new Label("title", new SolrFieldNameModel(new PropertyModel(selectionModel, "facetField.name"))));
     89        titleLink.add(new Label("title", new SolrFieldNameModel(new PropertyModel(getModel(), "facetField.name"))));
    9290        return titleLink;
    9391    }
     
    9795        super.onConfigure();
    9896
    99         final boolean valuesSelected = !selectionModel.getObject().getFacetValues().isEmpty();
     97        final boolean valuesSelected = !getModelObject().getFacetValues().isEmpty();
    10098        facetValuesPanel.setVisible(!valuesSelected);
    10199        selectedFacetPanel.setVisible(valuesSelected);
    102100
    103101        // hide this entire panel is no values are selectable
    104         setVisible(!isHideIfNoValues() || valuesSelected || selectionModel.getObject().getFacetField().getValueCount() > 0);
     102        setVisible(!isHideIfNoValues() || valuesSelected || getModelObject().getFacetField().getValueCount() > 0);
    105103    }
    106104
     
    116114    private FacetValuesPanel createFacetValuesPanel(String id) {
    117115        return new FacetValuesPanel(id,
    118                 new PropertyModel<FacetField>(selectionModel, "facetField"),
    119                 new PropertyModel<QueryFacetsSelection>(selectionModel, "selection")) {
     116                new PropertyModel<FacetField>(getModel(), "facetField"),
     117                new PropertyModel<QueryFacetsSelection>(getModel(), "selection")) {
    120118                    @Override
    121119                    public void onValuesSelected(String facet, Collection<String> value, AjaxRequestTarget target) {
    122120                        // A value has been selected on this facet's panel, update the model!
    123                         selectionModel.getObject().getSelection().selectValues(facet, value);
     121                        FacetPanel.this.getModelObject().getSelection().selectValues(facet, value);
    124122                        if (target != null) {
    125123                            // reload entire page for now
     
    131129
    132130    private SelectedFacetPanel createSelectedFacetPanel(String id) {
    133         return new SelectedFacetPanel(id, selectionModel) {
     131        return new SelectedFacetPanel(id, getModel()) {
    134132            @Override
    135133            public void onValuesUnselected(String facet, Collection<String> valuesRemoved, AjaxRequestTarget target) {
    136                 final QueryFacetsSelection selection = selectionModel.getObject().getSelection();
     134                final QueryFacetsSelection selection = getModelObject().getSelection();
    137135
    138136                // Values have been removed, calculate remainder
Note: See TracChangeset for help on using the changeset viewer.