Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2011 itemis AG ( and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at /
 package org.eclipse.xtext.ui.refactoring.ui;
import  org.eclipse.jface.text.source.ISourceViewer;
import  org.eclipse.jface.text.source.SourceViewer;
import  org.eclipse.swt.SWT;
import  org.eclipse.swt.widgets.Composite;
import  org.eclipse.swt.widgets.Control;
import  org.eclipse.swt.widgets.Display;
import  org.eclipse.swt.widgets.Label;

Renders the current editor to a picture that hides the nifty details going on in the documents when the refactoring changes are applied. Same mechanism as in JDT.

Holger Schill - Initial contribution and API
public class ViewFreezer {
	protected ISourceViewer sourceViewer;
	protected Image image = null;
	protected Label label = null;
	public ViewFreezer(ISourceViewer viewer) {
		this. = viewer;
	public void freeze() {
		if ( instanceof SourceViewer) {
			Control viewerControl = ((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();
					 = new Image(gc.getDevice(), size.x, size.y);
					gc.copyArea(, 0, 0);
finally {
					gc = null;
				// Persist editor area while executing refactoring:
				 = new Label(composite, SWT.NONE);
				.setBounds(0, 0, size.x, size.y);
	public void release() {
		if ( != null)
		if ( != null)
New to GrepCode? Check out our FAQ X