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);
}
}
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());
}
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);
}
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;
}
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);
}
}
}
Aggregations