private void updateTreeModel(final boolean requestFocus, PanelProgressIndicator progress) throws ProcessCanceledException {
    Runnable updateModel = () -> {
      final ProcessCanceledException [] ex = new ProcessCanceledException[1];
      ApplicationManager.getApplication().runReadAction(() -> {
        if (myProject.isDisposed()) return;
        try {
          myTreeExpansionMonitor.freeze();
          TreeModel model = Objects.requireNonNull(PatternDialectProvider.getInstance(DependencyUISettings.getInstance().SCOPE_TYPE))
            .createTreeModel(myProject, myTreeMarker);
          ((PackageDependenciesNode)model.getRoot()).updateAndSortChildren();
          if (myErrorMessage == null) {
            String message = IdeBundle.message("label.scope.contains.files", model.getMarkedFileCount(), model.getTotalFileCount());
            myMatchingCountLabel.setText(message);
            myMatchingCountLabel.setForeground(new JLabel().getForeground());
          }
          else {
            showErrorMessage();
          }

          SwingUtilities.invokeLater(() -> { //not under progress
            if (myIsDisposed) return;
            var backgroundModel = new BackgroundTreeModel(() -> model, true);
            myPackageTreeInvoker = backgroundModel.getInvoker();
            var asyncModel = new AsyncTreeModel(backgroundModel, this);
            var oldModel = myPackageTree.getModel();
            myPackageTree.setModel(asyncModel);
            if (oldModel instanceof Disposable disposable) {
              Disposer.dispose(disposable);
            }
            myTreeExpansionMonitor.restoreAsync();
            TreeUtil.ensureSelection(myPackageTree);
          });
        } catch (ProcessCanceledException e) {
          ex[0] = e;
        }
        finally {
          SwingUtilities.invokeLater(() -> setToComponent(myMatchingCountLabel, requestFocus));
        }
      });
      if (ex[0] != null) {
        throw ex[0];
      }
    };
    ProgressManager.getInstance().runProcess(updateModel, progress);
  }
private void updateTreeModel(final boolean requestFocus, PanelProgressIndicator progress)