MicroStrategy ONE
ReportGridCellColHeaderImpl
ReportGridCellColHeaderImpl is a subclass of AbstractReportGridDisplayCell which is responsible for displaying the contents in the cells of a column 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 CustomReportGridCellColHeaderImpl.
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: CustomReportGridCellColHeaderImpl
* Description: Represents a Column Header cell in report grid
* Copyright: Copyright (c) 2006
* Company: MicroStrategy
*
*/
public class CustomReportGridCellColHeaderImpl extends ReportGridCellColHeaderImpl {
public CustomReportGridCellColHeaderImpl () {
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 column 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 colHeader
String colHeader = getText();
// Get the column 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(colHeader);
img.render(mo);
break;
//Displays an URL
case EnumDSSXMLBaseFormType.DssXmlBaseFormUrl:
AnchorTag anchor = tagsFactory.newAnchorTag();
anchor.setAttribute("href", getText());
anchor.addTextChild(colHeader);
anchor.render(mo);
break;
//Displays an e-mail address
case EnumDSSXMLBaseFormType.DssXmlBaseFormEmail:
AnchorTag anchor2 = tagsFactory.newAnchorTag();
anchor2.setAttribute("href", "mailto:"+getText());
anchor2.addTextChild(colHeader);
anchor2.render(mo);
break;
//Displays an HTML tag
case EnumDSSXMLBaseFormType.DssXmlBaseFormHTMLTag:
mo.append(HTMLHelper.decode(colHeader));
break;
default:
// Customize this portion by adding conditions
// to display content of your choice.
// This condition displays the company logo
// if the column header is AcmeCorp.
if (header.getDisplayName().equals("AcmeCorp")) {
//Display the company logo
mo.append("<IMG SRC='CompanyLogo.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
//with header.getWebElement().getElementID() as special
mo.append("<B>" + colHeader + "</B>");
} else {
mo.append(colHeader);
}
break;
}
}
}
}
See also
-
Customizing Cell Rendering Classes: Using Custom Cell Rendering Classes
-
References: API Reference