Search in sources :

Example 1 with IXtextModelListener

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);
}
Also used : CancelableUnitOfWork(org.eclipse.xtext.util.concurrent.CancelableUnitOfWork) XtextResource(org.eclipse.xtext.resource.XtextResource) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) IXtextModelListener(org.eclipse.xtext.ui.editor.model.IXtextModelListener)

Example 2 with IXtextModelListener

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());
}
Also used : XtextReconciler(org.eclipse.xtext.ui.editor.reconciler.XtextReconciler) XtextResource(org.eclipse.xtext.resource.XtextResource) CountDownLatch(java.util.concurrent.CountDownLatch) IXtextModelListener(org.eclipse.xtext.ui.editor.model.IXtextModelListener) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest)

Example 3 with IXtextModelListener

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);
    }
}
Also used : XtextResource(org.eclipse.xtext.resource.XtextResource) IXtextModelListener(org.eclipse.xtext.ui.editor.model.IXtextModelListener)

Aggregations

XtextResource (org.eclipse.xtext.resource.XtextResource)3 IXtextModelListener (org.eclipse.xtext.ui.editor.model.IXtextModelListener)3 CountDownLatch (java.util.concurrent.CountDownLatch)1 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)1 XtextReconciler (org.eclipse.xtext.ui.editor.reconciler.XtextReconciler)1 AbstractEditorTest (org.eclipse.xtext.ui.testing.AbstractEditorTest)1 CancelIndicator (org.eclipse.xtext.util.CancelIndicator)1 CancelableUnitOfWork (org.eclipse.xtext.util.concurrent.CancelableUnitOfWork)1 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)1 Test (org.junit.Test)1