Search in sources :

Example 56 with IEditorInput

use of org.eclipse.ui.IEditorInput in project xtext-xtend by eclipse.

the class XbaseEditorInputRedirectorTest method testOpenDerivedFileFromBin.

@Test
public void testOpenDerivedFileFromBin() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package mypack");
        _builder.newLine();
        _builder.append("class HelloXtend {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def void doStuff() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final IFile fileInSrc = this.helper.createFileImpl((WorkbenchTestHelper.TESTPROJECT_NAME + "/src/mypack/HelloXtend.xtend"), _builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("package mypack");
        _builder_1.newLine();
        _builder_1.append("class HelloXtend {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("def void doStuff() {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        final IFile fileInBin = this.helper.createFileImpl((WorkbenchTestHelper.TESTPROJECT_NAME + "/bin/mypack/HelloXtend.xtend"), _builder_1.toString());
        FileEditorInput _fileEditorInput = new FileEditorInput(fileInBin);
        final IEditorInput result = this.redirector.findOriginalSource(_fileEditorInput);
        Assert.assertEquals(fileInSrc, ResourceUtil.getFile(result));
        FileEditorInput _fileEditorInput_1 = new FileEditorInput(fileInSrc);
        final IEditorInput result2 = this.redirector.findOriginalSource(_fileEditorInput_1);
        Assert.assertEquals(fileInSrc, ResourceUtil.getFile(result2));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) IEditorInput(org.eclipse.ui.IEditorInput) Test(org.junit.Test)

Example 57 with IEditorInput

use of org.eclipse.ui.IEditorInput in project linuxtools by eclipse.

the class STLink2SourceSupport method openFileImpl.

private static boolean openFileImpl(IProject project, IPath sourceLoc, int lineNumber) {
    if (sourceLoc == null || "??".equals(sourceLoc.toString())) {
        // $NON-NLS-1$
        return false;
    }
    try {
        IEditorInput editorInput = getEditorInput(sourceLoc, project);
        IWorkbenchPage p = CUIPlugin.getActivePage();
        if (p != null) {
            if (editorInput == null) {
                p.openEditor(new STCSourceNotFoundEditorInput(project, sourceLoc, lineNumber), STCSourceNotFoundEditor.ID, true);
            } else {
                IEditorPart editor = p.openEditor(editorInput, CUIPlugin.EDITOR_ID, true);
                if (lineNumber > 0 && editor instanceof ITextEditor) {
                    IDocumentProvider provider = ((ITextEditor) editor).getDocumentProvider();
                    IDocument document = provider.getDocument(editor.getEditorInput());
                    try {
                        int start = document.getLineOffset(lineNumber - 1);
                        ((ITextEditor) editor).selectAndReveal(start, 0);
                        IWorkbenchPage page = editor.getSite().getPage();
                        page.activate(editor);
                        return true;
                    } catch (BadLocationException x) {
                    // ignore
                    }
                }
            }
        }
    } catch (PartInitException e) {
    }
    return false;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 58 with IEditorInput

use of org.eclipse.ui.IEditorInput in project linuxtools by eclipse.

the class ProfileUIUtils method openEditorAndSelect.

/**
 * Opens the specified file in an editor (or selects an already open
 * editor) and highlights the specified line.
 * @param result - result of performing source lookup with a org.eclipse.debug.core.model.ISourceLocator
 * @param line - line number to select, 0 to not select a line
 * @throws PartInitException - Failed to open editor
 * @throws BadLocationException - Line number not valid in file
 * @see DebugUITools#lookupSource(Object, org.eclipse.debug.core.model.ISourceLocator)
 */
public static void openEditorAndSelect(ISourceLookupResult result, int line) throws PartInitException, BadLocationException {
    IEditorInput input = result.getEditorInput();
    String editorID = result.getEditorId();
    if (input == null || editorID == null) {
        // Consult the CDT DebugModelPresentation
        Object sourceElement = result.getSourceElement();
        if (sourceElement != null) {
            // Resolve IResource in case we get a LocalFileStorage object
            if (sourceElement instanceof LocalFileStorage) {
                IPath filePath = ((LocalFileStorage) sourceElement).getFullPath();
                URI fileURI = URIUtil.toURI(filePath);
                IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
                IFile[] files = root.findFilesForLocationURI(fileURI);
                if (files.length > 0) {
                    // Take the first match
                    sourceElement = files[0];
                }
            }
            IDebugModelPresentation pres = DebugUITools.newDebugModelPresentation(CDebugCorePlugin.getUniqueIdentifier());
            input = pres.getEditorInput(sourceElement);
            editorID = pres.getEditorId(input, sourceElement);
            pres.dispose();
        }
    }
    if (input != null && editorID != null) {
        // Open the editor
        IWorkbenchPage activePage = ProfileUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IEditorPart editor = IDE.openEditor(activePage, input, editorID);
        // Select the line
        if (editor instanceof ITextEditor) {
            ITextEditor textEditor = (ITextEditor) editor;
            if (line > 0) {
                IDocumentProvider provider = textEditor.getDocumentProvider();
                IDocument document = provider.getDocument(textEditor.getEditorInput());
                // zero-indexed
                IRegion lineRegion = document.getLineInformation(line - 1);
                textEditor.selectAndReveal(lineRegion.getOffset(), lineRegion.getLength());
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IPath(org.eclipse.core.runtime.IPath) LocalFileStorage(org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage) IDebugModelPresentation(org.eclipse.debug.ui.IDebugModelPresentation) IEditorPart(org.eclipse.ui.IEditorPart) URI(java.net.URI) IRegion(org.eclipse.jface.text.IRegion) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorInput(org.eclipse.ui.IEditorInput) IDocument(org.eclipse.jface.text.IDocument)

Example 59 with IEditorInput

use of org.eclipse.ui.IEditorInput in project linuxtools by eclipse.

the class ChartExportTest method testChartExportPNG.

@Test
public void testChartExportPNG() throws Exception {
    ILaunchConfiguration config = createConfiguration(proj.getProject());
    // $NON-NLS-1$
    doLaunch(config, "testDefaults");
    IEditorInput input = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getEditorInput();
    assertTrue("input must be ChartEditorInput", input instanceof ChartEditorInput);
    Composite control = ((ChartEditorInput) input).getChart().getChartControl();
    if (control.getSize().x == 0 || control.getSize().y == 0) {
        // Manually resize the composite to non-zero width/height so it can be saved
        control.setSize(10, 10);
    }
    SaveChartAction saveChartAction = (SaveChartAction) getToolbarAction(MassifViewPart.SAVE_CHART_ACTION);
    assertNotNull(saveChartAction);
    for (IPath path : paths) {
        saveAsPath(saveChartAction, path);
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) SaveChartAction(org.eclipse.linuxtools.dataviewers.charts.actions.SaveChartAction) Composite(org.eclipse.swt.widgets.Composite) IPath(org.eclipse.core.runtime.IPath) ChartEditorInput(org.eclipse.linuxtools.internal.valgrind.massif.charting.ChartEditorInput) IEditorInput(org.eclipse.ui.IEditorInput) Test(org.junit.Test)

Example 60 with IEditorInput

use of org.eclipse.ui.IEditorInput in project linuxtools by eclipse.

the class DoubleClickTest method checkFile.

private IEditorPart checkFile(CachegrindFile file) {
    IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    IEditorInput input = editor.getEditorInput();
    IFileEditorInput fileInput = (IFileEditorInput) input;
    IResource expectedResource = proj.getProject().findMember(file.getName());
    File expectedFile = expectedResource.getLocation().toFile();
    File actualFile = fileInput.getFile().getLocation().toFile();
    assertEquals(expectedFile, actualFile);
    return editor;
}
Also used : IFileEditorInput(org.eclipse.ui.IFileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) File(java.io.File) CachegrindFile(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.CachegrindFile) IEditorInput(org.eclipse.ui.IEditorInput) IResource(org.eclipse.core.resources.IResource)

Aggregations

IEditorInput (org.eclipse.ui.IEditorInput)135 IFile (org.eclipse.core.resources.IFile)38 IEditorPart (org.eclipse.ui.IEditorPart)37 PartInitException (org.eclipse.ui.PartInitException)31 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)28 CoreException (org.eclipse.core.runtime.CoreException)25 IFileEditorInput (org.eclipse.ui.IFileEditorInput)22 IDocument (org.eclipse.jface.text.IDocument)17 IEditorReference (org.eclipse.ui.IEditorReference)17 FileEditorInput (org.eclipse.ui.part.FileEditorInput)16 File (java.io.File)14 ArrayList (java.util.ArrayList)14 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)14 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)14 IResource (org.eclipse.core.resources.IResource)13 Shell (org.eclipse.swt.widgets.Shell)13 IViewPart (org.eclipse.ui.IViewPart)13 IPath (org.eclipse.core.runtime.IPath)12 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)12 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)11