Forms


Basic concepts of Forms

Table of Contents

In this article, the basic concepts of Forms are explained.

Forms interact

In terms of the MVC concept, the Operations could be called the Controllers. The Forms would be the Views and the Database would be the Model.

A form communicates with the user. Information (handed down from an operation) can be presented and actions (for example button clicks) can invoke new actions.

The AI-Framework distinguishes three types:

  1. A form that is invoked by an Operation 
    This Operation can have more than one form. Data from the Operation is accessible through Operation.SomePublicPropertyOrVar.

  2. A form that is part of an Operation
    This is called a SimpleForm, which inherits from a SimpleFormOperationBase. The Operation and Form are both coded in the same class.

  3. The third option is the FormApplicationBase 
    This is the mechanism in which the menus are built. It is therefore the Main Form, that can only be created once. It is possible to override CreateUI in order to make custom UI. This concept of the ApplicationBase will be explained in other articles.

See also: Operations 

Code examples

The following examples show the different type of forms.

1. Form invoked by Operation

public class InvoiceOverviewOp : FormOperationExBase
{
   public InvoiceOverviewOp( ... , ... , IExpression<IDbKey<User>> userKey)
      : base(database, customerKey)
   {
      RegisterInputParameter(UserKey, userKey);
   }

   protected override IForm CreateStartupForm()
   {
      return new InvoiceOverviewFrm(this);
   }
   ...

This is an operation (normally we end the name of an operation file with the letters Op, as in InvoiceOverviewOp), that needs a form, in this case InvoiceOverviewFrm.

public class InvoiceOverviewFrm : FormBase<InvoiceOverviewOp>
  {
     public InvoiceOverviewFrm(InvoiceOverviewOp operation)
         : base(operation)
     {
     }

     protected override IUIElement CreateGui()
     {
         return new VBox
         {
         ...

This is the form, connected to the operation. 

Note 1: In the AI-Framework, the form has access to all public properties and methods of the operation.
The code is simply: Operation.SomeProperty for a property, or Operation.DoSomething() for a method.

Note 2: An operation may have more than one form. For example a form to show statistics, and another form to ask for additional input. A form can be associated with only one operation. In other words, the same form cannot be used for more than one operation.

 

2. Form part of Operation

public class ConfirmPriceOp: SimpleFormOperationBase
{
   public ConfirmPriceOp(IDbDefinition database)
      : base(database)
   {
   }

   ...

   protected override IUIElement CreateGui(IForm form)
   {
      return new HBox
      {
         ...
      }
   }

The operation ConfirmPriceOp needs one form. In this example, the form is defined and called within the operation class itself. The class inherits from SimpleFormOperationBase, in order to have the necessary elements available. 

Different from the previous example, here the UI is overridden directly in line 10.

 

3. FormApplicationBase

public class SomeApplication : FormApplicationBase, IFiliaalProcess
{

...

   protected override IMenuItem[] CreateMenuItems()
   {
      var mainMenuItems = new List<IMenuItem>
      {
         new GroupMenuItem("articles", Images.Article)
         {
            new FunctionCallMenuItem(new ArticleMaintenanceOp(... some parameters ...)
               .Start(this)
               .AddDisabledWhen(... some boolean ...)
               .Call())
            {
               VisibleWhen = IsActive
            },
            new FunctionCallMenuItem(new ArtikelAddOp(...

The class inherits from FormApplicationBase. This base contains the elements to build up a (grouped) menu structure.

See also Operations 

See also the Tutorial: Setting up an operation and a form  



Article ID: 167
Created: Tue, Aug 27, 2019
Last Updated: Thu, Jan 9, 2020

Online URL: https://wiki-ai-framework.abstract-it.nl/article/forms-167.html