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

The following examples show how to use com.intellij.openapi.project.Project#getMessageBus() . 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: FlutterSaveActionsManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private FlutterSaveActionsManager(@NotNull Project project) {
  this.myProject = project;

  final MessageBus bus = project.getMessageBus();
  final MessageBusConnection connection = bus.connect();
  connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerListener() {
    @Override
    public void beforeDocumentSaving(@NotNull Document document) {
      // Don't try and format read only docs.
      if (!document.isWritable()) {
        return;
      }

      handleBeforeDocumentSaving(document);
    }
  });
}
 
Example 2
Source File: FlutterViewMessages.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void sendDebugActive(@NotNull Project project,
                                   @NotNull FlutterApp app,
                                   @NotNull VmService vmService) {
  final MessageBus bus = project.getMessageBus();
  final FlutterDebugNotifier publisher = bus.syncPublisher(FLUTTER_DEBUG_TOPIC);

  assert (app.getFlutterDebugProcess() != null);

  final VMServiceManager vmServiceManager = new VMServiceManager(app, vmService);
  Disposer.register(app.getFlutterDebugProcess().getVmServiceWrapper(), vmServiceManager);
  app.setVmServices(vmService, vmServiceManager);
  publisher.debugActive(new FlutterDebugEvent(app, vmService));

  // TODO(pq): consider pushing into perf service.
  app.getFlutterLog().listenToVm(vmService);
}
 
Example 3
Source File: FlutterSaveActionsManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private FlutterSaveActionsManager(@NotNull Project project) {
  this.myProject = project;

  final MessageBus bus = project.getMessageBus();
  final MessageBusConnection connection = bus.connect();
  connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerListener() {
    @Override
    public void beforeDocumentSaving(@NotNull Document document) {
      // Don't try and format read only docs.
      if (!document.isWritable()) {
        return;
      }

      handleBeforeDocumentSaving(document);
    }
  });
}
 
Example 4
Source File: PsiModificationTrackerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Inject
public PsiModificationTrackerImpl(@Nonnull Application application, @Nonnull Project project) {
  MessageBus bus = project.getMessageBus();
  myPublisher = bus.syncPublisher(TOPIC);
  bus.connect().subscribe(DumbService.DUMB_MODE, new DumbService.DumbModeListener() {
    private void doIncCounter() {
      application.runWriteAction(() -> incCounter());
    }

    @Override
    public void enteredDumbMode() {
      doIncCounter();
    }

    @Override
    public void exitDumbMode() {
      doIncCounter();
    }
  });
}
 
Example 5
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 6
Source File: FindManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Inject
public FindManagerImpl(Project project, FindSettings findSettings, UsageViewManager anotherManager) {
  myProject = project;
  myBus = project.getMessageBus();
  findSettings.initModelBySetings(myFindInProjectModel);

  myFindInFileModel.setCaseSensitive(findSettings.isLocalCaseSensitive());
  myFindInFileModel.setWholeWordsOnly(findSettings.isLocalWholeWordsOnly());
  myFindInFileModel.setRegularExpressions(findSettings.isLocalRegularExpressions());

  myFindUsagesManager = new FindUsagesManager(myProject, anotherManager);
  myFindInProjectModel.setMultipleFiles(true);

  NotificationsConfigurationImpl.remove("FindInPath");
  Disposer.register(project, new Disposable() {
    @Override
    public void dispose() {
      if (myHelper != null) {
        Disposer.dispose(myHelper);
      }
    }
  });
}
 
Example 7
Source File: MetadataAction.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Project project = getEventProject(e);
    MessageBus messageBus = project.getMessageBus();

    ExecuteQueryEvent executeQueryEvent = messageBus.syncPublisher(ExecuteQueryEvent.EXECUTE_QUERY_TOPIC);

    ExecuteQueryPayload payload = new ExecuteQueryPayload(getQuery(data));

    DataSourcesComponent dataSourcesComponent = project.getComponent(DataSourcesComponent.class);
    Optional<DataSourceApi> dataSource = dataSourcesComponent.getDataSourceContainer().findDataSource(dataSourceUuid);

    dataSource.ifPresent(dataSourceApi -> executeQueryEvent.executeQuery(dataSourceApi, payload));

    ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(CONSOLE_TOOL_WINDOW);
    if (!toolWindow.isVisible()) {
        ConsoleToolWindow.ensureOpen(project);
        messageBus.syncPublisher(OpenTabEvent.OPEN_TAB_TOPIC).openTab(Tabs.TABLE);
    }
}
 
Example 8
Source File: VcsRootScanner.java    From consulo with Apache License 2.0 5 votes vote down vote up
private VcsRootScanner(@Nonnull Project project, @Nonnull List<VcsRootChecker> checkers) {
  myRootProblemNotifier = VcsRootProblemNotifier.getInstance(project);
  myCheckers = checkers;

  final MessageBus messageBus = project.getMessageBus();
  messageBus.connect().subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, this);
  messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, this);
  messageBus.connect().subscribe(ProjectTopics.PROJECT_ROOTS, this);

  myAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, project);
}
 
Example 9
Source File: ExternalSystemAutoImporter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void letTheMagicBegin(@Nonnull Project project) {
  List<MyEntry> autoImportAware = ContainerUtilRt.newArrayList();
  Collection<ExternalSystemManager<?, ?, ?, ?, ?>> managers = ExternalSystemApiUtil.getAllManagers();
  for (ExternalSystemManager<?, ?, ?, ?, ?> manager : managers) {
    AbstractExternalSystemSettings<?, ?, ?> systemSettings = manager.getSettingsProvider().fun(project);
    ExternalSystemAutoImportAware defaultImportAware = createDefault(systemSettings);
    final ExternalSystemAutoImportAware aware;
    if (manager instanceof ExternalSystemAutoImportAware) {
      aware = combine(defaultImportAware, (ExternalSystemAutoImportAware)manager);
    }
    else {
      aware = defaultImportAware;
    }
    autoImportAware.add(new MyEntry(manager.getSystemId(), systemSettings, aware));
  }

  MyEntry[] entries = autoImportAware.toArray(new MyEntry[autoImportAware.size()]);
  ExternalSystemAutoImporter autoImporter = new ExternalSystemAutoImporter(
    project,
    ServiceManager.getService(ProjectDataManager.class),
    entries
  );
  final MessageBus messageBus = project.getMessageBus();
  messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, autoImporter);

  EditorFactory.getInstance().getEventMulticaster().addDocumentListener(autoImporter, project);
}
 
Example 10
Source File: IdeHelper.java    From yiistorm with MIT License 5 votes vote down vote up
public static void showNotification(String message, NotificationType type, @Nullable Project project) {
    final MessageBus messageBus = project == null ? ApplicationManager.getApplication().getMessageBus() : project.getMessageBus();
    final Notification notification = new Notification("Notification", "Notification", message, type, null);

    ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
        @Override
        public void run() {
            messageBus.syncPublisher(Notifications.TOPIC).notify(notification);
        }
    });
}
 
Example 11
Source File: PsiDocumentManagerBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected PsiDocumentManagerBase(@Nonnull Project project, DocumentCommitProcessor documentCommitProcessor) {
  myProject = project;
  myPsiManager = PsiManager.getInstance(project);
  myDocumentCommitProcessor = documentCommitProcessor;
  mySynchronizer = new PsiToDocumentSynchronizer(this, project.getMessageBus());
  myPsiManager.addPsiTreeChangeListener(mySynchronizer);

  project.getMessageBus().connect(this).subscribe(PsiDocumentTransactionListener.TOPIC, (document, file) -> {
    myUncommittedDocuments.remove(document);
  });
}
 
Example 12
Source File: NodeDeleteAction.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Project project = getEventProject(e);
    if (project != null) {
        QueryExecutionService service = new QueryExecutionService(project.getMessageBus());

        service.executeQuery(dataSource, new ExecuteQueryPayload("MATCH (n) WHERE ID(n) = $id DETACH DELETE n",
                ImmutableMap.of("id", Long.parseLong(node.getId())),
                null));
    }
}
 
Example 13
Source File: ParametersPanel.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
public void initialize(GraphConsoleView graphConsoleView, Project project) {
    this.graphConsoleView = graphConsoleView;
    this.messageBus = project.getMessageBus();
    this.service = ServiceManager.getService(project, ParametersService.class);
    this.project = project;
    setupEditor(project);
    FileEditor selectedEditor = FileEditorManager.getInstance(project).getSelectedEditor();
    if (selectedEditor != null && selectedEditor.getFile() != null &&
            FileTypeExtensionUtil.isCypherFileTypeExtension(selectedEditor.getFile().getExtension())) {
        setupFileSpecificEditor(project, selectedEditor.getFile());
    }
}
 
Example 14
Source File: ExecuteQueryAction.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
protected void actionPerformed(AnActionEvent e, Project project, Editor editor, String query, Map<String, Object> parameters) {
    VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
    MessageBus messageBus = project.getMessageBus();
    DataSourcesComponent dataSourcesComponent = project.getComponent(DataSourcesComponent.class);

    query = decorateQuery(query);

    ExecuteQueryPayload executeQueryPayload = new ExecuteQueryPayload(query, parameters, editor);
    ConsoleToolWindow.ensureOpen(project);

    if (nonNull(virtualFile)) {
        String fileName = virtualFile.getName();
        if (fileName.startsWith(GraphConstants.BOUND_DATA_SOURCE_PREFIX)) {
            Optional<? extends DataSourceApi> boundDataSource = dataSourcesComponent.getDataSourceContainer()
                    .findDataSource(NameUtil.extractDataSourceUUID(fileName));
            if (boundDataSource.isPresent()) {
                executeQuery(messageBus, boundDataSource.get(), executeQueryPayload);
                return;
            }
        }
    }

    ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(
            "Choose Data Source",
            new ChooseDataSourceActionGroup(messageBus, dataSourcesComponent, executeQueryPayload),
            e.getDataContext(),
            JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
            false
    );

    Component eventComponent = e.getInputEvent().getComponent();
    if (eventComponent instanceof ActionButtonComponent) {
        popup.showUnderneathOf(eventComponent);
    } else {
        popup.showInBestPositionFor(e.getDataContext());
    }
}
 
Example 15
Source File: CleanCanvasAction.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
    Project project = getEventProject(e);

    if (project == null) {
        return;
    }

    MessageBus messageBus = project.getMessageBus();
    messageBus.syncPublisher(CleanCanvasEvent.CLEAN_CANVAS_TOPIC).cleanCanvas();
}
 
Example 16
Source File: CommittedChangesCache.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Inject
public CommittedChangesCache(final Project project, final ProjectLevelVcsManager vcsManager) {
  myProject = project;
  myVcsManager = vcsManager;
  myBus = project.getMessageBus();

  if (!project.isDefault()) {
    myConnection = myBus.connect();
    final VcsListener vcsListener = new VcsListener() {
      @Override
      public void directoryMappingChanged() {
        myLocationCache.reset();
        refreshAllCachesAsync(false, true);
        refreshIncomingChangesAsync();
        myTaskQueue.run(new Runnable() {
          @Override
          public void run() {
            final List<ChangesCacheFile> files = myCachesHolder.getAllCaches();
            for (ChangesCacheFile file : files) {
              final RepositoryLocation location = file.getLocation();
              fireChangesLoaded(location, Collections.<CommittedChangeList>emptyList());
            }
            fireIncomingReloaded();
          }
        });
      }
    };
    myLocationCache = new RepositoryLocationCache(project);
    myCachesHolder = new CachesHolder(project, myLocationCache);
    myTaskQueue = new ProgressManagerQueue(project, VcsBundle.message("committed.changes.refresh.progress"));
    ((ProjectLevelVcsManagerImpl)vcsManager).addInitializationRequest(VcsInitObject.COMMITTED_CHANGES_CACHE, new Runnable() {
      @Override
      public void run() {
        ApplicationManager.getApplication().runReadAction(new Runnable() {
          @Override
          public void run() {
            if (myProject.isDisposed()) return;
            myTaskQueue.start();
            myConnection.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, vcsListener);
            myConnection.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED_IN_PLUGIN, vcsListener);
          }
        });
      }
    });
    Disposer.register(project, () -> {
      cancelRefreshTimer();
      myConnection.disconnect();
    });
    myExternallyLoadedChangeLists = ContainerUtil.newConcurrentMap();
  }
}
 
Example 17
Source File: CommittedChangesViewManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
public CommittedChangesViewManager(final Project project, final ProjectLevelVcsManager vcsManager) {
  myProject = project;
  myVcsManager = vcsManager;
  myBus = project.getMessageBus();
}
 
Example 18
Source File: HighlightingSettingsPerFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Inject
public HighlightingSettingsPerFile(@Nonnull Project project) {
  myBus = project.getMessageBus();
}
 
Example 19
Source File: ShelveChangesManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Inject
public ShelveChangesManager(Project project, ProjectPathMacroManager projectPathMacroManager, SchemesManagerFactory schemesManagerFactory, ChangeListManager changeListManager) {
  myProject = project;
  myPathMacroSubstitutor = projectPathMacroManager.createTrackingSubstitutor();
  myBus = project.getMessageBus();
  mySchemeManager = schemesManagerFactory.createSchemesManager(SHELVE_MANAGER_DIR_PATH, new BaseSchemeProcessor<ShelvedChangeList>() {
    @Nullable
    @Override
    public ShelvedChangeList readScheme(@Nonnull Element element, boolean duringLoad) throws InvalidDataException {
      return readOneShelvedChangeList(element);
    }

    @Nonnull
    @Override
    public Parent writeScheme(@Nonnull ShelvedChangeList scheme) throws WriteExternalException {
      Element child = new Element(ELEMENT_CHANGELIST);
      scheme.writeExternal(child);
      myPathMacroSubstitutor.collapsePaths(child);
      return child;
    }
  }, RoamingType.PER_USER);

  myCleaningFuture = JobScheduler.getScheduler().scheduleWithFixedDelay(new Runnable() {
    @Override
    public void run() {
      cleanSystemUnshelvedOlderOneWeek();
    }
  }, 1, 1, TimeUnit.DAYS);
  Disposer.register(project, new Disposable() {
    @Override
    public void dispose() {
      stopCleanScheduler();
    }
  });

  File shelfDirectory = mySchemeManager.getRootDirectory();
  myFileProcessor = new CompoundShelfFileProcessor(shelfDirectory);
  // do not try to ignore when new project created,
  // because it may lead to predefined ignore creation conflict; see ConvertExcludedToIgnoredTest etc
  if (shelfDirectory.exists()) {
    changeListManager.addDirectoryToIgnoreImplicitly(shelfDirectory.getAbsolutePath());
  }
}
 
Example 20
Source File: ModuleVcsDetector.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Inject
public ModuleVcsDetector(final Project project, final ProjectLevelVcsManager vcsManager) {
  myProject = project;
  myMessageBus = project.getMessageBus();
  myVcsManager = (ProjectLevelVcsManagerImpl) vcsManager;
}