All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hfg.xml.msofficexml.docx.wordprocessingml.WmlTableCell Maven / Gradle / Ivy

There is a newer version: 20240423
Show newest version
package com.hfg.xml.msofficexml.docx.wordprocessingml;


import com.hfg.util.collection.CollectionUtil;
import com.hfg.xml.msofficexml.docx.Docx;

//------------------------------------------------------------------------------
/**
 Represents an Office Open XML table cell (<w:tc>) tag.

 @author J. Alex Taylor, hairyfatguy.com
 */
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------

public class WmlTableCell extends WmlXMLTag
{
   private WmlTableCellProperties mTableCellProps;
   private WmlParagraph           mParagraph;

   //---------------------------------------------------------------------------
   public WmlTableCell(Docx inDocx)
   {
      super(WmlXML.TABLE_CELL, inDocx);
      // Ensure that the cell has a paragraph or Word will complain
      getParagraph();
   }

   //---------------------------------------------------------------------------
   public WmlParagraph getParagraph()
   {
      if (null == mParagraph)
      {
         // Check it it has been added via addSubtag()...
         mParagraph = getOptionalSubtagByName(WmlXML.P);
         if (null == mParagraph)
         {
            mParagraph = new WmlParagraph(getParentDoc());
            addSubtag(mParagraph);
         }
      }

      return mParagraph;
   }

   //---------------------------------------------------------------------------
   public void addSubtag(WmlParagraph inParagraph)
   {
      // If the initial empty placehoder paragraph is present, remove it.
      if (mParagraph != null
            && ! CollectionUtil.hasValues(mParagraph.getSubtags()))
      {
         removeSubtag(mParagraph);
      }

      mParagraph = inParagraph;
      super.addSubtag(mParagraph);
   }

   //---------------------------------------------------------------------------
   public WmlParagraph addParagraph()
   {
      WmlParagraph paragraph;
      // If the initial empty placehoder paragraph is present, return it.
      if (mParagraph != null
            && ! CollectionUtil.hasValues(mParagraph.getSubtags()))
      {
         paragraph = mParagraph;
      }
      else
      {
         paragraph = new WmlParagraph(getParentDoc());
         super.addSubtag(paragraph);

         if (null == mParagraph)
         {
            mParagraph = paragraph;
         }
      }

      return paragraph;
   }

   //---------------------------------------------------------------------------
   public WmlTableCell setCellProperties(WmlTableCellProperties inValue)
   {
      mTableCellProps = inValue;
      return this;
   }

   //---------------------------------------------------------------------------
   /**
    * Returns the table cell properties tag if one exists or else instantiates a new one.
    * @return the table cell properties for this cell
    */
   public WmlTableCellProperties getCellProperties()
   {
      if (null == mTableCellProps)
      {
         // Check it it has been added via addSubtag()...
         mTableCellProps = (WmlTableCellProperties) getOptionalSubtagByName(WmlXML.TABLE_CELL_PROPS);
         if (null == mTableCellProps)
         {
            mTableCellProps = new WmlTableCellProperties(getParentDoc());
            addSubtag(mTableCellProps);
         }
      }

      return mTableCellProps;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy