Customizing the main user interface

A solution often contains at least a editing dialog for a global settings object and often several custom tools.

To access these tools and dialogs you need to customize the main user interface. This is accomplished by creating UiComponents.

Add a new item using the Visual template Dynamix 6 - Ui Component.

public partial class MyUiComponent : UiComponent
{
    public MyUiComponent() {}

    public override IEnumerable<UiComponent> GetDependencies()
    {
        // Ensure that the main interface is loaded before this component
        // since we are adding to it.
        yield return Dynamix.MainUiComponent.Instance;
    }

    public override void CreateUi( MainInterfaceUi interfaceUi )
    {
        // Add a wrapping control for our UI
        new MyUiManager().AppendTo( interfaceUi );
    }

    public class MyUiManager : Dynamix.Ui6.Controls.ClientControl {
        // See below
    }
}

Inside the control MyUiManager you can add toolbars, tabs, buttons and other controls to the interface:

public class MyUiManager : Dynamix.Ui6.Controls.ClientControl
{
    protected override void CreateChildControls()
    {
        var toolbar = new Toolbar {
            Headline ="My tools"
        }.AppendTo( MainUiComponent.ToolsTab );

        new ToolbarButton
        {
            Text = "Settings",
            Icon = "gearwheel",
            Client = {
                Click = ClientUtil.EditAndSaveObject(MySettings.Instance)
            }
        }.AppendTo( toolbar.Items );

        new ToolbarButton
        {
            Icon = "newspaper",
            Text = "Nyheter",
            Client = { Click = new MyNewsDialog().Show() }
        }.AppendTo( toolbar.Items );
    }
}

If access to tools depend on the editor having certain privileges we can check this before the button is added.

public class MyUiManager : Dynamix.Ui6.Controls.ClientControl
{
    protected override void CreateChildControls()
    {
        var user = RequestContext.Current.User;
        if( user.HasSystemPrivilege<MyManageNewsPrivilege>() ) {
            new ToolbarButton
            {
                Text = "Settings",
                Icon = "gearwheel",
                Client = {
                    Click = new MyNewsDialog().Show()
                }
            }.AppendTo( toolbar.Items );
        }
    \
}

Last updated 2016-01-15