Search in sources :

Example 61 with ITextViewer

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

the class TextViewerMoveLinesAction method beginCompoundEdit.

/**
 * Ends the compound change.
 */
private void beginCompoundEdit() {
    ITextViewer viewer = getTextViewer();
    if (fEditInProgress || viewer == null || !(viewer instanceof ITextViewerExtension))
        return;
    fEditInProgress = true;
    fStrategy.arm(viewer);
    IRewriteTarget target = ((ITextViewerExtension) viewer).getRewriteTarget();
    if (target != null) {
        target.beginCompoundChange();
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) IRewriteTarget(org.eclipse.jface.text.IRewriteTarget) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 62 with ITextViewer

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

the class TextViewerMoveLinesAction method endCompoundEdit.

/**
 * Ends the compound change.
 */
private void endCompoundEdit() {
    ITextViewer viewer = getTextViewer();
    if (!fEditInProgress || viewer == null || !(viewer instanceof ITextViewerExtension))
        return;
    IRewriteTarget target = ((ITextViewerExtension) viewer).getRewriteTarget();
    if (target != null) {
        target.endCompoundChange();
    }
    fEditInProgress = false;
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) IRewriteTarget(org.eclipse.jface.text.IRewriteTarget) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 63 with ITextViewer

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

the class CrossReferenceProposalTest method testBug276742_09b.

@Test
public void testBug276742_09b() 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, 0, resource);
    assertEquals(1, contexts.length);
    for (ContentAssistContext context : contexts) {
        assertEquals(CrossReferenceProposalTestPackage.Literals.MODEL, context.getCurrentModel().eClass());
    }
}
Also used : XtextContentAssistProcessor(org.eclipse.xtext.ui.editor.contentassist.XtextContentAssistProcessor) ContentAssistProcessorTestBuilder(org.eclipse.xtext.ui.testing.ContentAssistProcessorTestBuilder) ContentAssistContext(org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext) XtextResource(org.eclipse.xtext.resource.XtextResource) ITextViewer(org.eclipse.jface.text.ITextViewer) Test(org.junit.Test)

Example 64 with ITextViewer

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

the class XtextSourceViewerConfiguration method getHyperlinkDetectors.

@Override
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
    List<IHyperlinkDetector> detectors = new LinkedList<IHyperlinkDetector>();
    IHyperlinkDetector[] inheritedDetectors = super.getHyperlinkDetectors(sourceViewer);
    if (inheritedDetectors != null) {
        for (final IHyperlinkDetector detector : inheritedDetectors) {
            detectors.add(new IHyperlinkDetector() {

                @Override
                public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
                    try {
                        IHyperlink[] result = detector.detectHyperlinks(textViewer, region, canShowMultipleHyperlinks);
                        // but null (see org.eclipse.jface.text.hyperlink.HyperlinkManager.findHyperlinks(IRegion))
                        if (result != null && result.length == 0) {
                            return null;
                        }
                        return result;
                    } catch (Throwable e) {
                    // fail safe hyperlink detector - prevent others
                    // from failing
                    }
                    return null;
                }
            });
        }
    }
    detectors.add(detector);
    return detectors.toArray(new IHyperlinkDetector[detectors.size()]);
}
Also used : IHyperlinkDetector(org.eclipse.jface.text.hyperlink.IHyperlinkDetector) LinkedList(java.util.LinkedList) IRegion(org.eclipse.jface.text.IRegion) ITextViewer(org.eclipse.jface.text.ITextViewer)

Example 65 with ITextViewer

use of org.eclipse.jface.text.ITextViewer in project dbeaver by serge-rider.

the class ToggleBreakpointHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (activeEditor != null) {
        SQLEditorBase sqlEditor = activeEditor.getAdapter(SQLEditorBase.class);
        if (sqlEditor != null) {
            ITextViewer textViewer = sqlEditor.getAdapter(ITextViewer.class);
            if (textViewer != null) {
                IVerticalRulerInfo rulerInfo = sqlEditor.getAdapter(IVerticalRulerInfo.class);
                ToggleBreakpointAction action = new ToggleBreakpointAction(sqlEditor, textViewer.getDocument(), rulerInfo);
                action.runWithEvent(new Event());
            }
        }
    }
    return null;
}
Also used : SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) Event(org.eclipse.swt.widgets.Event) IEditorPart(org.eclipse.ui.IEditorPart) IVerticalRulerInfo(org.eclipse.jface.text.source.IVerticalRulerInfo) ToggleBreakpointAction(org.eclipse.debug.ui.actions.ToggleBreakpointAction) ITextViewer(org.eclipse.jface.text.ITextViewer)

Aggregations

ITextViewer (org.eclipse.jface.text.ITextViewer)75 BadLocationException (org.eclipse.jface.text.BadLocationException)13 IDocument (org.eclipse.jface.text.IDocument)13 Region (org.eclipse.jface.text.Region)13 StyledText (org.eclipse.swt.custom.StyledText)13 IRegion (org.eclipse.jface.text.IRegion)11 ArrayList (java.util.ArrayList)9 Point (org.eclipse.swt.graphics.Point)9 Test (org.junit.Test)9 ITextSelection (org.eclipse.jface.text.ITextSelection)8 IEditorPart (org.eclipse.ui.IEditorPart)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