com.intellij.util.messages.MessageBus Java Examples

The following examples show how to use com.intellij.util.messages.MessageBus. 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: 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 #2
Source File: ConfigurationErrors.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void _do(@Nonnull final ConfigurationError error, @Nonnull final Project project,
                       @Nonnull final PairProcessor<ConfigurationErrors, ConfigurationError> fun) {
  if (!project.isInitialized()) {
    StartupManager.getInstance(project).runWhenProjectIsInitialized(new Runnable() {
       @Override
       public void run() {
         fun.process(project.getMessageBus().syncPublisher(TOPIC), error);
       }
     });

    return;
  }

  final MessageBus bus = project.getMessageBus();
  if (EventQueue.isDispatchThread()) fun.process(bus.syncPublisher(TOPIC), error);
  else {
    //noinspection SSBasedInspection
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        fun.process(bus.syncPublisher(TOPIC), error);
      }
    });
  }
}
 
Example #3
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 #4
Source File: IdeDocumentHistoryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void putLastOrMerge(@Nonnull PlaceInfo next, int limit, boolean isChanged) {
  LinkedList<PlaceInfo> list = isChanged ? myChangePlaces : myBackPlaces;
  MessageBus messageBus = myProject.getMessageBus();
  RecentPlacesListener listener = messageBus.syncPublisher(RecentPlacesListener.TOPIC);
  if (!list.isEmpty()) {
    PlaceInfo prev = list.getLast();
    if (isSame(prev, next)) {
      PlaceInfo removed = list.removeLast();
      listener.recentPlaceRemoved(removed, isChanged);
    }
  }

  list.add(next);
  listener.recentPlaceAdded(next, isChanged);
  if (list.size() > limit) {
    PlaceInfo first = list.removeFirst();
    listener.recentPlaceRemoved(first, isChanged);
  }
}
 
Example #5
Source File: Alarm.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void addRequest(@Nonnull final Runnable request, final int delay, boolean runWithActiveFrameOnly) {
  if (runWithActiveFrameOnly && !ApplicationManager.getApplication().isActive()) {
    final MessageBus bus = ApplicationManager.getApplication().getMessageBus();
    final MessageBusConnection connection = bus.connect(this);
    connection.subscribe(ApplicationActivationListener.TOPIC, new ApplicationActivationListener() {
      @Override
      public void applicationActivated(@Nonnull IdeFrame ideFrame) {
        connection.disconnect();
        addRequest(request, delay);
      }
    });
  }
  else {
    addRequest(request, delay);
  }
}
 
Example #6
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 #7
Source File: WakaTime.java    From jetbrains-wakatime with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void setupEventListeners() {
    ApplicationManager.getApplication().invokeLater(new Runnable(){
        public void run() {

            // save file
            MessageBus bus = ApplicationManager.getApplication().getMessageBus();
            connection = bus.connect();
            connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new CustomSaveListener());

            // edit document
            EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new CustomDocumentListener());

            // mouse press
            EditorFactory.getInstance().getEventMulticaster().addEditorMouseListener(new CustomEditorMouseListener());

            // scroll document
            EditorFactory.getInstance().getEventMulticaster().addVisibleAreaListener(new CustomVisibleAreaListener());
        }
    });
}
 
Example #8
Source File: IdeaMocksExtension.java    From GitToolBox with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeEach(ExtensionContext context) {
  IdeaMocksImpl ideaMocks = new IdeaMocksImpl();
  Project project = mock(Project.class);
  MessageBus messageBus = mock(MessageBus.class);
  when(project.getMessageBus()).thenReturn(messageBus);
  when(messageBus.syncPublisher(any(Topic.class))).thenAnswer(invocation -> {
    Topic topic = invocation.getArgument(0);
    Class<?> listenerClass = topic.getListenerClass();
    if (ideaMocks.hasMockListener(listenerClass)) {
      return ideaMocks.getMockListener(listenerClass);
    } else {
      return ideaMocks.mockListener(listenerClass);
    }
  });
  Store store = context.getStore(NS);
  ParameterHolder holder = ParameterHolder.getHolder(store);
  holder.register(Project.class, Suppliers.ofInstance(project));
  holder.register(MessageBus.class, Suppliers.ofInstance(messageBus));
  holder.register(IdeaMocks.class, Suppliers.ofInstance(ideaMocks));
}
 
Example #9
Source File: IdeaLightweightExtension.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
private void initializeApplication(Application application) {
    DefaultPicoContainer pico = new DefaultPicoContainer();
    when(application.getPicoContainer()).thenReturn(pico);

    MessageBus bus = new SingleThreadedMessageBus(null);
    when(application.getMessageBus()).thenReturn(bus);

    // Service setup.  See ServiceManager
    pico.registerComponent(service(PasswordSafe.class, new MockPasswordSafe()));
    pico.registerComponent(service(VcsContextFactory.class, new MockVcsContextFactory()));

    VirtualFileManager vfm = mock(VirtualFileManager.class);
    when(application.getComponent(VirtualFileManager.class)).thenReturn(vfm);

    AccessToken readToken = mock(AccessToken.class);
    when(application.acquireReadActionLock()).thenReturn(readToken);

    ApplicationInfo appInfo = mock(ApplicationInfo.class);
    when(appInfo.getApiVersion()).thenReturn("IC-182.1.1");
    registerApplicationService(ApplicationInfo.class, appInfo);
}
 
Example #10
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 #11
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 #12
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 #13
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 #14
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 #15
Source File: StateStorageManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
public StateStorageManagerImpl(@Nullable TrackingPathMacroSubstitutor pathMacroSubstitutor,
                               String rootTagName,
                               @Nullable Disposable parentDisposable,
                               @Nonnull Supplier<MessageBus> messageBusSupplier,
                               @Nonnull StateStorageFacade stateStorageFacade) {
  myMessageBusSupplier = messageBusSupplier;
  myRootTagName = rootTagName;
  myPathMacroSubstitutor = pathMacroSubstitutor;
  myStateStorageFacade = stateStorageFacade;
  if (parentDisposable != null) {
    Disposer.register(parentDisposable, this);
  }
}
 
Example #16
Source File: FilePropertyPusher.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @deprecated use {@link FilePropertyPusher#initExtra(Project, MessageBus)} instead
 */
//@ApiStatus.ScheduledForRemoval(inVersion = "2021.3")
@Deprecated
@SuppressWarnings("unused")
default void initExtra(@Nonnull Project project, @Nonnull MessageBus bus, @Nonnull Engine languageLevelUpdater) {
  initExtra(project, bus);
}
 
Example #17
Source File: ComponentStoreImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void reinitComponents(@Nonnull Set<String> componentNames, @Nonnull Collection<? extends StateStorage> changedStorages) {
  MessageBus messageBus = getMessageBus();
  messageBus.syncPublisher(BatchUpdateListener.TOPIC).onBatchUpdateStarted();
  try {
    for (String componentName : componentNames) {
      reinitComponent(componentName, changedStorages);
    }
  }
  finally {
    messageBus.syncPublisher(BatchUpdateListener.TOPIC).onBatchUpdateFinished();
  }
}
 
Example #18
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 #19
Source File: NoAccessDuringPsiEvents.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static boolean isInsideEventProcessing() {
  Application application = ApplicationManager.getApplication();
  if (!application.isWriteAccessAllowed()) return false;

  MessageBus bus = application.getMessageBus();
  return bus.hasUndeliveredEvents(VirtualFileManager.VFS_CHANGES) || bus.hasUndeliveredEvents(PsiModificationTracker.TOPIC);
}
 
Example #20
Source File: ExecuteAllAction.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) {
        Notifier.error("Query execution error", "No project present.");
        return;
    }
    MessageBus messageBus = project.getMessageBus();
    ParametersService parameterService = ServiceManager.getService(project, ParametersService.class);
    PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);

    StatementCollector statementCollector = new StatementCollector(messageBus, parameterService);

    // This should never happen
    if (psiFile == null) {
        Notifier.error("Internal error", "No PsiFile present.");
    }
    psiFile.acceptChildren(statementCollector);
    if (!statementCollector.hasErrors()) {
        ExecuteQueryPayload executeQueryPayload =
            new ExecuteQueryPayload(statementCollector.getQueries(), statementCollector.getParameters(), psiFile.getName());
        ConsoleToolWindow.ensureOpen(project);

        DataSourcesComponent dataSourcesComponent = project.getComponent(DataSourcesComponent.class);
        ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(
            "Choose Data Source",
            new ChooseDataSourceActionGroup(messageBus, dataSourcesComponent, executeQueryPayload),
            e.getDataContext(),
            JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
            false
        );
        popup.showInBestPositionFor(e.getDataContext());
    } else {
        Notifier.error("Query execution error", "File contains errors");
    }
}
 
Example #21
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 #22
Source File: ConfigProjectComponent.java    From editorconfig-jetbrains with MIT License 5 votes vote down vote up
public ConfigProjectComponent(Project project) {
    this.project = project;

    // Register project-level config managers
    MessageBus bus = project.getMessageBus();
    codeStyleManager = new CodeStyleManager(project);
    EditorSettingsManager editorSettingsManager = new EditorSettingsManager();
    EncodingManager encodingManager = new EncodingManager(project);
    LineEndingsManager lineEndingsManager = new LineEndingsManager(project);
    bus.connect().subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, codeStyleManager);
    bus.connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, encodingManager);
    bus.connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, editorSettingsManager);
    bus.connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC, lineEndingsManager);
}
 
Example #23
Source File: AbstractContextTest.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Before
public void setup() {
  container = ContextMocker.emptyContext();

  // mock IntelliJ dependencies
  mockStaticGetInstance(PropertiesComponent.class, null);

  // mock IntelliJ dependent calls to get current IDE and plugin version
  PowerMock.mockStaticPartial(
      IntellijVersionProvider.class, "getPluginVersion", "getBuildNumber");

  EasyMock.expect(IntellijVersionProvider.getPluginVersion()).andReturn("0.1.0");
  EasyMock.expect(IntellijVersionProvider.getBuildNumber()).andReturn("1");

  PowerMock.replay(IntellijVersionProvider.class);

  // mock application related requests
  MessageBusConnection messageBusConnection = EasyMock.createNiceMock(MessageBusConnection.class);
  EasyMock.replay(messageBusConnection);

  MessageBus messageBus = EasyMock.createNiceMock(MessageBus.class);
  EasyMock.expect(messageBus.connect()).andReturn(messageBusConnection);
  EasyMock.replay(messageBus);

  Application application = EasyMock.createNiceMock(Application.class);
  EasyMock.expect(application.getMessageBus()).andReturn(messageBus);
  EasyMock.replay(application);

  PowerMock.mockStaticPartial(ApplicationManager.class, "getApplication");
  EasyMock.expect(ApplicationManager.getApplication()).andReturn(application);
  PowerMock.replay(ApplicationManager.class);
}
 
Example #24
Source File: CSharpFilePropertyPusher.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
public void initExtra(@Nonnull Project project, @Nonnull MessageBus messageBus)
{
	project.getMessageBus().connect().subscribe(ModuleExtension.CHANGE_TOPIC, (oldExtension, newExtension) ->
	{
		if(oldExtension instanceof CSharpSimpleModuleExtension && newExtension instanceof CSharpSimpleModuleExtension)
		{
			if(((CSharpSimpleModuleExtension) oldExtension).getLanguageVersion() != ((CSharpSimpleModuleExtension) newExtension).getLanguageVersion())
			{
				addChanged(project, newExtension);
			}
		}

		if(oldExtension instanceof DotNetSimpleModuleExtension && newExtension instanceof DotNetSimpleModuleExtension)
		{
			if(!((DotNetSimpleModuleExtension) oldExtension).getVariables().equals(((DotNetSimpleModuleExtension) newExtension).getVariables()))
			{
				addChanged(project, newExtension);
			}
		}
	});
}
 
Example #25
Source File: CopyQueryOutputAction.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = getEventProject(e);

    if (project == null) {
        return;
    }

    MessageBus messageBus = project.getMessageBus();
    messageBus.syncPublisher(CopyQueryOutputEvent.COPY_QUERY_OUTPUT_TOPIC).copyQueryOutputToClipboard();
}
 
Example #26
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 #27
Source File: AbstractRefactoringPanel.java    From IntelliJDeodorant with MIT License 5 votes vote down vote up
/**
 * Adds a listener that invalidates found refactoring opportunities if the structure of PSI is changed.
 */
private void registerPsiModificationListener() {
    if (!isPreviewUsage) {
        MessageBus projectMessageBus = scope.getProject().getMessageBus();
        projectMessageBus.connect().subscribe(PsiModificationTracker.TOPIC, () -> ApplicationManager.getApplication().invokeLater(this::showRefreshingProposal));
    }
}
 
Example #28
Source File: ChooseDataSourceAction.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
public ChooseDataSourceAction(DataSourceApi dataSource, DataSourcesComponent component,
                              MessageBus messageBus, ExecuteQueryPayload executeQueryPayload) {
    super(dataSource.getName(), null, dataSource.getDescription().getIcon());
    this.dataSource = dataSource;
    this.messageBus = messageBus;
    this.executeQueryPayload = executeQueryPayload;
}
 
Example #29
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 #30
Source File: ChooseDataSourceActionGroup.java    From jetbrains-plugin-graph-database-support with Apache License 2.0 5 votes vote down vote up
public ChooseDataSourceActionGroup(MessageBus messageBus,
                                   DataSourcesComponent component,
                                   ExecuteQueryPayload executeQueryPayload) {
    this.messageBus = messageBus;
    this.component = component;
    this.executeQueryPayload = executeQueryPayload;
}