Search in sources :

Example 51 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project webtools.sourceediting by eclipse.

the class TaglibJarHyperlink method open.

public void open() {
    // $NON-NLS-1$
    IEditorInput input = new URLFileHyperlink.StorageEditorInput(new ZipStorage(fZipFilePath.toFile(), "META-INF/taglib.tld"));
    IEditorDescriptor descriptor;
    try {
        descriptor = IDE.getEditorDescriptor(input.getName());
        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);
    }
}
Also used : IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 52 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project webtools.sourceediting by eclipse.

the class AbstractOpenOn method getEditorId.

/**
 * Determines the editor associated with the given file name
 *
 * @param filename
 * @return editor id of the editor associated with the given file name
 */
private String getEditorId(String filename) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IEditorRegistry editorRegistry = workbench.getEditorRegistry();
    IEditorDescriptor descriptor = editorRegistry.getDefaultEditor(filename);
    if (descriptor != null)
        return descriptor.getId();
    return EditorsUI.DEFAULT_TEXT_EDITOR_ID;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IEditorRegistry(org.eclipse.ui.IEditorRegistry)

Example 53 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project n4js by eclipse.

the class N4JSApplicationWorkbenchWindowAdvisor method updateDefaultEditorMappingIfAbsent.

private void updateDefaultEditorMappingIfAbsent() {
    final EditorRegistry registry = (EditorRegistry) WorkbenchPlugin.getDefault().getEditorRegistry();
    for (final IFileEditorMapping editorMapping : registry.getFileEditorMappings()) {
        final IEditorDescriptor defaultEditor = editorMapping.getDefaultEditor();
        if (null == defaultEditor) {
            final String extension = editorMapping.getExtension();
            LOGGER.info("No default editor is associated with files with extension: '." + extension + "'.");
            final IEditorDescriptor defaultTextEditor = registry.findEditor(DEFAULT_TEXT_EDITOR_ID);
            if (null != defaultTextEditor) {
                ((FileEditorMapping) editorMapping).setDefaultEditor(defaultTextEditor);
                String editorName = defaultTextEditor.getLabel();
                if (null == editorName) {
                    editorName = defaultTextEditor.getId();
                }
                if (null != editorName) {
                    LOGGER.info("Associated files with extension " + extension + " with '" + editorName + "'.");
                }
            }
        }
    }
    registry.saveAssociations();
    PrefUtil.savePrefs();
}
Also used : EditorRegistry(org.eclipse.ui.internal.registry.EditorRegistry) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IFileEditorMapping(org.eclipse.ui.IFileEditorMapping) FileEditorMapping(org.eclipse.ui.internal.registry.FileEditorMapping) IFileEditorMapping(org.eclipse.ui.IFileEditorMapping)

Example 54 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project liferay-ide by liferay.

the class DefaultScriptEditorHelper method getEditorId.

public String getEditorId() {
    IContentType contentType = Platform.getContentTypeManager().getContentType("org.eclipse.core.runtime.text");
    IWorkbench workBench = PlatformUI.getWorkbench();
    IEditorRegistry editRegistry = workBench.getEditorRegistry();
    IEditorDescriptor defaultEditorDescriptor = editRegistry.getDefaultEditor("default.txt", contentType);
    return defaultEditorDescriptor.getId();
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IContentType(org.eclipse.core.runtime.content.IContentType) IEditorRegistry(org.eclipse.ui.IEditorRegistry)

Example 55 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project liferay-ide by liferay.

the class OpenPortletResourceAction method findEditor.

/**
 * @param file
 * @return
 */
protected IEditorDescriptor findEditor(IFile file) {
    IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
    IContentType contentType = IDE.getContentType(file);
    IEditorDescriptor editorDescriptor = registry.getDefaultEditor(file.getName(), contentType);
    if (editorDescriptor == null) {
        // no editor associated...
        return null;
    }
    return editorDescriptor;
}
Also used : IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IContentType(org.eclipse.core.runtime.content.IContentType) IEditorRegistry(org.eclipse.ui.IEditorRegistry)

Aggregations

IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)74 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)34 PartInitException (org.eclipse.ui.PartInitException)34 FileEditorInput (org.eclipse.ui.part.FileEditorInput)27 IWorkbench (org.eclipse.ui.IWorkbench)25 IEditorPart (org.eclipse.ui.IEditorPart)21 IFile (org.eclipse.core.resources.IFile)19 IEditorRegistry (org.eclipse.ui.IEditorRegistry)18 CoreException (org.eclipse.core.runtime.CoreException)10 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)10 IEditorInput (org.eclipse.ui.IEditorInput)8 IContentType (org.eclipse.core.runtime.content.IContentType)7 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)7 AbstractTextEditor (org.eclipse.ui.texteditor.AbstractTextEditor)7 Image (org.eclipse.swt.graphics.Image)5 InputStream (java.io.InputStream)4 BadLocationException (org.eclipse.jface.text.BadLocationException)4 Path (org.eclipse.core.runtime.Path)3 IContentDescription (org.eclipse.core.runtime.content.IContentDescription)3 JavaModelException (org.eclipse.jdt.core.JavaModelException)3