Share via


How to: Create an Indicator Wizard Template

To create an indicator wizard template, your extension must:

  • Reference the Microsoft.PerformancePoint.Scorecards.ModelerPlugins assembly.

  • Reference the Microsoft.PerformancePoint.Scorecards.Client assembly.

  • Inherit from the TemplateFactory class, which is in the ModelerPlugins DLL.

  • Override the GetTemplateTypeId, GetTemplateType, GetTemplateItems, and CreateTemplateItem methods.

Implementing TemplateFactory to create a custom indicator

The following code example creates an indicator that displays the performance status of a KPI.

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

using Microsoft.PerformancePoint.Scorecards.Modeler.Framework;
using Microsoft.PerformancePoint.Scorecards.WizardFramework;
using Microsoft.PerformancePoint.Scorecards;
using Microsoft.PerformancePoint.Scorecards.ModelerWorkspace;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Templates;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Controls;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Utilities;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Indicators;

namespace SampleIndicator
{
    public class SampleIndicatorTemplateFactory : TemplateFactory
    {
        #region Member Data

        // The identifier for the TemplateFactory class.
        public static readonly string TemplateTypeId = "SampleIndicatorTemplateFactory";
        public static readonly string SampleTemplateId = "Blank";

        #endregion

        #region Methods

        // Get the identifier for the TemplateFactory class.
        public override string GetTemplateTypeId()
        {
            return TemplateTypeId; 
        }

        // Get the type of TemplateFactory.
        public override Type GetTemplateType()
        {
            return typeof(SampleIndicatorTemplateFactory);
        }

        // Get the available template items for the
        // creation wizard.
        public override List<TemplateItem> GetTemplateItems()
        {
            List<TemplateItem> items = new List<TemplateItem>();

            // Create a template item.
            TemplateItem item1 = new TemplateItem();

            // Set properties for the item.
            item1.Name = "_Sample Indicator";
            item1.Folder = @"All Indicators\Test"; 
            item1.Description = "Sample Indicator";

            // The image for the custom indicator template. 
            // Change the image name to reference your custom image.
            item1.Image = Resource1.BeanmanQuest; 
            item1.TemplateId = SampleTemplateId; 
            item1.TemplateTypeId = GetTemplateTypeId();
            items.Add(item1);
            return items;
        }

        // Create a template item (indicator) by using the template 
        // specified in the "item" parameter.
        public override void CreateTemplateItem(TemplateItem item)
        { 
            if (item.TemplateId == SampleTemplateId)

                // Call the method that creates the template item (indicator).
                // You must develop your own method to create the 
                // template item.
                CreateSampleIndicator(); 
        }
        private void CreateSampleIndicator()
        {
            WizardForm form = new WizardForm();
            form.Title = "Sample Indicator Title";
            //form.Icon = Properties.Resources.Main;

            // Instantiate the wizard and set properties for it.
            CreateElementWizardPage pageElement = new CreateElementWizardPage(form, typeof(Indicator));

            // Change the image name to your custom image.
            pageElement.Logo = Resource1.BeanmanQuest; 
            pageElement.Headline = "createElement Sample Indicator Headline";
            pageElement.StepTitle = "createElement Sample Indicator StepTitle";
            form.AddPage(pageElement);

            CreateIndicatorWizardPage pageType = new CreateIndicatorWizardPage(form);
            pageType.Headline = "createIndicator Headline";
            pageType.StepTitle = "createIndicator Stepline";
            form.AddPage(pageType);

            // Open the wizard.
            form.Start(MainForm.GetInstance()); 

            // Click finish to create the indicator.
            if (form.DialogResult == DialogResult.OK)
            {

                // Create the indicator and set indicator properties.
                Indicator indicator = new Indicator();
                indicator.Guid = Guid.NewGuid();
                indicator.CreatedDate = DateTime.Now;
                pageElement.SetElement(indicator);

                indicator.IndicatorType = pageType.Centered ? IndicatorType.Centered : IndicatorType.Standard;
                //int numberofLevels = indicator.IndicatorType == IndicatorType.Standard ? pageType.Levels : pageType.Levels * 2;
                int numberofLevels = pageType.Levels;
                for (int indLevel = 0; indLevel < numberofLevels; indLevel++)
                {

                    // Set the banding for the indicator.
                    IndicatorBand band = new IndicatorBand(); 
                    indicator.IndicatorBands.Add(band);
                }
                SetIndicatorBandToolTip(indicator);
                if (indicator.IndicatorType == IndicatorType.Centered)
                CreateCentered(indicator);
                SetIndicatorBandToolTip(indicator);

                // Add the indicator to the workspace.
                GeneralUtilities.AddToWorkspace(indicator, true);
            }
            form.Dispose();
        }

        private void CreateCentered(Indicator indicator)
        {
            for (int i = indicator.IndicatorBands.Count - 1; i > -1; i--)
            {
                IndicatorBand band = indicator.IndicatorBands[i].Clone() as IndicatorBand;
                indicator.IndicatorBands.Add(band); 
            }
            SetIndicatorBandToolTip(indicator);
        }

        public static void SetIndicatorBandToolTip(Indicator indicator)
        {
            string onTargetToolTip = "On target";
            string moderatelyoffToolTip = "Moderately off";
            string offTargetToolTip = "Off Target";
            indicator.NoDataIndicatorBand.ToolTip = "No data";

            int end = indicator.IndicatorType == IndicatorType.Standard ? indicator.IndicatorBands.Count - 1 : indicator.IndicatorBands.Count / 2;
            for (int i = 0; i < indicator.IndicatorBands.Count; i++)
            {
                if (i == 0)
                    indicator.IndicatorBands[i].ToolTip = offTargetToolTip;
                else if (i == end || i == end + 1)
                    indicator.IndicatorBands[i].ToolTip = onTargetToolTip;
                else if (i == indicator.IndicatorBands.Count - 1)
                    indicator.IndicatorBands[i].ToolTip = offTargetToolTip;
                else
                    indicator.IndicatorBands[i].ToolTip = moderatelyoffToolTip;
            }
        }

        #endregion
    }
}

See Also

Tasks

How to: Install a Wizard Template

Other Resources

Wizard Templates