# Class PartSelectionListener

java.lang.Object
org.eclipse.ui.internal.PartSelectionListener

All Implemented Interfaces:
  `EventListener, INullSelectionListener, ISelectionListener`

public class PartSelectionListener extends Object implements ISelectionListener, INullSelectionListener
An intermediate selection listener that filters selection change events based on one or more predicates and forwards it to the functional selection listener. Instances of this class can be obtained via the `SelectionListenerFactory` class.

## Constructor Summary

Constructors
Constructor
Description
`PartSelectionListener(IWorkbenchPart part, ISelectionListener callbackListener, Predicate<SelectionListenerFactory.ISelectionModel> predicate)`
Constructs the intermediate selection listener to filter selections before they are passed on the the callback listener.

## Method Summary

Modifier and Type
Method
Description
`PartSelectionListener`
`addPredicate(Predicate<SelectionListenerFactory.ISelectionModel> predicate)`
And-chains this predicate to the already existing predicate.
`void`
`selectionChanged(IWorkbenchPart part, ISelection selection)`
Notifies this listener that the selection has changed.

### Methods inherited from class Object

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

## Constructor Details

### PartSelectionListener

public PartSelectionListener(IWorkbenchPart part, ISelectionListener callbackListener, Predicate<SelectionListenerFactory.ISelectionModel> predicate)
Constructs the intermediate selection listener to filter selections before they are passed on the the callback listener.

Parameters:
  `part` - the part which may not be null.
  `callbackListener` - the callback listener which may not be null.
  `predicate` - the predicate which may not be null.

## Method Details

### selectionChanged

public void selectionChanged(IWorkbenchPart part, ISelection selection)
Description copied from interface: `ISelectionListener`
Notifies this listener that the selection has changed.

Note: it is important that this method returns as quickly as possible to avoid UI freezes. For example, do not update the UI if the UI is not visible. See the `SelectionListenerFactory` for listeners that are build for this purpose.

This method is called when the selection changes to a `non-null` value, but not when the selection changes to `null`. If there is a requirement to be notified in the latter scenario, implement `INullSelectionListener`. The event will be posted through this method.

Specified by:
  `selectionChanged` in interface `ISelectionListener`
Parameters:
  `part` - the workbench part containing the selection
  `selection` - the current selection. This may be `null` if `INullSelectionListener` is implemented.
See Also:
  - `SelectionListenerFactory.createVisibleListener(IWorkbenchPart, ISelectionListener)`
  - `SelectionListenerFactory.createVisibleSelfMutedListener(IWorkbenchPart, ISelectionListener)`

### addPredicate

public PartSelectionListener addPredicate(Predicate<SelectionListenerFactory.ISelectionModel> predicate)
And-chains this predicate to the already existing predicate. Nothing happens if the passed predicate is null.

Parameters:
  `predicate` - the non-null predicate to and-chain to the existing predicate
Returns:
  this