On working with repository objects it is available to execute various operations whether via context menu or in visual interface of objects. Operations can be common for all objects, for example, opening for viewing or editing. Each object can have a specific set of available functionalities. In order to not repeat implementation of various visual dialog boxes or visual interface of the objects, the Ui assembly implements specific means to execute various commands on repository objects. The list of available commands and sets of parameters required for execution are given in description of the IUiCommandTarget.Execute method. The following stages are to be executed to execute the command in code:
Using the IWinApplication.GetObjectTarget or IWinApplication.GetPluginTarget method get the object that will be used to execute commands. The IWinApplication.GetObjectTarget method is used on executing general commands for selected object, the IWinApplication.GetPluginTarget method is used on executing commands of the plugin that is used to work with a specific block or tool of Foresight Analytics Platform.
Using the IUiCommandTarget.CreateExecutionContext method create the context that is used to set parameters of command execution.
Call the IUiCommandTarget.Execute method to execute the command.
The result of commands execution is various standard visual dialog boxes that are used on working with tools in Foresight Analytics Platform.
See below examples of some commands execution:
// Open repository object
Sub OpenObject;
Var
Mb: IMetabase;
ObjDes: IMetabaseObjectDescriptor;
Target: IUiCommandTarget;
Begin
MB := MetabaseClass.Active;
ObjDes := MB.ItemById("Report");
// Execute command for the specified repository object
Target := WinApplication.Instance.GetObjectTarget(ObjDes);
Target.Execute("Object.Open", Null);
End Sub OpenObject;
// Set up user properties
Sub UserProperty;
Var
Mb: IMetabase;
MbSec: IMetabaseSecurity;
User: ISecuritySubject;
Target: IUiCommandTarget;
Context: IUiCommandExecutionContext;
Data: Array;
Begin
MB := MetabaseClass.Active;
MbSec := MB.Security;
User := MbSec.ResolveName("USER");
// Execute administration plugin commands
Target := WinApplication.Instance.GetPluginTarget("Adm");
// Context for setting up command execution parameters
Context := Target.CreateExecutionContext;
Data := New Variant[2];
// Security manager
Data[0] := MbSec;
// User
Data[1] := User;
Context.Data := Data;
Target.Execute("ShowUserProp", Context);
End Sub UserProperty;
// Set up conditional format parameters for the specified cell range
Sub FormatConditions;
Var
Mb: IMetabase;
Report: IPrxReport;
Sheet: ITabSheet;
Target: IUiCommandTarget;
Context: IUiCommandExecutionContext;
Data: Array;
Result: Variant;
Begin
Mb := MetabaseClass.Active;
// Open report for edit
Report := Mb.ItemById("Report").Edit As IPrxReport;
// Get active sheet table
Sheet := (Report.ActiveSheet As IPrxTable).TabSheet;
Target := WinApplication.Instance.GetPluginTarget("Report");
Context := Target.CreateExecutionContext;
Data := New Variant[2];
Data[0] := Sheet;
// Range, for which it is required to set up conditional formatting
Data[1] := Sheet.ParseRange("A0:B10");
Context.Data := Data;
Result := Target.Execute("FormatConditionsSetup", Context);
// If in the dialog box the user clicked OK, then save report with changes
If Result Then
(Report As IMetabaseObject).Save;
End If;
End Sub FormatConditions;
See also: