Java Code Examples for com.intellij.openapi.project.Project#isOpen()

The following examples show how to use com.intellij.openapi.project.Project#isOpen() . These examples are extracted from open source projects. 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
@Override
public void ensureInitializationCompleted(Project project, ProgressIndicator indicator) {
  final int id = getProjectId(project);
  synchronized (myAsyncScanLock) {
    while (myInitInProgress.containsKey(id)) {
      if (!project.isOpen() || project.isDisposed() || (indicator != null && indicator.isCanceled())) {
        // makes no sense to continue waiting
        break;
      }
      try {
        myAsyncScanLock.wait(500);
      }
      catch (InterruptedException ignored) {
        break;
      }
    }
  }
}
 
Example 2
Source Project: consulo   File: VcsActionGroup.java    License: Apache License 2.0 6 votes vote down vote up
public void update(AnActionEvent event) {
  super.update(event);

  Presentation presentation = event.getPresentation();
  Project project = event.getDataContext().getData(CommonDataKeys.PROJECT);
  if (project == null){
    presentation.setVisible(false);
    presentation.setEnabled(false);
  } else if (!project.isOpen()) {
    presentation.setVisible(false);
    presentation.setEnabled(false);
  } else {
    presentation.setVisible(true);
    presentation.setEnabled(true);
  }
}
 
Example 3
Source Project: consulo   File: ExternalSystemUtil.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Nullable
public static <T> T getToolWindowElement(@Nonnull Class<T> clazz,
                                         @Nonnull Project project,
                                         @Nonnull Key<T> key,
                                         @Nonnull ProjectSystemId externalSystemId) {
  if (project.isDisposed() || !project.isOpen()) {
    return null;
  }
  final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
  if (toolWindowManager == null) {
    return null;
  }
  final ToolWindow toolWindow = ensureToolWindowContentInitialized(project, externalSystemId);
  if (toolWindow == null) {
    return null;
  }

  final ContentManager contentManager = toolWindow.getContentManager();
  if (contentManager == null) {
    return null;
  }

  for (Content content : contentManager.getContents()) {
    final JComponent component = content.getComponent();
    if (component instanceof DataProvider) {
      final Object data = ((DataProvider)component).getData(key);
      if (data != null && clazz.isInstance(data)) {
        return (T)data;
      }
    }
  }
  return null;
}
 
Example 4
Source Project: consulo   File: TooltipController.java    License: Apache License 2.0 5 votes vote down vote up
public void showTooltipByMouseMove(@Nonnull final Editor editor,
                                   @Nonnull final RelativePoint point,
                                   final TooltipRenderer tooltipObject,
                                   final boolean alignToRight,
                                   @Nonnull final TooltipGroup group,
                                   @Nonnull HintHint hintHint) {
  LightweightHint currentTooltip = myCurrentTooltip;
  if (currentTooltip == null || !currentTooltip.isVisible()) {
    if (currentTooltip != null) {
      if (!IdeTooltipManager.getInstance().isQueuedToShow(currentTooltip.getCurrentIdeTooltip())) {
        myCurrentTooltipObject = null;
      }
    }
    else {
      myCurrentTooltipObject = null;
    }
  }

  if (Comparing.equal(tooltipObject, myCurrentTooltipObject)) {
    IdeTooltipManager.getInstance().cancelAutoHide();
    return;
  }
  hideCurrentTooltip();

  if (tooltipObject != null) {
    final Point p = point.getPointOn(editor.getComponent().getRootPane().getLayeredPane()).getPoint();
    if (!hintHint.isAwtTooltip()) {
      p.x += alignToRight ? -10 : 10;
    }

    Project project = editor.getProject();
    if (project != null && !project.isOpen()) return;
    if (editor.getContentComponent().isShowing()) {
      showTooltip(editor, p, tooltipObject, alignToRight, group, hintHint);
    }
  }
}
 
Example 5
Source Project: consulo   File: TemplateManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void editorReleased(@Nonnull EditorFactoryEvent event) {
  Editor editor = event.getEditor();
  Project project = editor.getProject();
  if (project == null || project.isDisposed() || !project.isOpen()) {
    return;
  }
  
  TemplateState state = getTemplateState(editor);
  if (state != null) {
    state.gotoEnd();
  }
  clearTemplateState(editor);
}
 
Example 6
Source Project: consulo   File: CodeFoldingManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void releaseFoldings(@Nonnull Editor editor) {
  ApplicationManager.getApplication().assertIsDispatchThread();
  final Project project = editor.getProject();
  if (project != null && (!project.equals(myProject) || !project.isOpen())) return;

  Document document = editor.getDocument();
  PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
  if (file == null || !file.getViewProvider().isPhysical() || !file.isValid()) return;

  EditorFoldingInfo.get(editor).dispose();
}
 
Example 7
public static void install(@Nonnull Project project) {
  if (!project.isOpen()) {
    throw new RuntimeException("Already closed: " + project);
  }
  getInstance(project);
}