Changeset 4542


Ignore:
Timestamp:
02/20/14 16:29:00 (10 years ago)
Author:
twagoo
Message:

Refactored FacetSelection?, now an interface with the wicket model implementing it itself

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

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/pojo/FacetSelection.java

    r4540 r4542  
    1515 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
     17
    1718package eu.clarin.cmdi.vlo.pojo;
    1819
    19 import java.io.Serializable;
    2020import java.util.List;
    21 import java.util.concurrent.CopyOnWriteArrayList;
    22 import org.apache.wicket.model.IModel;
    2321
    2422/**
     
    2624 * @author twagoo
    2725 */
    28 public class FacetSelection implements Serializable {
     26public interface FacetSelection {
    2927
    30     private final String facet;
    31     private final IModel<QueryFacetsSelection> selectionModel;
     28    String getFacet();
    3229
    33     public FacetSelection(String facet, IModel<QueryFacetsSelection> selectionModel) {
    34         this.facet = facet;
    35         this.selectionModel = selectionModel;
    36     }
     30    List<String> getFacetValues();
    3731
    38     public String getFacet() {
    39         return facet;
    40     }
    41 
    42     public QueryFacetsSelection getSelection() {
    43         return selectionModel.getObject();
    44     }
    45 
    46     public List<String> getFacetValues() {
    47         return new CopyOnWriteArrayList<String>(getSelection().getSelectionValues(facet));
    48     }
    49 
     32    QueryFacetsSelection getSelection();
     33   
    5034}
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/components/FacetsPanel.java

    r4540 r4542  
    1717package eu.clarin.cmdi.vlo.wicket.components;
    1818
    19 import eu.clarin.cmdi.vlo.pojo.FacetSelection;
     19import eu.clarin.cmdi.vlo.wicket.model.FacetSelectionModel;
    2020import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    2121import eu.clarin.cmdi.vlo.service.FacetFieldsService;
     
    2929import org.apache.wicket.markup.repeater.data.DataView;
    3030import org.apache.wicket.model.IModel;
    31 import org.apache.wicket.model.Model;
    3231import org.apache.wicket.spring.injection.annot.SpringBean;
    3332
     
    9695
    9796    private SelectedFacetPanel createSelectedFacetPanel(String facetName) {
    98         final FacetSelection selection = new FacetSelection(facetName, model);
    99         return new SelectedFacetPanel("facet", new Model(selection)) {
     97        return new SelectedFacetPanel("facet", new FacetSelectionModel(facetName, model)) {
    10098
    10199            @Override
  • vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/model/FacetSelectionModel.java

    r4540 r4542  
    1515 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1616 */
    17 package eu.clarin.cmdi.vlo.pojo;
     17package eu.clarin.cmdi.vlo.wicket.model;
    1818
    19 import java.io.Serializable;
     19import eu.clarin.cmdi.vlo.pojo.FacetSelection;
     20import eu.clarin.cmdi.vlo.pojo.QueryFacetsSelection;
    2021import java.util.List;
    2122import java.util.concurrent.CopyOnWriteArrayList;
     23import org.apache.wicket.model.AbstractReadOnlyModel;
    2224import org.apache.wicket.model.IModel;
    2325
    2426/**
     27 * Model for FacetSelection that simply wraps a QueryFacetsSelection model and
     28 * 'filters' for the specified facet
    2529 *
    2630 * @author twagoo
    2731 */
    28 public class FacetSelection implements Serializable {
     32public class FacetSelectionModel extends AbstractReadOnlyModel<FacetSelection> implements FacetSelection {
    2933
    3034    private final String facet;
    3135    private final IModel<QueryFacetsSelection> selectionModel;
    3236
    33     public FacetSelection(String facet, IModel<QueryFacetsSelection> selectionModel) {
     37    /**
     38     *
     39     * @param facet facet to represent selection for
     40     * @param selectionModel broad (multi-facet) selection model
     41     */
     42    public FacetSelectionModel(String facet, IModel<QueryFacetsSelection> selectionModel) {
    3443        this.facet = facet;
    3544        this.selectionModel = selectionModel;
    3645    }
    3746
     47    @Override
    3848    public String getFacet() {
    3949        return facet;
    4050    }
    4151
     52    @Override
     53    public List<String> getFacetValues() {
     54        return new CopyOnWriteArrayList<String>(getSelection().getSelectionValues(facet));
     55    }
     56
     57    @Override
    4258    public QueryFacetsSelection getSelection() {
    4359        return selectionModel.getObject();
    4460    }
    4561
    46     public List<String> getFacetValues() {
    47         return new CopyOnWriteArrayList<String>(getSelection().getSelectionValues(facet));
     62    @Override
     63    public FacetSelection getObject() {
     64        return this;
     65    }
     66
     67    @Override
     68    public void detach() {
     69        selectionModel.detach();
    4870    }
    4971
Note: See TracChangeset for help on using the changeset viewer.