Search in sources :

Example 1 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project xtext-eclipse by eclipse.

the class AbstractCompositeHoverTest method testMultipleHovers.

@SuppressWarnings("deprecation")
@Test
public void testMultipleHovers() {
    final ITextHover hover1 = new ITextHover() {

        @Override
        public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
            // TODO Auto-generated method stub
            if (offset == 0)
                return new Region(offset, 0);
            return null;
        }

        @Override
        public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
            return "hover1";
        }
    };
    final ITextHover hover2 = new ITextHover() {

        @Override
        public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
            // TODO Auto-generated method stub
            if (offset == 1)
                return new Region(offset, 0);
            return null;
        }

        @Override
        public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
            return "hover2";
        }
    };
    AbstractCompositeHover hover = new AbstractCompositeHover() {

        @Override
        protected List<ITextHover> createHovers() {
            List<ITextHover> hovers = Lists.newArrayList();
            hovers.add(hover1);
            hovers.add(hover2);
            return hovers;
        }
    };
    assertEquals(2, hover.getHovers().size());
    assertNotNull(hover.getHoverRegion(editor.getInternalSourceViewer(), 0));
    assertEquals("hover1", hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(0, 0)));
    assertNotNull(hover.getHoverRegion(editor.getInternalSourceViewer(), 1));
    assertEquals("hover2", hover.getHoverInfo(editor.getInternalSourceViewer(), new Region(1, 0)));
}
Also used : ITextHover(org.eclipse.jface.text.ITextHover) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion) ITextViewer(org.eclipse.jface.text.ITextViewer) AbstractCompositeHover(org.eclipse.xtext.ui.editor.hover.AbstractCompositeHover) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Example 2 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project xtext-eclipse by eclipse.

the class CrossReferenceProposalTest method testBug276742_08b.

@Test
public void testBug276742_08b() throws Exception {
    String modelAsString = "Foo {}";
    ContentAssistProcessorTestBuilder builder = newBuilder();
    XtextContentAssistProcessor processor = get(XtextContentAssistProcessor.class);
    XtextResource resource = getResourceFromString(modelAsString);
    ITextViewer viewer = builder.getSourceViewer(modelAsString, builder.getDocument(resource, modelAsString));
    ContentAssistContext[] contexts = processor.getContextFactory().create(viewer, modelAsString.length(), resource);
    assertEquals(2, contexts.length);
    Set<EClass> contextTypes = Sets.newHashSet(CrossReferenceProposalTestPackage.Literals.MODEL, CrossReferenceProposalTestPackage.Literals.CLASS);
    CrossReferenceProposalTestLanguageGrammarAccess grammarAccess = get(CrossReferenceProposalTestLanguageGrammarAccess.class);
    for (ContentAssistContext context : contexts) {
        EObject model = context.getCurrentModel();
        assertTrue(contextTypes.remove(model.eClass()));
        if (context.getFirstSetGrammarElements().contains(grammarAccess.getClassAccess().getRightCurlyBracketKeyword_3())) {
            assertEquals(CrossReferenceProposalTestPackage.Literals.CLASS, model.eClass());
        } else {
            assertEquals(CrossReferenceProposalTestPackage.Literals.MODEL, model.eClass());
        }
    }
}
Also used : XtextContentAssistProcessor(org.eclipse.xtext.ui.editor.contentassist.XtextContentAssistProcessor) CrossReferenceProposalTestLanguageGrammarAccess(org.eclipse.xtext.ui.tests.editor.contentassist.services.CrossReferenceProposalTestLanguageGrammarAccess) ContentAssistProcessorTestBuilder(org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder) EClass(org.eclipse.emf.ecore.EClass) ContentAssistContext(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext) EObject(org.eclipse.emf.ecore.EObject) XtextResource(org.eclipse.xtext.resource.XtextResource) ITextViewer(org.eclipse.jface.text.ITextViewer) Test(org.junit.Test)

Example 3 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project xtext-eclipse by eclipse.

the class TextViewerDeleteLineAction method update.

/*
	 * @see IUpdate#update()
	 */
@Override
public void update() {
    super.update();
    if (!isEnabled())
        return;
    if (!canModifyViewer()) {
        setEnabled(false);
        return;
    }
    ITextViewer viewer = getTextViewer();
    if (viewer != null) {
        if (fTarget == null) {
            fTarget = new TextViewerDeleteLineTarget(viewer);
        }
    } else {
        fTarget = null;
    }
    setEnabled(fTarget != null);
}
Also used : ITextViewer(org.eclipse.jface.text.ITextViewer) TextViewerDeleteLineTarget(org.eclipse.ui.texteditor.TextViewerDeleteLineTarget)

Example 4 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project xtext-eclipse by eclipse.

the class TextViewerDeleteLineAction method run.

/*
	 * @see IAction#run()
	 */
@Override
public void run() {
    if (fTarget == null)
        return;
    ITextViewer viewer = getTextViewer();
    if (viewer == null)
        return;
    if (!canModifyViewer())
        return;
    IDocument document = viewer.getDocument();
    if (document == null)
        return;
    ITextSelection selection = getSelection(viewer);
    if (selection == null)
        return;
    try {
        fTarget.deleteLine(document, selection, fType, fCopyToClipboard);
    } catch (BadLocationException e) {
    // should not happen
    }
}
Also used : IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection) BadLocationException(org.eclipse.jface.text.BadLocationException) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 5 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project xtext-eclipse by eclipse.

the class TextViewerJoinLinesAction method run.

@Override
public void run() {
    ITextViewer viewer = getTextViewer();
    if (viewer == null)
        return;
    if (!canModifyViewer())
        return;
    IDocument document = viewer.getDocument();
    if (document == null)
        return;
    ITextSelection selection = getSelection(viewer);
    if (selection == null)
        return;
    int startLine = selection.getStartLine();
    int endLine = selection.getEndLine();
    try {
        int caretOffset = joinLines(document, startLine, endLine);
        if (caretOffset > -1) {
            StyledText widget = viewer.getTextWidget();
            widget.setRedraw(false);
            adjustHighlightRange(viewer, caretOffset, 0);
            viewer.revealRange(caretOffset, 0);
            viewer.setSelectedRange(caretOffset, 0);
            widget.setRedraw(true);
        }
    } catch (BadLocationException e) {
    // should not happen
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection) BadLocationException(org.eclipse.jface.text.BadLocationException) ITextViewer(org.eclipse.jface.text.ITextViewer)

Aggregations

ITextViewer (org.eclipse.jface.text.ITextViewer)71 IDocument (org.eclipse.jface.text.IDocument)13 Region (org.eclipse.jface.text.Region)13 BadLocationException (org.eclipse.jface.text.BadLocationException)12 StyledText (org.eclipse.swt.custom.StyledText)12 IRegion (org.eclipse.jface.text.IRegion)11 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 ITextSelection (org.eclipse.jface.text.ITextSelection)8 Point (org.eclipse.swt.graphics.Point)8 ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)6 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)6 Document (org.eclipse.jface.text.Document)5 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)5 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)5 Display (org.eclipse.swt.widgets.Display)5 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)5 List (java.util.List)4 ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)4 Control (org.eclipse.swt.widgets.Control)4