Search in sources :

Example 1 with SourceViewer

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

the class AbstractSourceView method setViewerFont.

private void setViewerFont() {
    Font font = getFont(getViewerFontName());
    SourceViewer viewer = getSourceViewer();
    if (viewer.getDocument() != null) {
        Point selection = viewer.getSelectedRange();
        int topIndex = viewer.getTopIndex();
        StyledText styledText = viewer.getTextWidget();
        Control parent = viewer.getControl();
        parent.setRedraw(false);
        styledText.setFont(font);
        viewer.setSelectedRange(selection.x, selection.y);
        viewer.setTopIndex(topIndex);
        if (parent instanceof Composite) {
            Composite composite = (Composite) parent;
            composite.layout(true);
        }
        parent.setRedraw(true);
    } else {
        StyledText styledText = viewer.getTextWidget();
        styledText.setFont(font);
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) SourceViewer(org.eclipse.jface.text.source.SourceViewer) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.swt.graphics.Point)

Example 2 with SourceViewer

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

the class DefaultMergeEditor method createPartControl.

@Override
public void createPartControl(Composite composite) {
    SourceViewer sourceViewer = (SourceViewer) createSourceViewer(composite, createVerticalRuler(), SWT.H_SCROLL | SWT.V_SCROLL | textOrientation);
    setSourceViewer(this, sourceViewer);
    getSourceViewer().configure(getXtextSourceViewerConfiguration());
    getSourceViewerDecorationSupport(sourceViewer).install(getPreferenceStore());
    getSelectionProvider().addSelectionChangedListener(getSelectionChangedListener());
}
Also used : SourceViewer(org.eclipse.jface.text.source.SourceViewer)

Example 3 with SourceViewer

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

the class DefaultMergeViewer method createSourceViewer.

@Override
protected SourceViewer createSourceViewer(Composite parent, int textOrientation) {
    if (getSite() != null) {
        if (sourceViewerEditorMap == null) {
            sourceViewerEditorMap = Maps.newHashMapWithExpectedSize(3);
        }
        DefaultMergeEditor mergeEditor = createMergeEditor();
        mergeEditor.setXtextEditorCallback(new CompoundXtextEditorCallback(null));
        mergeEditor.setTextOrientation(textOrientation);
        mergeEditor.setInternalSite(getSite());
        mergeEditor.createPartControl(parent);
        SourceViewer internalSourceViewer = (SourceViewer) mergeEditor.getInternalSourceViewer();
        sourceViewerEditorMap.put(internalSourceViewer, mergeEditor);
        return internalSourceViewer;
    }
    return super.createSourceViewer(parent, textOrientation);
}
Also used : ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) CompoundXtextEditorCallback(org.eclipse.xtext.ui.editor.CompoundXtextEditorCallback)

Example 4 with SourceViewer

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

the class HighlightingPresenter method createPresentation.

/**
 * Create a text presentation in the background.
 * <p>
 * NOTE: Called from background thread.
 * </p>
 *
 * @param addedPositions
 *            the added positions
 * @param removedPositions
 *            the removed positions
 * @return the text presentation or <code>null</code>, if reconciliation should be canceled
 */
public TextPresentation createPresentation(List<AttributedPosition> addedPositions, List<AttributedPosition> removedPositions) {
    SourceViewer sourceViewer = fSourceViewer;
    XtextPresentationReconciler presentationReconciler = fPresentationReconciler;
    if (sourceViewer == null || presentationReconciler == null)
        return null;
    if (isCanceled())
        return null;
    IDocument document = sourceViewer.getDocument();
    if (document == null)
        return null;
    int minStart = Integer.MAX_VALUE;
    int maxEnd = Integer.MIN_VALUE;
    for (int i = 0, n = removedPositions.size(); i < n; i++) {
        Position position = removedPositions.get(i);
        int offset = position.getOffset();
        minStart = Math.min(minStart, offset);
        maxEnd = Math.max(maxEnd, offset + position.getLength());
    }
    for (int i = 0, n = addedPositions.size(); i < n; i++) {
        Position position = addedPositions.get(i);
        int offset = position.getOffset();
        minStart = Math.min(minStart, offset);
        maxEnd = Math.max(maxEnd, offset + position.getLength());
    }
    if (minStart < maxEnd)
        try {
            return presentationReconciler.createRepairDescription(new Region(minStart, maxEnd - minStart), document);
        } catch (RuntimeException e) {
            log.error(e.getMessage(), e);
        }
    return null;
}
Also used : XtextSourceViewer(org.eclipse.xtext.ui.editor.XtextSourceViewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) Position(org.eclipse.jface.text.Position) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IDocument(org.eclipse.jface.text.IDocument) XtextPresentationReconciler(org.eclipse.xtext.ui.editor.XtextPresentationReconciler)

Example 5 with SourceViewer

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

the class ViewFreezer method freeze.

public void freeze() {
    release();
    if (sourceViewer instanceof SourceViewer) {
        Control viewerControl = ((SourceViewer) sourceViewer).getControl();
        if (viewerControl instanceof Composite) {
            Composite composite = (Composite) viewerControl;
            Display display = composite.getDisplay();
            // Flush pending redraw requests:
            while (!display.isDisposed() && display.readAndDispatch()) {
            }
            // Copy editor area:
            GC gc = new GC(composite);
            Point size;
            try {
                size = composite.getSize();
                image = new Image(gc.getDevice(), size.x, size.y);
                gc.copyArea(image, 0, 0);
            } finally {
                gc.dispose();
                gc = null;
            }
            // Persist editor area while executing refactoring:
            label = new Label(composite, SWT.NONE);
            label.setImage(image);
            label.setBounds(0, 0, size.x, size.y);
            label.moveAbove(null);
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) SourceViewer(org.eclipse.jface.text.source.SourceViewer) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Image(org.eclipse.swt.graphics.Image) Display(org.eclipse.swt.widgets.Display)

Aggregations

SourceViewer (org.eclipse.jface.text.source.SourceViewer)67 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)39 IDocument (org.eclipse.jface.text.IDocument)26 GridData (org.eclipse.swt.layout.GridData)24 Label (org.eclipse.swt.widgets.Label)23 Composite (org.eclipse.swt.widgets.Composite)16 Document (org.eclipse.jface.text.Document)15 SourceViewerConfiguration (org.eclipse.jface.text.source.SourceViewerConfiguration)14 StructuredTextViewer (org.eclipse.wst.sse.ui.internal.StructuredTextViewer)14 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)13 Control (org.eclipse.swt.widgets.Control)12 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 Button (org.eclipse.swt.widgets.Button)11 Iterator (java.util.Iterator)10 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)10 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)10 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)8 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8