List<OperationCategory> primaryCategories = activeModalToolProxy.getOperationCategories();
Collection<OperationCategory> secondaryCategories = getOperationMenuFactory()
.getCategories().values();
for( int i = 0; i < primaryCategories.size(); i++ ) {
OperationCategory category = primaryCategories.get(i);
// Limit the size of the context menu to 20, but don't ever display a portion of
// a category, only always the entire thing.
if (contextManager.getItems().length >= 15 && category.getActions().size() > 5) {
break;
}
MenuManager menu = category.createContextMenu();
if ((i != 0 && menu.getItems().length != 0)
&& (secondaryCategories.size() != 0 || getOperationMenuFactory()
.getActions().size() != 0)) {
contextManager.add(new Separator());
}
for( IContributionItem item : menu.getItems() ) {
contextManager.add(item);
}
}
// if primaryCategories are present, create an "Other" submenu
if (contextManager.getItems().length != 0) {
RunOperationsAction action = new RunOperationsAction();
action.setText(Messages.ToolCategory_other);
contextManager.add(new Separator());
contextManager.add(action);
} else {
Iterator iter = secondaryCategories.iterator();
while( iter.hasNext() ) {
OperationCategory category = (OperationCategory) iter.next();
for( OpAction action : category.getActions() ) {
if( selection instanceof IStructuredSelection )
action.updateEnablement((IStructuredSelection) selection, true);
if (action.isEnabled())
contextManager.add(action);
}