Skip to main content
RSS feed Subscribe to feed

 

How to Configure the Initial State of the Analysis

This tutorial describes how to open a parameterized analysis using values from an existing analysis.

Overview

If an analysis is open, the parameter values from the open analysis can be passed into another analysis to be opened. This is useful when handling large data sets.

This tutorial describes a scenario where the current analysis, Sales.dxp, is replaced by the new analysis, SalesDetails.dxp. This is achieved by creating an alternative file open dialog that uses a configuration block to enable the end user to assign parameters before opening an detail analysis.

Dialog for parameterized analysis
Background Information
  • Creating a Configuration Block
    A configuration block configures the initial state of an analysis. It has two sections: a list of parameter assignments and a list of configuration statements.
Prerequisites
  • Spotfire SDK\Examples\Extensions\SpotfireDeveloper.ParameterizedAnalysisToolExample

The Tool

The alternative Open Parameterized Analysis file open dialog, is implemented as a tool. In the dialog, the user selects an analysis file and adds any number of parameters.

In the additional Add parameter dialog it is possible to fetch column values from the current analysis, if such an analysis exists. Values may be fetched from a visualization or a data table, possibly restricted by a filtering or a marking selection.

The user clicks the Open button when all required parameters have been assigned. The current analysis is replaced with the new one.

Handling parameters for the parameterized analysis

The tool is made to be generic, in the sense that it enables the user to start with any analysis and then open another arbitrary analysis. But, since the tool cannot automatically derive the parameters that must be assigned, the user is responsible to assign them before opening the second analysis.

The tool can be tailored to a specific scenario by defining the analysis to open and parameters to add. This way user prompting can be omitted completely.

The Implementation

The logic and dialogs of the SpotfireDeveloper.ParameterizedAnalysisToolExample is implemented in the following files:

OpenParameterizedAnalysisTool.cs

The file contains the tool class that implements the CustomTool class at AnalysisApplication level.

public sealed class OpenParameterizedAnalysisTool :CustomTool<AnalysisApplication>
{
}

In the ExecuteCore method, the tool dialog is shown. If user clicks OK, a configuration block is created from the assigned parameters and passed to the Open method in the AnalysisApplication:

protected override void ExecuteCore(AnalysisApplication application)
{
    // Set the current document on the settings object. This is needed by the form.
    // Note: it is important that we clear this field, to let go of the reference.
    Settings.Document = application.Document;

    // Show UI
    PromptService promptService = application.GetService<PromptService>();
    PromptResult promptResult = promptService.Prompt(Settings);

    // Clear the document field
    Settings.Document = null;

    if (promptResult == PromptResult.Cancel)
    {
        return;
    }

    // Open the parameterized analysis
    DocumentOpenSettings documentOpenSettings = new DocumentOpenSettings();
    documentOpenSettings.ConfigurationBlockText = CreateConfigurationBlockText(Settings.Parameters);

    try
    {
        application.Open(Settings.FileName, documentOpenSettings);
    }
    catch (CanceledException)
    {
        // This is a no-op.
    }
    catch (TargetInvocationException ex)
    {
        // The StartTopLevelProgress will wrap all exceptions except 
        // ProgressCanceledException in a TargetInvocationException.
        string message = string.Format(Properties.Resources.OpenFailureDialogText, ex.InnerException.Message);
        MessageBox.Show(message, Properties.Resources.OpenFailureDialogCaption);
    }
    catch (ImportException ex)
    {
        string message = string.Format(Properties.Resources.OpenFailureDialogText, ex.Message);
        MessageBox.Show(message, Properties.Resources.OpenFailureDialogCaption);
    }
}

OpenParameterizedAnalysisToolSettings.cs

Contains a settings class for the tool.

OpenParameterizedAnalysisForm.cs

Contains the main tool dialog.

AddEditParameterDialog.cs

Contains a dialog class for adding new or editing existing parameters.

GetColumnsDialog.cs

Contains a dialog class for creating parameters values from columns in the current analysis.