use of com.intellij.openapi.progress.Progressive in project intellij-community by JetBrains.
the class AssociationsEditor method expandTree.
private void expandTree(DefaultTreeModel newModel) {
final TreePath rootPath = new TreePath(newModel.getRoot());
final Object element = myBuilder.getTreeStructure().getRootElement();
myBuilder.batch(new Progressive() {
@Override
public void run(@NotNull ProgressIndicator indicator) {
myBuilder.expand(element, null);
myBuilder.expand(myBuilder.getTreeStructure().getChildElements(element), null);
}
});
myTree.setSelectionPath(rootPath);
myTree.scrollRectToVisible(new Rectangle(new Point(0, 0)));
}
use of com.intellij.openapi.progress.Progressive in project intellij-community by JetBrains.
the class TreeUiTest method testBatchUpdate.
public void testBatchUpdate() throws Exception {
buildStructure(myRoot);
myElementUpdate.clear();
final NodeElement[] toExpand = new NodeElement[] { new NodeElement("com"), new NodeElement("jetbrains"), new NodeElement("org"), new NodeElement("xUnit") };
final ActionCallback done = new ActionCallback();
final Ref<ProgressIndicator> indicatorRef = new Ref<>();
final Ref<ActionCallback> ready = new Ref<>();
myElementUpdateHook = new ElementUpdateHook() {
@Override
public void onElementAction(String action, Object element) {
if (new NodeElement("jetbrains").equals(element) && ready.get() == null) {
ActionCallback readyCallback = new ActionCallback();
assertFalse(getBuilder().getUi().isReady());
getBuilder().getReady(this).notify(readyCallback);
ready.set(readyCallback);
}
}
};
invokeLaterIfNeeded(() -> getBuilder().batch(new Progressive() {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicatorRef.set(indicator);
expandNext(toExpand, 0, indicator, done);
}
}).notify(done));
waitBuilderToCome(o -> done.isProcessed());
assertTrue(done.isDone());
assertNotNull(ready.get());
assertTrue(ready.get().isDone());
assertTree("-/\n" + " -com\n" + " +intellij\n" + " -jetbrains\n" + " +fabrique\n" + " -org\n" + " +eclipse\n" + " -xUnit\n" + " runner\n");
assertFalse(indicatorRef.get().isCanceled());
}
use of com.intellij.openapi.progress.Progressive in project intellij-community by JetBrains.
the class CloudRuntimeTask method perform.
private T perform(boolean modal, final Disposable disposable) {
final Semaphore semaphore = new Semaphore();
semaphore.down();
final AtomicReference<T> result = new AtomicReference<>();
final Progressive progressive = new Progressive() {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
while (!indicator.isCanceled()) {
if (semaphore.waitFor(500)) {
if (mySuccess.get()) {
UIUtil.invokeLaterIfNeeded(() -> {
if (disposable == null || !Disposer.isDisposed(disposable)) {
postPerform(result.get());
}
});
}
break;
}
}
}
};
Task task;
boolean cancellable = isCancellable(modal);
if (modal) {
task = new Task.Modal(myProject, myTitle, cancellable) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
progressive.run(indicator);
}
};
} else {
task = new Task.Backgroundable(myProject, myTitle, cancellable) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
progressive.run(indicator);
}
@Override
public boolean shouldStartInBackground() {
return CloudRuntimeTask.this.shouldStartInBackground();
}
};
}
mySuccess.set(false);
myErrorMessage.set(null);
run(semaphore, result);
task.queue();
return result.get();
}
use of com.intellij.openapi.progress.Progressive in project intellij-community by JetBrains.
the class BaseProjectTreeBuilder method revalidateElement.
@NotNull
@Override
public AsyncResult<Object> revalidateElement(Object element) {
final AsyncResult<Object> result = new AsyncResult<>();
if (element instanceof AbstractTreeNode) {
AbstractTreeNode node = (AbstractTreeNode) element;
final Object value = node.getValue();
final ActionCallback callback = new ActionCallback();
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(ObjectUtils.tryCast(value, PsiElement.class));
final FocusRequestor focusRequestor = IdeFocusManager.getInstance(myProject).getFurtherRequestor();
batch(new Progressive() {
@Override
public void run(@NotNull ProgressIndicator indicator) {
final Ref<Object> target = new Ref<>();
_select(value, virtualFile, false, Conditions.<AbstractTreeNode>alwaysTrue(), callback, indicator, target, focusRequestor, false);
callback.doWhenDone(() -> result.setDone(target.get())).doWhenRejected(() -> result.setRejected());
}
});
} else {
result.setRejected();
}
return result;
}
use of com.intellij.openapi.progress.Progressive in project intellij-community by JetBrains.
the class TreeUiTest method testCancelUpdateBatch.
public void testCancelUpdateBatch() throws Exception {
buildStructure(myRoot);
myAlwaysShowPlus.add(new NodeElement("com"));
myAlwaysShowPlus.add(new NodeElement("jetbrains"));
myAlwaysShowPlus.add(new NodeElement("org"));
myAlwaysShowPlus.add(new NodeElement("xUnit"));
final Ref<Boolean> cancelled = new Ref<>(false);
myElementUpdateHook = new ElementUpdateHook() {
@Override
public void onElementAction(String action, Object element) {
NodeElement stopElement = new NodeElement("com");
if (cancelled.get()) {
myCancelRequest = new AssertionError("Not supposed to update after element=" + stopElement);
return;
}
if (element.equals(stopElement) && action.equals("getChildren")) {
cancelled.set(true);
getBuilder().cancelUpdate();
}
}
};
final NodeElement[] toExpand = new NodeElement[] { new NodeElement("com"), new NodeElement("jetbrains"), new NodeElement("org"), new NodeElement("xUnit") };
final ActionCallback done = new ActionCallback();
final Ref<ProgressIndicator> indicatorRef = new Ref<>();
invokeLaterIfNeeded(() -> getBuilder().batch(new Progressive() {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicatorRef.set(indicator);
expandNext(toExpand, 0, indicator, done);
}
}).notify(done));
waitBuilderToCome(o -> done.isProcessed() || myCancelRequest != null);
assertNull(myCancelRequest);
assertTrue(done.isRejected());
assertTrue(indicatorRef.get().isCanceled());
assertFalse(getBuilder().getUi().isCancelProcessed());
}
Aggregations