Dynamically generating menus [message #1128050] |
Mon, 07 October 2013 09:27  |
Eclipse User |
|
|
|
I would like to create a dynamic number of menus based on the result of a lookup call.
In the example below, getTable().setMenus doesn't exist.
The alternative which I had thought possible was to use getMenus and and setMenus on the page instead of its table (and there, setMenus does exist) but it doesn't seem to have an effect. Any idea why this is not straight forward?
@Override
protected void execInitPage() throws ProcessingException {
ArrayList<IMenu> menus = new ArrayList<>();
menus.addAll(Arrays.asList(getTable().getMenus()));
SomeLookupCall call = new SomeLookupCall();
call.setText("A7* - ");
LookupRow[] rows = null;
try {
rows = call.getDataByText();
}
catch (ProcessingException e) {
// do nothing
}
if (rows != null) {
for (LookupRow row : rows) {
final String s = row.getText();
IMenu menu = new AbstractMenu() {
@Override
public String getText() {
return s;
}
@Override
protected void execAction() throws ProcessingException {
doSomethingAwesomeWith(s);
}
};
menus.add(menu);
}
getTable().setMenus(menus.toArray(new IMenu[0]));
}
}
|
|
|
|
|
Re: Dynamically generating menus [message #1545849 is a reply to message #1129299] |
Sun, 04 January 2015 15:23  |
Eclipse User |
|
|
|
I just discovered that for the Luna release, any dynamically generated sub-menus should override getConfiguredMenuTypes() and specify the same values as the container menu they are being added to.
e.g. You have a multi-select menu called "Send to ->" which contains a list of recipients loaded from a favourite contacts table page.
Send to -> Harry
Joe
Fred Because the "Send to" menu's getConfiguredMenuTypes() includes TreeMenuType.MultiSelection, so must all sub-menus being added to it. If not, they will simply not appear, and nor will the parent menu. This is somewhat tricky to debug.
|
|
|
Powered by
FUDForum. Page generated in 0.02747 seconds