private static IStructuredSelection getStructuredSelection(
      ISelection selection, IWorkbenchPart workbenchPart) {
    if (selection == null) return null;

    IStructuredSelection structuredSelection = null;

    if (selection instanceof IStructuredSelection) {
      structuredSelection = (IStructuredSelection) selection;
    } else if (workbenchPart != null) {
      try {
        structuredSelection = SelectionConverter.getStructuredSelection(workbenchPart);
      } catch (JavaModelException e) {
        return null;
      }
    }

    return structuredSelection;
  }