Java Code Examples for org.jetbrains.concurrency.Promise#onSuccess()
The following examples show how to use
org.jetbrains.concurrency.Promise#onSuccess() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OptionsTree.java From consulo with Apache License 2.0 | 6 votes |
@Override protected Promise<?> refilterNow(Object preferredSelection, boolean adjustSelection) { final List<Object> toRestore = new ArrayList<>(); if (myContext.isHoldingFilter() && !myWasHoldingFilter && myToExpandOnResetFilter == null) { myToExpandOnResetFilter = myBuilder.getUi().getExpandedElements(); } else if (!myContext.isHoldingFilter() && myWasHoldingFilter && myToExpandOnResetFilter != null) { toRestore.addAll(myToExpandOnResetFilter); myToExpandOnResetFilter = null; } myWasHoldingFilter = myContext.isHoldingFilter(); Promise<?> result = super.refilterNow(preferredSelection, adjustSelection); myRefilteringNow = true; return result.onSuccess((c) -> { myRefilteringNow = false; if (!myContext.isHoldingFilter() && getSelectedElements().isEmpty()) { restoreExpandedState(toRestore); } }); }
Example 2
Source File: AsyncFilterRunner.java From consulo with Apache License 2.0 | 6 votes |
void highlightHyperlinks(@Nonnull Project project, @Nonnull Filter customFilter, final int startLine, final int endLine) { if (endLine < 0) return; myQueue.offer(new HighlighterJob(project, customFilter, startLine, endLine, myEditor.getDocument())); if (ApplicationManager.getApplication().isWriteAccessAllowed()) { runTasks(); highlightAvailableResults(); return; } Promise<?> promise = ReadAction.nonBlocking(this::runTasks).submit(ourExecutor); if (isQuick(promise)) { highlightAvailableResults(); } else { promise.onSuccess(__ -> { if (hasResults()) { ApplicationManager.getApplication().invokeLater(this::highlightAvailableResults, ModalityState.any()); } }); } }
Example 3
Source File: AsyncTreeModel.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private Promise<TreePath> resolve(Promise<TreePath> promise) { if (promise == null && isValidThread()) { return rejectedPromise(); } AsyncPromise<TreePath> async = new AsyncPromise<>(); if (promise == null) { onValidThread(() -> async.setError("rejected")); } else { promise.onError(onValidThread(async::setError)); promise.onSuccess(onValidThread(path -> resolve(async, path))); } return async; }
Example 4
Source File: ScopeChooserCombo.java From consulo with Apache License 2.0 | 5 votes |
private void rebuildModelAndSelectScopeOnSuccess(@Nullable Object selection) { DefaultComboBoxModel<ScopeDescriptor> model = new DefaultComboBoxModel<>(); Promise<DataContext> promise = DataManager.getInstance().getDataContextFromFocusAsync(); promise.onSuccess(c -> { processScopes(myProject, c, myOptions, descriptor -> { if (myScopeFilter == null || myScopeFilter.value(descriptor)) { model.addElement(descriptor); } return true; }); getComboBox().setModel(model); selectItem(selection); }); }
Example 5
Source File: AbstractTreeUi.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull private Promise<Boolean> update(@Nonnull final NodeDescriptor nodeDescriptor, boolean now) { Promise<Boolean> promise; if (now || isPassthroughMode()) { promise = Promises.resolvedPromise(update(nodeDescriptor)); } else { final AsyncPromise<Boolean> result = new AsyncPromise<>(); promise = result; boolean bgLoading = isToBuildInBackground(nodeDescriptor); boolean edt = isEdt(); if (bgLoading) { if (edt) { final AtomicBoolean changes = new AtomicBoolean(); queueToBackground(new TreeRunnable("AbstractTreeUi.update: build") { @Override public void perform() { changes.set(update(nodeDescriptor)); } }, new TreeRunnable("AbstractTreeUi.update: post") { @Override public void perform() { result.setResult(changes.get()); } }); } else { result.setResult(update(nodeDescriptor)); } } else { if (edt || !myWasEverShown) { result.setResult(update(nodeDescriptor)); } else { invokeLaterIfNeeded(false, new TreeRunnable("AbstractTreeUi.update: later") { @Override public void perform() { execute(new TreeRunnable("AbstractTreeUi.update: later execute") { @Override public void perform() { result.setResult(update(nodeDescriptor)); } }); } }); } } } promise.onSuccess(changes -> { if (!changes) { return; } invokeLaterIfNeeded(false, new TreeRunnable("AbstractTreeUi.update: on done result") { @Override public void perform() { Object element = nodeDescriptor.getElement(); DefaultMutableTreeNode node = element == null ? null : getNodeForElement(element, false); if (node != null) { TreePath path = getPathFor(node); if (myTree.isVisible(path)) { updateNodeImageAndPosition(node); } } } }); }); return promise; }
Example 6
Source File: BaseProjectTreeBuilder.java From consulo with Apache License 2.0 | 4 votes |
private void expandChild(@Nonnull final List<? extends AbstractTreeNode> kids, int i, @Nonnull final Condition<AbstractTreeNode> nonStopCondition, final VirtualFile file, final Object element, @Nonnull final AsyncPromise<? super AbstractTreeNode> async, @Nonnull final ProgressIndicator indicator, final Ref<Object> virtualSelectTarget) { while (i < kids.size()) { final AbstractTreeNode eachKid = kids.get(i); final boolean[] nodeWasCollapsed = {true}; final DefaultMutableTreeNode nodeForElement = getNodeForElement(eachKid); if (nodeForElement != null) { nodeWasCollapsed[0] = getTree().isCollapsed(new TreePath(nodeForElement.getPath())); } if (nonStopCondition.value(eachKid)) { final Promise<AbstractTreeNode> result = expandPathTo(file, eachKid, element, nonStopCondition, indicator, virtualSelectTarget); result.onSuccess(abstractTreeNode -> { indicator.checkCanceled(); async.setResult(abstractTreeNode); }); if (result.getState() == Promise.State.PENDING) { final int next = i + 1; result.onError(error -> { indicator.checkCanceled(); if (nodeWasCollapsed[0] && virtualSelectTarget == null) { collapseChildren(eachKid, null); } expandChild(kids, next, nonStopCondition, file, element, async, indicator, virtualSelectTarget); }); return; } else { if (result.getState() == Promise.State.REJECTED) { indicator.checkCanceled(); if (nodeWasCollapsed[0] && virtualSelectTarget == null) { collapseChildren(eachKid, null); } i++; } else { return; } } } else { //filter tells us to stop here (for instance, in case of module nodes) break; } } async.cancel(); }
Example 7
Source File: AsyncProjectViewSupport.java From consulo with Apache License 2.0 | 4 votes |
public void updateAll(Runnable onDone) { LOG.debug(new RuntimeException("reload a whole tree")); Promise<?> promise = myStructureTreeModel.invalidate(); if (onDone != null) promise.onSuccess(res -> myAsyncTreeModel.onValidThread(onDone)); }