Java Code Examples for org.eclipse.ui.IEditorRegistry#getDefaultEditor()

The following examples show how to use org.eclipse.ui.IEditorRegistry#getDefaultEditor() . 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: SVNConflictResolver.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private String getEditorId(IFileStore file) {
	IWorkbench workbench = PlatformUI.getWorkbench();
	IEditorRegistry editorRegistry= workbench.getEditorRegistry();
	IEditorDescriptor descriptor= editorRegistry.getDefaultEditor(file.getName(), getContentType(file));

	// check the OS for in-place editor (OLE on Win32)
	if (descriptor == null && editorRegistry.isSystemInPlaceEditorAvailable(file.getName()))
		descriptor= editorRegistry.findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);
	
	// check the OS for external editor
	if (descriptor == null && editorRegistry.isSystemExternalEditorAvailable(file.getName()))
		descriptor= editorRegistry.findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
	
	if (descriptor != null)
		return descriptor.getId();
	
	return EditorsUI.DEFAULT_TEXT_EDITOR_ID;
}
 
Example 2
Source File: OpenJavaSourceAction.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private String getEditorId( IFileStore file )
{
	IWorkbench workbench = window.getWorkbench( );
	IEditorRegistry editorRegistry = workbench.getEditorRegistry( );
	IEditorDescriptor descriptor = editorRegistry.getDefaultEditor( file.getName( ),
			getContentType( file ) );

	// check the OS for in-place editor (OLE on Win32)
	if ( descriptor == null
			&& editorRegistry.isSystemInPlaceEditorAvailable( file.getName( ) ) )
	{
		descriptor = editorRegistry.findEditor( IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID );
	}

	// check the OS for external editor
	if ( descriptor == null
			&& editorRegistry.isSystemExternalEditorAvailable( file.getName( ) ) )
	{
		descriptor = editorRegistry.findEditor( IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID );
	}

	return ( descriptor == null ) ? "" : descriptor.getId( ); //$NON-NLS-1$
}
 
Example 3
Source File: PyOpenResourceAction.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void openFiles(PythonpathZipChildTreeNode[] pythonPathFilesSelected) {
    for (PythonpathZipChildTreeNode n : pythonPathFilesSelected) {
        try {
            if (PythonPathHelper.isValidSourceFile(n.zipPath)) {
                new PyOpenAction().run(new ItemPointer(n.zipStructure.file, new Location(), new Location(), null,
                        n.zipPath));
            } else {
                IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();
                IEditorDescriptor defaultEditor = editorReg.getDefaultEditor(n.zipPath);
                PydevZipFileStorage storage = new PydevZipFileStorage(n.zipStructure.file, n.zipPath);
                PydevZipFileEditorInput input = new PydevZipFileEditorInput(storage);

                if (defaultEditor != null) {
                    IDE.openEditor(page, input, defaultEditor.getId());
                } else {
                    IDE.openEditor(page, input, EditorsUI.DEFAULT_TEXT_EDITOR_ID);
                }
            }
        } catch (PartInitException e) {
            Log.log(e);
        }
    }
}
 
Example 4
Source File: AbapGitStagingService.java    From ADT_Frontend with MIT License 5 votes vote down vote up
private String getEditorId(String fileName) {
	if (fileName.endsWith("xml")) { //$NON-NLS-1$
		//if file type is .xml, return the associated XML editor
		IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor desc = editorReg.getDefaultEditor(fileName, Platform.getContentTypeManager().findContentTypeFor(fileName));
		if (desc != null) {
			return desc.getId();
		}
	}
	//use eclipse default text editor for all other files
	return IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID;
}
 
Example 5
Source File: OpenXMLResultsAction.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static String getEditorId(File file) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IEditorRegistry editorRegistry = workbench.getEditorRegistry();
    IEditorDescriptor descriptor = editorRegistry.getDefaultEditor(file.getName(), getContentType(file));
    if (descriptor != null) {
        return descriptor.getId();
    }
    return EditorsUI.DEFAULT_TEXT_EDITOR_ID;
}
 
Example 6
Source File: ViewLogCommandHandler.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param filePath
 *            TODO: we should really make this into a utility function, and have the Ruble::Editor.open method use
 *            it. But I am giving up for now because Eclipse plugin dependencies drive me crazy!
 */
private void openEditorForFile(String filePath)
{
	File file = new File(filePath);
	// Process an existing file.
	if (file.exists() && file.isFile())
	{
		Path path = new Path(filePath);
		IFile fileForLocation = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
		IEditorRegistry editorRegistry = PlatformUI.getWorkbench().getEditorRegistry();
		IEditorDescriptor editorDescriptor = null;
		if (fileForLocation == null)
		{
			IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(filePath);
			editorDescriptor = editorRegistry.getDefaultEditor(filePath, contentType);
		}
		else
		{
			editorDescriptor = editorRegistry.getDefaultEditor(filePath);
		}
		String editorId = (editorDescriptor == null) ? "com.aptana.editor.text" : editorDescriptor.getId(); //$NON-NLS-1$
		try
		{
			IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), file.toURI(),
					editorId, true);
		}
		catch (PartInitException e)
		{
			IdeLog.logError(UIPlugin.getDefault(), e);
		}
	}
}
 
Example 7
Source File: URIHyperlink.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected IEditorDescriptor getEditorDescriptor()
{
	IEditorRegistry editorReg = PlatformUI.getWorkbench().getEditorRegistry();
	if (uri.getPath() == null || uri.getPath().equals("/") || uri.getPath().trim().equals("")) //$NON-NLS-1$ //$NON-NLS-2$
	{
		return null;
	}
	IPath path = new Path(uri.getPath());
	return editorReg.getDefaultEditor(path.lastSegment());
}
 
Example 8
Source File: OpenFileAction.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private IEditorDescriptor getEditorDescriptor( IEditorInput input,
		boolean determineContentType )
{
	if ( input == null )
	{
		throw new IllegalArgumentException( );
	}
	IContentType contentType = Platform.getContentTypeManager( )
			.findContentTypeFor( input.getName( ) );
	IEditorRegistry editorReg = PlatformUI.getWorkbench( )
			.getEditorRegistry( );
	return editorReg.getDefaultEditor( input.getName( ), contentType );
}