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

                          SwingUtilities.invokeLater(
                              new Runnable() {
                                public void run() { // not under progress
                                  myPackageTree.setModel(model);
                                  myTreeExpansionMonitor.restore();
                                }
                              });
                        } catch (ProcessCanceledException e) {
                          ex[0] = e;
                        } finally {
                          myCurrentProgress = null;
                          // update label
                          setToComponent(myMatchingCountLabel, requestFocus);
                        }
                      }
                    });
            if (ex[0] != null) {
              throw ex[0];
            }
          }
        };
    ProgressManager.getInstance().runProcess(updateModel, progress);
  }
 public void stop() {
   super.stop();
   setToComponent(myMatchingCountLabel, myRequestFocus);
 }
 public void start() {
   super.start();
   myTextChanged = false;
 }
 public void cancelCurrentProgress() {
   if (myCurrentProgress != null && myCurrentProgress.isRunning()) {
     myCurrentProgress.cancel();
   }
 }