There are plenty of actions enabled/disabled based on the type of element currently selected.
See for instance the "Copy" actions on an element not meant to be copied:
That means you can check how a org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart
manages its own contextual menu and their associated actions.
Start from the method menuAboutToShow()
, using a PackageExplorerActionGroup
class, including a CCPActionGroup
which manage to Copy, Cut and Paste actions.
That last class illistrates the registration of Actions, amongst them the CopyToClipboardAction
:
It does implement a selectionChanged
method.
public void selectionChanged(IStructuredSelection selection) {
try {
List JavaDoc elements= selection.toList();
IResource[] resources= ReorgUtils.getResources(elements);
IJavaElement[] javaElements= ReorgUtils.getJavaElements(elements);
if (elements.size() != resources.length + javaElements.length)
setEnabled(false);
else
setEnabled(canEnable(resources, javaElements));
} catch (JavaModelException e) {
//no ui here - this happens on selection changes
// http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
if (JavaModelUtil.isExceptionToBeLogged(e))
JavaPlugin.log(e);
setEnabled(false);
}
}