CustomPreference Class TIBCO Spotfire 6.0 API Reference
Extend this class to implement a set of preferences that are persisted locally and on the TIBCO Spotfire Analytics server.
Inheritance Hierarchy

System Object
  DedicatedThreadAccessible
    Spotfire.Dxp.Framework.Preferences PreferenceBase
      Spotfire.Dxp.Application.Extension CustomPreference

Namespace: Spotfire.Dxp.Application.Extension
Assembly: Spotfire.Dxp.Application (in Spotfire.Dxp.Application.dll) Version: 13.19.7018.3940 (13.19.7018.3940)
Syntax

public abstract class CustomPreference : PreferenceBase
Remarks

Preferences are used by add-ins to persist one or more values, for example last used settings, user preferred values, etc. An object of this type can contain one or more such values, referred to as Preference Properties. Thus to create a set of preference properties, extend this class and populate that class with the properties that shall be persisted.

When a user is logged on, the preference is populated with its persisted values, if such exist. If not, the preference is given default values while waiting for the user to set its values. When preferences are saved, their values are persisted using .Net serialization on the client and on the server depending on the settings of the preference.

Preferences properties can be applied to single users or to user groups. Preferences applied to a group are inherited by all members of the group. The users can, however, choose to override the properties with custom values. In the same way, a group can override the properties inherited from its parent groups. If the group has more than one parent group, the value from the Primary parent group (as defined using the TIBCO Spotfire Administration Manager).

It is important for your preference implementation class to be decorated with the PersistenceVersionAttribute. If it is not, it will not be possible to register the preference class with the preference framework.

Examples

The following example shows an implementation of a preference class that stores two preferences of types string and ArrayList of integers.
[Spotfire.Dxp.Framework.Persistence.PersistenceVersion(1, 0)]
public class MyPreference : CustomPreference
{
    private PreferenceProperty<string> myString; // Defaults to null 
    private PreferenceProperty<ArrayList> numberList;

    public override string Category
    {
        get { return "MyCategory"; }
    }

    public override string SubCategory
    {
        get { return "MySubCategory"; }
    }

    public void AddToList(int value)
    {
        this.numberList.Value.Add(value);
        // Notify the framework of changes 
        this.numberList.OnValueChanged();
    }

    public string MyString
    {
        get { return this.myString.Value; }
        set
        {
            // The framwork is aware of the change to the property since 
            // it is explicitly set. 
            this.myString.Value = value;
        }
    }

    public MyPreference()
    {
        this.myString = this.AddPreference<string>(
            new PreferenceProperty<string>(
            "myString", "1.0",
            PreferencePersistenceScope.Server,
            PreferenceUsage.SingleUser));

        this.numberList = this.AddPreference<ArrayList>(
            new PreferenceProperty<ArrayList>(
                "numberList", "1.0",
                PreferencePersistenceScope.Server,
                PreferenceUsage.SingleUser,
                delegate
                {
                    // Calculate the default value
                    ArrayList defaultList = new ArrayList();
                    defaultList.Add(10);
                    return defaultList;
                }));
    }
}
See Also