on 04-24-2008 5:32 AM
Dear all,
Can I bind RFC for menu? In my project, menu is having six levels of sub menus.Can I add submenus dynamically, like reading any property file?
Thanks
Rajani
Hi,
Following is the sample code to create menu and menu items dynamically
IWDMenu menu = (IWDMenu)view.createElement(IWDMenu.class);
IWDMenuItem menuItem = (IWDMenu)view.createElement(IWDMenuItem.class);
menu.addItem(menuItem);
IWDMenuActionItem menuActionItem = (IWDMenuActionItem) view.createElement(IWDMenuActionItem.class);
menu.addItem(menuActionItem);
Regards
Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Which release are you using and where do you want to attach the menu?
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Still unclear. Where are these menus, in a MenuBar? When exactly do you want to change the menu content, after executing some action?
If you want to add a submenu after an action has been triggered, you can do this as follows:
Add a boolean context attribute "updateMenu" to the view context. Set this to true in the action handler.
In method wdDoModifyView(), write something like
wdDoModifyView(...)
{
if ( wdContext.currentContextElement().getUpdateMenu() )
{
/* reset flag */
wdContext.currentContextElement().setUpdateMenu(false);
/* access parent menu and submenu, create if not yet existing */
IWDMenu parentMenu = (IWDMenu) view.getElement("ID_of_parent_menu");
IWDMenu menu = (IWDMenu) view.getElement("ID_of_submenu");
if (menu == null)
{
menu = (IWDMenu) view.createElement(IWDMenu.class, "ID_of_submenu");
menu.setTitle("Title of Submenu");
parentMenu.addItem(menu /*, index*/);
}
else
{
/* here you can clear the previous menu items if needed: */
menu.destroyAllItems();
}
/* Just an example, real data could come from model or wherever */
String[][] itemDefs = { {"Command1", "Text1"}, {"Command2", "Text2"} };
for (int i = 0; i < itemDefs.length; ++i)
{
String[] itemDef = itemDefs<i>;
IWDMenuActionItem item = (IWDMenuActionItem) view.createElement(IWDMenuActionItem.class, null);
menu.addItem(item);
item.setText(itemDef[1]);
item.setOnAction( wdThis.wdGet<CommonActionForAllItems>Action() );
/* use a constant event parameter to determine in the action handler which menu item was selected */
item.mappingOfOnAction().setString("command", itemDef[0]);
}
}
/** Action handler for common action. Add parameter "command" to action! */
void onAction<CommonActionForAllItems>(..., String command)
{
if ("Command1".equals(command))
{
/* menu item corresponding to command1 has been selected */
}
/* etc. */
}
Armin
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.