@Override
protected void onBeforeRender() {
Workspace workspace = workspaceModel.getObject();
BrixNode node;
try {
node = getModelObject();
}
catch (JcrException e) {
if (e.getCause() instanceof ItemNotFoundException) {
node = SitePlugin.get().getSiteRootNode(workspace.getId());
getModel().setObject(null);
selectNode(node);
setupDefaultEditor();
tree.invalidateAll();
} else {
throw (e);
}
}
String nodeWorkspaceName = node.getSession().getWorkspace().getName();
if (!nodeWorkspaceName.equals(workspace.getId())) {
// we have to either update node or workspace
if (oldWorkspaceId != null && workspace.getId().equals(oldWorkspaceId)) {
// the node changed, need to update the workspace
Workspace newWorkspace = node.getBrix().getWorkspaceManager().getWorkspace(
nodeWorkspaceName);
workspaceModel.setObject(newWorkspace);
} else {
// the workspace has changed, update the node
// 1 try to get node with same UUID, 2 try to get node with same
// path, 3 get root node
JcrSession newSession = node.getBrix().getCurrentSession(workspace.getId());
String uuid = node.getIdentifier();
BrixNode newNode = JcrUtil.getNodeByUUID(newSession, uuid);
if (newNode == null) {
String path = node.getPath();
if (newSession.getRootNode().hasNode(path.substring(1))) {
newNode = (BrixNode) newSession.getItem(path);
}