You are viewing limited content. For full access, please sign in.

Question

Question

Is there a way to access the Token Browser inside of a custom control inside a Custom Workflow Activity?

SDK
asked on April 9, 2020

     I am currently working on building some custom controls inside a workflow activity and I have hit a wall. I have almost everything else working but I am stuck trying to get the Token Browser to work inside a custom control class. What I am trying to do is use a textbox to capture a selected token from a token dialog control, then add that value to a listview all inside a custom control. I know that you can have the proxy generator link a browser button on a public string or object inside the activity itself, but how can you get the browser or tokenTextBoxEditControl to work inside a custom control? How can I reference the context or workflow connection? Any help will be very much appreciated.

0 0

Answer

SELECTED ANSWER
replied on April 10, 2020

This example is a little contrived as the user control contains only the token textbox.  Typically you would have several controls bound to some type of data object that is feeding the all of the controls their values on load and storing them on save.

Here is the design mode;

Here is the code with overridden methods;

using Laserfiche;
using Laserfiche.UI.EditPanel;
using Laserfiche.Workflow.ComponentModel;
using Laserfiche.Custom.Activities;

public class MyUserControl : EditPanelControlBase
{
    private bool _allowEdit = false;


    public new void Load()
    {
        _allowEdit = false;

        this.SuspendLayout();

        try
        {
            this.TextboxWithTokens1.Value = this.Value;
        }
        finally
        {
            this.ResumeLayout();
            _allowEdit = true;
        }
    }

    public override void RefreshContext()
    {
        base.RefreshContext();

        this.TextboxWithTokens1.ClearTokens();
        if ((this.Context != null) && (this.Context.Instance is IActivityProxyEx))
            this.TextboxWithTokens1.SetTokens((ICustomActivityProxy)this.Context.Instance, Design.CustomTokenType.None, Design.CustomTokenType.All);

        this.TextboxWithTokens1.ReparseTokens();
    }

    public override void Save()
    {
        this.Value = (object)this.TextboxWithTokens1.Value;
    }

    protected override void OnContextChanged()
    {
        base.OnContextChanged();
        this.RefreshContext();
    }

    protected override void OnValueChanged(Laserfiche.ComponentModel.PropertyValueChangedEventArgs e)
    {
        this.Load();
        base.OnValueChanged(e);
    }



    private void TextboxWithTokens1_ValueChanged(object sender, ChangedEventArgs<string> e)
    {
        if (_allowEdit)
            this.Save();
    }
}

The RefreshContext method is where the tokens get bound to the control.  In this example I am displaying ALL tokens and denying NONE but in a real world application you would probably limit the types of tokens displayed.

As I mentioned, in a real world application the value of the user control would probably be an object that would be providing values for several controls instead of a single value that is populating the textbox value alone.

1 0

Replies

replied on April 9, 2020

Phil,

Not hard to do but you have to jump through some hoops.  

In the Visual Studio IDE you can add a tab to the Toolbox and add some native Laserfiche controls to your project.  One of those native Laserfiche controls is called TextboxWithTokens.  That control, when properly configured, will provide the functionality you need.

Right mouse click on the Toolbox in the Visual Studio IDE, select the 'Add Tab' option

Name your tab something like 'Laserfiche Custom Controls'.  Right mouse click inside the new tab to get the context menu and select the 'Choose Items' option.

In the 'Choose Items' dialog click the 'Browse' button.  Navigate to the 'C:\Program Files (x86)\Common Files\Laserfiche\Workflow' folder and select the 'Laserfiche.Workflow.Activities.Custom.dll' assembly.

That will add several controls to your project.  The one you want is the 'TexboxWithTokens' control.

You can now drag/drop that control onto your custom control to configure it. 

I assume you have already changed your custom control to inherit from EditPanelControlBase instead of the default System.Windows.Form.UserControl.  You will need to override several methods in EditPanelControlBase to properly configure the new control.

Let me know if you need code examples for those overridden methods.

 

0 0
replied on April 10, 2020

Hello Cliff,

     Thank you so much for your reply. It is odd that I had chosen the Laserfiche.Workflow.Activities.Custom.dll from a different location and I had a different control. I used your method and grabbed the TextBoxwithToken Control. However, I am still stuck with the same issue. I used the textboxwithtokens control and the context menu appears but when you select "Token Dialog" nothing happens. It sounds like I am missing some of the override commands. I am overriding Save, NotifyPanelShown, and Load. If you could share some example code that would be fantastic.

Thank you for your time and effort to reply.

0 0
SELECTED ANSWER
replied on April 10, 2020

This example is a little contrived as the user control contains only the token textbox.  Typically you would have several controls bound to some type of data object that is feeding the all of the controls their values on load and storing them on save.

Here is the design mode;

Here is the code with overridden methods;

using Laserfiche;
using Laserfiche.UI.EditPanel;
using Laserfiche.Workflow.ComponentModel;
using Laserfiche.Custom.Activities;

public class MyUserControl : EditPanelControlBase
{
    private bool _allowEdit = false;


    public new void Load()
    {
        _allowEdit = false;

        this.SuspendLayout();

        try
        {
            this.TextboxWithTokens1.Value = this.Value;
        }
        finally
        {
            this.ResumeLayout();
            _allowEdit = true;
        }
    }

    public override void RefreshContext()
    {
        base.RefreshContext();

        this.TextboxWithTokens1.ClearTokens();
        if ((this.Context != null) && (this.Context.Instance is IActivityProxyEx))
            this.TextboxWithTokens1.SetTokens((ICustomActivityProxy)this.Context.Instance, Design.CustomTokenType.None, Design.CustomTokenType.All);

        this.TextboxWithTokens1.ReparseTokens();
    }

    public override void Save()
    {
        this.Value = (object)this.TextboxWithTokens1.Value;
    }

    protected override void OnContextChanged()
    {
        base.OnContextChanged();
        this.RefreshContext();
    }

    protected override void OnValueChanged(Laserfiche.ComponentModel.PropertyValueChangedEventArgs e)
    {
        this.Load();
        base.OnValueChanged(e);
    }



    private void TextboxWithTokens1_ValueChanged(object sender, ChangedEventArgs<string> e)
    {
        if (_allowEdit)
            this.Save();
    }
}

The RefreshContext method is where the tokens get bound to the control.  In this example I am displaying ALL tokens and denying NONE but in a real world application you would probably limit the types of tokens displayed.

As I mentioned, in a real world application the value of the user control would probably be an object that would be providing values for several controls instead of a single value that is populating the textbox value alone.

1 0
replied on April 10, 2020

You Sir are a genius!! Thanks that is exactly what I needed, I was missing the RefreshContext override method!!!!!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.