use of org.eclipse.wst.json.core.document.IJSONNode in project webtools.sourceediting by eclipse.
the class JSONModelNotifierImpl method notifyDeferred.
/**
*/
private void notifyDeferred() {
if (this.fEvents == null)
return;
if (this.flushing)
return;
// force notification
this.flushing = true;
int count = this.fEvents.size();
if (!doingNewModel && fOptimizeDeferred) {
Map notifyEvents = new HashMap();
for (int i = 0; i < count; i++) {
NotifyEvent event = (NotifyEvent) this.fEvents.get(i);
if (event == null)
// error
continue;
event.index = i;
if (event.type == INodeNotifier.REMOVE) {
addToMap(event.oldValue, event, notifyEvents);
}
if (event.type == INodeNotifier.ADD) {
addToMap(event.newValue, event, notifyEvents);
}
}
Iterator it = notifyEvents.values().iterator();
while (it.hasNext()) {
NotifyEvent[] es = (NotifyEvent[]) it.next();
for (int i = 0; i < es.length - 1; i++) {
NotifyEvent event = es[i];
if (es[i].discarded)
continue;
NotifyEvent next = es[i + 1];
if (es[i].type == INodeNotifier.ADD && next.type == INodeNotifier.REMOVE) {
// Added then removed later, discard both
event.discarded = true;
next.discarded = true;
if (Debug.debugNotifyDeferred) {
event.reason = event.reason + ADDED_THEN_REMOVED + "(see " + next.index + // $NON-NLS-1$ //$NON-NLS-2$
")";
next.reason = next.reason + ADDED_THEN_REMOVED + "(see " + event.index + // $NON-NLS-1$ //$NON-NLS-2$
")";
}
}
}
}
for (int i = 0; i < count; i++) {
NotifyEvent event = (NotifyEvent) this.fEvents.get(i);
if (event == null)
// error
continue;
if (event.discarded)
continue;
if (event.notifier != null && fOptimizeDeferredAccordingToParentAdded) {
if (event.type == INodeNotifier.ADD) {
NotifyEvent[] es = (NotifyEvent[]) notifyEvents.get(event.notifier);
if (es != null)
for (int p = 0; p < es.length && es[p].index < event.index; p++) {
NotifyEvent prev = es[p];
if (prev.type == INodeNotifier.REMOVE && prev.oldValue == event.notifier) {
// parent is reparented, do not discard
if (Debug.debugNotifyDeferred) {
event.reason = event.reason + PARENT_IS_REPARENTED + "(see " + prev.index + // $NON-NLS-1$ //$NON-NLS-2$
")";
}
break;
} else if (prev.type == INodeNotifier.ADD && prev.newValue == event.notifier) {
// parent has been added, discard this
event.discarded = true;
if (Debug.debugNotifyDeferred) {
event.reason = event.reason + PARENT_IS_ADDED + "(see " + prev.index + // $NON-NLS-1$ //$NON-NLS-2$
")";
}
break;
}
}
}
}
if (event.discarded)
continue;
if (event.notifier != null && fOptimizeDeferredAccordingToParentRemoved) {
if (event.type == INodeNotifier.REMOVE) {
NotifyEvent[] es = (NotifyEvent[]) notifyEvents.get(event.notifier);
if (es != null)
for (int n = 0; n < es.length; n++) {
NotifyEvent next = es[n];
if (next.index > event.index && next.type == INodeNotifier.REMOVE) {
if (next.oldValue == event.notifier) {
// parent will be removed, discard this
event.discarded = true;
if (Debug.debugNotifyDeferred) {
event.reason = event.reason + PARENT_IS_REMOVED_TOO + "(see " + next.index + // $NON-NLS-1$ //$NON-NLS-2$
")";
}
break;
}
}
}
}
}
if (event.discarded)
continue;
}
}
for (int i = 0; i < count; i++) {
NotifyEvent event = (NotifyEvent) this.fEvents.get(i);
if (event == null)
// error
continue;
if (event.discarded)
continue;
notify(event.notifier, event.type, event.changedFeature, event.oldValue, event.newValue, event.pos);
}
if (Debug.debugNotifyDeferred) {
for (int l = 0; l < count; l++) {
NotifyEvent event = (NotifyEvent) this.fEvents.get(l);
Object o = null;
String t = null;
if (event.type == INodeNotifier.ADD) {
o = event.newValue;
// $NON-NLS-1$
t = " + ";
} else if (event.type == INodeNotifier.REMOVE) {
o = event.oldValue;
// $NON-NLS-1$
t = " - ";
}
if (o instanceof IJSONObject) {
String p = ((IJSONNode) event.notifier).getNodeName();
String c = ((IJSONNode) o).getNodeName();
// $NON-NLS-1$ //$NON-NLS-2$
String d = (event.discarded ? "! " : " ");
System.out.println(d + p + t + c);
}
}
}
this.flushing = false;
this.fEvents = null;
}
Aggregations