use of org.eclipse.xtext.ui.editor.model.IXtextModelListener in project xtext-eclipse by eclipse.
the class DocumentLockerTest method addReaderCancelationListener.
private void addReaderCancelationListener(final IXtextDocument document, final List<CancelIndicator> cancelIndicators) {
final IXtextModelListener _function = (XtextResource it) -> {
final CancelableUnitOfWork<Boolean, XtextResource> _function_1 = new CancelableUnitOfWork<Boolean, XtextResource>() {
@Override
public Boolean exec(final XtextResource state, final CancelIndicator cancelIndicator) throws Exception {
boolean _xblockexpression = false;
{
Assert.assertFalse(cancelIndicator.isCanceled());
_xblockexpression = cancelIndicators.add(cancelIndicator);
}
return Boolean.valueOf(_xblockexpression);
}
};
final CancelableUnitOfWork<Boolean, XtextResource> work = _function_1;
document.<Boolean>readOnly(work);
};
document.addModelListener(_function);
}
use of org.eclipse.xtext.ui.editor.model.IXtextModelListener in project xtext-eclipse by eclipse.
the class RealXtextDocumentModifyTest method testModelListenerNotNotified.
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=406811
@Test
public void testModelListenerNotNotified() throws Exception {
final String grammar = "grammar foo.Foo\n" + "generate foo \"http://foo.net/foo\"\n" + "Foo: 'foo';";
final IXtextDocument document = createDocument(grammar);
// wait for the forced reconcile operation to finish
Job.getJobManager().join(XtextReconciler.class.getName(), null);
CountDownLatch countDownLatch = new CountDownLatch(1);
final CountDownLatch[] changeCounter = new CountDownLatch[] { countDownLatch };
document.addModelListener(new IXtextModelListener() {
@Override
public void modelChanged(XtextResource resource) {
changeCounter[0].countDown();
}
});
document.modify(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
document.replace(grammar.indexOf("Foo"), 3, "Bar");
}
});
assertEquals("IXtextModelListener should not have been directly notified", 1, countDownLatch.getCount());
document.readOnly(new IUnitOfWork.Void<XtextResource>() {
@Override
public void process(XtextResource state) throws Exception {
}
});
/* Let the UI thread process any queued operation for a while so that the IXtextModelListener
* are called. If processing fails too long, then give up. */
long start = System.currentTimeMillis();
long timeout = TimeUnit.MILLISECONDS.convert(10, TimeUnit.SECONDS);
long maxEndTime = start + timeout;
boolean moreWorkForTheUiThread = true;
boolean latchReachedZero = false;
while (moreWorkForTheUiThread && !latchReachedZero && System.currentTimeMillis() < maxEndTime) {
moreWorkForTheUiThread = Display.getDefault().readAndDispatch();
latchReachedZero = countDownLatch.getCount() <= 0;
}
assertEquals("Reconciler should have notified IXtextModelListener", 0, countDownLatch.getCount());
}
use of org.eclipse.xtext.ui.editor.model.IXtextModelListener in project xtext-eclipse by eclipse.
the class OutlinePage method configureModelListener.
protected void configureModelListener() {
if (xtextDocument != null) {
// possibly disposed in the meantime
modelListener = new IXtextModelListener() {
@Override
public void modelChanged(XtextResource resource) {
try {
scheduleRefresh();
} catch (Throwable t) {
LOG.error("Error refreshing outline", t);
}
}
};
xtextDocument.addModelListener(modelListener);
}
}
Aggregations