Java源码示例:org.eclipse.xtext.service.OperationCanceledManager

示例1
/**
 * Same as {@link #runInModalDialog(OperationCanceledManager, IRunnableWithProgress)}, but allows reacting to
 * exceptions.
 *
 * @param throwableHandler
 *            will be invoked on the runnable's thread in case the runnable throws an exception other than a
 *            {@link OperationCanceledManager#isOperationCanceledException(Throwable) cancellation exception}. May
 *            be <code>null</code> if no handling of exceptions is required.
 */
public static void runInModalDialog(OperationCanceledManager ocm, IRunnableWithProgress runnable,
		Consumer<Throwable> throwableHandler) {
	try {
		final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
		final ProgressMonitorDialog dlg = new ProgressMonitorDialog(shell);
		dlg.run(true, true, monitor -> {
			try {
				runnable.run(monitor);
			} catch (Throwable th) {
				// translate cancellation exceptions from Eclipse/Xtext to SWT/JFace world
				if (ocm.isOperationCanceledException(th)) {
					throw new InterruptedException();
				}
				if (throwableHandler != null) {
					throwableHandler.accept(th);
				}
				throw th;
			}
		});
	} catch (InvocationTargetException | InterruptedException e) {
		// ignore
	}
}
 
示例2
@Override
protected void doLoad(InputStream inputStream, Map<?, ?> options) throws IOException {
	try {
		if (getURI() != null && mirror != null) {
			if (mirror instanceof IMirrorOptionsAware) {
				((IMirrorOptionsAware)mirror).initialize(this, options);
			} else {
				mirror.initialize(this);
			}
		}
	} catch(Exception e) {
		if (typeResourceServices != null) {
			OperationCanceledManager operationCanceledManager = typeResourceServices.getOperationCanceledManager();
			if (operationCanceledManager.isOperationCanceledException(e)) {
				unload();
			}
			operationCanceledManager.propagateAsErrorIfCancelException(e);
		}	
		throw new CannotLoadTypeResourceException(e);
	}
}
 
示例3
private IXtextDocument createDocument(String model) throws Exception {
	resource = getResource(new StringInputStream(model));
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>(){
		@Override
		public Lexer get() {
			return new InternalXtextLexer();
		}});
	
	final XtextDocument document = new XtextDocument(tokenSource, get(ITextEditComposer.class), new OutdatedStateManager(), new OperationCanceledManager()) {
		@Override
		public <T> T internalModify(IUnitOfWork<T, XtextResource> work) {
			try {
				return work.exec((XtextResource) resource);
			}
			catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
	};
	document.set(model);
	return document;
}
 
示例4
public XtextDocument getDocument(String s) {
	TerminalsTokenTypeToPartitionMapper mapper = new TerminalsTokenTypeToPartitionMapper() {{
		setTokenDefProvider(new AntlrTokenDefProvider() {
			{
				setAntlrTokenFileProvider(new XtextAntlrTokenFileProvider());
			}
		});
	}};
	PartitionTokenScanner scanner = new PartitionTokenScanner();
	scanner.setMapper(mapper);
	DocumentPartitioner partitioner = new DocumentPartitioner(scanner, mapper);
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return new org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer();
		}
	});
	XtextDocument document = new XtextDocument(tokenSource, null, new OutdatedStateManager(), new OperationCanceledManager());
	document.setDocumentPartitioner(partitioner);
	partitioner.connect(document);
	document.set(s);
	return document;
}
 
示例5
@SuppressWarnings("javadoc")
public IssuesProvider(IResourceValidator resourceValidator, Resource res, CheckMode checkMode,
		OperationCanceledManager operationCanceledManager, CancelIndicator ci) {
	this.rv = resourceValidator;
	this.r = res;
	this.checkMode = checkMode;
	this.operationCanceledManager = operationCanceledManager;
	this.ci = ci;
}
 
示例6
/**
 * Creates a new, empty inference context for the given inference variables. The cancellation manager and indicator
 * may be <code>null</code>.
 *
 * @param G
 *            a rule environment used for subtype checking, etc. during constraint resolution. This rule environment
 *            will not be changed by the inference context AND it is expected to <b>not</b> be changed by anyone
 *            else during the life-time of the inference context.
 * @param inferenceVariables
 *            the meta variables to be inferred.
 */
public InferenceContext(N4JSTypeSystem ts, TypeSystemHelper tsh, OperationCanceledManager operationCanceledManager,
		CancelIndicator cancelIndicator, RuleEnvironment G, InferenceVariable... inferenceVariables) {
	Objects.requireNonNull(ts);
	Objects.requireNonNull(tsh);
	Objects.requireNonNull(G);
	this.ts = ts;
	this.tsh = tsh;
	this.operationCanceledManager = operationCanceledManager;
	this.cancelIndicator = cancelIndicator;
	this.G = G;
	addInferenceVariables(false, inferenceVariables);
	this.reducer = new Reducer(this, G, ts, tsh);
	this.currentBounds = new BoundSet(this, G, ts);
}
 
示例7
protected XtextDocument createXtextDocument(String modelAsText) throws Exception {
	final XtextResource resource = getResource(modelAsText, "test.outlinetestlanguage");
	DocumentTokenSource tokenSource = new DocumentTokenSource();
	tokenSource.setLexer(new Provider<Lexer>(){
		@Override
		public Lexer get() {
			return new InternalXtextLexer();
		}});
	XtextDocument xtextDocument = new XtextDocument(tokenSource, null, new OutdatedStateManager(), new OperationCanceledManager());
	xtextDocument.setInput(resource);
	xtextDocument.set(modelAsText);
	return xtextDocument;	
}
 
示例8
protected Document createDocument(String before) {
	DocumentTokenSource source = new DocumentTokenSource();
	source.setLexer(new Provider<Lexer>() {
		@Override
		public Lexer get() {
			return new org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer();
		}
	});
	XtextDocument document = new XtextDocument(source, null, new OutdatedStateManager(), new OperationCanceledManager());
	document.set(before);
	return document;
}
 
示例9
@Inject
private SourceContainerAwareResourceValidator(IN4JSEclipseCore eclipseCore,
		OperationCanceledManager operationCanceledManager) {
	this.eclipseCore = eclipseCore;
	this.operationCanceledManager = operationCanceledManager;
}
 
示例10
public OperationCanceledManager getOperationCanceledManager() {
	return operationCanceledManager;
}
 
示例11
public OperationCanceledManager getOperationCanceledManager() {
	return operationCanceledManager;
}
 
示例12
/**
 * @since 2.8
 * @noreference This constructor is not intended to be referenced by clients. Only for testing
 */
public XtextDocument(DocumentTokenSource tokenSource, ITextEditComposer composer, OutdatedStateManager outdatedStateManager, OperationCanceledManager operationCanceledManager) {
	this(tokenSource, composer);
	this.outdatedStateManager = outdatedStateManager;
	this.operationCanceledManager = operationCanceledManager;
}
 
示例13
/**
 * @since 2.8
 */
protected OperationCanceledManager getCancelManager() {
	return cancelManager;
}
 
示例14
public CancelableResolutionAcceptor(IssueResolutionAcceptor delegate, CancelIndicator monitor, OperationCanceledManager manager) {
	super(null);
	this.delegate = delegate;
	this.monitor = monitor;
	this.manager = manager;
}
 
示例15
/**
 * @since 2.9
 */
protected OperationCanceledManager getOperationCanceledManager() {
	return operationCanceledManager;
}
 
示例16
/**
 * @since 2.18
 */
public OperationCanceledManager getOperationCanceledManager() {
	return operationCanceledManager;
}
 
示例17
/**
 * @since 2.18
 */
public void setOperationCanceledManager(OperationCanceledManager operationCanceledManager) {
	this.operationCanceledManager = operationCanceledManager;
}
 
示例18
@Inject
public DirectRequestManager(final OperationCanceledManager operationCanceledManager) {
  super(null, operationCanceledManager);
}
 
示例19
public TestedResource() {
	operationCanceledManager = new OperationCanceledManager();
}
 
示例20
@Inject
public RequestManager(ExecutorService parallel, OperationCanceledManager operationCanceledManager) {
	this.parallel = parallel;
	this.operationCanceledManager = operationCanceledManager;
}
 
示例21
protected final OperationCanceledManager getOperationCanceledManager() {
	return operationCanceledManager;
}
 
示例22
/**
 * Runs the given runnable in a {@link ProgressMonitorDialog}. Must be called from the UI thread.
 * <p>
 * <b>Before using this method</b>, ensure that in your use case it makes sense to have a modal dialog instead of
 * using an Eclipse {@link Job} (by default, always use the job framework!) and that this method's exact behavior is
 * appropriate for your use case (e.g. calling the <code>run()</code> method with 'fork' set to <code>true</code>,
 * ignoring invocation target exceptions).
 *
 * @param ocm
 *            an operation canceled manager as obtained via injection.
 * @param runnable
 *            the runnable to execute.
 */
public static void runInModalDialog(OperationCanceledManager ocm, IRunnableWithProgress runnable) {
	runInModalDialog(ocm, runnable, null);
}