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.runtime.model; 017 018import java.util.ArrayList; 019import java.util.Collections; 020import java.util.List; 021 022/** 023 * Abstract class for group of view items 024 */ 025public abstract class AbstractViewItemGroup implements ViewItemGroup 026{ 027 /** The role of the view item group */ 028 protected String _role; 029 030 /** The view item group's children */ 031 protected List<ViewItem> _children = new ArrayList<>(); 032 033 public String getRole() 034 { 035 return _role; 036 } 037 038 public void setRole(String role) 039 { 040 _role = role; 041 } 042 043 public List<ViewItem> getViewItems() 044 { 045 return Collections.unmodifiableList(_children); 046 } 047 048 public void addViewItem(ViewItem item) 049 { 050 _children.add(item); 051 } 052 053 public void insertViewItem(ViewItem item, int index) 054 { 055 if (index >= 0 && index < _children.size()) 056 { 057 _children.add(index, item); 058 } 059 else 060 { 061 throw new IllegalArgumentException("Unable to insert an item at index " + index + ". This group contains " + _children.size() + "items."); 062 } 063 } 064}