Java 类org.eclipse.xtext.util.concurrent.CancelableUnitOfWork 实例源码

项目:statecharts    文件:AsyncXtextContentAssistProcessor.java   
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
    if (getContentProposalProvider() == null)
        return null;
    IXtextDocument document = (IXtextDocument) viewer.getDocument();
    final CancelableCompletionProposalComputer computer = createCompletionProposalComputer(viewer, offset);
    ICompletionProposal[] result = document
            .readOnly(new CancelableUnitOfWork<ICompletionProposal[], XtextResource>() {
                @Override
                public ICompletionProposal[] exec(XtextResource state, CancelIndicator cancelIndicator)
                        throws Exception {
                    computer.setCancelIndicator(cancelIndicator);
                    try {
                        return computer.exec(state);
                    } catch (Throwable t) {
                        return new ICompletionProposal[] {};
                    }
                }
            });
    Arrays.sort(result, getCompletionProposalComparator());
    result = getCompletionProposalPostProcessor().postProcess(result);
    return result;
}
项目:xtext-core    文件:OutdatedStateManager.java   
public <R extends Object, P extends Resource> R exec(final IUnitOfWork<R, P> work, final P param) {
  try {
    R _xblockexpression = null;
    {
      final Boolean wasCancelationAllowed = this.cancelationAllowed.get();
      R _xtrycatchfinallyexpression = null;
      try {
        R _xblockexpression_1 = null;
        {
          if ((work instanceof CancelableUnitOfWork<?, ?>)) {
            CancelIndicator _xifexpression = null;
            if ((param == null)) {
              final CancelIndicator _function = () -> {
                return true;
              };
              _xifexpression = _function;
            } else {
              _xifexpression = this.newCancelIndicator(param.getResourceSet());
            }
            ((CancelableUnitOfWork<?, ?>)work).setCancelIndicator(_xifexpression);
          } else {
            this.cancelationAllowed.set(Boolean.valueOf(false));
          }
          _xblockexpression_1 = work.exec(param);
        }
        _xtrycatchfinallyexpression = _xblockexpression_1;
      } finally {
        this.cancelationAllowed.set(wasCancelationAllowed);
      }
      _xblockexpression = _xtrycatchfinallyexpression;
    }
    return _xblockexpression;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
项目:gama    文件:GamaSourceViewer.java   
/**
 * @param gamlEditor
 */
public void setResourceListener(final IGamlBuilderListener listener) {
    this.resourceListener = listener;
    ((IXtextDocument) getDocument()).readOnly(new CancelableUnitOfWork<Object, XtextResource>() {

        @Override
        public Object exec(final XtextResource state, final CancelIndicator cancelIndicator) throws Exception {
            if (state != null)
                GamlResourceServices.addResourceListener(state.getURI(), listener);
            return null;
        }
    });
}
项目:gama    文件:GamlHyperlinkDetector.java   
@Override
public IHyperlink[] detectHyperlinks(final ITextViewer textViewer, final IRegion region,
        final boolean canShowMultipleHyperlinks) {
    final IXtextDocument document = (IXtextDocument) textViewer.getDocument();
    final IHyperlink[] importHyperlinks = importHyperlinks(document, region);
    if (importHyperlinks != NO_HYPERLINKS) { return importHyperlinks; }
    return document.readOnly(new CancelableUnitOfWork<IHyperlink[], XtextResource>() {

        @Override
        public IHyperlink[] exec(final XtextResource resource, final CancelIndicator c) {
            return getHelper().createHyperlinksByOffset(resource, region.getOffset(), canShowMultipleHyperlinks);
        }
    });
}
项目:gama    文件:GamlEditor.java   
public void openOutlinePopup() {

        getDocument().readOnly(new CancelableUnitOfWork<Object, XtextResource>() {

            @Override
            public Object exec(final XtextResource state, final CancelIndicator c) throws Exception {
                final QuickOutlinePopup popup = new GamlQuickOutlinePopup(GamlEditor.this, toolbar);
                injector.injectMembers(popup);
                return popup.open();
            }
        });

    }
项目:gama    文件:RevalidateModelSelectionListener.java   
/**
 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
 */
@Override
public void widgetSelected(final SelectionEvent e) {

    editor.getDocument().readOnly(new CancelableUnitOfWork<Object, XtextResource>() {

        @Override
        public Object exec(final XtextResource state, final CancelIndicator c) throws Exception {
            return GamlModelBuilder.compile(state.getURI(), null);
        }
    });

}