Interface IResourceChangeListener
- All Superinterfaces:
EventListener
- All Known Implementing Classes:
CloseResourceAction
,CloseUnrelatedProjectsAction
,FileDocumentProvider.FileSynchronizer
,OpenResourceAction
,SyncInfoCompareInput
,WorkbenchContentProvider
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Clients may implement this interface.
There are two ways to register a listener:- One could direct registration with IWorkspace#addResourceChangeListener(IResourceChangeListener, int) users should note that they are responsible to remove the listener if no longer needed to prevent memory leaks.
- One could register an OSGi Service making and it will automatically be
picked up leveraging the Whiteboard
Pattern. Services registered with an
PROPERTY_EVENT_MASK
property can be used to receive a sub-set of the events, by registering the value with theIWorkspace.addResourceChangeListener(IResourceChangeListener, int)
method. This allows (for example)IResourceChangeEvent.POST_CHANGE
events to be received by settingevent.mask=1
in the service registration.
For example the services can be registered with Declarative Services, which
allows a bundle to not require that the Workspace bundle be started prior to
accessing the resources, as until the IWorkspace is available the bundle will
not need any callbacks. This will also save potential NPEs when the
IWorkspace
shuts down, because the OSGi runtime will handle the
deregistration of services automatically:
<?xml version="1.0" encoding="UTF-8"?> <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.4.0" immediate="true" name="ExampleResourceListener"> <implementation class="org.example.ExampleResourceListener"/> <service> <provide interface="org.eclipse.core.resources.IResourceChangeListener"/> </service> <!-- 1 == IResourceChangeEvent.POST_CHANGE --> <property name="event.mask" type="Integer" value="1"/> </scr:component>
If you choose to register it with the core OSGi API (e.g. in an activator) you can use the following pattern:
bundleContext.registerService(IResourceChangeListener.class, myListener, IResourceChangeListener.getMaskProperties( IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_CLOSE | IResourceChangeEvent.PRE_DELETE));
- See Also:
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Dictionary<String,
?> getMaskProperties
(int mask) Creates aDictionary
suitable to be used when registering aIResourceChangeListener
as an OSGi service.void
Notifies this listener that some resource changes are happening, or have already happened.
-
Field Details
-
PROPERTY_EVENT_MASK
- Since:
- 3.17
- See Also:
-
-
Method Details
-
resourceChanged
Notifies this listener that some resource changes are happening, or have already happened.The supplied event gives details. This event object (and the resource delta within it) is valid only for the duration of the invocation of this method.
Note: This method is called by the platform; it is not intended to be called directly by clients.
Note that during resource change event notification, further changes to resources may be disallowed.
- Parameters:
event
- the resource change event- See Also:
-
getMaskProperties
Creates aDictionary
suitable to be used when registering aIResourceChangeListener
as an OSGi service.- Parameters:
mask
- seeIWorkspace.addResourceChangeListener(IResourceChangeListener, int)
- Returns:
- a new
Dictionary
representing the OSGi service properties for the given mask - Since:
- 3.17
-