Search in sources :

Example 56 with IEditorDescriptor

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

the class OpenPortletResourceAction method openEditor.

protected IEditorPart openEditor(IFile file) {
    IEditorDescriptor editorDescriptor = findEditor(file);
    IEditorPart editorPart = null;
    if (editorDescriptor != null) {
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
        try {
            editorPart = page.findEditor(new FileEditorInput(file));
            if (editorPart == null) {
                editorPart = page.openEditor(new FileEditorInput(file), editorDescriptor.getId());
            }
        } catch (Exception e) {
            MessageDialog.openError(page.getWorkbenchWindow().getShell(), Msgs.errorOpeningFile, e.getMessage());
        }
    }
    return editorPart;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) JavaModelException(org.eclipse.jdt.core.JavaModelException)

Example 57 with IEditorDescriptor

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

the class OpenPortletResourceAction method openPortletJavaClass.

/**
 * @param file
 */
protected void openPortletJavaClass(IFile file) {
    Element modelElement = ((PortletNode) selectedNode).getModel();
    if (modelElement instanceof Portlet) {
        Portlet portlet = (Portlet) modelElement;
        JavaTypeName portletClassFile = portlet.getPortletClass().content();
        Runnable run = new Runnable() {

            public void run() {
                IJavaProject project = JavaCore.create(file.getProject());
                String fullyQualifiedName = portletClassFile.qualified();
                try {
                    IType type = project.findType(fullyQualifiedName);
                    if ((type != null) && type.exists()) {
                        IResource resource = type.getResource();
                        if (resource instanceof IFile) {
                            IFile javaFile = (IFile) resource;
                            IEditorDescriptor editorDescriptor = findEditor(javaFile);
                            IEditorPart editorPart = null;
                            if (editorDescriptor != null) {
                                IWorkbench workbench = PlatformUI.getWorkbench();
                                IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
                                try {
                                    editorPart = page.findEditor(new FileEditorInput(javaFile));
                                    if (editorPart == null) {
                                        editorPart = page.openEditor(new FileEditorInput(javaFile), editorDescriptor.getId());
                                    }
                                } catch (Exception e) {
                                    MessageDialog.openError(page.getWorkbenchWindow().getShell(), Msgs.errorOpeningFile, e.getMessage());
                                }
                            }
                        }
                    }
                } catch (JavaModelException jme) {
                    PortletUIPlugin.logError(jme);
                }
            }
        };
        Display.getDefault().asyncExec(run);
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) Portlet(com.liferay.ide.portlet.core.model.Portlet) IFile(org.eclipse.core.resources.IFile) Element(org.eclipse.sapphire.Element) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IEditorPart(org.eclipse.ui.IEditorPart) JavaModelException(org.eclipse.jdt.core.JavaModelException) PortletNode(com.liferay.ide.portlet.ui.navigator.PortletNode) IType(org.eclipse.jdt.core.IType) IWorkbench(org.eclipse.ui.IWorkbench) IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaTypeName(org.eclipse.sapphire.java.JavaTypeName) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IResource(org.eclipse.core.resources.IResource)

Example 58 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project xtext-eclipse by eclipse.

the class StorageBasedTextEditorOpener method open.

@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);
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput)

Example 59 with IEditorDescriptor

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

the class EgitUiEditorUtils method getEditorId.

private static String getEditorId(String fileName, IContentType type) {
    IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
    IEditorDescriptor descriptor = registry.getDefaultEditor(fileName, type);
    String id;
    if (descriptor == null || descriptor.isOpenExternal()) {
        id = EditorsUI.DEFAULT_TEXT_EDITOR_ID;
    } else {
        id = descriptor.getId();
    }
    return id;
}
Also used : IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IEditorRegistry(org.eclipse.ui.IEditorRegistry)

Example 60 with IEditorDescriptor

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

the class OpenWorkingFileAction method openExternalFile.

/**
 * Opens external file, the editor that is used is based on best guess from
 * file name.
 *
 * @param file
 *            the external file
 */
protected void openExternalFile(File file) {
    try {
        boolean activate = OpenStrategy.activateOnOpen();
        IEditorDescriptor desc = IDE.getEditorDescriptor(file.getName());
        IDE.openEditor(getWorkbenchPage(), file.toURI(), desc.getId(), activate);
    } catch (PartInitException e) {
        ErrorDialog.openError(getWorkbenchPage().getWorkbenchWindow().getShell(), UIText.OpenWorkingFileAction_openWorkingFileShellTitle, e.getMessage(), e.getStatus());
    }
}
Also used : IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) PartInitException(org.eclipse.ui.PartInitException)

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