Search in sources :

Example 11 with IEditorRegistry

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

the class ReferencedFileErrorUtility method openEditorAndGotoError.

public static void openEditorAndGotoError(String uristring, final int line, final int column) {
    if (uristring != null) {
        try {
            URL uri = new URL(uristring);
            if (uri != null) {
                if (// $NON-NLS-1$
                "file".equals(uri.getProtocol())) {
                    String pathString = uri.getPath();
                    IPath path = new Path(pathString);
                    String device = path.getDevice();
                    if (// $NON-NLS-1$
                    (device != null) && device.startsWith("/")) {
                        path = path.setDevice(device.substring(1));
                    }
                    final IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
                    if ((iFile != null) && iFile.exists()) {
                        // Open the editor for this file.
                        final IWorkbench workbench = PlatformUI.getWorkbench();
                        final IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
                        Display.getDefault().asyncExec(new Runnable() {

                            public void run() {
                                try {
                                    IContentType contentType = iFile.getContentDescription().getContentType();
                                    IEditorRegistry editorRegistry = workbench.getEditorRegistry();
                                    String fileName = iFile.getName();
                                    IEditorDescriptor descriptor = editorRegistry.getDefaultEditor(fileName, contentType);
                                    String editorId;
                                    if (descriptor != null) {
                                        editorId = descriptor.getId();
                                    } else {
                                        // $NON-NLS-1$
                                        descriptor = editorRegistry.getDefaultEditor(fileName + ".txt");
                                        editorId = descriptor.getId();
                                    }
                                    if (editorId != null) {
                                        FileEditorInput editorInput = new FileEditorInput(iFile);
                                        IWorkbenchPage activePage = workbenchWindow.getActivePage();
                                        activePage.openEditor(editorInput, editorId);
                                    }
                                } catch (Exception ex) {
                                    // $NON-NLS-1$ //$NON-NLS-2$
                                    LoggerFactory.getLoggerInstance().logError("Exception encountered when attempting to open file: " + iFile + "\n\n", ex);
                                }
                            }
                        });
                        Runnable runnable = new Runnable() {

                            public void run() {
                                IEditorPart editorPart = workbenchWindow.getActivePage().getActiveEditor();
                                gotoError(editorPart, line, column);
                            }
                        };
                        Display.getCurrent().asyncExec(runnable);
                    }
                }
            }
        } catch (Exception e) {
        // Do nothing.
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IContentType(org.eclipse.core.runtime.content.IContentType) IEditorPart(org.eclipse.ui.IEditorPart) URL(java.net.URL) BadLocationException(org.eclipse.jface.text.BadLocationException) IWorkbench(org.eclipse.ui.IWorkbench) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorRegistry(org.eclipse.ui.IEditorRegistry)

Example 12 with IEditorRegistry

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

the class ExtendedStorageEditorInputView method getEditorId.

String getEditorId(IEditorInput input) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IEditorRegistry editorRegistry = workbench.getEditorRegistry();
    IContentType[] types = null;
    String editorID = null;
    if (input instanceof IStorageEditorInput) {
        InputStream inputStream = null;
        try {
            inputStream = ((IStorageEditorInput) input).getStorage().getContents();
        } catch (CoreException e) {
            e.printStackTrace();
        }
        try {
            types = Platform.getContentTypeManager().findContentTypesFor(inputStream, input.getName());
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            if (inputStream != null) {
                inputStream.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    IEditorDescriptor descriptor = editorRegistry.getDefaultEditor(input.getName(), types[0]);
    if (descriptor != null) {
        editorID = descriptor.getId();
    }
    if (editorID == null) {
        editorID = EditorsUI.DEFAULT_TEXT_EDITOR_ID;
    }
    return editorID;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IContentType(org.eclipse.core.runtime.content.IContentType) IOException(java.io.IOException) IEditorRegistry(org.eclipse.ui.IEditorRegistry)

Example 13 with IEditorRegistry

use of org.eclipse.ui.IEditorRegistry 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 14 with IEditorRegistry

use of org.eclipse.ui.IEditorRegistry 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 15 with IEditorRegistry

use of org.eclipse.ui.IEditorRegistry 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

IEditorRegistry (org.eclipse.ui.IEditorRegistry)19 IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)18 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)7 IWorkbench (org.eclipse.ui.IWorkbench)7 IContentType (org.eclipse.core.runtime.content.IContentType)5 Image (org.eclipse.swt.graphics.Image)5 InputStream (java.io.InputStream)2 Path (org.eclipse.core.runtime.Path)2 Point (org.eclipse.swt.graphics.Point)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IStorageEditorInput (org.eclipse.ui.IStorageEditorInput)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 FileEditorInput (org.eclipse.ui.part.FileEditorInput)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URL (java.net.URL)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1