MicroStrategy ONE

ReportGridCellRowHeaderImpl

ReportGridCellRowHeaderImpl is a subclass of AbstractReportGridDisplayCell which is responsible for displaying the contents in the cells of a row header of a report grid.

The following code sample shows how you can extend this class and generate customized content such as adding hyperlinks, images, and so on. The new custom class is called CustomReportGridCellRowHeaderImpl.

Code Sample

package com.microstrategy.web.app.transforms;

import com.microstrategy.web.app.utils.HTMLHelper;

import com.microstrategy.web.beans.MarkupOutput;

import com.microstrategy.web.objects.WebHeader;

import com.microstrategy.web.tags.AnchorTag;

import com.microstrategy.web.tags.ImageTag;

import com.microstrategy.web.tags.TagsFactory;

import com.microstrategy.webapi.EnumDSSXMLBaseFormType;

 

/**

 * Title: Transform Component: CustomReportGridCellRowHeaderImpl

 * Description: Represents a Row Header cell in report grid

 * Copyright: Copyright (c) 2009

 * Company: MicroStrategy

 *

 */

 

public class CustomReportGridCellRowHeaderImpl extends ReportGridCellRowHeaderImpl {

   public CustomReportGridCellRowHeaderImpl() {

      super();

   }

 

   //This method adds an HTML tag before the cell content

   public void generatePreContent(MarkupOutput mo) {

      super.generatePreContent(mo) ;

      mo.append("<B>");

   }

 

   // This method appends an HTML tag after the cell content

   public void generatePostContent(MarkupOutput mo) {

      mo.append("</B> <BR/><A href='http://www.microstrategy.com'>MSTR</A>");

      super.generatePostContent(mo);

   }

 

   /**

    * @param mo the MarkupOutput object

    */

   public void generateContent(MarkupOutput mo) {

      AnchorTag anchor = generateElementAnchor();

        

      MarkupOutput tempOut = (anchor != null) ? anchor.getContent() : mo;

      generateText(tempOut);

       

      if(anchor != null) {

        anchor.render(mo);

      }

    }

 

   /**

    * Generate the text contents of the cell

    * @param mo the MarkupOutput object

    *

    * This method can be overwritten to modify the contents

    * of the row header. You can render images, hyperlinks,

    * and so on based on the unit type, the attribute name,

    * and other conditions.

    *

    * The getText() method is called inside the generateText()

    * method which also renders 'drill' hyperlinks.

    * To avoid showing these links and create different

    * hyperlinks instead, initialize the "showDrillHyperlink"

    * tranform parameter to 'false'.

    * Refer to the Transform Parameters Reference in MSDL.

    **/

 

   public void generateText(MarkupOutput mo) {

 

      //Get the text for the rowHeader

 

      String rowHeader = getText();

      // Get the row header to decide what needs to be

      // displayed based on its type

      TagsFactory tagsFactory = TagsFactory.getInstance();

 

      WebHeader header = getWebHeader();

 

      if (header!=null) {

         switch (header.getSemantics()) {

 

         //Displays an image

         case EnumDSSXMLBaseFormType.DssXmlBaseFormPicture:

            ImageTag img = tagsFactory.newImageTag();

            img.setSrc(rowHeader);

            img.render(mo);

            break;

 

         //Displays an URL

         case EnumDSSXMLBaseFormType.DssXmlBaseFormUrl:

            AnchorTag anchor = tagsFactory.newAnchorTag();

            anchor.setAttribute("href", getText());

            anchor.addTextChild(rowHeader);

            anchor.render(mo);

            break;

 

         //Displays an e-mail address

         case EnumDSSXMLBaseFormType.DssXmlBaseFormEmail:

            AnchorTag anchor2 = tagsFactory.newAnchorTag();

            anchor2.setAttribute("href", "mailto:"+getText());

            anchor2.addTextChild(rowHeader);

            anchor2.render(mo);

            break;

 

         //Displays an HTML tag

         case EnumDSSXMLBaseFormType.DssXmlBaseFormHTMLTag:

            mo.append(HTMLHelper.decode(rowHeader));

            break;

 

         default:

            // Customize this portion by adding conditions

            // to display content of your choice.

            // This condition displays the icon for books

            // if the row header is Books.

            if (header.getDisplayName().equals("Books"))  {

               //Display the icon for books

               mo.append("<IMG SRC='BooksIcon.jpg' />");

            }

         // This condition highlights the attribute based on

         // a particular ID.

         else if (header.getWebElement().getElementID().equals("BB:8D679D3711D3E4981000E787EC6DE8A4:1:2:0:2:1:3:2:Food")) {

            //Highlight this header as it is identified by

            //header.getWebElement().getElementID() as special

            mo.append("<B>" + rowHeader + "</B>");

            } else {

               mo.append(rowHeader);

            }

         break;

 

         }

 

      }

 

   }

}

See also