Search in sources :

Example 31 with SourceViewer

use of org.eclipse.jface.text.source.SourceViewer in project erlide_eclipse by erlang.

the class ErlangSourceViewer method createErlangPreviewer.

public static SourceViewer createErlangPreviewer(final Composite parent, final IColorManager colorManager0, final IPreferenceStore topStore, final Map<TokenHighlight, HighlightStyle> colors0, final String content) {
    // TODO we should move this method, to a utility class (or maybe create
    // an ErlangPreviewSourceViewer class)
    final IColorManager colorManager = colorManager0 != null ? colorManager0 : new ColorManager();
    Map<TokenHighlight, HighlightStyle> colors;
    if (colors0 == null) {
        colors = Maps.newHashMap();
        for (final TokenHighlight th : TokenHighlight.values()) {
            colors.put(th, null);
        }
    } else {
        colors = colors0;
    }
    final IPreferenceStore generalTextStore = EditorsUI.getPreferenceStore();
    final IPreferenceStore store = topStore == null ? new ChainedPreferenceStore(new IPreferenceStore[] { generalTextStore }) : new ChainedPreferenceStore(new IPreferenceStore[] { topStore, generalTextStore });
    final SourceViewer viewer = new SourceViewer(parent, null, null, false, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    final IDocument document = new Document(content);
    viewer.setDocument(document);
    final ErlangDocumentSetupParticipant setupParticipant = new ErlangDocumentSetupParticipant();
    setupParticipant.setup(document);
    final ErlangSourceViewerConfiguration configuration = new SyntaxColorPreviewEditorConfiguration(store, colorManager);
    viewer.configure(configuration);
    final Font font = JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
    viewer.getTextWidget().setFont(font);
    new ErlangSourceViewerUpdater(viewer, configuration, store);
    viewer.setEditable(false);
    final Cursor arrowCursor = viewer.getTextWidget().getDisplay().getSystemCursor(SWT.CURSOR_ARROW);
    viewer.getTextWidget().setCursor(arrowCursor);
    return viewer;
}
Also used : SourceViewer(org.eclipse.jface.text.source.SourceViewer) IColorManager(org.erlide.ui.util.IColorManager) ChainedPreferenceStore(org.eclipse.ui.texteditor.ChainedPreferenceStore) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) Cursor(org.eclipse.swt.graphics.Cursor) TokenHighlight(org.erlide.ui.prefs.TokenHighlight) Font(org.eclipse.swt.graphics.Font) HighlightStyle(org.erlide.ui.prefs.HighlightStyle) ErlangSourceViewerUpdater(org.erlide.ui.prefs.plugin.internal.ErlangSourceViewerUpdater) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IColorManager(org.erlide.ui.util.IColorManager) ColorManager(org.erlide.ui.util.ColorManager) IDocument(org.eclipse.jface.text.IDocument)

Example 32 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 33 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 34 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)

Example 35 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)

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 Control (org.eclipse.swt.widgets.Control)13 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)13 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)11 Button (org.eclipse.swt.widgets.Button)11 Iterator (java.util.Iterator)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