# Listening To Targlet Container Events

Author: Eike Stepper

When the state of a `targlet container` changes registered `listeners` are sent one of the following `events`:

- `IDChangedEvent`
- `TargletsChangedEvent`
- `ProfileUpdateSucceededEvent`
- `ProfileUpdateFailedEvent`
- `WorkspaceUpdateFinishedEvent`

Listeners can be registered programmatically or declaratively:

- The `listener registry` provides methods to add or remove listeners.
- The `org.eclipse.oomph.targlets.core.targletContainerListeners` extension point accepts declarative listener contributions.

The following example shows a listener that prints information about all received events to the console:

| TargletContainerEventLogger.java |  |  |  |

`class TargletContainerEventLogger implements ITargletContainerListener
{
public TargletContainerEventLogger()
{
}
public void handleTargletContainerEvent(TargletContainerEvent event, IProgressMonitor monitor) throws Exception
{
ITargletContainer container = event.getSource();
if (event instanceof IDChangedEvent)
{
System.out.println("IDChangedEvent: " + container);
System.out.println(" oldID: " + ((IDChangedEvent)event).getOldID());
}
else if (event instanceof TargletsChangedEvent)
{
System.out.println("TargletsChangedEvent: " + container);
}
else if (event instanceof ProfileUpdateSucceededEvent)
{
System.out.println("ProfileUpdateSucceededEvent: " + container);
System.out.println(" metadataRepositories: " + ((ProfileUpdateSucceededEvent)event).getMetadataRepositories());
System.out.println(" workspaceIUInfos: " + ((ProfileUpdateSucceededEvent)event).getWorkspaceIUInfos());
System.out.println(" provisioningPlan: " + ((ProfileUpdateSucceededEvent)event).getProvisioningPlan());
System.out.println(" profile: " + ((ProfileUpdateSucceededEvent)event).getProfile());
}
else if (event instanceof ProfileUpdateFailedEvent)
{
System.out.println("ProfileUpdateFailedEvent: " + container);
System.out.println(" updateProblem: " + ((ProfileUpdateFailedEvent)event).getUpdateProblem());
}
else if (event instanceof WorkspaceUpdateFinishedEvent)
{
System.out.println("WorkspaceUpdateFinishedEvent: " + container);
System.out.println(" importResults: " + ((WorkspaceUpdateFinishedEvent)event).getImportResults());
}
else
{
System.out.println(event);
}
}
}`

.

See Also:

- Understanding Targlet Containers

Copyright (c) 2014 Eike Stepper (Loehne, Germany) and others.
All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v2.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v20.html