Search in sources :

Example 46 with IEditorDescriptor

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

the class ExternalFileHyperlink method getEditorLabel.

private String getEditorLabel() {
    final IFileStore store = EFS.getLocalFileSystem().getStore(fHyperlinkFile.toURI());
    final String name = store.fetchInfo().getName();
    if (name == null) {
        return null;
    }
    IContentType contentType = null;
    try {
        InputStream is = null;
        try {
            is = store.openInputStream(EFS.NONE, null);
            contentType = Platform.getContentTypeManager().findContentTypeFor(is, name);
        } finally {
            if (is != null) {
                is.close();
            }
        }
    } catch (CoreException ex) {
    // continue without content type
    } catch (IOException ex) {
    // continue without content type
    }
    final IEditorDescriptor descriptor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(name, contentType);
    return descriptor != null ? descriptor.getLabel() : null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) InputStream(java.io.InputStream) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IFileStore(org.eclipse.core.filesystem.IFileStore) IContentType(org.eclipse.core.runtime.content.IContentType) IOException(java.io.IOException)

Example 47 with IEditorDescriptor

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

the class URLStorageHyperlink method open.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.text.hyperlink.IHyperlink#open()
	 */
public void open() {
    if (fURL != null) {
        IEditorInput input = new StorageEditorInput(new URLStorage(fURL));
        try {
            final IEditorDescriptor descriptor = getEditorDescriptor();
            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);
            new URLHyperlink(fRegion, fURL.toString()).open();
        }
    }
}
Also used : IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) URLHyperlink(org.eclipse.jface.text.hyperlink.URLHyperlink) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 48 with IEditorDescriptor

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

the class NewXSDWizard method openEditor.

public void openEditor(final IFile iFile) {
    if (iFile != null) {
        IWorkbench workbench2;
        if (workbench == null) {
            workbench2 = XSDEditorPlugin.getPlugin().getWorkbench();
        } else {
            workbench2 = workbench;
        }
        final IWorkbenchWindow workbenchWindow = workbench2.getActiveWorkbenchWindow();
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                try {
                    String editorId = null;
                    IEditorDescriptor editor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(iFile.getLocation().toOSString(), iFile.getContentDescription().getContentType());
                    if (editor != null) {
                        editorId = editor.getId();
                    }
                    workbenchWindow.getActivePage().openEditor(new FileEditorInput(iFile), editorId);
                } catch (PartInitException ex) {
                } catch (CoreException ex) {
                }
            }
        });
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) CoreException(org.eclipse.core.runtime.CoreException) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) PartInitException(org.eclipse.ui.PartInitException)

Example 49 with IEditorDescriptor

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

the class URLFileRegionHyperlink method open.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.text.hyperlink.IHyperlink#open()
	 */
public void open() {
    if (fURL != null) {
        IEditorInput input = new StorageEditorInput(new URLStorage(fURL));
        IEditorDescriptor descriptor;
        try {
            descriptor = IDE.getEditorDescriptor(input.getName(), true);
            if (descriptor != null) {
                IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                IEditorPart openedEditor = IDE.openEditor(page, input, descriptor.getId(), true);
                IRegion definitionRegion = findDefinitionRegion(new URLStorage(fURL));
                if (definitionRegion != null) {
                    openedEditor.getSite().getSelectionProvider().setSelection(new TextSelection(definitionRegion.getOffset(), definitionRegion.getLength()));
                }
            }
        } catch (PartInitException e) {
            Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e);
        }
    }
}
Also used : IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) TextSelection(org.eclipse.jface.text.TextSelection) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput) IRegion(org.eclipse.jface.text.IRegion)

Example 50 with IEditorDescriptor

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

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