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:

Listeners can be registered programmatically or declaratively:

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: