use of org.eclipse.ui.actions.CommandNotMappedException in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method findContributedAction.
/**
* Returns the action with the given action id that has been contributed via XML to this editor.
* The lookup honors the dependencies of plug-ins.
*
* @param actionID the action id to look up
* @return the action that has been contributed
* @since 2.0
*/
private IAction findContributedAction(String actionID) {
List<IConfigurationElement> actions = new ArrayList<>();
// $NON-NLS-1$
IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(PlatformUI.PLUGIN_ID, "editorActions");
for (int i = 0; i < elements.length; i++) {
IConfigurationElement element = elements[i];
if (TAG_CONTRIBUTION_TYPE.equals(element.getName())) {
IWorkbenchPartSite site = getSite();
if (site == null) {
return null;
}
if (// $NON-NLS-1$
!site.getId().equals(element.getAttribute("targetID")))
continue;
// $NON-NLS-1$
IConfigurationElement[] children = element.getChildren("action");
for (int j = 0; j < children.length; j++) {
IConfigurationElement child = children[j];
if (// $NON-NLS-1$
actionID.equals(child.getAttribute("actionID")))
actions.add(child);
}
}
}
int actionSize = actions.size();
if (actionSize > 0) {
IConfigurationElement element;
if (actionSize > 1) {
IConfigurationElement[] actionArray = actions.toArray(new IConfigurationElement[actionSize]);
ConfigurationElementSorter sorter = new ConfigurationElementSorter() {
@Override
public IConfigurationElement getConfigurationElement(Object object) {
return (IConfigurationElement) object;
}
};
sorter.sort(actionArray);
element = actionArray[0];
} else
element = actions.get(0);
try {
return new ContributedAction(getSite(), element);
} catch (CommandNotMappedException e) {
// out of luck, no command action mapping
}
}
return null;
}
Aggregations