Java Code Examples for com.intellij.openapi.application.ApplicationManager#getApplication()
The following examples show how to use
com.intellij.openapi.application.ApplicationManager#getApplication() .
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 Project: consulo File: AbstractTreeBuilder.java License: Apache License 2.0 | 6 votes |
protected void runBackgroundLoading(@Nonnull final Runnable runnable) { if (isDisposed()) return; final Application app = ApplicationManager.getApplication(); if (app != null) { app.runReadAction(new TreeRunnable("AbstractTreeBuilder.runBackgroundLoading") { @Override public void perform() { runnable.run(); } }); } else { runnable.run(); } }
Example 2
Source Project: IntelliJ-Key-Promoter-X File: KPXStartupNotification.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void runActivity(@NotNull Project project) { if (ApplicationManager.getApplication().isUnitTestMode()) return; final Application application = ApplicationManager.getApplication(); final KeyPromoterSettings settings = ServiceManager.getService(KeyPromoterSettings.class); final String installedVersion = settings.getInstalledVersion(); final IdeaPluginDescriptor plugin = PluginManagerCore.getPlugin(PluginId.getId("Key Promoter X")); if (installedVersion != null && plugin != null) { final int compare = VersionComparatorUtil.compare(installedVersion, plugin.getVersion()); // if (true) { // TODO: Don't forget to remove that! For proofreading. if (compare < 0) { application.invokeLater(() -> KPXStartupDialog.showStartupDialog(project)); settings.setInstalledVersion(plugin.getVersion()); } } }
Example 3
Source Project: consulo File: ProgressIndicatorUtils.java License: Apache License 2.0 | 5 votes |
/** * Ensure the current EDT activity finishes in case it requires many write actions, with each being delayed a bit * by background thread read action (until its first checkCanceled call). Shouldn't be called from under read action. */ public static void yieldToPendingWriteActions() { Application application = ApplicationManager.getApplication(); if (application.isReadAccessAllowed()) { throw new IllegalStateException("Mustn't be called from within read action"); } if (application.isDispatchThread()) { throw new IllegalStateException("Mustn't be called from EDT"); } Semaphore semaphore = new Semaphore(1); application.invokeLater(semaphore::up, ModalityState.any()); awaitWithCheckCanceled(semaphore, ProgressIndicatorProvider.getGlobalProgressIndicator()); }
Example 4
Source Project: consulo File: DeprecatedVirtualFileSystem.java License: Apache License 2.0 | 5 votes |
protected void startEventPropagation() { Application application = ApplicationManager.getApplication(); if (application == null) { return; } application.getMessageBus().connect().subscribe( VirtualFileManager.VFS_CHANGES, new BulkVirtualFileListenerAdapter(myEventDispatcher.getMulticaster(), this)); }
Example 5
Source Project: consulo File: Messages.java License: Apache License 2.0 | 5 votes |
@TestOnly public static TestInputDialog setTestInputDialog(TestInputDialog newValue) { Application application = ApplicationManager.getApplication(); if (application != null) { LOG.assertTrue(application.isUnitTestMode(), "This method is available for tests only"); } TestInputDialog oldValue = ourTestInputImplementation; ourTestInputImplementation = newValue; return oldValue; }
Example 6
Source Project: consulo File: CommonShortcuts.java License: Apache License 2.0 | 5 votes |
@Nonnull private static CustomShortcutSet shortcutsById(String actionId) { Application application = ApplicationManager.getApplication(); KeymapManager keymapManager = application == null ? null : application.getComponent(KeymapManager.class); if (keymapManager == null) { return new CustomShortcutSet(Shortcut.EMPTY_ARRAY); } return new CustomShortcutSet(keymapManager.getActiveKeymap().getShortcuts(actionId)); }
Example 7
Source Project: consulo File: PlatformUltraLiteTestFixture.java License: Apache License 2.0 | 5 votes |
public void setUp() { final Application application = ApplicationManager.getApplication(); if (application == null) { myAppDisposable = Disposable.newDisposable(); ApplicationManager.setApplication(new MockApplication(myAppDisposable), myAppDisposable); } }
Example 8
Source Project: consulo File: Responses.java License: Apache License 2.0 | 5 votes |
public static void addServer(HttpResponse response) { if (SERVER_HEADER_VALUE == null) { Application app = ApplicationManager.getApplication(); if (app != null && !app.isDisposed()) { SERVER_HEADER_VALUE = ApplicationNamesInfo.getInstance().getFullProductName(); } } if (SERVER_HEADER_VALUE != null) { response.headers().set("Server", SERVER_HEADER_VALUE); } }
Example 9
Source Project: consulo File: ModuleCompilerUtil.java License: Apache License 2.0 | 5 votes |
public static void sortModules(final Project project, final List<Module> modules) { final Application application = ApplicationManager.getApplication(); Runnable sort = new Runnable() { public void run() { Comparator<Module> comparator = ModuleManager.getInstance(project).moduleDependencyComparator(); Collections.sort(modules, comparator); } }; if (application.isDispatchThread()) { sort.run(); } else { application.runReadAction(sort); } }
Example 10
Source Project: consulo File: HttpConfigurable.java License: Apache License 2.0 | 5 votes |
private static void runAboveAll(@Nonnull final Runnable runnable) { ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator(); if (progressIndicator != null && progressIndicator.isModal()) { WaitForProgressToShow.runOrInvokeAndWaitAboveProgress(runnable); } else { Application app = ApplicationManager.getApplication(); app.invokeAndWait(runnable, ModalityState.any()); } }
Example 11
Source Project: consulo File: NonProjectFileWritingAccessProvider.java License: Apache License 2.0 | 4 votes |
private static Application getApp() { return ApplicationManager.getApplication(); }
Example 12
Source Project: consulo File: NativeFileWatcherImpl.java License: Apache License 2.0 | 4 votes |
/** * Subclasses should override this method if they want to use custom logic to disable their file watcher. */ protected boolean isDisabled() { if (Boolean.getBoolean(PROPERTY_WATCHER_DISABLED)) return true; Application app = ApplicationManager.getApplication(); return app.isCommandLine() || app.isUnitTestMode(); }
Example 13
Source Project: consulo File: PendingEventDispatcher.java License: Apache License 2.0 | 4 votes |
private void assertDispatchThread() { Application application = ApplicationManager.getApplication(); if (myAssertDispatchThread && !application.isUnitTestMode()) { application.assertIsDispatchThread(); } }
Example 14
Source Project: consulo File: ChooseLibrariesDialogBase.java License: Apache License 2.0 | 4 votes |
protected RootDescriptor(final Project project) { super(project, null, ApplicationManager.getApplication()); }
Example 15
Source Project: EclipseCodeFormatter File: Classloaders.java License: Apache License 2.0 | 4 votes |
private static boolean isUnitTest() { return ApplicationManager.getApplication() == null || ApplicationManager.getApplication().isUnitTestMode(); }
Example 16
Source Project: consulo File: PlatformLiteFixture.java License: Apache License 2.0 | 4 votes |
public static MockApplicationEx getApplication() { return (MockApplicationEx)ApplicationManager.getApplication(); }
Example 17
Source Project: consulo File: WebApplication.java License: Apache License 2.0 | 4 votes |
@Nullable static WebApplication getInstance() { return (WebApplication)ApplicationManager.getApplication(); }
Example 18
Source Project: consulo File: ShowFeatureUsageStatisticsDialog.java License: Apache License 2.0 | 4 votes |
protected JComponent createCenterPanel() { Splitter splitter = new Splitter(true); splitter.setShowDividerControls(true); ProductivityFeaturesRegistry registry = ProductivityFeaturesRegistry.getInstance(); ArrayList<FeatureDescriptor> features = new ArrayList<FeatureDescriptor>(); for (String id : registry.getFeatureIds()) { features.add(registry.getFeatureDescriptor(id)); } final TableView table = new TableView<FeatureDescriptor>(new ListTableModel<FeatureDescriptor>(COLUMNS, features, 0)); new TableViewSpeedSearch<FeatureDescriptor>(table) { @Override protected String getItemText(@Nonnull FeatureDescriptor element) { return element.getDisplayName(); } }; JPanel controlsPanel = new JPanel(new VerticalFlowLayout()); Application app = ApplicationManager.getApplication(); long uptime = System.currentTimeMillis() - app.getStartTime(); long idleTime = app.getIdleTime(); final String uptimeS = FeatureStatisticsBundle.message("feature.statistics.application.uptime", ApplicationNamesInfo.getInstance().getFullProductName(), DateFormatUtil.formatDuration(uptime)); final String idleTimeS = FeatureStatisticsBundle.message("feature.statistics.application.idle.time", DateFormatUtil.formatDuration(idleTime)); String labelText = uptimeS + ", " + idleTimeS; CompletionStatistics stats = ((FeatureUsageTrackerImpl)FeatureUsageTracker.getInstance()).getCompletionStatistics(); if (stats.dayCount > 0 && stats.sparedCharacters > 0) { String total = formatCharacterCount(stats.sparedCharacters, true); String perDay = formatCharacterCount(stats.sparedCharacters / stats.dayCount, false); labelText += "<br>Code completion has saved you from typing at least " + total + " since " + DateFormatUtil.formatDate(stats.startDate) + " (~" + perDay + " per working day)"; } CumulativeStatistics fstats = ((FeatureUsageTrackerImpl)FeatureUsageTracker.getInstance()).getFixesStats(); if (fstats.dayCount > 0 && fstats.invocations > 0) { labelText += "<br>Quick fixes have saved you from " + fstats.invocations + " possible bugs since " + DateFormatUtil.formatDate(fstats.startDate) + " (~" + fstats.invocations / fstats.dayCount + " per working day)"; } controlsPanel.add(new JLabel("<html><body>" + labelText + "</body></html>"), BorderLayout.NORTH); JPanel topPanel = new JPanel(new BorderLayout()); topPanel.add(controlsPanel, BorderLayout.NORTH); topPanel.add(ScrollPaneFactory.createScrollPane(table), BorderLayout.CENTER); splitter.setFirstComponent(topPanel); final JEditorPane browser = new JEditorPane(UIUtil.HTML_MIME, ""); browser.setEditable(false); splitter.setSecondComponent(ScrollPaneFactory.createScrollPane(browser)); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { Collection selection = table.getSelection(); try { if (selection.isEmpty()) { browser.read(new StringReader(""), null); } else { FeatureDescriptor feature = (FeatureDescriptor)selection.iterator().next(); TipUIUtil.openTipInBrowser(feature.getTipFileName(), browser, feature.getProvider()); } } catch (IOException ex) { LOG.info(ex); } } }); return splitter; }
Example 19
Source Project: consulo File: AbstractVcsHelperImpl.java License: Apache License 2.0 | 4 votes |
@Override public void run(@Nonnull final ProgressIndicator indicator) { final AsynchConsumer<List<CommittedChangeList>> appender = myDlg.getAppender(); final BufferedListConsumer<CommittedChangeList> bufferedListConsumer = new BufferedListConsumer<>(10, appender, -1); final Application application = ApplicationManager.getApplication(); try { myProvider.loadCommittedChanges(mySettings, myLocation, 0, new AsynchConsumer<CommittedChangeList>() { @Override public void consume(CommittedChangeList committedChangeList) { myRevisionsReturned = true; bufferedListConsumer.consumeOne(committedChangeList); if (myCanceled) { indicator.cancel(); } } @Override public void finished() { bufferedListConsumer.flush(); appender.finished(); if (! myRevisionsReturned) { application.invokeLater(new Runnable() { @Override public void run() { myDlg.close(-1); } }, ModalityState.stateForComponent(myDlg.getWindow())); } } }); } catch (VcsException e) { myExceptions.add(e); application.invokeLater(new Runnable() { @Override public void run() { myDlg.close(-1); } }, ModalityState.stateForComponent(myDlg.getWindow())); } }
Example 20
Source Project: CppTools File: CppSupportSettings.java License: Apache License 2.0 | 4 votes |
public static CppSupportSettings getInstance() { final Application application = ApplicationManager.getApplication(); if (application.isUnitTestMode()) return instance; return application.getComponent(CppSupportSettings.class); }