return matched;
}
};
// this listener will listen for updates to the managed element
elementListener = new ODOMChangeListener() {
// javadoc inherited
public void changed(ODOMObservable node,
ODOMChangeEvent event) {
// three types of changes can occur.
// 1. The managed element could be deleted. We need to handle
// this by removing the listener from the element.
// 2. The managed element could be modified. If this occurs
// then we might need to add a standard element.
// 3. The managed element could be created. This will never
// happen as this listener will not be registered when the
// managed element does not exist.
if (event.getOldValue() == parent &&
event.getNewValue() == null &&
event.getSource() == element) {
// the managed element has been delelted
// unregister this listener with the element
// Note: we don't remove the parentListener from the
// parent element as this
element.removeChangeListener(elementListener);
} else if(event.getSource().getName().
equals(DeviceRepositorySchemaConstants.
STANDARD_ELEMENT_NAME) &&
event.getNewValue()==null) {
// Here we have the content of the standard element
// being removed. This can only happen here if an
// undo/redo is in progresss. In this case the
// standard element is no longer relevant and is
// about to be deleted itself.
element.removeChangeListener(elementListener);
} else {
// the managed element has been modified. See if it has
// a standard element
if (findStandardElement(element) == null) {
// this is the first time the element has changed so
// we need to add the standard element to the managed
// element
((ODOMElement) element.getParent()).
removeChangeListener(parentListener,
ChangeQualifier.HIERARCHY);
element.removeChangeListener(elementListener);
element.getChildren().add(
createStandardElement(originalElement));
element.addChangeListener(elementListener);
((ODOMElement) element.getParent()).
addChangeListener(parentListener,
ChangeQualifier.HIERARCHY);
}
}
}
};
// This will listen for the creation of the managed element.
parentListener = new ODOMChangeListener() {
// javadoc inherited
public void changed(ODOMObservable node,
ODOMChangeEvent event) {
// only interested if the element does not exist and the event
// indicates a node has been added