001package com.hfg.xml.msofficexml.docx.wordprocessingml;
002
003
004import com.hfg.util.StringUtil;
005import com.hfg.xml.msofficexml.docx.Docx;
006
007import java.util.List;
008
009//------------------------------------------------------------------------------
010/**
011 Represents an Office Open XML table row (<w:tr>) tag.
012
013 @author J. Alex Taylor, hairyfatguy.com
014 */
015//------------------------------------------------------------------------------
016// com.hfg XML/HTML Coding Library
017//
018// This library is free software; you can redistribute it and/or
019// modify it under the terms of the GNU Lesser General Public
020// License as published by the Free Software Foundation; either
021// version 2.1 of the License, or (at your option) any later version.
022//
023// This library is distributed in the hope that it will be useful,
024// but WITHOUT ANY WARRANTY; without even the implied warranty of
025// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
026// Lesser General Public License for more details.
027//
028// You should have received a copy of the GNU Lesser General Public
029// License along with this library; if not, write to the Free Software
030// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
031//
032// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
033// jataylor@hairyfatguy.com
034//------------------------------------------------------------------------------
035
036public class WmlTableRow extends WmlXMLTag
037{
038   private WmlTableRowProperties mTableRowProps;
039
040   //---------------------------------------------------------------------------
041   public WmlTableRow(Docx inDocx)
042   {
043      super(WmlXML.TABLE_ROW, inDocx);
044   }
045
046   //---------------------------------------------------------------------------
047   /**
048    * Generates a new table cell.
049    */
050   public WmlTableCell addCell()
051   {
052      WmlTableCell cell = new WmlTableCell(getParentDoc());
053      addSubtag(cell);
054
055      return cell;
056   }
057
058   //---------------------------------------------------------------------------
059   /**
060    * Generates a new table cell.
061    */
062   public WmlTableCell addCell(WmlParagraph inParagraph)
063   {
064      WmlTableCell cell = new WmlTableCell(getParentDoc());
065      addSubtag(cell);
066      cell.addSubtag(inParagraph);
067
068      return cell;
069   }
070
071   //---------------------------------------------------------------------------
072   /**
073    * Generates a new table cell.
074    */
075   public WmlTableCell addCell(String inContent)
076   {
077      WmlTableCell cell = addCell();
078      if (StringUtil.isSet(inContent))
079      {
080         cell.getParagraph().addTextRun().addText(inContent);
081      }
082
083      return cell;
084   }
085
086   //---------------------------------------------------------------------------
087   /**
088    * Returns the row cells.
089    */
090   public List<WmlTableCell> getCells()
091   {
092      return getSubtagsByName(WmlXML.TABLE_CELL);
093   }
094
095   //---------------------------------------------------------------------------
096   /**
097    * Returns the table row properties tag if one exists or else instantiates a new one.
098    * @return the table row properties for this cell
099    */
100   public WmlTableRowProperties getRowProperties()
101   {
102      if (null == mTableRowProps)
103      {
104         // Check it it has been added via addSubtag()...
105         mTableRowProps = getOptionalSubtagByName(WmlXML.TABLE_ROW_PROPS);
106         if (null == mTableRowProps)
107         {
108            mTableRowProps = new WmlTableRowProperties(getParentDoc());
109            addSubtag(mTableRowProps);
110         }
111      }
112
113      return mTableRowProps;
114   }
115}