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