/**
   * Opens the editor currently associated with the given element (DartElement, IFile, IStorage...)
   *
   * @return an open editor or <code>null</code> if an external editor was opened
   * @throws PartInitException if the editor could not be opened or the input element is not valid
   */
  public static IEditorPart openInEditor(Object inputElement, boolean activate)
      throws DartModelException, PartInitException {

    if (inputElement instanceof IFile) {
      return openInEditor((IFile) inputElement, activate);
    }
    DartX.todo();
    if (inputElement instanceof ImportElement) {
      inputElement = ((ImportElement) inputElement).getImportedLibrary();
    }
    if (inputElement instanceof Element) {
      CompilationUnitElement cu = getCompilationUnit((Element) inputElement);
      IWorkbenchPage page = DartToolsPlugin.getActivePage();
      if (cu != null && page != null) {
        IEditorPart editor = page.getActiveEditor();
        if (editor != null) {
          Element editorCU = EditorUtility.getEditorInputDartElement2(editor, false);
          if (cu.equals(editorCU)) {
            if (activate && page.getActivePart() != editor) {
              page.activate(editor);
            }
            return editor;
          }
        }
      }
    }

    IEditorInput input = getEditorInput(inputElement);

    if (input == null) {
      return null;
    }

    return openInEditor(input, getEditorID(input), activate);
  }