use of com.intellij.openapi.wm.ex.ProgressIndicatorEx in project intellij-community by JetBrains.
the class CompilerTask method addIndicatorDelegate.
private void addIndicatorDelegate() {
ProgressIndicator indicator = myIndicator;
if (!(indicator instanceof ProgressIndicatorEx)) {
return;
}
((ProgressIndicatorEx) indicator).addStateDelegate(new AbstractProgressIndicatorExBase() {
@Override
public void cancel() {
super.cancel();
selectFirstMessage();
stopAppIconProgress();
}
@Override
public void stop() {
super.stop();
if (!isCanceled()) {
selectFirstMessage();
}
stopAppIconProgress();
}
private void selectFirstMessage() {
if (!isHeadlessMode()) {
SwingUtilities.invokeLater(() -> {
if (myProject != null && myProject.isDisposed()) {
return;
}
synchronized (myMessageViewLock) {
if (myErrorTreeView != null) {
myErrorTreeView.selectFirstMessage();
}
}
});
}
}
private void stopAppIconProgress() {
UIUtil.invokeLaterIfNeeded(() -> {
if (myProject != null && myProject.isDisposed()) {
return;
}
final AppIcon appIcon = AppIcon.getInstance();
if (appIcon.hideProgress(myProject, APP_ICON_ID)) {
if (myErrorCount > 0) {
appIcon.setErrorBadge(myProject, String.valueOf(myErrorCount));
appIcon.requestAttention(myProject, true);
} else if (!myCompilationStartedAutomatically) {
appIcon.setOkBadge(myProject, true);
appIcon.requestAttention(myProject, false);
}
}
});
}
@Override
public void setText(final String text) {
super.setText(text);
updateProgressText();
}
@Override
public void setText2(final String text) {
super.setText2(text);
updateProgressText();
}
@Override
public void setFraction(final double fraction) {
super.setFraction(fraction);
updateProgressText();
GuiUtils.invokeLaterIfNeeded(() -> AppIcon.getInstance().setProgress(myProject, APP_ICON_ID, AppIconScheme.Progress.BUILD, fraction, true), ModalityState.any());
}
@Override
protected void onProgressChange() {
prepareMessageView();
}
});
}
use of com.intellij.openapi.wm.ex.ProgressIndicatorEx in project intellij-community by JetBrains.
the class DumbServiceImpl method runBackgroundProcess.
private void runBackgroundProcess(@NotNull final ProgressIndicator visibleIndicator) {
if (!myState.compareAndSet(State.SCHEDULED_TASKS, State.RUNNING_DUMB_TASKS))
return;
final ShutDownTracker shutdownTracker = ShutDownTracker.getInstance();
final Thread self = Thread.currentThread();
try {
shutdownTracker.registerStopperThread(self);
if (visibleIndicator instanceof ProgressIndicatorEx) {
((ProgressIndicatorEx) visibleIndicator).addStateDelegate(new AppIconProgress());
}
DumbModeTask task = null;
while (true) {
Pair<DumbModeTask, ProgressIndicatorEx> pair = getNextTask(task, visibleIndicator);
if (pair == null)
break;
task = pair.first;
ProgressIndicatorEx taskIndicator = pair.second;
if (visibleIndicator instanceof ProgressIndicatorEx) {
taskIndicator.addStateDelegate(new AbstractProgressIndicatorExBase() {
@Override
protected void delegateProgressChange(@NotNull IndicatorAction action) {
super.delegateProgressChange(action);
action.execute((ProgressIndicatorEx) visibleIndicator);
}
});
}
try (AccessToken ignored = HeavyProcessLatch.INSTANCE.processStarted("Performing indexing tasks")) {
runSingleTask(task, taskIndicator);
}
}
} catch (Throwable unexpected) {
LOG.error(unexpected);
} finally {
shutdownTracker.unregisterStopperThread(self);
}
}
use of com.intellij.openapi.wm.ex.ProgressIndicatorEx in project intellij-community by JetBrains.
the class InfoAndProgressPanel method removeProgress.
private void removeProgress(@NotNull InlineProgressIndicator progress) {
synchronized (myOriginals) {
// already disposed
if (!myInline2Original.containsKey(progress))
return;
final boolean last = myOriginals.size() == 1;
final boolean beforeLast = myOriginals.size() == 2;
myPopup.removeIndicator(progress);
final ProgressIndicatorEx original = removeFromMaps(progress);
if (myOriginals.contains(original)) {
Disposer.dispose(progress);
return;
}
if (last) {
restoreEmptyStatus();
if (myShouldClosePopupAndOnProcessFinish) {
hideProcessPopup();
}
} else {
if (myPopup.isShowing() || myOriginals.size() > 1) {
buildInProcessCount();
} else if (beforeLast) {
buildInInlineIndicator(createInlineDelegate(myInfos.get(0), myOriginals.get(0), true));
} else {
restoreEmptyStatus();
}
}
runQuery();
}
Disposer.dispose(progress);
}
use of com.intellij.openapi.wm.ex.ProgressIndicatorEx in project intellij-community by JetBrains.
the class ProgressIndicatorTest method testNestedIndicatorsAreCanceledRight.
public void testNestedIndicatorsAreCanceledRight() {
checkCanceledCalled = false;
ProgressManager.getInstance().executeProcessUnderProgress(() -> {
assertFalse(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
ProgressIndicator indicator = ProgressIndicatorProvider.getGlobalProgressIndicator();
assertTrue(indicator != null && !indicator.isCanceled());
indicator.cancel();
assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
assertTrue(indicator.isCanceled());
final ProgressIndicatorEx nested = new ProgressIndicatorBase();
nested.addStateDelegate(new ProgressIndicatorStub() {
@Override
public void checkCanceled() throws ProcessCanceledException {
checkCanceledCalled = true;
throw new RuntimeException("must not call checkCanceled()");
}
});
ProgressManager.getInstance().executeProcessUnderProgress(() -> {
assertFalse(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
ProgressIndicator indicator2 = ProgressIndicatorProvider.getGlobalProgressIndicator();
assertTrue(indicator2 != null && !indicator2.isCanceled());
assertSame(indicator2, nested);
ProgressManager.checkCanceled();
}, nested);
ProgressIndicator indicator3 = ProgressIndicatorProvider.getGlobalProgressIndicator();
assertSame(indicator, indicator3);
assertTrue(CoreProgressManager.threadsUnderCanceledIndicator.contains(Thread.currentThread()));
}, new EmptyProgressIndicator());
assertFalse(checkCanceledCalled);
}
use of com.intellij.openapi.wm.ex.ProgressIndicatorEx in project intellij-community by JetBrains.
the class ProgressIndicatorTest method testCheckCanceledGranularity.
public void testCheckCanceledGranularity() throws InterruptedException {
prevTime = now = 0;
final long warmupEnd = System.currentTimeMillis() + 1000;
final TLongArrayList times = new TLongArrayList();
final long end = warmupEnd + 1000;
ApplicationManagerEx.getApplicationEx().runProcessWithProgressSynchronously(() -> {
final Alarm alarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, getTestRootDisposable());
ProgressIndicatorEx indicator = (ProgressIndicatorEx) ProgressIndicatorProvider.getGlobalProgressIndicator();
prevTime = System.currentTimeMillis();
assert indicator != null;
indicator.addStateDelegate(new ProgressIndicatorStub() {
@Override
public void checkCanceled() throws ProcessCanceledException {
now = System.currentTimeMillis();
if (now > warmupEnd) {
int delta = (int) (now - prevTime);
times.add(delta);
}
prevTime = now;
}
});
while (System.currentTimeMillis() < end) {
ProgressManager.checkCanceled();
}
alarm.cancelAllRequests();
}, "", false, getProject(), null, "");
long averageDelay = ArrayUtil.averageAmongMedians(times.toNativeArray(), 5);
System.out.println("averageDelay = " + averageDelay);
assertTrue(averageDelay < CoreProgressManager.CHECK_CANCELED_DELAY_MILLIS * 3);
}
Aggregations