001package com.hfg.xml.msofficexml.xlsx.spreadsheetml; 002 003 004import java.util.List; 005 006import com.hfg.util.StringUtil; 007import com.hfg.xml.XMLTag; 008import com.hfg.xml.msofficexml.xlsx.CellRange; 009import com.hfg.xml.msofficexml.xlsx.Xlsx; 010 011//------------------------------------------------------------------------------ 012/** 013 Represents an Office Open XML data validation (<ssml:dataValidation>) tag. 014 015 @author J. Alex Taylor, hairyfatguy.com 016 */ 017//------------------------------------------------------------------------------ 018// com.hfg XML/HTML Coding Library 019// 020// This library is free software; you can redistribute it and/or 021// modify it under the terms of the GNU Lesser General Public 022// License as published by the Free Software Foundation; either 023// version 2.1 of the License, or (at your option) any later version. 024// 025// This library is distributed in the hope that it will be useful, 026// but WITHOUT ANY WARRANTY; without even the implied warranty of 027// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 028// Lesser General Public License for more details. 029// 030// You should have received a copy of the GNU Lesser General Public 031// License along with this library; if not, write to the Free Software 032// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 033// 034// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 035// jataylor@hairyfatguy.com 036//------------------------------------------------------------------------------ 037 038public class SsmlDataValidation extends SsmlXMLTag 039{ 040 //########################################################################### 041 // PRIVATE FIELDS 042 //########################################################################### 043 044 private XMLTag mFormulaTag; 045 046 //########################################################################### 047 // CONSTRUCTORS 048 //########################################################################### 049 050 //--------------------------------------------------------------------------- 051 public SsmlDataValidation(Xlsx inXlsx, CellRange inCellRange) 052 { 053 super(SsmlXML.DATA_VALIDATION, inXlsx); 054 055 // Set some default attributes 056 setType(SsmlDataValidationType.list); 057 setAllowBlank(true); 058 059 setCellRange(inCellRange); 060 } 061 062 //########################################################################### 063 // PUBLIC METHODS 064 //########################################################################### 065 066 //--------------------------------------------------------------------------- 067 public SsmlDataValidation setType(SsmlDataValidationType inValue) 068 { 069 setAttribute(SsmlXML.TYPE_ATT, inValue.name()); 070 return this; 071 } 072 073 //--------------------------------------------------------------------------- 074 public SsmlDataValidation setAllowBlank(boolean inValue) 075 { 076 setAttribute(SsmlXML.ALLOW_BLANK_ATT, inValue ? "1" : "0"); 077 return this; 078 } 079 080 //--------------------------------------------------------------------------- 081 public SsmlDataValidation setCellRange(CellRange inValue) 082 { 083 setAttribute(SsmlXML.SQUARE_REF_ATT, inValue); 084 return this; 085 } 086 087 //--------------------------------------------------------------------------- 088 public SsmlDataValidation setValues(List<String> inValues) 089 { 090 if (null == mFormulaTag) 091 { 092 // Check it it has been added via addSubtag()... 093 mFormulaTag = getOptionalSubtagByName(SsmlXML.FORMULA1); 094 if (null == mFormulaTag) 095 { 096 mFormulaTag = new XMLTag(SsmlXML.FORMULA1); 097 addSubtag(mFormulaTag); 098 } 099 } 100 101 mFormulaTag.setContent(StringUtil.quote(StringUtil.join(inValues, ","))); 102 103 return this; 104 } 105}