This is an example Custom Entity UI it uses Custom Entity created in the Custom Entity Project.
You will need three components to implement a custom entity UI: Commands, Controller, Default Layout.
Starting with Commands you will need the following references, this example uses the Custom Entity created in the examples.
using LemonEdge.API.Client;
using LemonEdge.Client.Core;
using LemonEdge.Client.Core.Commands.Core;
using LemonEdge.Client.Core.Views.Core;
using LemonEdge.Client.UI.API.Enums;
using LemonEdge.Client.UI.API.Layouts;
using LemonEdge.Examples.CustomEntity.Core.Entities;
using LemonEdge.Examples.CustomEntity.Core.Interfaces;
The EntityCollectionCommand{T} is used for opening a collection of any particular entity type in the system. Here we can override base details of the command within the context of the UI such as hotkeys, if/when the command can be executed (defaults to true), or what actions should occur when the command is executed
[CommandDescriptorOptions(typeof(EntityHelper), EntityHelper.CustomEntityCommandIDString)]
public class CollectionCommands : EntityCollectionCommand<ICustomEntity>
The overrides for the class are very basic as they don't do perform any function for this example
public CollectionCommands(Client.UI.API.Controllers.IRootController controller, IModelLayoutCommon owner) : base(controller, owner)
{
}
public override KeyboardModifierKeys ModifierKeys => KeyboardModifierKeys.Alt;
public override KeyboardKey Key => KeyboardKey.C;
public override bool InternalCanExecute(object parameter)
{
return base.InternalCanExecute(parameter);
}
public override void InternalExecute(object parameter)
{
base.InternalExecute(parameter);
}
The controller deals with displaying information and modifying data. Next you need following refernces for the controller.
using LemonEdge.Client.Core.Views.Core;
using LemonEdge.Client.UI.API.Controls;
using LemonEdge.Examples.CustomEntity.Core.Interfaces;
The BaseGridController{T} is one of many base classes for the configuration of views within the UI. The grid is used when displaying a collection of entities.
public class CustomEntityGridController : BaseGridController<ICustomEntity>
The constructor for the class
public CustomEntityGridController(IBaseGrid<ICustomEntity> view) : base(view)
{
}
Whether to show the "new" command which will allow the user to create a new entity of {T} type within the grid.
public override bool AllowNewCommand => true;
Whether or not to open a newly created item in a new tab. A BaseDefaultSingleViewController{T} mustexist for this entity to work properly.
public override bool AutoOpenNewItemInTab => false;
This code manages how the grid columns are displayed and how they function
protected override IEnumerable<ControlDisplayInfoLight> ColumnNames()
{
return new[]
{
// We configure each control (i.e. column) of the grid in terms of which properties of the entity are shown are shown amongst other details/behavior
new ControlDisplayInfoLight(nameof(ICustomEntity.SomeCustomBool), true)
{ Width = ControlDisplayInfo.DEFAULT_CONTROL_WIDTH_NORMAL, Visible = true },
new ControlDisplayInfoLight(nameof(ICustomEntity.SomeCustomNumber), true)
{ Width = ControlDisplayInfo.DEFAULT_CONTROL_WIDTH_NORMAL, Visible = true },
new ControlDisplayInfoLight(nameof(ICustomEntity.SomeCustomString), true)
{ Width = ControlDisplayInfo.DEFAULT_CONTROL_WIDTH_LARGE, Visible = true }
};
}
The UpdateNewItem method allows us to alter a newly created item before it is added to the grid itself.
protected override Task UpdateNewItem(ICustomEntity item)
{
// Here we are setting a default value to the number property of the custom entity
item.SomeCustomNumber = 100;
return base.UpdateNewItem(item);
}
Default layouts as the name suggest are the default way to set a default layout for a given UI. The following references are needed for the Default layout
using LemonEdge.API.Descriptors;
using LemonEdge.Client.Core.Views.Core;
using LemonEdge.Client.Core.Views.DefaultLayouts;
using LemonEdge.Client.Core.Views.DefaultLayouts.Core;
using LemonEdge.Client.UI.API.Layouts;
using LemonEdge.Examples.CustomEntity.Core.Interfaces;
using LemonEdge.Examples.CustomEntity.UI.Views.Controllers;
For a default layout to work you need the [DefaultLayout] attribute and for the class to inherit from DefaultLayoutGenerator.
public class CustomEntityGridController : BaseGridController<ICustomEntity>
The EntityDescriptor that the layout is for needs to be referenced like this.
public SomeCustomEntityDefaultLayout(Client.UI.API.Controllers.IRootController controller) : base(controller) { }
private readonly EntityDescriptor _desc = EntityDescriptorFactory.Instance.GetDescriptor(typeof(ICustomEntity));
Returns true if this default layout generator works for the specific uniqueLayouName and layoutParam combination.
public override bool CanGenerateLayout(string uniqueLayoutName, string layoutParam)
{
return _desc.SetName == uniqueLayoutName;
}
GenerateLayout creates the layout for the specific entity.
public override Task<LayoutDescriptor> GenerateLayout(string uniqueLayoutName, string layoutParam)
{
var descriptor = new LayoutDescriptor { Name = "Some Custom Entity" };
var mainTab = new LayoutTabSetting { Name = "Entity View", Loaded = false };
var vdf = RootController.UIContext.ViewDescriptorInstanceFactory;
mainTab.Loader = x =>
{
x.HorizontalOrientation = true;
var groupOne = x.AddGroup(true, LayoutDockPosition.Center, 100, 100);
var soleView = vdf.FromView(typeof(IBaseGrid<>), _desc.InterfaceType.Name,
controllerName: nameof(CustomEntityGridController));
groupOne.AddView(soleView, LayoutDockPosition.Center, 100, 100);
return Task.FromResult(1);
};
descriptor.AddTab(mainTab);
return Task.FromResult(descriptor);
}