Search in sources :

Example 1 with Accessor

use of org.eclipse.text.tests.Accessor in project eclipse.platform.text by eclipse.

the class EncodingChangeTests method testChangeEncodingViaFile.

@Test
public void testChangeEncodingViaFile() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    try {
        fFile.setCharset(NON_DEFAULT_ENCODING, null);
    } catch (CoreException ex) {
        fail();
    }
    try {
        fEditor = IDE.openEditor(page, fFile);
        if (fEditor instanceof TextEditor) {
            TextEditor editor = (TextEditor) fEditor;
            Accessor accessor = new Accessor(editor, StatusTextEditor.class);
            while (editor.getSite().getShell().getDisplay().readAndDispatch()) {
            }
            ScrolledComposite composite = (ScrolledComposite) accessor.get("fStatusControl");
            assertNull(composite);
            DefaultEncodingSupport encodingSupport = (DefaultEncodingSupport) editor.getAdapter(IEncodingSupport.class);
            assertEquals(NON_DEFAULT_ENCODING, encodingSupport.getEncoding());
        } else
            fail();
    } catch (PartInitException e) {
        fail();
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) DefaultEncodingSupport(org.eclipse.ui.editors.text.DefaultEncodingSupport) StatusTextEditor(org.eclipse.ui.texteditor.StatusTextEditor) TextEditor(org.eclipse.ui.editors.text.TextEditor) CoreException(org.eclipse.core.runtime.CoreException) IEncodingSupport(org.eclipse.ui.editors.text.IEncodingSupport) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) PartInitException(org.eclipse.ui.PartInitException) Accessor(org.eclipse.text.tests.Accessor) Test(org.junit.Test)

Example 2 with Accessor

use of org.eclipse.text.tests.Accessor in project eclipse.platform.text by eclipse.

the class EncodingChangeTests method testChangeEncodingViaEncodingSupport.

@Test
public void testChangeEncodingViaEncodingSupport() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    try {
        fEditor = IDE.openEditor(page, fFile);
        if (fEditor instanceof TextEditor) {
            TextEditor editor = (TextEditor) fEditor;
            while (editor.getSite().getShell().getDisplay().readAndDispatch()) {
            }
            DefaultEncodingSupport encodingSupport = (DefaultEncodingSupport) editor.getAdapter(IEncodingSupport.class);
            encodingSupport.setEncoding(NON_DEFAULT_ENCODING);
            Accessor accessor = new Accessor(editor, StatusTextEditor.class);
            while (editor.getSite().getShell().getDisplay().readAndDispatch()) {
            }
            ScrolledComposite composite = (ScrolledComposite) accessor.get("fStatusControl");
            assertNull(composite);
            String actual = null;
            try {
                actual = fFile.getCharset(false);
            } catch (CoreException e1) {
                fail();
            }
            assertEquals(NON_DEFAULT_ENCODING, actual);
        } else
            fail();
    } catch (PartInitException e) {
        fail();
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) DefaultEncodingSupport(org.eclipse.ui.editors.text.DefaultEncodingSupport) StatusTextEditor(org.eclipse.ui.texteditor.StatusTextEditor) TextEditor(org.eclipse.ui.editors.text.TextEditor) CoreException(org.eclipse.core.runtime.CoreException) IEncodingSupport(org.eclipse.ui.editors.text.IEncodingSupport) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) PartInitException(org.eclipse.ui.PartInitException) Accessor(org.eclipse.text.tests.Accessor) Test(org.junit.Test)

Example 3 with Accessor

use of org.eclipse.text.tests.Accessor in project eclipse.platform.text by eclipse.

the class EncodingChangeTests method testAInvalidEncoding.

@Test
public void testAInvalidEncoding() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    try {
        fFile.setCharset("nonexistent", null);
    } catch (CoreException e2) {
        fail();
    }
    try {
        fEditor = IDE.openEditor(page, fFile);
        if (fEditor instanceof TextEditor) {
            TextEditor editor = (TextEditor) fEditor;
            Accessor accessor = new Accessor(editor, StatusTextEditor.class);
            while (editor.getSite().getShell().getDisplay().readAndDispatch()) {
            }
            ITextFileBuffer fileBuffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
            DefaultEncodingSupport encodingSupport = (DefaultEncodingSupport) editor.getAdapter(IEncodingSupport.class);
            String expected = encodingSupport.getStatusMessage(fileBuffer.getStatus());
            Composite composite = (Composite) accessor.get("fStatusControl");
            ScrolledComposite scrolledComposite = (ScrolledComposite) composite.getChildren()[0];
            StyledText statusText = (StyledText) ((Composite) scrolledComposite.getContent()).getChildren()[5];
            String actual = statusText.getText();
            assertEquals(expected, actual);
        } else
            fail();
    } catch (PartInitException e) {
        fail();
    }
}
Also used : DefaultEncodingSupport(org.eclipse.ui.editors.text.DefaultEncodingSupport) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IEncodingSupport(org.eclipse.ui.editors.text.IEncodingSupport) Accessor(org.eclipse.text.tests.Accessor) IWorkbench(org.eclipse.ui.IWorkbench) StatusTextEditor(org.eclipse.ui.texteditor.StatusTextEditor) TextEditor(org.eclipse.ui.editors.text.TextEditor) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) PartInitException(org.eclipse.ui.PartInitException) Test(org.junit.Test)

Example 4 with Accessor

use of org.eclipse.text.tests.Accessor in project eclipse.platform.text by eclipse.

the class GotoLineTest method goToLine.

private void goToLine(int line, int expectedResult) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
    try {
        IEditorPart part = IDE.openEditor(page, fFile);
        if (part instanceof ITextEditor) {
            ITextEditor editor = (ITextEditor) part;
            IAction action = editor.getAction(ITextEditorActionConstants.GOTO_LINE);
            Accessor accessor = new Accessor(action, GotoLineAction.class);
            accessor.invoke("gotoLine", new Class[] { int.class }, new Integer[] { Integer.valueOf(line) });
            Control control = part.getAdapter(Control.class);
            if (control instanceof StyledText) {
                int caretLine = -1;
                StyledText styledText = (StyledText) control;
                int caret = styledText.getCaretOffset();
                try {
                    IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
                    caretLine = document.getLineOfOffset(caret);
                } catch (BadLocationException e1) {
                    fail();
                }
                assertEquals(expectedResult, caretLine);
            } else
                fail();
        } else
            fail();
    } catch (PartInitException e) {
        fail();
    }
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) Control(org.eclipse.swt.widgets.Control) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) StyledText(org.eclipse.swt.custom.StyledText) IAction(org.eclipse.jface.action.IAction) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) Accessor(org.eclipse.text.tests.Accessor) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 5 with Accessor

use of org.eclipse.text.tests.Accessor in project eclipse.platform.text by eclipse.

the class ContextInfoTest method testContextInfo_hide_Bug512251.

@Test
public void testContextInfo_hide_Bug512251() throws Exception {
    cleanFileAndEditor();
    createAndOpenFile("foobar.txt", BarContentAssistProcessor.PROPOSAL);
    final Set<Shell> beforeShells = Arrays.stream(editor.getSite().getShell().getDisplay().getShells()).filter(Shell::isVisible).collect(Collectors.toSet());
    TextOperationAction action = (TextOperationAction) editor.getAction(ITextEditorActionConstants.CONTENT_ASSIST_CONTEXT_INFORMATION);
    editor.selectAndReveal(4, 0);
    action.update();
    action.run();
    waitAndDispatch(100);
    this.completionShell = findNewShell(beforeShells);
    editor.selectAndReveal(8, 0);
    action.update();
    action.run();
    waitAndDispatch(100);
    this.completionShell = findNewShell(beforeShells);
    editor.getAction(ITextEditorActionConstants.DELETE_LINE).run();
    SourceViewer sourceViewer = getSourceViewer();
    ContentAssistant assist = (ContentAssistant) new Accessor(sourceViewer, SourceViewer.class).get("fContentAssistant");
    new Accessor(assist, ContentAssistant.class).invoke("hide", new Object[0]);
}
Also used : Shell(org.eclipse.swt.widgets.Shell) SourceViewer(org.eclipse.jface.text.source.SourceViewer) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant) Accessor(org.eclipse.text.tests.Accessor) TextOperationAction(org.eclipse.ui.texteditor.TextOperationAction) Test(org.junit.Test)

Aggregations

Accessor (org.eclipse.text.tests.Accessor)12 Test (org.junit.Test)5 Shell (org.eclipse.swt.widgets.Shell)4 IWorkbench (org.eclipse.ui.IWorkbench)4 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)4 PartInitException (org.eclipse.ui.PartInitException)4 ArrayList (java.util.ArrayList)3 CoreException (org.eclipse.core.runtime.CoreException)3 IDocument (org.eclipse.jface.text.IDocument)3 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)3 StyledText (org.eclipse.swt.custom.StyledText)3 DefaultEncodingSupport (org.eclipse.ui.editors.text.DefaultEncodingSupport)3 IEncodingSupport (org.eclipse.ui.editors.text.IEncodingSupport)3 TextEditor (org.eclipse.ui.editors.text.TextEditor)3 StatusTextEditor (org.eclipse.ui.texteditor.StatusTextEditor)3 AbstractInformationControl (org.eclipse.jface.text.AbstractInformationControl)2 AbstractReconciler (org.eclipse.jface.text.reconciler.AbstractReconciler)2 DirtyRegion (org.eclipse.jface.text.reconciler.DirtyRegion)2 IReconcilingStrategy (org.eclipse.jface.text.reconciler.IReconcilingStrategy)2 TestTextViewer (org.eclipse.jface.text.tests.TestTextViewer)2