예제 #1
0
  private static IEditorPart openInEditor(IFile file, boolean activate) throws PartInitException {

    UIInstrumentationBuilder instrumentation =
        UIInstrumentation.builder("EditorUtility.openInEditor-IFile");
    try {

      if (file == null) {
        throwPartInitException(DartEditorMessages.EditorUtility_file_must_not_be_null);
      }

      instrumentation.data("FileName", file.getName());
      instrumentation.data("FilePath", file.getFullPath().toOSString());
      instrumentation.metric("activate", activate);

      IWorkbenchPage p = DartToolsPlugin.getActivePage();
      if (p == null) {
        throwPartInitException(DartEditorMessages.EditorUtility_no_active_WorkbenchPage);
      }

      IEditorDescriptor desc = IDE.getEditorDescriptor(file, true);

      String editorId = desc.getId();
      boolean isTooComplex = false;
      editorId = maybeSwapDefaultEditorDescriptor(editorId);
      if (DartUI.isTooComplexDartFile(file)) {
        isTooComplex = true;
        editorId = EditorsUI.DEFAULT_TEXT_EDITOR_ID;
      }

      IEditorPart editor = IDE.openEditor(p, file, editorId, activate);
      if (isTooComplex) {
        DartUI.showTooComplexDartFileWarning(editor);
      }
      initializeHighlightRange(editor);
      return editor;
    } catch (RuntimeException e) {
      instrumentation.metric("Exception", e.getClass().toString());
      instrumentation.data("Exception", e.toString());
      throw e;
    } finally {
      instrumentation.log();
    }
  }