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

The following examples show how to use com.intellij.openapi.project.Project#isInitialized() . 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: DesktopPsiAwareTextEditorProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public TextEditorState getStateImpl(final Project project, @Nonnull final Editor editor, @Nonnull final FileEditorStateLevel level) {
  final TextEditorState state = super.getStateImpl(project, editor, level);
  // Save folding only on FULL level. It's very expensive to commit document on every
  // type (caused by undo).
  if (FileEditorStateLevel.FULL == level) {
    // Folding
    if (project != null && !project.isDisposed() && !editor.isDisposed() && project.isInitialized()) {
      state.setFoldingState(CodeFoldingManager.getInstance(project).saveFoldingState(editor));
    }
    else {
      state.setFoldingState(null);
    }
  }

  return state;
}
 
Example 2
Source File: RestfulWindowToolWindowFactory.java    From NutzCodeInsight with Apache License 2.0 6 votes vote down vote up
@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
    final SimpleTree apiTree = new SimpleTree();
    apiTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    this.toolWindowEx = (ToolWindowEx) toolWindow;
    RefreshAction refreshAction = new RefreshAction("刷新", "重新加载URL", AllIcons.Actions.Refresh, toolWindowEx, apiTree);
    toolWindowEx.setTitleActions(refreshAction, actionManager.getAction("GoToRequestMapping"));
    apiTree.addMouseListener(new ApiTreeMouseAdapter(apiTree));
    ContentManager contentManager = toolWindow.getContentManager();
    Content content = contentManager.getFactory().createContent(new RestServicesNavigatorPanel(apiTree), null, false);
    contentManager.addContent(content);
    contentManager.setSelectedContent(content);
    if (project.isInitialized()) {
        refreshAction.loadTree(project);
    }
}
 
Example 3
Source File: ProjectUtils.java    From embeddedlinux-jvmdebugger-intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Runs a thread when initialized
 *
 * @param project
 * @param r
 */
public static void runWhenInitialized(final Project project, final Runnable r) {
    if (project.isDisposed()) return;

    if (isNoBackgroundMode()) {
        r.run();
        return;
    }

    if (!project.isInitialized()) {
        StartupManager.getInstance(project).registerPostStartupActivity(DisposeAwareRunnable.create(r, project));
        return;
    }

    runDumbAware(project, r);
}
 
Example 4
Source File: LookupDocumentSavingVetoer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean maySaveDocument(@Nonnull Document document, boolean isSaveExplicit) {
  if (ApplicationManager.getApplication().isDisposed() || isSaveExplicit) {
    return true;
  }

  for (Project project : ProjectManager.getInstance().getOpenProjects()) {
    if (!project.isInitialized() || project.isDisposed()) {
      continue;
    }
    LookupEx lookup = LookupManager.getInstance(project).getActiveLookup();
    if (lookup != null) {
      Editor editor = InjectedLanguageUtil.getTopLevelEditor(lookup.getEditor());
      if (editor.getDocument() == document) {
        return false;
      }
    }
  }
  return true;
}
 
Example 5
Source File: IdeaModifiableModelsProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public LibraryTable.ModifiableModel getLibraryTableModifiableModel() {
  final Project[] projects = ProjectManager.getInstance().getOpenProjects();
  for (Project project : projects) {
    if (!project.isInitialized()) {
      continue;
    }
    StructureConfigurableContext context = getProjectStructureContext(project);
    LibraryTableModifiableModelProvider provider = context != null ? context.createModifiableModelProvider(LibraryTablesRegistrar.APPLICATION_LEVEL) : null;
    final LibraryTable.ModifiableModel modifiableModel = provider != null ? provider.getModifiableModel() : null;
    if (modifiableModel != null) {
      return modifiableModel;
    }
  }
  return LibraryTablesRegistrar.getInstance().getLibraryTable().getModifiableModel();
}
 
Example 6
Source File: IntellijReferencePoint.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
public IntellijReferencePoint(@NotNull Project project, @NotNull VirtualFile virtualFile) {

    if (!project.isInitialized()) {
      throw new IllegalArgumentException("The given project must be initialized - " + project);
    }

    if (!virtualFile.exists()) {
      throw new IllegalArgumentException("The given virtual file must exist - " + virtualFile);

    } else if (!virtualFile.isDirectory()) {
      throw new IllegalArgumentException(
          "The given virtual file must be a directory - " + virtualFile);
    }

    this.project = project;
    this.virtualFile = virtualFile;
  }
 
Example 7
Source File: RunConfigurationsComboBoxAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void update(@Nonnull AnActionEvent e) {
  Presentation presentation = e.getPresentation();
  Project project = e.getData(CommonDataKeys.PROJECT);
  if (ActionPlaces.isMainMenuOrActionSearch(e.getPlace())) {
    presentation.setDescription(ExecutionBundle.message("choose.run.configuration.action.description"));
  }
  try {
    if (project == null || project.isDisposed() || !project.isInitialized()) {
      updatePresentation(null, null, null, presentation);
      presentation.setEnabled(false);
    }
    else {
      updatePresentation(ExecutionTargetManager.getActiveTarget(project), RunManagerEx.getInstanceEx(project).getSelectedConfiguration(), project, presentation);
      presentation.setEnabled(true);
    }
  }
  catch (IndexNotReadyException e1) {
    presentation.setEnabled(false);
  }
}
 
Example 8
Source File: StatusBar.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void set(@Nullable final String text, @Nullable final Project project, @Nullable final String requestor) {
  if (project != null) {
    if (project.isDisposed()) return;
    if (!project.isInitialized()) {
      StartupManager.getInstance(project).runWhenProjectIsInitialized(new Runnable() {
        public void run() {
          project.getMessageBus().syncPublisher(TOPIC).setInfo(text, requestor);
        }
      });
      return;
    }
  }

  final MessageBus bus = project == null ? ApplicationManager.getApplication().getMessageBus() : project.getMessageBus();
  bus.syncPublisher(TOPIC).setInfo(text, requestor);
}
 
Example 9
Source File: MessageViewImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Inject
public MessageViewImpl(final Project project, final StartupManager startupManager, final ToolWindowManager toolWindowManager) {
  final Runnable runnable = new Runnable() {
    @Override
    public void run() {
      myToolWindow = toolWindowManager.registerToolWindow(ToolWindowId.MESSAGES_WINDOW, true, ToolWindowAnchor.BOTTOM, project, true);
      myToolWindow.setIcon(AllIcons.Toolwindows.ToolWindowMessages);
      new ContentManagerWatcher(myToolWindow, getContentManager());
      for (Runnable postponedRunnable : myPostponedRunnables) {
        postponedRunnable.run();
      }
      myPostponedRunnables.clear();
    }
  };
  if (project.isInitialized()) {
    runnable.run();
  }
  else {
    startupManager.registerPostStartupActivity(runnable::run);
  }

}
 
Example 10
Source File: VfsIconUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean wasEverInitialized(@Nonnull Project project) {
  Boolean was = project.getUserData(PROJECT_WAS_EVER_INITIALIZED);
  if (was == null) {
    if (project.isInitialized()) {
      was = Boolean.valueOf(true);
      project.putUserData(PROJECT_WAS_EVER_INITIALIZED, was);
    }
    else {
      was = Boolean.valueOf(false);
    }
  }

  return was.booleanValue();
}
 
Example 11
Source File: ComponentStoreImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void validateUnusedMacros(@Nullable final String componentName, final boolean service) {
  final Project project = getProject();
  if (project == null) return;

  if (!ApplicationManager.getApplication().isHeadlessEnvironment() && !ApplicationManager.getApplication().isUnitTestMode()) {
    if (service && componentName != null && project.isInitialized()) {
      final TrackingPathMacroSubstitutor substitutor = getStateStorageManager().getMacroSubstitutor();
      if (substitutor != null) {
        StorageUtil.notifyUnknownMacros(substitutor, project, componentName);
      }
    }
  }
}
 
Example 12
Source File: IdeaGateway.java    From consulo with Apache License 2.0 5 votes vote down vote up
VersionedFilterData() {
  Project[] openProjects = ProjectManager.getInstance().getOpenProjects();

  for (Project each : openProjects) {
    if (each.isDefault()) continue;
    if (!each.isInitialized()) continue;

    myWorkspaceFiles.add(each.getWorkspaceFile());
    myOpenedProjects.add(each);
    myProjectFileIndices.add(ProjectRootManager.getInstance(each).getFileIndex());
  }
}
 
Example 13
Source File: IdeFocusManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
static IdeFocusManager getInstanceSafe(@Nullable Project project) {
  if (project != null && !project.isDisposed() && project.isInitialized()) {
    return getInstance(project);
  }
  return null;
}
 
Example 14
Source File: DocumentCommitThread.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void doQueue(@Nonnull Project project, @Nonnull Document document, @Nonnull Object reason, @Nullable TransactionId context, @Nonnull CharSequence lastCommittedText) {
  synchronized (lock) {
    if (!project.isInitialized()) return;  // check the project is disposed under lock.
    CommitTask newTask = createNewTaskAndCancelSimilar(project, document, reason, context, lastCommittedText, false);

    documentsToCommit.offer(newTask);
    log(project, "Queued", newTask, reason);

    wakeUpQueue();
  }
}
 
Example 15
Source File: CrudUtils.java    From crud-intellij-plugin with Apache License 2.0 5 votes vote down vote up
public static void runWhenInitialized(final Project project, final Runnable r) {
    if (project.isDisposed()) {
        return;
    }
    if (isNoBackgroundMode()) {
        r.run();
        return;
    }
    if (!project.isInitialized()) {
        StartupManager.getInstance(project).registerPostStartupActivity(DisposeAwareRunnable.create(r, project));
        return;
    }
    runDumbAware(project, r);
}
 
Example 16
Source File: VFSUtils.java    From SmartIM4IntelliJ with Apache License 2.0 5 votes vote down vote up
public static String getPath(VirtualFile file) {
    String result = null;
    Document document = FileDocumentManager.getInstance().getDocument(file);

    Project[] openProjects = VFSUtils.getOpenProjects();
    for (int i = 0; i < openProjects.length && result == null; i++) {
        Project openProject = openProjects[i];
        if (!openProject.isInitialized() && !ApplicationManager.getApplication().isUnitTestMode())
            continue;
        if (document != null) {
            PsiFile psiFile = PsiDocumentManager.getInstance(openProject).getPsiFile(document);
            result = PsiFileTypeFactory.create(psiFile).getQualifiedName(psiFile);
        }
        ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(openProject).getFileIndex();
        if (projectFileIndex.isInSource(file)) {
            VirtualFile sourceRoot = projectFileIndex.getSourceRootForFile(file);
            result = (getRelativePath(file, sourceRoot));
        }

        if (projectFileIndex.isInContent(file)) {
            VirtualFile contentRoot = projectFileIndex.getContentRootForFile(file);
            result = (getRelativePath(file, contentRoot));
        }

    }
    return result;
}
 
Example 17
Source File: DaemonCodeAnalyzerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
  ApplicationManager.getApplication().assertIsDispatchThread();
  Project project = myProject;
  DaemonCodeAnalyzerImpl dca;
  if (project == null || !project.isInitialized() || project.isDisposed() || PowerSaveMode.isEnabled() || (dca = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project)).myDisposed) {
    return;
  }

  final Collection<FileEditor> activeEditors = dca.getSelectedEditors();
  boolean updateByTimerEnabled = dca.isUpdateByTimerEnabled();
  PassExecutorService
          .log(dca.getUpdateProgress(), null, "Update Runnable. myUpdateByTimerEnabled:", updateByTimerEnabled, " something disposed:", PowerSaveMode.isEnabled() || !myProject.isInitialized(),
               " activeEditors:", activeEditors);
  if (!updateByTimerEnabled) return;

  if (activeEditors.isEmpty()) return;

  if (ApplicationManager.getApplication().isWriteAccessAllowed()) {
    // makes no sense to start from within write action, will cancel anyway
    // we'll restart when the write action finish
    return;
  }
  if (dca.myPsiDocumentManager.hasUncommitedDocuments()) {
    // restart when everything committed
    dca.myPsiDocumentManager.performLaterWhenAllCommitted(this);
    return;
  }
  if (RefResolveService.ENABLED && !RefResolveService.getInstance(myProject).isUpToDate() && RefResolveService.getInstance(myProject).getQueueSize() == 1) {
    return; // if the user have just typed in something, wait until the file is re-resolved
    // (or else it will blink like crazy since unused symbols calculation depends on resolve service)
  }

  Map<FileEditor, HighlightingPass[]> passes = new THashMap<>(activeEditors.size());
  for (FileEditor fileEditor : activeEditors) {
    BackgroundEditorHighlighter highlighter = fileEditor.getBackgroundHighlighter();
    if (highlighter != null) {
      HighlightingPass[] highlightingPasses = highlighter.createPassesForEditor();
      passes.put(fileEditor, highlightingPasses);
    }
  }

  // wait for heavy processing to stop, re-schedule daemon but not too soon
  if (HeavyProcessLatch.INSTANCE.isRunning()) {
    boolean hasPasses = false;
    for (Map.Entry<FileEditor, HighlightingPass[]> entry : passes.entrySet()) {
      HighlightingPass[] filtered = Arrays.stream(entry.getValue()).filter(DumbService::isDumbAware).toArray(HighlightingPass[]::new);
      entry.setValue(filtered);
      hasPasses |= filtered.length != 0;
    }
    if (!hasPasses) {
      HeavyProcessLatch.INSTANCE.executeOutOfHeavyProcess(() -> dca.stopProcess(true, "re-scheduled to execute after heavy processing finished"));
      return;
    }
  }

  // cancel all after calling createPasses() since there are perverts {@link com.intellij.util.xml.ui.DomUIFactoryImpl} who are changing PSI there
  dca.cancelUpdateProgress(true, "Cancel by alarm");
  dca.myUpdateRunnableFuture.cancel(false);
  DaemonProgressIndicator progress = dca.createUpdateProgress(passes.keySet());
  dca.myPassExecutorService.submitPasses(passes, progress);
}
 
Example 18
Source File: IdeFocusManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static IdeFocusManager getInstance(@Nullable Project project) {
  if (project == null || project.isDisposed() || !project.isInitialized()) return getGlobalInstance();

  return project.getComponent(ProjectIdeFocusManager.class);
}
 
Example 19
Source File: ProjectMessage.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
static boolean canSendMessage(@NotNull Project project) {
    return project.isInitialized() && !project.isDisposed();
}
 
Example 20
Source File: BuildFileFormatOnSaveHandler.java    From intellij with Apache License 2.0 4 votes vote down vote up
private static boolean isProjectValid(Project project) {
  return project.isInitialized() && !project.isDisposed();
}