Search in sources :

Example 71 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project titan.EclipsePlug-ins by eclipse.

the class OpenDeclaration method selectAndRevealRegion.

/**
 * Opens an editor for the provided declaration, and in this editor the
 * location of the declaration is revealed and highlighted.
 *
 * @param file
 *                The file to open.
 * @param offset
 *                The start position of the declaration to select.
 * @param endOffset
 *                The end position of the declaration to select.
 * @param select
 *                Select the given region if true.
 */
private void selectAndRevealRegion(final IFile file, final int offset, final int endOffset, final boolean select) {
    IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
    if (desc == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(EDITORNOTFOUND);
        return;
    }
    if (!select) {
        return;
    }
    try {
        IWorkbenchPage page = targetEditor.getSite().getPage();
        IEditorPart editorPart = page.openEditor(new FileEditorInput(file), desc.getId());
        if (editorPart != null) {
            // not AbstractTextEditor.
            if (editorPart instanceof ConfigEditor) {
                ((AbstractTextEditor) ((ConfigEditor) editorPart).getEditor()).selectAndReveal(offset, endOffset - offset);
            } else if (editorPart instanceof AbstractTextEditor) {
                ((AbstractTextEditor) editorPart).selectAndReveal(offset, endOffset - offset);
            }
        }
    } catch (PartInitException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
}
Also used : IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ConfigEditor(org.eclipse.titan.designer.editors.configeditor.ConfigEditor) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 72 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project titan.EclipsePlug-ins by eclipse.

the class OpenDeclaration method selectAndRevealDeclaration.

/**
 * Opens an editor for the provided declaration, and in this editor the
 * location of the declaration is revealed and selected.
 *
 * @param declaration
 *                the declaration to reveal
 */
private void selectAndRevealDeclaration(final Location location) {
    IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(location.getFile().getName());
    if (desc == null) {
        targetEditor.getEditorSite().getActionBars().getStatusLineManager().setErrorMessage(ASN1EDITORNOTFOUND);
        return;
    }
    try {
        IWorkbenchPage page = targetEditor.getSite().getPage();
        IEditorPart editorPart = page.openEditor(new FileEditorInput((IFile) location.getFile()), desc.getId());
        if (editorPart != null && (editorPart instanceof AbstractTextEditor)) {
            ((AbstractTextEditor) editorPart).selectAndReveal(location.getOffset(), location.getEndOffset() - location.getOffset());
        }
    } catch (PartInitException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException)

Example 73 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project titan.EclipsePlug-ins by eclipse.

the class NewConfigFileWizard method selectAndRevealNewModule.

/**
 * Opens the new module in an editor, plus selects and reveals it in
 * every open windows.
 *
 * @param newModule
 *                the module to be revealed
 */
private void selectAndRevealNewModule(final IFile newModule) {
    final IWorkbench workbench = getWorkbench();
    final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    if (window != null) {
        final IEditorDescriptor desc = ConfigTextEditor.findCFGEditor(workbench);
        final IWorkbenchPage page = window.getActivePage();
        try {
            page.openEditor(new FileEditorInput(newModule), desc.getId());
        } catch (PartInitException e) {
            ErrorReporter.logExceptionStackTrace(e);
        }
    }
    // select and reveal the new file in every window open
    selectAndReveal(newModule);
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException)

Example 74 with IEditorDescriptor

use of org.eclipse.ui.IEditorDescriptor in project erlide_eclipse by erlang.

the class OpenResultsJob method openInEditor.

private void openInEditor(final IFile file) {
    if (file == null) {
        return;
    }
    try {
        file.refreshLocal(IResource.DEPTH_ZERO, null);
    } catch (final CoreException e) {
    }
    final IWorkbench wbench = PlatformUI.getWorkbench();
    final IWorkbenchPage page = wbench.getActiveWorkbenchWindow().getActivePage();
    final IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
    try {
        page.openEditor(new FileEditorInput(file), desc.getId());
    } catch (final PartInitException e) {
        ErlLogger.error(e);
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) CoreException(org.eclipse.core.runtime.CoreException) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) 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