// Create a selection listener for the ODOMSelectionManager which
// updates the PolicyController whenever the device selection
// changes. The PolicyController only updates if it detects a
// different device.
final ODOMElementSelectionListener selectionListener =
new ODOMElementSelectionListener() {
public void selectionChanged(
ODOMElementSelectionEvent event) {
// This is a single-select context. Note that this
// retrieved element comes from the hierarchy
// document and not from a device document.
if (!event.getSelection().isEmpty()) {
ODOMElement selectedElement = (ODOMElement)
event.getSelection().getFirstElement();
String deviceName =
selectedElement.getAttributeValue(
DeviceRepositorySchemaConstants.
DEVICE_NAME_ATTRIBUTE);
controller.setDeviceName(deviceName);
}
}
};
selectionListenerList.add(selectionListener);
context.getODOMSelectionManager().addSelectionListener(selectionListener,
DEVICE_FILTER);
if (selectedDeviceName != null) {
controller.setDeviceName(selectedDeviceName);
}
}
// Adds a dispose listener to the built category composite. This
// listener cleans up by removing the selection listeners added to
// the selection manager (above) for each PolicyController, and
// disposes of each PolicyController.
categoryComposite.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
// The selection listeners inform the policy controllers
// of changes. Logically, it is safest to remove the listeners
// before dealing with the policy controller cleanup.
Iterator it = selectionListenerList.iterator();
while (selectionListenerList.size() > 0) {
ODOMElementSelectionListener listener =
(ODOMElementSelectionListener)
selectionListenerList.remove(0);
context.getODOMSelectionManager().
removeSelectionListener(listener,