@SuppressWarnings({"unchecked", "fallthrough", "rawtypes"}) // NodeMutationHandler is generic
private void setupBehaviour(ContentElement element, Level oldLevel) {
AgentAdapter e = (AgentAdapter) element;
ElementHandlerRegistry elementRegistry = registries.getElementHandlerRegistry();
// bootstrapping for new nodes
if (oldLevel == null) {
NodeMutationHandler mutationHandler = elementRegistry.getMutationHandler(e);
if (mutationHandler instanceof PermanentMutationHandler) {
e.setNodeMutationHandler(mutationHandler);
}
oldLevel = Level.SHELVED;
}
boolean notRendered = (e.getRenderer() == AgentAdapter.noRenderer);
assert notRendered == (oldLevel == Level.SHELVED) : "oldLevel: " + oldLevel + " notRendered:"+notRendered;
boolean shouldBeRendered = level.isAtLeast(Level.RENDERED);
// Increasing level
switch (oldLevel) {
case SHELVED: // -> RENDERED
if (level.isAtMost(Level.SHELVED)) break;
setupRenderer(e, true);
if (e == fullRawSubstrate.getDocumentElement()) {
initRootElementRendering(true);
}
e.setNodeMutationHandler(elementRegistry.getMutationHandler(e));
case RENDERED: // -> INTERACTIVE
if (level.isAtMost(Level.RENDERED)) break;
e.setNodeEventHandler(elementRegistry.getEventHandler(e));
maybeSetupGwtWidget(e);
case INTERACTIVE: // -> EDITING
if (level.isAtMost(Level.INTERACTIVE)) break;
maybeSetupModeNotifications(e);
break;
}
// Decreasing level
switch (oldLevel) {
case EDITING: // -> INTERACTIVE
if (level.isAtLeast(Level.EDITING)) break;
// No need to cleanup mode notifications
case INTERACTIVE: // -> RENDERED
if (level.isAtLeast(Level.INTERACTIVE)) break;
maybeSetupGwtWidget(e);
e.setNodeEventHandler(null);
case RENDERED: // -> SHELVED
if (level.isAtLeast(Level.RENDERED)) break;
NodeMutationHandler mutationHandler = elementRegistry.getMutationHandler(e);
if (mutationHandler instanceof PermanentMutationHandler) {
e.setNodeMutationHandler(mutationHandler);
} else {
e.setNodeMutationHandler(null);
}