if (mAddresses == null) {
createDefaultSettings();
}
Action mainAction = getMainContextMenuAction();
if (program == getPluginManager().getExampleProgram()) {
return new ActionMenu(mainAction);
}
final ArrayList<Object> actionList = new ArrayList<Object>();
listActors = null;
for (int i = 0; i < mAddresses.size(); i++) {
try {
WebAddress address = mAddresses.get(i);
String actionName = mLocalizer.msg("SearchOn", "Search on ") + " " + address.getName();
if (address.getUrl().equals(PROGRAM_SITE)) {
final String url = program.getTextField(ProgramFieldType.URL_TYPE);
if (url != null && url.length() > 0) {
address = new WebAddress(mLocalizer.msg("programPage", "Open page of program"),url,null,false,address.isActive());
actionName = address.getName();
}
else {
address = null;
}
}
// create address of channel on the fly
if (address != null && address.getUrl().equals(CHANNEL_SITE)) {
final Channel channel = program.getChannel();
address = new WebAddress(mLocalizer.msg("channelPage",
"Open page of {0}", channel.getName()), channel.getWebpage(),
null, false, address.isActive());
actionName = address.getName();
/*
// automatically add separator if it is the last menu item (as it is by default)
if (i == mAddresses.size() - 1) {
actionList.add(ContextMenuSeparatorAction.getInstance());
}
*/
}
if (address != null && address.isActive()) {
// create items for a possible sub menu
if (address.getUrl().contains(WEBSEARCH_ALL) && listActors == null) {
findSearchItems(program);
}
if (address.getUrl().contains(WEBSEARCH_ALL) && (listActors.size() + listDirectors.size() + listScripts.size() > 0) && mShowDetails) {
final ArrayList<Object> categoryList = new ArrayList<Object>();
// title
final WebAddress adrTitle = new WebAddress(address.getName(), address.getUrl().replace(WEBSEARCH_ALL, "\"" + program.getTitle() + "\""), null, false, true);
categoryList.add(createSearchAction(program, adrTitle, program.getTitle()));
categoryList.add(ContextMenuSeparatorAction.getDisabledOnTaskMenuInstance());
createSubMenu(program, address, categoryList, mLocalizer.msg("actor", "Actor"), listActors);
createSubMenu(program, address, categoryList, mLocalizer.msg("director","Director"), listDirectors);
createSubMenu(program, address, categoryList, mLocalizer.msg("script","Script"), listScripts);
if (categoryList.size() == 2) {
categoryList.remove(1);
}
final ActionMenu searchMenu = new ActionMenu(actionName, address.getIcon(), categoryList.toArray());
actionList.add(searchMenu);
}
// create only a single menu item for this search
else {
final WebAddress adrTitle = new WebAddress(address.getName(), address.getUrl().replace(WEBSEARCH_ALL, "\"" + program.getTitle() + "\""), null, false, true);
final AbstractAction action = createSearchAction(program, adrTitle,
actionName);
action.putValue(Action.SMALL_ICON, address.getIcon());
actionList.add(action);
}
}
} catch (RuntimeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (actionList.size() == 1) {
final Object action = actionList.get(0);
if (action instanceof ActionMenu) {
return (ActionMenu) action;
}
else if (action instanceof Action) {
return new ActionMenu((Action)action);
}
}
final Object[] actions = new Object[actionList.size()];
actionList.toArray(actions);
return new ActionMenu((String)mainAction.getValue(Action.NAME), (Icon)mainAction.getValue(Action.SMALL_ICON), actions);
}