com.intellij.openapi.application
Interface Application

All Superinterfaces:
ComponentManager, UserDataHolder

public interface Application
extends ComponentManager

Provides access to core application-wide functionality and methods for working with the IDEA thread model. The thread model defines two main types of actions which can access the PSI and other IDEA data structures: read actions (which do not modify the data) and write actions (which modify some data).

You can call methods requiring read access from the Swing event-dispatch thread without using runReadAction(java.lang.Runnable) method. If you need to invoke such methods from another thread you have to use runReadAction(java.lang.Runnable). Multiple read actions can run at the same time without locking each other.

Write actions can be called only from the Swing thread using runWriteAction(java.lang.Runnable) method. If there are read actions running at this moment runWriteAction is blocked until they are completed.


Method Summary
 void addApplicationListener(ApplicationListener listener)
          Adds an ApplicationListener.
 void assertIsDispatchThread()
          Asserts whether the method is being called from the event dispatch thread.
 void assertReadAccessAllowed()
          Asserts whether the read access is allowed.
 void assertWriteAccessAllowed()
          Asserts whether the write access is allowed.
 void exit()
          Exits the application, showing the exit confirmation prompt if it is enabled.
 ModalityState getCurrentModalityState()
          Returns the current modality state for the Swing dispatch thread.
 java.lang.Object getCurrentWriteAction(java.lang.Class actionClass)
          Returns the currently executing write action of the specified class.
 ModalityState getDefaultModalityState()
          Returns the current modality state for the current thread (which may be different from the Swing dispatch thread).
 long getIdleTime()
          Returns the time in milliseconds during which IDEA received no input events.
 ModalityState getModalityStateForComponent(java.awt.Component c)
          Returns the modality state for the dialog to which the specified component belongs.
 ModalityState getNoneModalityState()
          Returns the modality state representing the state when no modal dialogs are active.
 long getStartTime()
          Returns the time of IDEA start, in milliseconds since midnight, January 1, 1970 UTC.
 void invokeAndWait(java.lang.Runnable runnable, ModalityState modalityState)
          Causes runnable.run() to be executed synchronously on the AWT event dispatching thread, when IDEA is in the specified modality state.
 void invokeLater(java.lang.Runnable runnable)
          Causes runnable.run() to be executed asynchronously on the AWT event dispatching thread.
 void invokeLater(java.lang.Runnable runnable, ModalityState state)
          Causes runnable.run() to be executed asynchronously on the AWT event dispatching thread, when IDEA is in the specified modality state.
 boolean isDispatchThread()
          Checks if the current thread is the Swing dispatch thread.
 boolean isHeadlessEnvironment()
          Checks if IDEA is running as a command line applet or in unit test mode.
 boolean isReadAccessAllowed()
          Checks if the read access is currently allowed.
 boolean isUnitTestMode()
          Checks if IDEA is currently running unit tests.
 boolean isWriteAccessAllowed()
          Checks if the write access is currently allowed.
 void removeApplicationListener(ApplicationListener listener)
          Removes an ApplicationListener.
 boolean runProcessWithProgressSynchronously(java.lang.Runnable process, java.lang.String progressTitle, boolean canBeCanceled, Project project)
          Runs the specified operation in a background thread and shows a modal progress dialog in the main thread while the operation is executing.
<T> T
runReadAction(Computable<T> computation)
          Runs the specified computation in a read action.
 void runReadAction(java.lang.Runnable action)
          Runs the specified read action.
<T> T
runWriteAction(Computable<T> computation)
          Runs the specified computation in a write action.
 void runWriteAction(java.lang.Runnable action)
          Runs the specified write action.
 void saveAll()
          Saves all open documents and projects.
 void saveSettings()
          Saves all application settings.
 
Methods inherited from interface com.intellij.openapi.components.ComponentManager
getComponent, getComponent, getComponent, getComponentInterfaces, getComponents, getPicoContainer, hasComponent
 
Methods inherited from interface com.intellij.openapi.util.UserDataHolder
getUserData, putUserData
 

Method Detail

runReadAction

void runReadAction(java.lang.Runnable action)
Runs the specified read action. Can be called from any thread. The action is executed immediately if no write action is currently running, or blocked until the currently running write action completes.

Parameters:
action - the action to run.

runReadAction

<T> T runReadAction(Computable<T> computation)
Runs the specified computation in a read action. Can be called from any thread. The action is executed immediately if no write action is currently running, or blocked until the currently running write action completes.

Parameters:
computation - the computation to perform.
Returns:
the result returned by the computation.

runWriteAction

void runWriteAction(java.lang.Runnable action)
Runs the specified write action. Must be called from the Swing dispatch thread. The action is executed immediately if no read actions are currently running, or blocked until all read actions complete.

Parameters:
action - the action to run

runWriteAction

<T> T runWriteAction(Computable<T> computation)
Runs the specified computation in a write action. Must be called from the Swing dispatch thread. The action is executed immediately if no read actions are currently running, or blocked until all read actions complete.

Parameters:
computation - the computation to run
Returns:
the result returned by the computation.

getCurrentWriteAction

@Nullable
java.lang.Object getCurrentWriteAction(java.lang.Class actionClass)
Returns the currently executing write action of the specified class.

Parameters:
actionClass - the class of the write action to return.
Returns:
the write action instance, or null if no action of the specified class is currently executing.

assertReadAccessAllowed

void assertReadAccessAllowed()
Asserts whether the read access is allowed.


assertWriteAccessAllowed

void assertWriteAccessAllowed()
Asserts whether the write access is allowed.


assertIsDispatchThread

void assertIsDispatchThread()
Asserts whether the method is being called from the event dispatch thread.


addApplicationListener

void addApplicationListener(ApplicationListener listener)
Adds an ApplicationListener.

Parameters:
listener - the listener to add

removeApplicationListener

void removeApplicationListener(ApplicationListener listener)
Removes an ApplicationListener.

Parameters:
listener - the listener to remove

saveAll

void saveAll()
Saves all open documents and projects.


saveSettings

void saveSettings()
Saves all application settings.


exit

void exit()
Exits the application, showing the exit confirmation prompt if it is enabled.


isWriteAccessAllowed

boolean isWriteAccessAllowed()
Checks if the write access is currently allowed.

Returns:
true if the write access is currently allowed, false otherwise.
See Also:
assertWriteAccessAllowed(), runWriteAction(Runnable)

isReadAccessAllowed

boolean isReadAccessAllowed()
Checks if the read access is currently allowed.

Returns:
true if the read access is currently allowed, false otherwise.
See Also:
assertReadAccessAllowed(), runReadAction(Runnable)

isDispatchThread

boolean isDispatchThread()
Checks if the current thread is the Swing dispatch thread.

Returns:
true if the current thread is the Swing dispatch thread, false otherwise.

runProcessWithProgressSynchronously

boolean runProcessWithProgressSynchronously(java.lang.Runnable process,
                                            java.lang.String progressTitle,
                                            boolean canBeCanceled,
                                            Project project)
Runs the specified operation in a background thread and shows a modal progress dialog in the main thread while the operation is executing.

Parameters:
process - the operation to execute.
progressTitle - the title of the progress window.
canBeCanceled - whether "Cancel" button is shown on the progress window.
project - the project in the context of which the operation is executed.
Returns:
true if the operation completed successfully, false if it was cancelled.

invokeLater

void invokeLater(java.lang.Runnable runnable)
Causes runnable.run() to be executed asynchronously on the AWT event dispatching thread. This will happen after all pending AWT events have been processed.

Parameters:
runnable - the runnable to execute.

invokeLater

void invokeLater(java.lang.Runnable runnable,
                 @NotNull
                 ModalityState state)
Causes runnable.run() to be executed asynchronously on the AWT event dispatching thread, when IDEA is in the specified modality state.

Parameters:
runnable - the runnable to execute.
state - the state in which the runnable will be executed.

invokeAndWait

void invokeAndWait(java.lang.Runnable runnable,
                   @NotNull
                   ModalityState modalityState)
Causes runnable.run() to be executed synchronously on the AWT event dispatching thread, when IDEA is in the specified modality state. This call blocks until all pending AWT events have been processed and (then) runnable.run() returns.

Parameters:
runnable - the runnable to execute.
modalityState - the state in which the runnable will be executed.

getCurrentModalityState

ModalityState getCurrentModalityState()
Returns the current modality state for the Swing dispatch thread.

Returns:
the current modality state.

getModalityStateForComponent

ModalityState getModalityStateForComponent(java.awt.Component c)
Returns the modality state for the dialog to which the specified component belongs.

Parameters:
c - the component for which the modality state is requested.
Returns:
the modality state.

getDefaultModalityState

ModalityState getDefaultModalityState()
Returns the current modality state for the current thread (which may be different from the Swing dispatch thread).

Returns:
the modality state for the current thread.

getNoneModalityState

ModalityState getNoneModalityState()
Returns the modality state representing the state when no modal dialogs are active.

Returns:
the modality state for no modal dialogs.

getStartTime

long getStartTime()
Returns the time of IDEA start, in milliseconds since midnight, January 1, 1970 UTC.

Returns:
the IDEA start time.

getIdleTime

long getIdleTime()
Returns the time in milliseconds during which IDEA received no input events.

Returns:
the idle time of IDEA.

isUnitTestMode

boolean isUnitTestMode()
Checks if IDEA is currently running unit tests. No UI should be shown when unit tests are being executed.

Returns:
true if IDEA is running unit tests, false otherwise

isHeadlessEnvironment

boolean isHeadlessEnvironment()
Checks if IDEA is running as a command line applet or in unit test mode. No UI should be shown when IDEA is running in this mode.

Returns:
true if IDEA is running in UI-less mode, false otherwise