001/* 002 * Copyright 2018 Anyware Services 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 */ 016package org.ametys.plugins.repository.model; 017 018import java.util.Map; 019 020import org.apache.cocoon.ProcessingException; 021 022import org.ametys.runtime.i18n.I18nizableText; 023import org.ametys.runtime.model.ModelItemGroup; 024 025/** 026 * Definition of a repeater. 027 */ 028public class RepeaterDefinition extends ModelItemGroup 029{ 030 /** Repeater type */ 031 public static final String TYPE = "repeater"; 032 033 private int _initializeSize; 034 private int _minSize; 035 private int _maxSize; 036 private I18nizableText _addLabel; 037 private I18nizableText _delLabel; 038 private String _headerLabel; 039 040 /** 041 * Retrieves the initial size. 042 * @return the initial size. 043 */ 044 public int getInitialSize() 045 { 046 return _initializeSize; 047 } 048 049 /** 050 * Set the initial size. 051 * @param size the initial size. 052 */ 053 public void setInitialSize(int size) 054 { 055 _initializeSize = size; 056 } 057 058 /** 059 * Retrieves the minimum size. 060 * @return the minimum size. 061 */ 062 public int getMinSize() 063 { 064 return _minSize; 065 } 066 067 /** 068 * Set the minimum size. 069 * @param size the minimum size. 070 */ 071 public void setMinSize(int size) 072 { 073 _minSize = size; 074 } 075 076 /** 077 * Retrieves the maximum size. 078 * @return the maximum size or <code>-1</code> if unbounded. 079 */ 080 public int getMaxSize() 081 { 082 return _maxSize; 083 } 084 085 /** 086 * Set the maximum size. 087 * @param size the maximum size or <code>-1</code> if unbounded. 088 */ 089 public void setMaxSize(int size) 090 { 091 _maxSize = size; 092 } 093 094 /** 095 * Retrieves the add label. 096 * @return the add label or <code>null</code> if none. 097 */ 098 public I18nizableText getAddLabel() 099 { 100 return _addLabel; 101 } 102 103 /** 104 * Set the add label. 105 * @param label the add label or <code>null</code> if none. 106 */ 107 public void setAddLabel(I18nizableText label) 108 { 109 _addLabel = label; 110 } 111 112 /** 113 * Retrieves the delete label. 114 * @return the delete label or <code>null</code> if none. 115 */ 116 public I18nizableText getDeleteLabel() 117 { 118 return _delLabel; 119 } 120 121 /** 122 * Set the delete label. 123 * @param label the delete label or <code>null</code> if none. 124 */ 125 public void setDeleteLabel(I18nizableText label) 126 { 127 _delLabel = label; 128 } 129 130 /** 131 * Get the header label. 132 * @return the header label or <code>null</code> if none. 133 */ 134 public String getHeaderLabel() 135 { 136 return _headerLabel; 137 } 138 139 /** 140 * Set the header label. 141 * @param label the header label or <code>null</code> if none. 142 */ 143 public void setHeaderLabel(String label) 144 { 145 _headerLabel = label; 146 } 147 148 @Override 149 public Map<String, Object> toJSON(boolean includeChildren) throws ProcessingException 150 { 151 Map<String, Object> result = super.toJSON(includeChildren); 152 153 result.put("type", TYPE); 154 result.put("add-label", getAddLabel()); 155 result.put("del-label", getDeleteLabel()); 156 result.put("header-label", getHeaderLabel()); 157 result.put("initial-size", getInitialSize()); 158 result.put("min-size", getMinSize()); 159 160 if (getMaxSize() >= 0) 161 { 162 result.put("max-size", getMaxSize()); 163 } 164 165 return result; 166 } 167}