001package com.hfg.javascript.ext; 002 003import com.hfg.xml.XMLTag; 004 005import java.util.ArrayList; 006import java.util.Collection; 007import java.util.List; 008 009//------------------------------------------------------------------------------ 010/** 011 An ordered and named collection of ExtJs grid columns. 012 <div> 013 @author J. Alex Taylor, hairyfatguy.com 014 </div> 015 */ 016//------------------------------------------------------------------------------ 017// com.hfg Library 018// 019// This library is free software; you can redistribute it and/or 020// modify it under the terms of the GNU Lesser General Public 021// License as published by the Free Software Foundation; either 022// version 2.1 of the License, or (at your option) any later version. 023// 024// This library is distributed in the hope that it will be useful, 025// but WITHOUT ANY WARRANTY; without even the implied warranty of 026// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 027// Lesser General Public License for more details. 028// 029// You should have received a copy of the GNU Lesser General Public 030// License along with this library; if not, write to the Free Software 031// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 032// 033// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 034// jataylor@hairyfatguy.com 035//------------------------------------------------------------------------------ 036 037public class ExtGridColList extends ArrayList<ExtGridCol> 038{ 039 private String mName; 040 041 042 private static final String XML_TAG_NAME = "ExtGridColList"; 043 private static final String XML_COLUMNS = "Columns"; 044 private static final String XML_NAME_ATT = "name"; 045 046 //########################################################################## 047 // CONSTRUCTORS 048 //########################################################################## 049 050 //-------------------------------------------------------------------------- 051 public ExtGridColList() 052 { 053 super(); 054 } 055 056 //-------------------------------------------------------------------------- 057 public ExtGridColList(int inInitialSize) 058 { 059 super(inInitialSize); 060 } 061 062 //-------------------------------------------------------------------------- 063 public ExtGridColList(Collection<ExtGridCol> inValues) 064 { 065 super(inValues); 066 } 067 068 //-------------------------------------------------------------------------- 069 public ExtGridColList(XMLTag inXMLTag) 070 { 071 this(); 072 073 inXMLTag.verifyTagName(XML_TAG_NAME); 074 075 setName(inXMLTag.getAttributeValue(XML_NAME_ATT)); 076 077 XMLTag columnsTag = inXMLTag.getOptionalSubtagByName(XML_COLUMNS); 078 if (columnsTag != null) 079 { 080 for (XMLTag subtag : (List<XMLTag>) (Object) columnsTag.getSubtags()) 081 { 082 add(new ExtGridCol(subtag)); 083 } 084 } 085 } 086 087 //########################################################################## 088 // PUBLIC METHODS 089 //########################################################################## 090 091 //-------------------------------------------------------------------------- 092 public String name() 093 { 094 return mName; 095 } 096 097 //-------------------------------------------------------------------------- 098 public ExtGridColList setName(String inValue) 099 { 100 mName = inValue; 101 return this; 102 } 103 104 //-------------------------------------------------------------------------- 105 public XMLTag toXMLTag() 106 { 107 XMLTag tag = new XMLTag(XML_TAG_NAME); 108 tag.setAttribute(XML_NAME_ATT, name()); 109 110 if (size() > 0) 111 { 112 XMLTag columnsTag = new XMLTag(XML_COLUMNS); 113 tag.addSubtag(columnsTag); 114 115 for (ExtGridCol col : this) 116 { 117 columnsTag.addSubtag(col.toXMLTag()); 118 } 119 } 120 121 return tag; 122 } 123}