Package org.eclipse.ui.internal

# Class PageEventAction

java.lang.Object
org.eclipse.core.commands.common.EventManager
org.eclipse.jface.action.AbstractAction
org.eclipse.jface.action.Action
org.eclipse.ui.actions.PartEventAction
org.eclipse.ui.internal.PageEventAction

All Implemented Interfaces:
  `IAction`, `ActionFactory.IWorkbenchAction`, `IPageListener`, `IPartListener`

Direct Known Subclasses:
  `CloseAllSavedAction`, `NavigationHistoryAction`

public abstract class PageEventAction extends PartEventAction implements IPageListener, ActionFactory.IWorkbenchAction
The abstract superclass for actions that listen to page activation and open/close events. This implementation tracks the active page (see `getActivePage`) and provides a convenient place to monitor page lifecycle events that could affect the availability of the action.

Subclasses must implement the following `IAction` method:

- `run` - to do the action's work

Subclasses may extend any of the `IPartListener` methods if the action availablity needs to be recalculated:

- `partActivated`
- `partDeactivated`
- `partOpened`
- `partClosed`
- `partBroughtToTop`

Subclasses may extend any of the `IPageListener` methods if the action availability needs to be recalculated:

- `pageActivated`
- `pageClosed`
- `pageOpened`

This method implements the `IPartListener` and `IPageListener`interfaces, and automatically registers listeners so that it can keep its enablement state up to date. Ordinarily, the window's references to these listeners will be dropped automatically when the window closes. However, if the client needs to get rid of an action while the window is still open, the client must call `dispose` to give the action an opportunity to deregister its listeners and to perform any other cleanup.

## Field Summary

### Fields inherited from interface org.eclipse.jface.action.IAction

`AS_CHECK_BOX, AS_DROP_DOWN_MENU, AS_PUSH_BUTTON, AS_RADIO_BUTTON, AS_UNSPECIFIED, CHECKED, DESCRIPTION, ENABLED, HANDLED, IMAGE, RESULT, TEXT, TOOL_TIP_TEXT`

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`PageEventAction(String text, IWorkbenchWindow window)`
Creates a new action with the given text.

## Method Summary

Modifier and Type
Method
Description
`void`
`dispose()`
The `PageEventAction` implementation of this `ActionFactory.IWorkbenchAction` method deregisters the part and page listener adding by the constructor.
`final IWorkbenchPage`
`getActivePage()`
Returns the currently active page in the workbench window.
`final IWorkbenchWindow`
`getWorkbenchWindow()`
Returns the workbench window this action applies to.
`void`
`pageActivated(IWorkbenchPage page)`
The `PageEventAction` implementation of this `IPageListener` method records that the given page is active.
`void`
`pageClosed(IWorkbenchPage page)`
The `PageEventAction` implementation of this `IPageListener` method clears the active page if it just closed.
`void`
`pageOpened(IWorkbenchPage page)`
The `PageEventAction` implementation of this `IPageListener` method does nothing.

### Methods inherited from class org.eclipse.ui.actions.PartEventAction

`getActivePart, partActivated, partBroughtToTop, partClosed, partDeactivated, partOpened`

### Methods inherited from class org.eclipse.jface.action.Action

`convertAccelerator, convertAccelerator, findKeyCode, findKeyString, findModifier, findModifierString, getAccelerator, getActionDefinitionId, getDescription, getDisabledImageDescriptor, getHelpListener, getHoverImageDescriptor, getId, getImageDescriptor, getMenuCreator, getStyle, getText, getToolTipText, isChecked, isEnabled, isHandled, notifyResult, removeAcceleratorText, removeMnemonics, run, runWithEvent, setAccelerator, setActionDefinitionId, setChecked, setDescription, setDisabledImageDescriptor, setEnabled, setHelpListener, setHoverImageDescriptor, setId, setImageDescriptor, setMenuCreator, setText, setToolTipText`

### Methods inherited from class org.eclipse.jface.action.AbstractAction

`addPropertyChangeListener, firePropertyChange, firePropertyChange, removePropertyChangeListener`

### Methods inherited from class org.eclipse.core.commands.common.EventManager

`addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.eclipse.jface.action.IAction

`addPropertyChangeListener, getAccelerator, getActionDefinitionId, getDescription, getDisabledImageDescriptor, getHelpListener, getHoverImageDescriptor, getId, getImageDescriptor, getMenuCreator, getStyle, getText, getToolTipText, isChecked, isEnabled, isHandled, removePropertyChangeListener, run, runWithEvent, setAccelerator, setActionDefinitionId, setChecked, setDescription, setDisabledImageDescriptor, setEnabled, setHelpListener, setHoverImageDescriptor, setId, setImageDescriptor, setMenuCreator, setText, setToolTipText`

## Constructor Details

### PageEventAction

protected PageEventAction(String text, IWorkbenchWindow window)
Creates a new action with the given text. Register this action with the workbench window for page lifecycle events.

Parameters:
  `text` - the string used as the text for the action, or `null` if there is no text
  `window` - the workbench window this action is registered with

## Method Details

### getActivePage

public final IWorkbenchPage getActivePage()
Returns the currently active page in the workbench window.

Returns:
  currently active page in the workbench window, or `null` in none

### getWorkbenchWindow

public final IWorkbenchWindow getWorkbenchWindow()
Returns the workbench window this action applies to.

Returns:
  the workbench window, or `null` if this action has been disposed

### pageActivated

public void pageActivated(IWorkbenchPage page)
The `PageEventAction` implementation of this `IPageListener` method records that the given page is active. Subclasses may extend this method if action availability has to be recalculated.

Specified by:
  `pageActivated` in interface `IPageListener`
Parameters:
  `page` - the page that was activated
See Also:
  - `IWorkbenchWindow.setActivePage(org.eclipse.ui.IWorkbenchPage)`

### pageClosed

public void pageClosed(IWorkbenchPage page)
The `PageEventAction` implementation of this `IPageListener` method clears the active page if it just closed. Subclasses may extend this method if action availability has to be recalculated.

Specified by:
  `pageClosed` in interface `IPageListener`
Parameters:
  `page` - the page that was closed
See Also:
  - `IWorkbenchPage.close()`

### pageOpened

public void pageOpened(IWorkbenchPage page)
The `PageEventAction` implementation of this `IPageListener` method does nothing. Subclasses should extend this method if action availability has to be recalculated.

Specified by:
  `pageOpened` in interface `IPageListener`
Parameters:
  `page` - the page that was opened
See Also:
  - `IWorkbenchWindow.openPage(java.lang.String, org.eclipse.core.runtime.IAdaptable)`

### dispose

public void dispose()
The `PageEventAction` implementation of this `ActionFactory.IWorkbenchAction` method deregisters the part and page listener adding by the constructor. Subclasses should extend this method to do additional cleanup.

Specified by:
  `dispose` in interface `ActionFactory.IWorkbenchAction`
Since:
  3.0