How to: Create a Dashboard Wizard Template
To create a dashboard wizard template, your extension must:
Reference the Microsoft.PerformancePoint.Scorecards.ModelerPlugins DLL.
Reference the Microsoft.PerformancePoint.Scorecards.Client DLL.
Inherit from the TemplateFactory or DashboardTemplateFactory class; both are in the ModelerPlugins DLL.
Override the GetTemplateTypeId, GetTemplateType, GetTemplateItems, and CreateTemplateItem methods.
The example in this topic inherits from the TemplateFactory class.
Implementing TemplateFactory to create a custom dashboard
The following code example creates a custom dashboard that contains user-specified zones.
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Text;
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.DataSources;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Utilities;
using Microsoft.PerformancePoint.Scorecards.ModelerPlugins.Dashboards;
namespace SampleDashboardTemplate
{
public class SampleDashboardTemplateFactory : TemplateFactory
{
#region Member Data
// The identifier for the TemplateFactory class.
public const string TemplateTypeId = "SampleDashboardTemplateFactory";
#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(SampleDashboardTemplateFactory);
}
// 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 = "Test Zone";
item1.Folder = "All";
// The image for the custom dashboard template.
// Change the image name to reference your custom image.
item1.Image = DashboardContainer.BeanmanQuest;
item1.TemplateId = "TestZone";
item1.TemplateTypeId = GetTemplateTypeId();
item1.Description = "SampleDashboardTemplate Description";
items.Add(item1);
return items;
}
// Create a new template item (dashboard) using the template
// specified in the "item" parameter.
public override void CreateTemplateItem(TemplateItem item)
{
if (item != null)
{
switch (item.TemplateId)
{
case "TestZone":
CreateDashboard(item.TemplateId);
break;
}
}
}
private void CreateDashboard(string templateId)
{
WizardForm form = new WizardForm();
form.Title = "Sample Dashboard Wizard";
// Instantiate the wizard and set properties for it.
CreateElementWizardPage pageElement = new CreateElementWizardPage(form, typeof(Dashboard));
pageElement.Logo = DashboardContainer.BeanmanQuest;
pageElement.Headline = "Sample Dashboard Wizard";
pageElement.StepTitle = "Create Sample Dashboard";
form.AddPage(pageElement);
// Open the wizard.
form.Start(MainForm.GetInstance());
// Click finish to create the dashboard.
if (form.DialogResult == DialogResult.OK)
{
// Create the dashboard and set dashboard properties.
Dashboard dashboard = new Dashboard();
dashboard.Guid = Guid.NewGuid();
dashboard.CreatedDate = DateTime.Now;
dashboard.TemplateType = templateId;
pageElement.SetElement(dashboard);
// Add the dashboard container to the dashboard.
dashboard.Pages.Add(CreateDashboardPage(templateId));
// Add the dashboard to the workspace.
GeneralUtilities.AddToWorkspace(dashboard, true);
}
form.Dispose();
}
// Create a new dashboard by using the specified template.
public DashboardElementContainer CreateDashboardPage(string templateId)
{
// Create the dashboard container based on the
// templateId, and return the container.
DashboardElementContainer newContainer = null;
switch ( templateId )
{
case DashboardTemplateId.BlankTemplateId:
newContainer = new DashboardElementContainer();
break;
case "TestZone":
newContainer = CreateMultipleZones();
break;
}
newContainer.Owner.Login = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
BpmPropertyDate createDate = new BpmPropertyDate();
createDate.UniqueName = "UpdateDate";
createDate.Date = DateTime.Now;
newContainer.Properties.Add(createDate);
return newContainer;
}
private static DashboardElementContainer CreateMultipleZones()
{
// Create the dashboard container and
// set properties for it.
DashboardElementContainer page = new DashboardElementContainer();
page.Guid = Guid.NewGuid();
page.Orientation = LayoutOrientation.VerticalTopJustified;
// Set the number of dashboard rows to create.
DashboardElementContainer rows = CreateRows(4);
// Set row height and width, and add the
// rows to the dashboard.
foreach (DashboardElementContainer childColumn in rows.DashboardElements)
{
childColumn.Width.Measurement = 90;
}
rows.Height.Measurement = 90;
page.DashboardElements.Add(rows);
// Set the number of dashboard columns to create.
DashboardElementContainer columns = CreateColumns(4);
// Set column height and width, and add the
// columns to the dashboard.
foreach (DashboardElementContainer childRow in columns.DashboardElements)
{
childRow.Height.Measurement = 90;
}
columns.Height.Measurement = 90;
page.DashboardElements.Add(columns);
return page;
}
// Create the dashboard columns.
private static DashboardElementContainer CreateColumns(int columns)
{
DashboardElementContainer page = new DashboardElementContainer();
page.Guid = Guid.NewGuid();
page.Orientation = LayoutOrientation.HorizontalLeftJustified;
int width = 100 / columns;
int totalWidth = 0;
// Create the specified number of columns.
for (int counter = 1; counter <= columns; counter++)
{
DashboardElementContainer column = new DashboardElementContainer();
column.Guid = Guid.NewGuid();
if (columns > 3)
{
column.Name.Text =
"Many Columns" + " " + counter.ToString(Helper.GetCurrentUICulture());
}
else if (columns == 3)
{
if (counter == 1)
{
column.Name.Text = "Many Columns; Left Column";
}
else if (counter == 2)
{
column.Name.Text = "Many Columns; center column";
}
else if (counter == 3)
{
column.Name.Text = "Many Columns";
}
}
else if (columns == 2)
{
if (counter == 1)
{
column.Name.Text = "Many Columns";
}
else if (counter == 2)
{
column.Name.Text = "Many Columns";
}
}
else if (columns == 1)
{
column.Name.Text = "Many Columns";
}
column.Width = new DashboardElementSize();
column.Width.Measurement = width;
column.Width.Units = SizeType.Percent;
column.Orientation = LayoutOrientation.VerticalTopJustified;
totalWidth += width;
page.DashboardElements.Add(column);
}
// Force width to equal 100.
if (totalWidth != 100)
{
page.DashboardElements[page.DashboardElements.Count - 1].Width.Measurement += 100 - totalWidth;
}
return page;
}
// Create the dashboard rows.
private static DashboardElementContainer CreateRows(int rows)
{
DashboardElementContainer page = new DashboardElementContainer();
page.Guid = Guid.NewGuid();
page.Orientation = LayoutOrientation.VerticalTopJustified;
int height = 100 / rows;
// Create the specified number of rows.
for (int counter = 1; counter <= rows; counter++)
{
DashboardElementContainer row = new DashboardElementContainer();
row.Guid = Guid.NewGuid();
if (rows > 3)
{
row.Name.Text =
"Many Rows" +" " + counter.ToString(Helper.GetCurrentUICulture());
}
else if (rows == 3)
{
if (counter == 1)
{
row.Name.Text = "Many Rows";
}
else if (counter == 2)
{
row.Name.Text = "Many Rows";
}
else if (counter == 3)
{
row.Name.Text = "Many Rows";
}
}
else if (rows == 2)
{
if (counter == 1)
{
row.Name.Text = "Many Rows";
}
else if (counter == 2)
{
row.Name.Text = "Many Rows";
}
}
else if (rows == 1)
{
row.Name.Text = "Many Rows";
}
row.Height = new DashboardElementSize();
row.Height.Measurement = height;
row.Height.Units = SizeType.Percent;
row.Orientation = LayoutOrientation.HorizontalLeftJustified;
page.DashboardElements.Add(row);
}
return page;
}
#endregion
}
}
See Also
Tasks
How to: Install a Wizard Template