+ class LoadNodeListener extends DisposableListener<IElement> {
+
+ final Resource element;
+ public IElement lastLoaded;
+
+ public LoadNodeListener(ListenerSupport support, Resource element) {
+ super(support);
+ this.element = element;
+ }
+
+ @Override
+ public String toString() {
+ return "Node load listener for " + element;
+ }
+
+ public void applyFirst(IElement loaded) {
+
+ Object data = loaded.getHint(ElementHints.KEY_OBJECT);
+
+ if (addedElementMap.containsKey(data)) {
+ // This element was just loaded, in
+ // which case its hints need to
+ // uploaded to the real mapped
+ // element immediately.
+ IElement mappedElement = getMappedElement(data);
+ if (DebugPolicy.DEBUG_NODE_LISTENER)
+ System.out.println("LOADED ADDED ELEMENT, currently mapped element: " + mappedElement);
+ if (mappedElement != null && (mappedElement instanceof Element)) {
+ if (DebugPolicy.DEBUG_NODE_LISTENER) {
+ System.out.println(" mapped hints: " + mappedElement.getHints());
+ System.out.println(" loaded hints: " + loaded.getHints());
+ }
+ updateMappedElement((Element) mappedElement, loaded);
+ }
+ }
+
+ }
+
+ @Override
+ public void execute(IElement loaded) {
+
+ // Invoked when the element has been loaded.
+ if (DebugPolicy.DEBUG_NODE_LISTENER)
+ System.out.println("NODE LoadListener for " + loaded);
+
+ if (loaded == null) {
+ disposeListener();
+ return;
+ }
+
+
+ boolean first = lastLoaded == null;
+
+ lastLoaded = loaded;
+
+ /*
+ * The first invocation is postponed
+ */
+ if(first) {
+ applyFirst(loaded);
+ return;
+ }
+
+ Object data = loaded.getHint(ElementHints.KEY_OBJECT);
+
+ // Logic for disposing listener
+ if (!previousContent.nodeSet.contains(data)) {
+ if (DebugPolicy.DEBUG_NODE_LISTENER)
+ System.out.println("NODE LoadListener, node not in current content: " + data + ". Disposing.");
+ disposeListener();
+ return;
+ }
+
+ // This element was already loaded.
+ // Just schedule an update some time
+ // in the future.
+ if (DebugPolicy.DEBUG_NODE_LISTENER)
+ System.out.println("PREVIOUSLY LOADED NODE UPDATED, scheduling update into the future");
+ offerGraphUpdate( nodeUpdater(element, loaded) );
+
+ }
+
+ }
+
+ void processNodes(AsyncReadGraph graph) throws DatabaseException {