All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.xtext.junit4.ui.AbstractLinkedEditingIntegrationTest Maven / Gradle / Ivy

There is a newer version: 2.4.3
Show newest version
/*******************************************************************************
 * Copyright (c) 2011 itemis AG (http://www.itemis.eu) 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
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.xtext.junit4.ui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.junit4.ui.AbstractEditorTest;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;

/**
 * @author Holger Schill - Initial contribution and API
 */
public abstract class AbstractLinkedEditingIntegrationTest extends AbstractEditorTest {

	protected void waitForReconciler(final XtextEditor editor) {
		editor.getDocument().readOnly(new IUnitOfWork.Void() {
			@Override
			public void process(XtextResource state) throws Exception {
				// do nothing
			}
		});
	}
	
	protected void waitForDisplay() {
		while(Display.getDefault().readAndDispatch()) {
		}
	}
	
	protected void pressKeys(XtextEditor editor, String string) throws Exception {
		for(int i = 0; i < string.length(); i++) {
			pressKey(editor, string.charAt(i));
		}
	}

	protected void pressKey(XtextEditor editor, char c) throws Exception {
		StyledText textWidget = editor.getInternalSourceViewer().getTextWidget();
		Event e = new Event();
		e.character = c;
		e.type = SWT.KeyDown;
		e.doit = true;
		//XXX Hack!
		if (c == SWT.ESC) {
			e.keyCode = 27;
		}
		textWidget.notifyListeners(SWT.KeyDown, e);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy