Search in sources :

Example 41 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project eclipse.platform.text by eclipse.

the class ReconcilerTest method testMultipleReconcilers.

@Test
public void testMultipleReconcilers() throws Exception {
    secondFile = project.getFile("bar.txt");
    secondFile.create(new ByteArrayInputStream("".getBytes()), true, null);
    secondEditor = (ExtensionBasedTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new FileEditorInput(secondFile), "org.eclipse.ui.genericeditor.GenericEditor");
    performTestOnEditor(ReconcilerStrategyFirst.SEARCH_TERM, secondEditor, ReconcilerStrategySecond.REPLACEMENT);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileEditorInput(org.eclipse.ui.part.FileEditorInput) Test(org.junit.Test)

Example 42 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project eclipse.platform.text by eclipse.

the class ReconcilerTest method testMultipleEditors.

@Test
public void testMultipleEditors() throws Exception {
    secondProject = ResourcesPlugin.getWorkspace().getRoot().getProject(getClass().getName() + System.currentTimeMillis());
    secondProject.create(null);
    secondProject.open(null);
    secondFile = secondProject.getFile("foo.txt");
    secondFile.create(new ByteArrayInputStream("bar 'bar'".getBytes()), true, null);
    secondEditor = (ExtensionBasedTextEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(new FileEditorInput(secondFile), "org.eclipse.ui.genericeditor.GenericEditor");
    performTestOnEditor(ReconcilerStrategyFirst.SEARCH_TERM, editor, ReconcilerStrategyFirst.REPLACEMENT);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileEditorInput(org.eclipse.ui.part.FileEditorInput) Test(org.junit.Test)

Example 43 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project linuxtools by eclipse.

the class ContentAssistTests method getResults.

protected ICompletionProposal[] getResults(IFile file, int offset) throws Exception {
    disableContributions();
    // call the ContentAssistProcessor
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    FileEditorInput editorInput = new FileEditorInput(file);
    IEditorPart editorPart = page.openEditor(editorInput, "org.eclipse.cdt.ui.editor.CEditor");
    CEditor editor = (CEditor) editorPart;
    @SuppressWarnings("unused") IAction completionAction = editor.getAction("ContentAssistProposal");
    String contentType = editor.getViewer().getDocument().getContentType(offset);
    ContentAssistant assistant = new ContentAssistant();
    CContentAssistProcessor processor = new CContentAssistProcessor(editor, assistant, contentType);
    return processor.computeCompletionProposals(editor.getViewer(), offset);
}
Also used : CEditor(org.eclipse.cdt.internal.ui.editor.CEditor) IAction(org.eclipse.jface.action.IAction) CContentAssistProcessor(org.eclipse.cdt.internal.ui.text.contentassist.CContentAssistProcessor) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant)

Example 44 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project linuxtools by eclipse.

the class SpecStructureCreator method parseSpecfile.

private void parseSpecfile(DocumentRangeNode root, IDocument doc, IFile file) {
    SpecfileParser parser = new SpecfileParser();
    // FIXME: error markers do not show
    if (file != null) {
        FileEditorInput fei = new FileEditorInput(file);
        // without it, the compare editor is blank
        try {
            SpecfileEditor.getSpecfileDocumentProvider().disconnect(fei);
            SpecfileEditor.getSpecfileDocumentProvider().connect(fei);
        } catch (CoreException e) {
            SpecfileLog.logError(e);
        }
        parser.setErrorHandler(new SpecfileErrorHandler(fei, doc));
        parser.setTaskHandler(new SpecfileTaskHandler(fei, doc));
        Specfile specfile = parser.parse(doc);
        String id = specfile.getName();
        // Be a child under parent node of specfileSectionRoot (would be
        // rootNode)
        SpecNode fileNode = new SpecNode((DocumentRangeNode) root.getParentNode(), 1, id, doc, 0, doc.getLength());
        for (SpecfileSection sec : specfile.getSections()) {
            try {
                addNode(root, doc, sec.getName(), doc.getLineOffset(sec.getLineNumber()), doc.getLineOffset(sec.getSectionEndLine()) - doc.getLineOffset(sec.getLineNumber()), 2);
            } catch (BadLocationException e) {
                SpecfileLog.logError(e);
            }
        }
        // Be a child under the parent file node
        for (SpecfilePackage sPackage : specfile.getPackages().getPackages()) {
            try {
                SpecNode pNode = addNode(fileNode, doc, sPackage.getPackageName(), doc.getLineOffset(sPackage.getLineNumber()), doc.getLineOffset(sPackage.getSectionEndLine()) - doc.getLineOffset(sPackage.getLineNumber()), 3);
                for (SpecfileSection section : sPackage.getSections()) {
                    addNode(pNode, doc, section.getName(), doc.getLineOffset(section.getLineNumber()), doc.getLineOffset(section.getSectionEndLine()) - doc.getLineOffset(section.getLineNumber()), 4);
                }
            } catch (BadLocationException e) {
                SpecfileLog.logError(e);
            }
        }
    }
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) SpecfileSection(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection) SpecfileTaskHandler(org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileTaskHandler) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) SpecfileErrorHandler(org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler) SpecfileParser(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser) SpecfilePackage(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 45 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project linuxtools by eclipse.

the class SourcesFileHyperlinkDetector method detectHyperlinks.

@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    if (region == null || textViewer == null) {
        return null;
    }
    if (editor == null) {
        editor = this.getAdapter(SpecfileEditor.class);
        if (editor == null) {
            return null;
        }
    }
    IDocument document = textViewer.getDocument();
    int offset = region.getOffset();
    if (document == null) {
        return null;
    }
    IRegion lineInfo;
    String line;
    try {
        lineInfo = document.getLineInformationOfOffset(offset);
        line = document.get(lineInfo.getOffset(), lineInfo.getLength());
    } catch (BadLocationException ex) {
        return null;
    }
    List<IHyperlink> tempHList = new ArrayList<>();
    // !! it feels like there is duplicate code, fix that !!
    if (editor.getEditorInput() instanceof FileEditorInput) {
        IFile original = ((FileEditorInput) editor.getEditorInput()).getFile();
        if (line.startsWith(SOURCE_IDENTIFIER) || line.startsWith(PATCH_IDENTIFIER) || line.startsWith(URL_IDENTIFIER)) {
            int delimiterIndex = line.indexOf(':') + 1;
            String identifierValue = line.substring(delimiterIndex).trim();
            boolean validURL = RPMUtils.isValidUrl(identifierValue);
            // if valid URL, get its file name; else make file name the original identifier value
            String fileName = validURL ? RPMUtils.getURLFilename(identifierValue) : identifierValue;
            String resolvedFileName = UiUtils.resolveDefines(editor.getSpecfile(), fileName);
            boolean fileExists = RPMUtils.fileExistsInSources(original, resolvedFileName);
            if (region.getOffset() > lineInfo.getOffset() + line.indexOf(identifierValue)) {
                IRegion fileNameRegion = new Region(lineInfo.getOffset() + line.indexOf(identifierValue), identifierValue.length());
                if (fileExists) {
                    // add "Open" file option
                    tempHList.add(new SourcesFileHyperlink(original, resolvedFileName, fileNameRegion));
                } else {
                    if (line.startsWith(PATCH_IDENTIFIER) && !identifierValue.endsWith("/")) {
                        // $NON-NLS-1$
                        // add "Create" patch option using filename
                        tempHList.add(new SourcesFileCreateHyperlink(original, resolvedFileName, fileNameRegion));
                    }
                }
                // if valid URL and has a valid file
                if (validURL && !identifierValue.endsWith("/")) {
                    // $NON-NLS-1$
                    // add "Download" option
                    tempHList.add(new SourcesFileDownloadHyperlink(original, UiUtils.resolveDefines(editor.getSpecfile(), identifierValue), fileNameRegion));
                }
            }
        }
    }
    return tempHList.isEmpty() ? null : tempHList.toArray(new IHyperlink[tempHList.size()]);
}
Also used : IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IRegion(org.eclipse.jface.text.IRegion) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) FileEditorInput(org.eclipse.ui.part.FileEditorInput) SpecfileEditor(org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileEditor) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

FileEditorInput (org.eclipse.ui.part.FileEditorInput)262 IFile (org.eclipse.core.resources.IFile)187 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)99 PartInitException (org.eclipse.ui.PartInitException)96 IEditorPart (org.eclipse.ui.IEditorPart)64 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)58 IPath (org.eclipse.core.runtime.IPath)57 IEditorInput (org.eclipse.ui.IEditorInput)55 CoreException (org.eclipse.core.runtime.CoreException)51 IResource (org.eclipse.core.resources.IResource)39 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)38 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)37 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)35 SaveAsDialog (org.eclipse.ui.dialogs.SaveAsDialog)35 EObject (org.eclipse.emf.ecore.EObject)33 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)33 HashMap (java.util.HashMap)32 Resource (org.eclipse.emf.ecore.resource.Resource)32 ISelection (org.eclipse.jface.viewers.ISelection)32 URI (org.eclipse.emf.common.util.URI)31