Java Code Examples for com.intellij.openapi.application.ModalityState#current()

The following examples show how to use com.intellij.openapi.application.ModalityState#current() . 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: FreezeLoggerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void runUnderPerformanceMonitor(@Nullable Project project, @Nonnull Runnable action) {
  if (!shouldReport() || isUnderDebug() || ApplicationManager.getApplication().isUnitTestMode()) {
    action.run();
    return;
  }

  final ModalityState initial = ModalityState.current();
  ALARM.cancelAllRequests();
  ALARM.addRequest(() -> dumpThreads(project, initial), MAX_ALLOWED_TIME);

  try {
    action.run();
  }
  finally {
    ALARM.cancelAllRequests();
  }
}
 
Example 2
Source File: FlutterSettingsConfigurable.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void onVersionChanged() {
  final Workspace workspace = workspaceCache.get();
  if (workspaceCache.isBazel()) {
    if (mySdkCombo.isEnabled()) {
      // The workspace is not null if workspaceCache.isBazel() is true.
      assert (workspace != null);

      mySdkCombo.setEnabled(false);
      mySdkCombo.getComboBox().getEditor()
        .setItem(workspace.getRoot().getPath() + '/' + workspace.getSdkHome() + " <set by bazel project>");
    }
  }
  else {
    mySdkCombo.setEnabled(true);
  }

  final FlutterSdk sdk = FlutterSdk.forPath(getSdkPathText());
  if (sdk == null) {
    // Clear the label out with a non-empty string, so that the layout doesn't give this element 0 height.
    myVersionLabel.setText(" ");
    fullVersionString = null;
    return;
  }

  final ModalityState modalityState = ModalityState.current();

  final boolean trackWidgetCreationRecommended = sdk.getVersion().isTrackWidgetCreationRecommended();
  myDisableTrackWidgetCreationCheckBox.setVisible(trackWidgetCreationRecommended);

  // TODO(devoncarew): Switch this to expecting json output.
  sdk.flutterVersion().start((ProcessOutput output) -> {
    final String fullVersionText = output.getStdout();
    fullVersionString = fullVersionText;

    final String[] lines = StringUtil.splitByLines(fullVersionText);
    final String singleLineVersion = lines.length > 0 ? lines[0] : "";
    ApplicationManager.getApplication().invokeLater(() -> updateVersionTextIfCurrent(sdk, singleLineVersion), modalityState);
  }, null);
}
 
Example 3
Source File: FlutterSettingsConfigurable.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void onVersionChanged() {
  final Workspace workspace = workspaceCache.get();
  if (workspaceCache.isBazel()) {
    if (mySdkCombo.isEnabled()) {
      // The workspace is not null if workspaceCache.isBazel() is true.
      assert (workspace != null);

      mySdkCombo.setEnabled(false);
      mySdkCombo.getComboBox().getEditor()
        .setItem(workspace.getRoot().getPath() + '/' + workspace.getSdkHome() + " <set by bazel project>");
    }
  }
  else {
    mySdkCombo.setEnabled(true);
  }

  final FlutterSdk sdk = FlutterSdk.forPath(getSdkPathText());
  if (sdk == null) {
    // Clear the label out with a non-empty string, so that the layout doesn't give this element 0 height.
    myVersionLabel.setText(" ");
    fullVersionString = null;
    return;
  }

  final ModalityState modalityState = ModalityState.current();

  final boolean trackWidgetCreationRecommended = sdk.getVersion().isTrackWidgetCreationRecommended();
  myDisableTrackWidgetCreationCheckBox.setVisible(trackWidgetCreationRecommended);

  // TODO(devoncarew): Switch this to expecting json output.
  sdk.flutterVersion().start((ProcessOutput output) -> {
    final String fullVersionText = output.getStdout();
    fullVersionString = fullVersionText;

    final String[] lines = StringUtil.splitByLines(fullVersionText);
    final String singleLineVersion = lines.length > 0 ? lines[0] : "";
    ApplicationManager.getApplication().invokeLater(() -> updateVersionTextIfCurrent(sdk, singleLineVersion), modalityState);
  }, null);
}
 
Example 4
Source File: DirDiffTableModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void reloadModel(final boolean userForcedRefresh) {
  myUpdating.set(true);
  myTable.getEmptyText().setText(StatusText.DEFAULT_EMPTY_TEXT);
  final JBLoadingPanel loadingPanel = getLoadingPanel();
  loadingPanel.startLoading();

  final ModalityState modalityState = ModalityState.current();

  ApplicationManager.getApplication().executeOnPooledThread(() -> {
    EmptyProgressIndicator indicator = new EmptyProgressIndicator(modalityState);
    ProgressManager.getInstance().executeProcessUnderProgress(() -> {
      try {
        if (myDisposed) return;
        myUpdater = new Updater(loadingPanel, 100);
        myUpdater.start();
        text.set("Loading...");
        myTree = new DTree(null, "", true);
        mySrc.refresh(userForcedRefresh);
        myTrg.refresh(userForcedRefresh);
        scan(mySrc, myTree, true);
        scan(myTrg, myTree, false);
      }
      catch (final IOException e) {
        LOG.warn(e);
        reportException(VcsBundle.message("refresh.failed.message", StringUtil.decapitalize(e.getLocalizedMessage())));
      }
      finally {
        if (myTree != null) {
          myTree.setSource(mySrc);
          myTree.setTarget(myTrg);
          myTree.update(mySettings);
          applySettings();
        }
      }
    }, indicator);
  });
}
 
Example 5
Source File: SwingWorker.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Start a thread that will call the <code>construct</code> method
 * and then exit.
 */

public SwingWorker() {
  myModalityState = ModalityState.current();

  final Runnable doFinished = new Runnable() {
    public void run() {
      finished();
    }
  };

  Runnable doConstruct = new Runnable() {
    public void run() {
      try{
        setValue(construct());
        if (LOG.isDebugEnabled()) {
          LOG.debug("construct() terminated");
        }
      }
      catch (Throwable e) {
        LOG.error(e);
        onThrowable();
        throw new RuntimeException(e);
      }
      finally{
        myThreadVar.clear();
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("invoking 'finished' action");
      }
      ApplicationManager.getApplication().invokeLater(doFinished, myModalityState);
    }
  };

  final Thread workerThread = new Thread(doConstruct, "SwingWorker work thread");
  workerThread.setPriority(Thread.NORM_PRIORITY);
  myThreadVar = new ThreadVar(workerThread);
}
 
Example 6
Source File: DesktopCommandProcessorImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
protected AsyncResult<Void> invokeLater(@Nonnull Runnable command, @Nonnull Condition<?> expire) {
  DesktopApplicationImpl application = (DesktopApplicationImpl)Application.get();

  ModalityState modalityState = ModalityPerProjectEAPDescriptor.is() ? ModalityState.current() : ModalityState.NON_MODAL;
  return application.getInvokator().invokeLater(command, modalityState, expire);
}
 
Example 7
Source File: AutoScrollFromSourceHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected ModalityState getModalityState() {
  return ModalityState.current();
}
 
Example 8
Source File: AbstractPopup.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void dispose() {
  if (myState == State.SHOWN) {
    LOG.debug("shown popup must be cancelled");
    cancel();
  }
  if (myState == State.DISPOSE) {
    return;
  }

  debugState("dispose popup", State.INIT, State.CANCEL);
  myState = State.DISPOSE;

  if (myDisposed) {
    return;
  }
  myDisposed = true;

  if (LOG.isDebugEnabled()) {
    LOG.debug("start disposing " + myContent);
  }

  Disposer.dispose(this, false);

  ApplicationManager.getApplication().assertIsDispatchThread();

  if (myPopup != null) {
    cancel(myDisposeEvent);
  }

  if (myContent != null) {
    Container parent = myContent.getParent();
    if (parent != null) parent.remove(myContent);
    myContent.removeAll();
    myContent.removeKeyListener(mySpeedSearch);
  }
  myContent = null;
  myPreferredFocusedComponent = null;
  myComponent = null;
  myCallBack = null;
  myListeners = null;

  if (myMouseOutCanceller != null) {
    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    // it may happen, but have no idea how
    // http://www.jetbrains.net/jira/browse/IDEADEV-21265
    if (toolkit != null) {
      toolkit.removeAWTEventListener(myMouseOutCanceller);
    }
  }
  myMouseOutCanceller = null;

  if (myFinalRunnable != null) {
    final ActionCallback typeAheadDone = new ActionCallback();
    IdeFocusManager.getInstance(myProject).typeAheadUntil(typeAheadDone, "Abstract Popup Disposal");

    ModalityState modalityState = ModalityState.current();
    Runnable finalRunnable = myFinalRunnable;

    getFocusManager().doWhenFocusSettlesDown(() -> {

      if (ModalityState.current().equals(modalityState)) {
        typeAheadDone.setDone();
        ((TransactionGuardEx)TransactionGuard.getInstance()).performUserActivity(finalRunnable);
      }
      else {
        typeAheadDone.setRejected();
        LOG.debug("Final runnable of popup is skipped");
      }
      // Otherwise the UI has changed unexpectedly and the action is likely not applicable.
      // And we don't want finalRunnable to perform potentially destructive actions
      //   in the context of a suddenly appeared modal dialog.
    });
    myFinalRunnable = null;
  }

  if (LOG.isDebugEnabled()) {
    LOG.debug("stop disposing content");
  }
}
 
Example 9
Source File: UiActivityMonitorImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
protected ModalityState getCurrentState() {
  return ModalityState.current();
}
 
Example 10
Source File: ChangesBrowserDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void initDialog(final Project project, final CommittedChangesTableModel changes, final Mode mode) {
  myProject = project;
  myChanges = changes;
  myMode = mode;
  setTitle(VcsBundle.message("dialog.title.changes.browser"));
  setCancelButtonText(CommonBundle.getCloseButtonText());
  final ModalityState currentState = ModalityState.current();
  if ((mode != Mode.Choose) && (ModalityState.NON_MODAL.equals(currentState))) {
    setModal(false);
  }
  myAppender = new AsynchConsumer<List<CommittedChangeList>>() {

    public void finished() {
      SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
          if (ChangesBrowserDialog.this.isShowing()) {
            myCommittedChangesBrowser.stopLoading();
          }
        }
      });
    }

    public void consume(final List<CommittedChangeList> committedChangeLists) {
      SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
          if (ChangesBrowserDialog.this.isShowing()) {
            final boolean selectFirst = (myChanges.getRowCount() == 0) && (!committedChangeLists.isEmpty());
            myChanges.addRows(committedChangeLists);
            if (selectFirst) {
              myCommittedChangesBrowser.selectFirstIfAny();
            }
          }
        }
      });
    }
  };

  init();

  if (myInitRunnable != null) {
    new AdjustComponentWhenShown() {
      @Override
      protected boolean init() {
        myInitRunnable.consume(ChangesBrowserDialog.this);
        return true;
      }
    }.install(myCommittedChangesBrowser);
  }
}