Java Code Examples for com.intellij.util.ui.UIUtil#invokeLaterIfNeeded()

The following examples show how to use com.intellij.util.ui.UIUtil#invokeLaterIfNeeded() . 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: DialogWrapperPeerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("SSBasedInspection")
protected void dispose() {
  LOG.assertTrue(EventQueue.isDispatchThread(), "Access is allowed from event dispatch thread only");
  for (Runnable runnable : myDisposeActions) {
    runnable.run();
  }
  myDisposeActions.clear();
  Runnable disposer = () -> {
    Disposer.dispose(myDialog);
    myProject = null;

    SwingUtilities.invokeLater(() -> {
      if (myDialog != null && myDialog.getRootPane() != null) {
        myDialog.remove(myDialog.getRootPane());
      }
    });
  };

  UIUtil.invokeLaterIfNeeded(disposer);
}
 
Example 2
Source File: XDebuggerInlayUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void createInlay(@Nonnull Project project, @Nonnull VirtualFile file, int offset, String inlayText) {
  UIUtil.invokeLaterIfNeeded(() -> {
    FileEditor editor = FileEditorManager.getInstance(project).getSelectedEditor(file);
    if (editor instanceof TextEditor) {
      Editor e = ((TextEditor)editor).getEditor();
      CharSequence text = e.getDocument().getImmutableCharSequence();

      int insertOffset = offset;
      while (insertOffset < text.length() && Character.isJavaIdentifierPart(text.charAt(insertOffset))) insertOffset++;

      List<Inlay> existing = e.getInlayModel().getInlineElementsInRange(insertOffset, insertOffset);
      for (Inlay inlay : existing) {
        if (inlay.getRenderer() instanceof MyRenderer) {
          Disposer.dispose(inlay);
        }
      }

      e.getInlayModel().addInlineElement(insertOffset, new MyRenderer(inlayText));
    }
  });
}
 
Example 3
Source File: BreadcrumbsInitializingActivity.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void runActivity(@Nonnull Project project) {
  if (project.isDefault() || ApplicationManager.getApplication().isUnitTestMode() || project.isDisposed()) {
    return;
  }

  MessageBusConnection connection = project.getMessageBus().connect();
  connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new MyFileEditorManagerListener());
  connection.subscribe(FileTypeManager.TOPIC, new FileTypeListener() {
    @Override
    public void fileTypesChanged(@Nonnull FileTypeEvent event) {
      reinitBreadcrumbsInAllEditors(project);
    }
  });

  VirtualFileManager.getInstance().addVirtualFileListener(new MyVirtualFileListener(project), project);
  connection.subscribe(UISettingsListener.TOPIC, uiSettings -> reinitBreadcrumbsInAllEditors(project));

  UIUtil.invokeLaterIfNeeded(() -> reinitBreadcrumbsInAllEditors(project));
}
 
Example 4
Source File: DiffRequestProcessor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void dispose() {
  if (myDisposed) return;
  UIUtil.invokeLaterIfNeeded(new Runnable() {
    @Override
    public void run() {
      if (myDisposed) return;
      myDisposed = true;

      onDispose();

      myState.destroy();
      myToolbarStatusPanel.setContent(null);
      myToolbarPanel.setContent(null);
      myContentPanel.setContent(null);

      myActiveRequest.onAssigned(false);

      myState = EmptyState.INSTANCE;
      myActiveRequest = NoDiffRequest.INSTANCE;
    }
  });
}
 
Example 5
Source File: XDebugSessionImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private XSuspendContext doResume() {
  if (!myPaused.getAndSet(false)) {
    return null;
  }

  myDispatcher.getMulticaster().beforeSessionResume();
  XSuspendContext context = mySuspendContext;
  mySuspendContext = null;
  myCurrentExecutionStack = null;
  myCurrentStackFrame = null;
  myTopFramePosition = null;
  myActiveNonLineBreakpoint = null;
  updateExecutionPosition();
  UIUtil.invokeLaterIfNeeded(() -> {
    if (mySessionTab != null) {
      mySessionTab.getUi().clearAttractionBy(XDebuggerUIConstants.LAYOUT_VIEW_BREAKPOINT_CONDITION);
    }
  });
  myDispatcher.getMulticaster().sessionResumed();
  return context;
}
 
Example 6
Source File: UsageViewImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void setSearchInProgress(boolean searchInProgress) {
  mySearchInProgress = searchInProgress;
  if (!myPresentation.isDetachedMode()) {
    UIUtil.invokeLaterIfNeeded(() -> {
      if (isDisposed()) return;
      final UsageNode firstUsageNode = myModel.getFirstUsageNode();
      if (firstUsageNode == null) return;

      Node node = getSelectedNode();
      if (node != null && !Comparing.equal(new TreePath(node.getPath()), TreeUtil.getFirstNodePath(myTree))) {
        // user has selected node already
        return;
      }
      showNode(firstUsageNode);
      if (getUsageViewSettings().isExpanded() && myUsageNodes.size() < 10000) {
        expandAll();
      }
    });
  }
}
 
Example 7
Source File: ProgressWindow.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public synchronized void stop() {
  LOG.assertTrue(!myStoppedAlready);

  super.stop();

  UIUtil.invokeLaterIfNeeded(() -> {
    if (myDialog != null) {
      myDialog.hide();
    }

    synchronized (this) {
      myStoppedAlready = true;
    }

    Disposer.dispose(this);
  });

  //noinspection SSBasedInspection
  SwingUtilities.invokeLater(EmptyRunnable.INSTANCE); // Just to give blocking dispatching a chance to go out.
}
 
Example 8
Source File: GlobalInspectionContextImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void notifyInspectionsFinished() {
  if (ApplicationManager.getApplication().isUnitTestMode()) return;
  UIUtil.invokeLaterIfNeeded(new Runnable() {
    @Override
    public void run() {
      LOG.info("Code inspection finished");

      if (myView != null) {
        if (!myView.update() && !getUIOptions().SHOW_ONLY_DIFF) {
          NOTIFICATION_GROUP.createNotification(InspectionsBundle.message("inspection.no.problems.message"), MessageType.INFO).notify(getProject());
          close(true);
        }
        else {
          addView(myView);
        }
      }
    }
  });
}
 
Example 9
Source File: Unity3dProjectImportUtil.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
private static void importAfterDefines(@Nonnull final Project project,
									   @Nullable final Sdk sdk,
									   final boolean runValidator,
									   @Nonnull ProgressIndicator indicator,
									   @Nullable UnityOpenFilePostHandlerRequest requestor,
									   @Nullable UnitySetDefines setDefines)
{
	try
	{
		Collection<String> defines = null;
		if(setDefines != null)
		{
			VirtualFile maybeProjectDir = LocalFileSystem.getInstance().findFileByPath(setDefines.projectPath);
			if(maybeProjectDir != null && maybeProjectDir.equals(project.getBaseDir()))
			{
				defines = new TreeSet<>(Arrays.asList(setDefines.defines));
			}
		}

		importOrUpdate(project, sdk, null, indicator, defines);
	}
	finally
	{
		project.putUserData(ourInProgressFlag, null);
	}

	if(runValidator)
	{
		UnityPluginFileValidator.runValidation(project);
	}

	if(requestor != null)
	{
		UIUtil.invokeLaterIfNeeded(() -> UnityOpenFilePostHandler.openFile(project, requestor));
	}
}
 
Example 10
Source File: DebuggerSessionTabBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void select() {
  if (ApplicationManager.getApplication().isUnitTestMode()) return;

  UIUtil.invokeLaterIfNeeded(() -> {
    if (myRunContentDescriptor != null) {
      RunContentManager manager = ExecutionManager.getInstance(myProject).getContentManager();
      ToolWindow toolWindow = manager.getToolWindowByDescriptor(myRunContentDescriptor);
      Content content = myRunContentDescriptor.getAttachedContent();
      if (toolWindow == null || content == null) return;
      manager.selectRunContent(myRunContentDescriptor);
    }
  });
}
 
Example 11
Source File: CertificateConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void certificateAdded(final X509Certificate certificate) {
  UIUtil.invokeLaterIfNeeded(new Runnable() {
    @Override
    public void run() {
      if (myTreeBuilder != null && !myCertificates.contains(certificate)) {
        myCertificates.add(certificate);
        myTreeBuilder.addCertificate(certificate);
        addCertificatePanel(certificate);
      }
    }
  });
}
 
Example 12
Source File: DockablePopupManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
void restartAutoUpdate(final boolean state) {
  if (state && myToolWindow != null) {
    if (myAutoUpdateRequest == null) {
      myAutoUpdateRequest = this::updateComponent;

      UIUtil.invokeLaterIfNeeded(() -> IdeEventQueue.getInstance().addIdleListener(myAutoUpdateRequest, 500));
    }
  }
  else {
    if (myAutoUpdateRequest != null) {
      IdeEventQueue.getInstance().removeIdleListener(myAutoUpdateRequest);
      myAutoUpdateRequest = null;
    }
  }
}
 
Example 13
Source File: PantsUtil.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
public static void invokeLaterIfNeeded(Runnable task) {
  // calling directly ensures that the underlying exception gets propagated and
  // can then be asserted in tests - otherwise it gets swallowed underneath
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    task.run();
  }
  else {
    UIUtil.invokeLaterIfNeeded(task);
  }
}
 
Example 14
Source File: PlatformOrPluginUpdateChecker.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static AsyncResult<Void> checkAndNotifyForUpdates(@Nullable Project project, boolean showResults, @Nullable ProgressIndicator indicator) {
  AsyncResult<Void> actionCallback = AsyncResult.undefined();
  PlatformOrPluginUpdateResult updateResult = checkForUpdates(showResults, indicator);
  if (updateResult == PlatformOrPluginUpdateResult.CANCELED) {
    actionCallback.setDone();
    return actionCallback;
  }

  UIUtil.invokeLaterIfNeeded(() -> {
    actionCallback.setDone();

    showUpdateResult(project, updateResult, showResults);
  });
  return actionCallback;
}
 
Example 15
Source File: AbstractConsoleRunnerWithHistory.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Launch process, setup history, actions etc.
 *
 * @throws ExecutionException
 */
public void initAndRun() throws ExecutionException {
  // Create Server process
  final Process process = createProcess();
  UIUtil.invokeLaterIfNeeded(() -> {
    // Init console view
    myConsoleView = createConsoleView();
    if (myConsoleView instanceof JComponent) {
      ((JComponent)myConsoleView).setBorder(new SideBorder(JBColor.border(), SideBorder.LEFT));
    }
    myProcessHandler = createProcessHandler(process);

    myConsoleExecuteActionHandler = createExecuteActionHandler();

    ProcessTerminatedListener.attach(myProcessHandler);

    myProcessHandler.addProcessListener(new ProcessAdapter() {
      @Override
      public void processTerminated(ProcessEvent event) {
        finishConsole();
      }
    });

    // Attach to process
    myConsoleView.attachToProcess(myProcessHandler);

    // Runner creating
    createContentDescriptorAndActions();

    // Run
    myProcessHandler.startNotify();
  });
}
 
Example 16
Source File: AbstractTreeBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void updateAfterLoadedInBackground(@Nonnull Runnable runnable) {
  AbstractTreeUi ui = getUi();
  if (ui == null) return;

  if (ui.isPassthroughMode()) {
    runnable.run();
  }
  else {
    UIUtil.invokeLaterIfNeeded(runnable);
  }
}
 
Example 17
Source File: DiffRequestPanelImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public synchronized void setRequest(@javax.annotation.Nullable DiffRequest request, @javax.annotation.Nullable Object identity) {
  if (myRequestIdentity != null && identity != null && myRequestIdentity.equals(identity)) return;

  myRequest = request != null ? request : NoDiffRequest.INSTANCE;
  myRequestIdentity = identity;

  UIUtil.invokeLaterIfNeeded(() -> updateRequest());
}
 
Example 18
Source File: MergeRequestProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void dispose() {
  if (myDisposed) return;
  UIUtil.invokeLaterIfNeeded(new Runnable() {
    @Override
    public void run() {
      if (myDisposed) return;
      myDisposed = true;

      onDispose();

      destroyViewer();
    }
  });
}
 
Example 19
Source File: UiActivityMonitorImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void addActivity(@Nonnull final UiActivity activity, @Nonnull final ModalityState effectiveModalityState) {
  if (!isActive()) return;

  UIUtil.invokeLaterIfNeeded(() -> getBusyContainer(null).addActivity(activity, effectiveModalityState));
}
 
Example 20
Source File: Messages.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static Runnable createMessageDialogRemover(@Nullable Project project) {
  consulo.ui.Window projectWindow = project == null ? null : WindowManager.getInstance().suggestParentWindow(project);
  return () -> UIUtil
          .invokeLaterIfNeeded(() -> makeCurrentMessageDialogGoAway(projectWindow != null ? TargetAWT.to(projectWindow).getOwnedWindows() : Window.getWindows()));
}