MicroStrategy ONE

Example: Use a Custom Transform and Custom Layout Definition File in iOS

The code sample in this topic illustrates how to create a custom widget properties editor that uses a custom transform and a custom layout definition file. The code produces a properties editor like the one shown below—with a dynamically populated drop-down menu that displays the list of attributes from a report.

In this example, a custom transform is used for the widget properties editor because the editor displays a dynamically-generated list of elements for a control. The code for the custom transform and the custom layout definition file that are responsible for displaying this properties editor is shown below. This is followed by an explanation of relevant sections of the code.

Code explanation for the custom transform

Transforms are discussed in detail in the Web SDK section of the MSDL under Customizing MicroStrategy Web -> Part I: Fundamentals of Customization -> Data Presentation -> Transforms.

Copy
package com.microstrategy.web.app.transforms;
import com.microstrategy.utils.HashList;
import com.microstrategy.web.objects.WebAttribute;
import com.microstrategy.web.app.transforms.VisualizationPropertiesTransform;
import com.microstrategy.web.beans.MarkupOutput;
import com.microstrategy.web.objects.WebAxis;
import com.microstrategy.web.objects.WebTemplate;
import com.microstrategy.web.objects.WebTemplateAttribute;
import com.microstrategy.web.transform.LayoutTransform;
import com.microstrategy.webapi.EnumDSSXMLTemplateUnitType;
 
public class VizPropertiesCustomTransform extends VisualizationPropertiesTransform implements LayoutTransform {
    
        HashList<String, String> attsList = new HashList<String, String>();
        WebTemplate template = getWebTemplate();
        WebAxis axis = template.getRows();
        for (int i = 0; i < axis.size(); i++) {
            if (template.getRows().get(i).getUnitType() == EnumDSSXMLTemplateUnitType.DssXmlTemplateAttribute) {
                WebAttribute attr = (WebAttribute) ((WebTemplateAttribute) template.getRows().get(i).getTarget()).getAttributeInfo();
                attsList.add(attr.getID(), attr.getDisplayName());
            }
        }
        renderSelectBox(out, propName, attsList);
    }
}

Because the custom transform extends the default transform, VisualizationPropertiesTransform, it includes supporting methods—such as renderCheckbox(), renderRadio(), renderSelectBox(), and renderTextbox()—that can be called from the custom layout definition file.

The custom transform includes a new method, called renderAttributeDropDown(), that is used to pass a dynamically generated list of the attributes present on the report. This method retrieves the report template and traverses the rows to generate a HashList of key-value pairs that represent the ID and the name for the attribute. After this HashList is generated, the method calls renderSelectBox() to render the drop-down menu and to persist the value selected by the user. This property-value combination is saved in the metadata and retrieved for the user when the widget properties editor is opened.

Code explanation for the layout definition file

Layout definition files are discussed in detail in the Web SDK section of the MSDL under Customizing MicroStrategy Web -> Part I: Fundamentals of Customization -> Data Presentation -> Layout Definitions.

Copy
 <!DOCTYPE mstrlayout:layout SYSTEM "mstrlayout.dtd">
 <mstrlayout:layout>
    <div>
 
    <span style="font-weight:bold;">
       <mstrlayout:render name="descriptor">
          <mstrlayout:argument type="string" value="scenario2.1"/>
          <!-- Descriptor for text "Select an attribute:" -->
       </mstrlayout:render>
    </span>&#160; &#160;
    <mstrlayout:render name="AttributeDropDown">
       <mstrlayout:argument type="string" value="att" />
    </mstrlayout:render>
  </div>
 
</mstrlayout:layout>

The custom layout definition file renders the widget properties editor, using a combination of its own code and the logic in the renderAttributeDropDown() method invoked from the custom transform. This method passes a dynamically generated list of the attributes present on the report. The property named “att” holds the value that the user selected from the drop-down menu. This property-value combination is saved in the metadata and retrieved for the user when the widget properties editor is opened. The text “Select an attribute:” for the drop-down menu is rendered using localization descriptor files.