001/* 002 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Anahide Tchertchian 018 */ 019package org.nuxeo.ecm.platform.query.api; 020 021import java.util.ArrayList; 022import java.util.Collection; 023import java.util.List; 024 025/** 026 * List of {@link PageSelection} elements. 027 * 028 * @author Anahide Tchertchian 029 */ 030public class PageSelections<T> { 031 032 protected String name; 033 034 protected boolean selected; 035 036 protected List<PageSelection<T>> entries; 037 038 public PageSelections() { 039 super(); 040 } 041 042 public PageSelections(Collection<? extends PageSelection<T>> c) { 043 super(); 044 if (c != null) { 045 this.entries = new ArrayList<PageSelection<T>>(c); 046 } 047 } 048 049 public void setName(String name) { 050 this.name = name; 051 } 052 053 public String getName() { 054 return name; 055 } 056 057 public void setSelected(boolean selected) { 058 this.selected = selected; 059 if (entries != null) { 060 for (PageSelection<T> item : entries) { 061 item.setSelected(selected); 062 } 063 } 064 } 065 066 public boolean isSelected() { 067 return selected; 068 } 069 070 public List<PageSelection<T>> getEntries() { 071 return entries; 072 } 073 074 public void setEntries(List<PageSelection<T>> entries) { 075 this.entries = entries; 076 } 077 078 /** 079 * @since 6.0 080 */ 081 public void add(PageSelection<T> entry) { 082 if (entries == null) { 083 entries = new ArrayList<>(); 084 } 085 entries.add(entry); 086 } 087 088 public int getSize() { 089 if (entries == null) { 090 return 0; 091 } else { 092 return entries.size(); 093 } 094 } 095 096 /** 097 * @deprecated just here for compatibility with SelectDatamodel methods, use {@link #getSize()} instead 098 */ 099 @Deprecated 100 public int getRowCount() { 101 return getSize(); 102 } 103 104 /** 105 * @deprecated just here for compatibility with SelectDatamodel methods, use {@link #getEntries()} instead 106 */ 107 @Deprecated 108 public List<PageSelection<T>> getRows() { 109 return getEntries(); 110 } 111 112 /** 113 * @since 7.4 114 */ 115 public boolean isEmpty() { 116 return getSize() == 0; 117 } 118}