I have been looking to make use of Context Menu (CM) in Dexterity but lacked the opportunity. I have finally found the chance in developing my Account Hierarchy window and here is how it works.
First my CM options are valid when the user is operating within the Tree View (TV) control. If the user right-clicks while in the TV then I want those options to be actions the user can take. I provided the following options for the user.
1. Add Hierarchy As Child
2. Add Hierarchy As Sibling
3. Add Account As Child
4. Add Account As Sibling
5 Remove Node
I implemented my CM menu as follows.
A. Added a ContextMenu script to the TV control.
B. Added Commands to the Form to relate to each CM menu option.
C. Added stored procedures to SQL to act on the user's selection.
In the CM script I first use the TreeView_GetSelectedNode function to locate where the user is working from. This is important because if the user right clicks an existing Account node then they cannot go any further down in the hierarchy thus no Child options will be offered to them.
I then use the Command_GetTag function to start a CM. I follow that by Command_GetTag and CommandList_Add functions for each menu item.
local integer result;
local integer command_tag;
local integer context_menu_command_list;
local long node_ID;
local long parent_ID;
{Get the ID of the clicked-on node.}
node_ID = TreeView_GetSelectedNode('(L) tvHierarchy');
{Get the index of the table record.}
parent_ID = TreeView_GetNodeData('(L) tvHierarchy', node_ID);
{look up the selected record}
HID of table ThyHierarchy = parent_ID;
get table ThyHierarchy;
{Build the context menu}
context_menu_command_list = Command_GetTag(command cmdListContextMenu);
if length('Segment ID' of table ThyHierarchy) = 0 then
{this is not an account}
{AddHierarchyChild}
command_tag = Command_GetTag(command AddHierarchyChild of form Hierarchy);
result = CommandList_Add(context_menu_command_list, command_tag);
{AddHierarchySibling}
command_tag = Command_GetTag(command AddHierarchySibling of form Hierarchy);
result = CommandList_Add(context_menu_command_list, command_tag);
{Separator}
command_tag = Command_GetTag(command cmdSeparator);
result = CommandList_Add(context_menu_command_list, command_tag);
{AddAccountChild}
command_tag = Command_GetTag(command AddAccountChild of form Hierarchy);
result = CommandList_Add(context_menu_command_list, command_tag);
end if;
{AddAccountSibling}
command_tag = Command_GetTag(command AddAccountSibling of form Hierarchy);
result = CommandList_Add(context_menu_command_list, command_tag);
{Separator}
command_tag = Command_GetTag(command cmdSeparator);
result = CommandList_Add(context_menu_command_list, command_tag);
{RemoveNode}
command_tag = Command_GetTag(command RemoveNode of form Hierarchy);
result = CommandList_Add(context_menu_command_list, command_tag);
Each CM option has a corresponding Command definition similar to below. The Display Name is what the user sees in the right-click menu.
This in turn calls a script that runs the stored procedure that performs whatever is required of the process. This one adds a new Account node as a child of the current node.
local long ret_code;
local long node_ID;
local long parent_ID;
local string account;
{Get the ID of the expanding node.}
node_ID = TreeView_GetSelectedNode('(L) tvHierarchy' of window Hierarchy);
{Get the index of the table record.}
parent_ID = TreeView_GetNodeData('(L) tvHierarchy' of window Hierarchy, node_ID);
if getstring("Enter as many of the first digits of the account number as a mask (i.e. 11)",false,account) then
call ThyHIAddAccountChild, ret_code, parent_ID, account;
node_ID = TreeView_AddNode(
'(L) tvHierarchy' of window Hierarchy,
account,0,node_ID, false, 3, 3, 1);
end if;
I can't wait to use this feature again in Dexterity.

No comments:
Post a Comment