org.eclipse.ui.ide.IDE#getEditorDescriptor ( )源码实例Demo

下面列出了org.eclipse.ui.ide.IDE#getEditorDescriptor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public boolean collectSourceFileOpeners(IEditorPart editor, IAcceptor<FileOpener> acceptor) {
	if (!(editor instanceof XtextEditor) && editor.getEditorInput() != null) {
		try {
			IClassFile classFile = Adapters.adapt(editor, IClassFile.class);
			if (classFile == null) {
				return false;
			}
			ITrace trace = traceForTypeRootProvider.getTraceToSource(classFile);
			if (trace == null) {
				return false;
			}
			for (ILocationInResource location : trace.getAllAssociatedLocations()) {
				String name = location.getAbsoluteResourceURI().getURI().lastSegment();
				IEditorDescriptor editorDescriptor = IDE.getEditorDescriptor(name);
				acceptor.accept(createEditorOpener(editor.getEditorInput(), editorDescriptor.getId()));
				return true;
			}
		} catch (PartInitException e) {
			LOG.error(e.getMessage(), e);
		}
	}
	return false;
}
 
源代码2 项目: typescript.java   文件: EditorOpener.java
public IEditorPart openAndSelect(IWorkbenchPage wbPage, IFile file, int offset, int length, boolean activate) throws PartInitException {
	String editorId= null;
	IEditorDescriptor desc= IDE.getEditorDescriptor(file);
	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;
}
 
源代码3 项目: Pydev   文件: EditorOpener.java
public IEditorPart openAndSelect(IWorkbenchPage wbPage, IFile file, int offset, int length, boolean activate)
        throws PartInitException {
    String editorId = null;
    IEditorDescriptor desc = IDE.getEditorDescriptor(file);
    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;
}
 
@Override
public void open(IWorkbenchPage page) {
	try {
		IEditorInput input = EditorUtils.createEditorInput(storage);
		IEditorDescriptor editorDescriptor = IDE.getEditorDescriptor(storage.getName());
		IEditorPart opened = IDE.openEditor(page, input, editorDescriptor.getId());
		if (region != null && opened instanceof ITextEditor) {
			ITextEditor openedTextEditor = (ITextEditor) opened;
			openedTextEditor.selectAndReveal(region.getOffset(), region.getLength());
		}
	} catch (PartInitException e) {
		LOG.error(e.getMessage(), e);
	}
}
 
源代码5 项目: xds-ide   文件: CoreEditorUtils.java
public static String getEditorID(IEditorInput input) throws PartInitException {
    Assert.isNotNull(input);
    IEditorDescriptor editorDescriptor;
    if (input instanceof IFileEditorInput)
        editorDescriptor= IDE.getEditorDescriptor(((IFileEditorInput)input).getFile());
    else {
        editorDescriptor= IDE.getEditorDescriptor(input.getName());
    }
    return editorDescriptor.getId();
}
 
@SuppressWarnings("deprecation")
@Test
public void testDefaultEditorBinding() throws Exception {
  IEditorDescriptor editorDescriptor = IDE.getEditorDescriptor( fileName, true );

  assertThat( editorDescriptor.getId() ).isEqualTo( ImageViewerEditor.ID );
}
 
源代码7 项目: Pydev   文件: EditorOpener.java
private String getEditorID(IFile file) throws PartInitException {
    IEditorDescriptor desc = IDE.getEditorDescriptor(file);
    if (desc == null) {
        return PydevPlugin.getDefault().getWorkbench().getEditorRegistry()
                .findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID).getId();
    }
    return desc.getId();
}
 
源代码8 项目: typescript.java   文件: EditorOpener.java
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();
}
 
源代码9 项目: saros   文件: EditorAPI.java
/**
 * Opens the editor for the given file. Needs to be called from an UI thread.
 *
 * @param activate <code>true</code>, if editor should get focus, otherwise <code>false</code>
 * @return the opened editor or <code>null</code> if the editor couldn't be opened.
 */
public static IEditorPart openEditor(saros.filesystem.IFile wrappedFile, boolean activate) {
  IFile file = ((EclipseFileImpl) wrappedFile).getDelegate();

  if (!file.exists()) {
    log.error("EditorAPI cannot open file which does not exist: " + file, new StackTrace());
    return null;
  }

  IWorkbenchWindow window = getActiveWindow();

  if (window == null) return null;

  try {
    IWorkbenchPage page = window.getActivePage();

    /*
     * TODO Use
     *
     * IWorkbenchPage.openEditor(IEditorInput input, String editorId,
     * boolean activate)
     *
     * to open an editor and set activate to false! So that we can
     * separate opening from activating, which save us duplicate sending
     * of activated events.
     */

    IEditorDescriptor descriptor = IDE.getEditorDescriptor(file);
    if (descriptor.isOpenExternal()) {
      /*
       * WORK-AROUND for #224: Editors are opened externally
       * erroneously (http://sourceforge.net/p/dpp/bugs/224)
       *
       * TODO Open as an internal editor
       */
      log.warn(
          "Editor for file "
              + file.getName()
              + " is configured to be opened externally,"
              + " which is not supported by Saros");

      if (warnOnceExternalEditor) {
        warnOnceExternalEditor = false;
        WarningMessageDialog.showWarningMessage(
            "Unsupported Editor Settings",
            "Eclipse is configured to open this file externally, "
                + "which is not supported by Saros.\n\nPlease change the configuration"
                + " (Right Click on File -> Open With...) so that the file is opened in Eclipse."
                + "\n\nAll further "
                + "warnings of this type will be shown in the error "
                + "log.");
      }
      return null;
    }

    return IDE.openEditor(page, file, activate);
  } catch (PartInitException e) {
    log.error("could not initialize part: ", e);
  }

  return null;
}
 
源代码10 项目: goclipse   文件: GoNavigatorLabelProvider.java
@Override
protected DefaultGetImageSwitcher getBaseImage_switcher() {
	return new DefaultGetImageSwitcher() {
		
		@Override
		public ImageDescriptor visitResource(IResource resource) {
			return getResourceImageDescriptor(resource);
		}
		
		@Override
		public ImageDescriptor visitGoPathElement(GoPathElement goPathElement) {
			if(goPathElement instanceof GoRootElement) {
				return GoPluginImages.NAV_LibraryNative;
			}
			if(goPathElement instanceof GoPathEntryElement) {
				return GoPluginImages.NAVIGATOR_GOPATH_ENTRY.getDescriptor();
			}
			throw assertFail();
		}

		@Override
		public ImageDescriptor visitFileStoreElement(IFileStore fileStore) {
			try {
				if (fileStore.fetchInfo().isDirectory()) {
					return GoPluginImages.NAV_SourceFolder;
				}
				
				// TODO: should cleanup/review this.
				
				IEditorDescriptor descriptor = IDE.getEditorDescriptor(fileStore.getName(), true, false);
				if (descriptor != null) {
					return descriptor.getImageDescriptor();
				} else {
					IWorkbench workbench = PlatformUI.getWorkbench();
					return workbench.getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE);
				}
			} catch (PartInitException e) {
			}
			return null;
		}
		
		@Override
		public ImageDescriptor visitBundleElement(IBundleModelElement bundleElement) {
			return new BundleModelGetImageSwitcher() {
				
			}.switchBundleElement(bundleElement);
		}
		
	};
}