org.eclipse.ui.ide.IDE.getEditorDescriptor()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中org.eclipse.ui.ide.IDE.getEditorDescriptor()方法的一些代码示例,展示了IDE.getEditorDescriptor()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IDE.getEditorDescriptor()方法的具体详情如下:
包路径:org.eclipse.ui.ide.IDE
类名称:IDE
方法名:getEditorDescriptor

IDE.getEditorDescriptor介绍

[英]Returns an editor descriptor appropriate for opening a file resource with the given name.

The editor descriptor is determined using a multi-step process. This method will attempt to infer content type from the file name.

  1. The workbench editor registry is consulted to determine if an editor extension has been registered for the file type. If so, an instance of the editor extension is opened on the file. See IEditorRegistry.getDefaultEditor(String).
  2. The operating system is consulted to determine if an in-place component editor is available (e.g. OLE editor on Win32 platforms).
  3. The operating system is consulted to determine if an external editor is available.
  4. The workbench editor registry is consulted to determine if the default text editor is available.
    [中]返回适用于打开具有给定名称的文件资源的编辑器描述符。
    编辑器描述符是使用多步骤过程确定的。此方法将尝试从文件名推断内容类型。
    1.查阅workbench editor注册表以确定是否已为文件类型注册了编辑器扩展名。如果是,则在文件上打开编辑器扩展名的实例。请参见IEditorRegistry.getDefaultEditor(String)
    1.咨询操作系统以确定是否有就地组件编辑器可用(例如Win32平台上的OLE编辑器)。
    1.查阅操作系统以确定是否有外部编辑器可用。
    1.查阅workbench editor注册表以确定默认文本编辑器是否可用。

代码示例

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.ui.ide

public static IEditorDescriptor getEditorDescriptor(String name)
    throws PartInitException {
  return getEditorDescriptor(name, true);

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

private static String getEditorID(IEditorInput input) throws PartInitException {
  Assert.isNotNull(input);
  IEditorDescriptor editorDescriptor;
  if (input instanceof IFileEditorInput)
    editorDescriptor= IDE.getEditorDescriptor(((IFileEditorInput)input).getFile());
  else {
    String name= input.getName();
    if (name == null)
      throwPartInitException(JavaEditorMessages.EditorUtility_could_not_find_editorId);
    editorDescriptor= IDE.getEditorDescriptor(name);
  }
  return editorDescriptor.getId();
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.debug.ui

/**
 * @see IDebugModelPresentation#getEditorId(IEditorInput, Object)
 */
public String getEditorId(IEditorInput input, Object inputObject) {
  try {
    IEditorDescriptor descriptor= IDE.getEditorDescriptor(input.getName());
    return descriptor.getId();
  } catch (PartInitException e) {
    return null;
  }
}

代码示例来源:origin: org.apache.uima/ruta-ep-ide-ui

public String getEditorId(IEditorInput input, Object inputObject) {
 try {
  IEditorDescriptor descriptor = IDE.getEditorDescriptor(input.getName());
  return descriptor.getId();
 } catch (PartInitException e) {
  return null;
 }
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.ant.ui

/**
 * Opens an editor on the buildfile of the provided node and selects that node in the editor.
 * 
 * @param page
 *            the page to open the editor in
 * @param node
 *            the node from the buildfile to open and then select in the editor
 */
public static void openInEditor(IWorkbenchPage page, AntElementNode node) {
  IFile file = node.getIFile();
  IEditorDescriptor editorDesc;
  try {
    editorDesc = IDE.getEditorDescriptor(file, true, true);
  }
  catch (PartInitException e) {
    return;
  }
  openInEditor(page, editorDesc, node);
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.jdt.ui

public static String getEditorID(IEditorInput input) throws PartInitException {
  Assert.isNotNull(input);
  if (input instanceof IFileEditorInput)
    return IDE.getEditorDescriptor(((IFileEditorInput)input).getFile()).getId();
  String name= input.getName();
  if (input instanceof IClassFileEditorInput) {
    boolean hasSource;
    try {
      hasSource= ((IClassFileEditorInput) input).getClassFile().getSourceRange() != null;
    } catch (JavaModelException e) {
      hasSource= false;
    }
    if (!hasSource)
      name= "*.class without source"; //$NON-NLS-1$
  }
  return IDE.getEditorDescriptor(name).getId();
}

代码示例来源:origin: org.eclipse.jdt/org.eclipse.jdt.ui

public static String getEditorID(IEditorInput input) throws PartInitException {
  Assert.isNotNull(input);
  if (input instanceof IFileEditorInput)
    return IDE.getEditorDescriptor(((IFileEditorInput)input).getFile()).getId();
  String name= input.getName();
  if (input instanceof IClassFileEditorInput) {
    boolean hasSource;
    try {
      hasSource= ((IClassFileEditorInput) input).getClassFile().getSourceRange() != null;
    } catch (JavaModelException e) {
      hasSource= false;
    }
    if (!hasSource) {
      if (JavaModelUtil.MODULE_INFO_CLASS.equals(name)) {
        name= "module-info.class without source"; //$NON-NLS-1$
      } else {
        name= "*.class without source"; //$NON-NLS-1$
      }
    }
  }
  return IDE.getEditorDescriptor(name).getId();
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.team.ui

public static IEditorDescriptor getDefaultEditor(IFileRevision revision) {
  String name= revision.getName();
  // so far only the revision name is used to find the default editor
  try {
    return IDE.getEditorDescriptor(name);
  } catch (PartInitException e) {
    // Fallback to old way of getting the editor
    IEditorRegistry registry= PlatformUI.getWorkbench().getEditorRegistry();
    return registry.getDefaultEditor(name);
  }
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.ui.ide

editorDesc = getEditorDescriptor(input, true, true);
} catch (OperationCanceledException ex) {
  return null;

代码示例来源:origin: org.eclipse.pde/org.eclipse.pde.api.tools.ui

@Override
  public IStatus runInUIThread(IProgressMonitor monitor) {
    IEditorDescriptor edesc = null;
    try {
      edesc = IDE.getEditorDescriptor(index.getName());
      IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
      IDE.openEditor(window.getActivePage(), index.toURI(), edesc.getId(), true);
    } catch (PartInitException e) {
      e.printStackTrace();
    }
    return Status.OK_STATUS;
  }
};

代码示例来源:origin: org.eclipse.pde.api.tools/ui

public IStatus runInUIThread(IProgressMonitor monitor) {
    IEditorDescriptor edesc = null;
    try {
      edesc = IDE.getEditorDescriptor(index.getName());
      IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
      IDE.openEditor(window.getActivePage(), 
          index.toURI(), 
          edesc.getId(), 
          true);
    } catch (PartInitException e) {
      e.printStackTrace();
    }
    return Status.OK_STATUS;
  }
};

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.ui.ide

/**
 * Opens editors on given file resources.
 * <p>
 * If the page already has an editor open on the target object then that
 * editor is brought to front; otherwise, a new editor is opened. The editor created
 * for the first input will be activated.
 * </p>
 * @param page the page in which the editor will be opened
 * @param inputs the inputs for the editors
 * @return references to the editors opened; the corresponding editors might not be materialized
 * @exception MultiPartInitException if at least one of the editors could not be initialized
 * @since 3.5
 */
public static IEditorReference[] openEditors(IWorkbenchPage page, IFile[] inputs) throws MultiPartInitException {
  if ((page == null) || (inputs == null))
    throw new IllegalArgumentException();
  String[] editorDescriptions = new String[inputs.length];
  IEditorInput[] editorInputs = new IEditorInput[inputs.length];
  for(int i = 0 ; i < inputs.length; i++) {
    editorInputs[i] = new FileEditorInput(inputs[i]);
    try {
      editorDescriptions[i] = getEditorDescriptor(inputs[i]).getId();
    } catch (PartInitException e) {
      PartInitException[] exceptions = new PartInitException[inputs.length];
      exceptions[i] = e;
      throw new MultiPartInitException(new IWorkbenchPartReference[inputs.length], exceptions);
    }
  }
  return page.openEditors(editorInputs, editorDescriptions, IWorkbenchPage.MATCH_INPUT);
}

代码示例来源:origin: org.eclipse/org.eclipse.jdt.ui

private String getEditorID(IFile file) throws PartInitException {
  IEditorDescriptor desc= IDE.getEditorDescriptor(file);
  if (desc == null)
    return JavaPlugin.getDefault().getWorkbench().getEditorRegistry().findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID).getId();
  else
    return desc.getId();
}

代码示例来源:origin: org.eclipse/org.eclipse.search

private String getEditorID(IFile file) throws PartInitException {
  IEditorDescriptor desc= IDE.getEditorDescriptor(file);
  if (desc == null)
    return SearchPlugin.getDefault().getWorkbench().getEditorRegistry().findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID).getId();
  return desc.getId();
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.search

private String getEditorID(IFile file) throws PartInitException {
  IEditorDescriptor desc = IDE.getEditorDescriptor(file, true, true);
  if (desc == null)
    return SearchPlugin.getDefault().getWorkbench().getEditorRegistry().findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID).getId();
  return desc.getId();
}

代码示例来源:origin: org.eclipse.egit/ui

/**
 * Opens external file, the editor that is used is based on best guess from
 * file name.
 *
 * @param file
 *            the external file
 */
protected void openExternalFile(File file) {
  try {
    boolean activate = OpenStrategy.activateOnOpen();
    IEditorDescriptor desc = IDE.getEditorDescriptor(file.getName());
    IDE.openEditor(getWorkbenchPage(), file.toURI(), desc.getId(),
        activate);
  } catch (PartInitException e) {
    ErrorDialog.openError(getWorkbenchPage().getWorkbenchWindow()
        .getShell(),
        UIText.OpenWorkingFileAction_openWorkingFileShellTitle, e
            .getMessage(), e.getStatus());
  }
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.search

public IEditorPart openAndSelect(IWorkbenchPage wbPage, IFile file, int offset, int length, boolean activate) throws PartInitException {
  String editorId= null;
  IEditorDescriptor desc = IDE.getEditorDescriptor(file, true, true);
  if (desc == null || !desc.isInternal()) {
    editorId= "org.eclipse.ui.DefaultTextEditor"; //$NON-NLS-1$
  } else {
    editorId= desc.getId();
  }
  IEditorPart editor;
  if (NewSearchUI.reuseEditor()) {
    editor= showWithReuse(file, wbPage, editorId, activate);
  } else {
    editor= showWithoutReuse(file, wbPage, editorId, activate);
  }
  if (editor instanceof ITextEditor) {
    ITextEditor textEditor= (ITextEditor) editor;
    textEditor.selectAndReveal(offset, length);
  } else if (editor != null) {
    showWithMarker(editor, file, offset, length);
  }
  return editor;
}

代码示例来源:origin: org.eclipse/org.eclipse.wst.xml.ui

public void open() {
    if (fHyperlinkFile != null) {
      IEditorInput input = new ExternalFileEditorInput(fHyperlinkFile);
      IEditorDescriptor descriptor;
      try {
        descriptor = IDE.getEditorDescriptor(input.getName(), true);
        if (descriptor != null) {
          IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
          IDE.openEditor(page, input, descriptor.getId(), true);
        }
      }
      catch (PartInitException e) {
        Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
      }
    }
  }
}

代码示例来源:origin: ajermakovics/eclipse-instasearch

/**
 * @param doc
 * @param selectedLineMatches
 * @param contentProvider 
 * @param workbenchPage 
 * @throws Exception 
 */
public MatchHighlightJob(SearchResultDoc doc, MatchLine selectedLineMatches, ResultContentProvider contentProvider, Job searchJob, IWorkbenchPage workbenchPage) throws Exception 
{
  super("Highlight Matches");
  
  this.doc = doc;
  this.selectedLineMatches = selectedLineMatches;
  this.contentProvider = contentProvider;
  this.searchJob = searchJob;
  this.workbenchPage = workbenchPage;
  
  IEditorInput input = contentProvider.getEditorInput(doc);
  IEditorDescriptor editorDesc = IDE.getEditorDescriptor(doc.getFileName());
  
  IEditorPart editorPart = IDE.openEditor(workbenchPage, input, editorDesc.getId());
  this.editor = getTextEditor(input, editorPart);
  this.document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
  
  IStorage storage = contentProvider.getStorage(doc);
  this.file = null;
  if( storage instanceof IFile )
    file = (IFile) storage;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.ui.ide

IDE.setDefaultEditor(file, null);
try {
  openEditor(IDE.getEditorDescriptor(file, true, true), false);
} catch (PartInitException e) {
  DialogUtil.openError(page.getWorkbenchWindow()

相关文章