Java Code Examples for com.intellij.openapi.startup.StartupManager#getInstance()

The following examples show how to use com.intellij.openapi.startup.StartupManager#getInstance() . 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: ModuleVcsDetector.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void projectOpened() {
  if (ApplicationManager.getApplication().isUnitTestMode()) return;

  final StartupManager manager = StartupManager.getInstance(myProject);
  manager.registerStartupActivity(new Runnable() {
    @Override
    public void run() {
      if (myVcsManager.needAutodetectMappings()) {
        autoDetectVcsMappings(true);
      }
      myVcsManager.updateActiveVcss();
    }
  });
  manager.registerPostStartupActivity(new Runnable() {
    @Override
    public void run() {
      myConnection = myMessageBus.connect();
      final MyModulesListener listener = new MyModulesListener();
      myConnection.subscribe(ProjectTopics.MODULES, listener);
      myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, listener);
    }
  });
}
 
Example 2
Source File: UpdateRequestsQueue.java    From consulo with Apache License 2.0 6 votes vote down vote up
public UpdateRequestsQueue(final Project project, @Nonnull ChangeListManagerImpl.Scheduler scheduler, final Runnable delegate) {
  myProject = project;
  myScheduler = scheduler;

  myTrackHeavyLatch = Boolean.parseBoolean(System.getProperty(ourHeavyLatchOptimization));

  myDelegate = delegate;
  myPlVcsManager = ProjectLevelVcsManager.getInstance(myProject);
  myStartupManager = StartupManager.getInstance(myProject);
  myLock = new Object();
  myWaitingUpdateCompletionQueue = new ArrayList<>();
  // not initialized
  myStarted = false;
  myStopped = false;
  myIsStoppedGetter = new Getter<Boolean>() {
    @Override
    public Boolean get() {
      return isStopped();
    }
  };
}
 
Example 3
Source File: PlatformTestCase.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void simulateProjectOpen() {
  ModuleManagerImpl mm = (ModuleManagerImpl)ModuleManager.getInstance(myProject);
  StartupManagerImpl sm = (StartupManagerImpl)StartupManager.getInstance(myProject);

  mm.projectOpened();
  sm.runStartupActivities(UIAccess.get());
  // extra init for libraries
  sm.runPostStartupActivities(UIAccess.get());
}
 
Example 4
Source File: ProjectManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void openProjectRequireBackgroundTask(Project project, UIAccess uiAccess) {
  myApplication.getMessageBus().syncPublisher(TOPIC).projectOpened(project, uiAccess);

  final StartupManagerImpl startupManager = (StartupManagerImpl)StartupManager.getInstance(project);
  startupManager.runStartupActivities(uiAccess);
  startupManager.runPostStartupActivitiesFromExtensions(uiAccess);

  if (!project.isDisposed()) {
    startupManager.runPostStartupActivities(uiAccess);

    Application application = Application.get();
    if (!application.isHeadlessEnvironment() && !application.isUnitTestMode()) {
      final TrackingPathMacroSubstitutor macroSubstitutor = ((ProjectEx)project).getStateStore().getStateStorageManager().getMacroSubstitutor();
      if (macroSubstitutor != null) {
        StorageUtil.notifyUnknownMacros(macroSubstitutor, project, null);
      }
    }

    if (application.isActive()) {
      consulo.ui.Window projectFrame = WindowManager.getInstance().getWindow(project);
      if (projectFrame != null) {
        uiAccess.giveAndWaitIfNeed(() -> IdeFocusManager.getInstance(project).requestFocus(projectFrame, true));
      }
    }

    application.invokeLater(() -> {
      if (!project.isDisposedOrDisposeInProgress()) {
        startupManager.scheduleBackgroundPostStartupActivities(uiAccess);
      }
    }, ModalityState.NON_MODAL, o -> project.isDisposedOrDisposeInProgress());
  }
}
 
Example 5
Source File: ContentResourceChangeListener.java    From aem-ide-tooling-4-intellij with Apache License 2.0 4 votes vote down vote up
public ContentResourceChangeListener(@NotNull Project project) {
    super(project);
    final ServerConnectionManager serverConnectionManager = ComponentProvider.getComponent(project, ServerConnectionManager.class);
    pluginConfiguration = ComponentProvider.getComponent(project, AEMPluginConfiguration.class);
    this.serverConnectionManager = serverConnectionManager;
    this.project = project;

    // Register a Startup Manager to check the project if it is default after the project is initialized
    StartupManager startupManager = StartupManager.getInstance(project);
    startupManager.runWhenProjectIsInitialized(
        new Runnable() {
            @Override
            public void run() {
                SlingServerTreeManager slingServerTreeManager = ComponentProvider.getComponent(myProject, SlingServerTreeManager.class);
                if(slingServerTreeManager != null) {
                    // At the end of the Tool Window is created we run the Check if a project is marked as Default
                    Object modelRoot = slingServerTreeManager.getTree().getModel().getRoot();
                    if (modelRoot instanceof DefaultMutableTreeNode) {
                        DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) modelRoot;
                        Enumeration e = rootNode.children();
                        while (e.hasMoreElements()) {
                            TreeNode child = (TreeNode) e.nextElement();
                            if (child instanceof DefaultMutableTreeNode) {
                                DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) child;
                                Object target = childNode.getUserObject();
                                if (target instanceof SlingServerNodeDescriptor) {
                                    ActionManager actionManager = ActionManager.getInstance();
                                    SlingServerNodeDescriptor descriptor = (SlingServerNodeDescriptor) target;
                                    switch (descriptor.getTarget().getDefaultMode()) {
                                        case run:
                                            slingServerTreeManager.getTree().setSelectionPath(new TreePath(childNode.getPath()));
                                            StartRunConnectionAction runAction = (StartRunConnectionAction) actionManager.getAction("AEM.Check.Action");
                                            if (runAction != null) {
                                                runAction.doRun(myProject, SimpleDataContext.EMPTY_CONTEXT, new ProgressHandlerImpl("Connection Change Listener Check").setForceAsynchronous(false));
                                            }
                                            break;
                                        case debug:
                                            slingServerTreeManager.getTree().setSelectionPath(new TreePath(childNode.getPath()));
                                            StartDebugConnectionAction debugAction = (StartDebugConnectionAction) actionManager.getAction("AEM.Start.Debug.Action");
                                            if (debugAction != null) {
                                                debugAction.doDebug(myProject, serverConnectionManager);
                                            }
                                            break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    );
}
 
Example 6
Source File: OneFileAtProjectTestCase.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void runStartupActivities() {
  final StartupManagerImpl startupManager = (StartupManagerImpl)StartupManager.getInstance(myProject);
  startupManager.runStartupActivities(UIAccess.get());
  startupManager.runPostStartupActivities(UIAccess.get());
}
 
Example 7
Source File: PlatformTestCase.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void runStartupActivities() {
  final StartupManagerImpl startupManager = (StartupManagerImpl)StartupManager.getInstance(myProject);
  startupManager.runStartupActivities(UIAccess.get());
  startupManager.runPostStartupActivities(UIAccess.get());
}
 
Example 8
Source File: InspectionProjectProfileManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void projectOpened() {
  StartupManager startupManager = StartupManager.getInstance(myProject);
  if (startupManager == null) {
    return; // upsource
  }
  startupManager.registerPostStartupActivity(new DumbAwareRunnable() {
    @Override
    public void run() {
      final Set<Profile> profiles = new HashSet<Profile>();
      profiles.add(getProjectProfileImpl());
      profiles.addAll(getProfiles());
      profiles.addAll(InspectionProfileManager.getInstance().getProfiles());
      final Application app = ApplicationManager.getApplication();
      Runnable initInspectionProfilesRunnable = new Runnable() {
        @Override
        public void run() {
          for (Profile profile : profiles) {
            initProfileWrapper(profile);
          }
          fireProfilesInitialized();
        }
      };
      if (app.isUnitTestMode() || app.isHeadlessEnvironment()) {
        initInspectionProfilesRunnable.run();
        UIUtil.dispatchAllInvocationEvents(); //do not restart daemon in the middle of the test
      }
      else {
        app.executeOnPooledThread(initInspectionProfilesRunnable);
      }
      myScopeListener = new NamedScopesHolder.ScopeListener() {
        @Override
        public void scopesChanged() {
          for (Profile profile : getProfiles()) {
            ((InspectionProfile)profile).scopesChanged();
          }
        }
      };
      myHolder.addScopeListener(myScopeListener, myProject);
      myLocalScopesHolder.addScopeListener(myScopeListener, myProject);
    }
  });
}
 
Example 9
Source File: ProjectManagerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@RequiredUIAccess
public boolean openProject(@Nonnull final Project project, @Nonnull UIAccess uiAccess) {
  if (isLight(project)) {
    ((ProjectImpl)project).setTemporarilyDisposed(false);
    boolean isInitialized = StartupManagerEx.getInstanceEx(project).startupActivityPassed();
    if (isInitialized) {
      addToOpened(project);
      // events already fired
      return true;
    }
  }

  for (Project p : getOpenProjects()) {
    if (ProjectUtil.isSameProject(project.getProjectFilePath(), p)) {
      GuiUtils.invokeLaterIfNeeded(() -> ProjectUtil.focusProjectWindow(p, false), ModalityState.NON_MODAL);
      return false;
    }
  }

  if (!addToOpened(project)) {
    return false;
  }

  Runnable process = () -> {
    TransactionGuard.getInstance().submitTransactionAndWait(() -> myApplication.getMessageBus().syncPublisher(TOPIC).projectOpened(project, uiAccess));

    final StartupManagerImpl startupManager = (StartupManagerImpl)StartupManager.getInstance(project);
    startupManager.runStartupActivities(uiAccess);
    startupManager.runPostStartupActivitiesFromExtensions(uiAccess);

    GuiUtils.invokeLaterIfNeeded(() -> {
      if (!project.isDisposed()) {
        startupManager.runPostStartupActivities(uiAccess);


        if (!myApplication.isHeadlessEnvironment() && !myApplication.isUnitTestMode()) {
          final TrackingPathMacroSubstitutor macroSubstitutor = ((ProjectEx)project).getStateStore().getStateStorageManager().getMacroSubstitutor();
          if (macroSubstitutor != null) {
            StorageUtil.notifyUnknownMacros(macroSubstitutor, project, null);
          }
        }

        if (myApplication.isActive()) {
          Window projectFrame = TargetAWT.to(WindowManager.getInstance().getWindow(project));
          if (projectFrame != null) {
            IdeFocusManager.getInstance(project).requestFocus(projectFrame, true);
          }
        }
      }
    }, ModalityState.NON_MODAL);
  };

  ProgressIndicator indicator = myProgressManager.getProgressIndicator();
  if (indicator != null) {
    indicator.setText("Preparing workspace...");
    process.run();
    return true;
  }

  boolean ok = myProgressManager.runProcessWithProgressSynchronously(process, "Preparing workspace...", canCancelProjectLoading(), project);
  if (!ok) {
    closeProject(project, false, false, true);
    notifyProjectOpenFailed();
    return false;
  }

  return true;
}
 
Example 10
Source File: FileBasedIndexProjectHandler.java    From consulo with Apache License 2.0 4 votes vote down vote up
public FileBasedIndexProjectHandler(@Nonnull Project project, FileBasedIndex index, FileBasedIndexScanRunnableCollector collector) {
  myIndex = index;
  myCollector = collector;

  if (ApplicationManager.getApplication().isInternal()) {
    project.getMessageBus().connect(this).subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() {

      @Override
      public void exitDumbMode() {
        LOG.info("Has changed files: " + (createChangedFilesIndexingTask(project) != null) + "; project=" + project);
      }
    });
  }

  if(project.isDefault()) {
    return;
  }

  StartupManager startupManager = StartupManager.getInstance(project);
  if (startupManager != null) {
    startupManager.registerPreStartupActivity(() -> {
      PushedFilePropertiesUpdater.getInstance(project).initializeProperties();

      // schedule dumb mode start after the read action we're currently in
      TransactionGuard.submitTransaction(project, () -> {
        if (FileBasedIndex.getInstance() instanceof FileBasedIndexImpl) {
          DumbService.getInstance(project).queueTask(new UnindexedFilesUpdater(project));
        }
      });

      myIndex.registerIndexableSet(this, project);
      project.getMessageBus().connect(this).subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
        private boolean removed;

        @Override
        public void projectClosing(@Nonnull Project eventProject) {
          if (eventProject == project && !removed) {
            removed = true;
            myIndex.removeIndexableSet(FileBasedIndexProjectHandler.this);
          }
        }
      });
    });
  }
}