/**
* {@inheritDoc}
*/
public IStructuredSelection findSelection(Object object) {
if (object instanceof ElementImpl) {
ElementImpl element = (ElementImpl) object;
IStructuredDocument document = element.getStructuredDocument();
IFile resource = SpringUIUtils.getFile(document);
// Ensure that if the project is not loaded we skip this in the UI
IBeansProject project = BeansCorePlugin.getModel().getProject(resource.getProject());
if (project instanceof ILazyInitializedModelElement
&& !((ILazyInitializedModelElement) project).isInitialized()) {
return StructuredSelection.EMPTY;
}
// Make sure that the file is actually a beans config
if (!BeansCoreUtils.isBeansConfig(resource)) {
return null;
}
// The line number-based approach is the best approximation that we can currently do
int startLine = document.getLineOfOffset(element.getStartOffset()) + 1;
int endLine = document.getLineOfOffset(element.getEndOffset()) + 1;
IModelElement modelElement = BeansModelUtils.getMostSpecificModelElement(startLine, endLine, resource,
new NullProgressMonitor());
if (modelElement != null) {
return new TreeSelection(BeansUIUtils.createTreePath(modelElement));