Java Code Examples for org.eclipse.ui.ide.IDE#getEditorDescriptor()
The following examples show how to use
org.eclipse.ui.ide.IDE#getEditorDescriptor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditorOpener.java From typescript.java with MIT License | 8 votes |
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; }
Example 2
Source File: ClassFileBasedOpenerContributor.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@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; }
Example 3
Source File: EditorOpener.java From Pydev with Eclipse Public License 1.0 | 6 votes |
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; }
Example 4
Source File: StorageBasedTextEditorOpener.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@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); } }
Example 5
Source File: CoreEditorUtils.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
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(); }
Example 6
Source File: ContentTypeExtensionPDETest.java From eclipse-extras with Eclipse Public License 1.0 | 5 votes |
@SuppressWarnings("deprecation") @Test public void testDefaultEditorBinding() throws Exception { IEditorDescriptor editorDescriptor = IDE.getEditorDescriptor( fileName, true ); assertThat( editorDescriptor.getId() ).isEqualTo( ImageViewerEditor.ID ); }
Example 7
Source File: EditorOpener.java From Pydev with Eclipse Public License 1.0 | 5 votes |
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(); }
Example 8
Source File: EditorOpener.java From typescript.java with MIT License | 4 votes |
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(); }
Example 9
Source File: EditorAPI.java From saros with GNU General Public License v2.0 | 4 votes |
/** * 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; }
Example 10
Source File: GoNavigatorLabelProvider.java From goclipse with Eclipse Public License 1.0 | 4 votes |
@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); } }; }