static public class ChangePageNodeActionListener extends EventListener<UIPortal>
{
@Override
public void execute(Event<UIPortal> event) throws Exception
{
UIPortal showedUIPortal = event.getSource();
UIPortalApplication uiPortalApp = showedUIPortal.getAncestorOfType(UIPortalApplication.class);
//This code snippet is to make sure that Javascript/Skin is fully loaded at the first request
UIWorkingWorkspace uiWorkingWS = uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
PortalRequestContext pcontext = Util.getPortalRequestContext();
pcontext.setFullRender(true);
pcontext.addUIComponentToUpdateByAjax(uiWorkingWS);
PageNavigation currentNav = showedUIPortal.getSelectedNavigation();
String currentUri = showedUIPortal.getSelectedNode().getUri();
if(currentUri.startsWith("/"))
{
currentUri = currentUri.substring(1);
}
//This if branche is to make sure that the first time user logs in, showedUIPortal has selectedPaths
//Otherwise, there will be NPE on BreadcumbsPortlet
if(showedUIPortal.getSelectedPath() == null)
{
List<PageNode> currentSelectedPath = findPath(currentNav, currentUri.split("/"));
showedUIPortal.setSelectedPath(currentSelectedPath);
}
String targetedUri = ((PageNodeEvent<UIPortal>)event).getTargetNodeUri();
if(targetedUri.startsWith("/"))
{
targetedUri = targetedUri.substring(1);
}
PageNavigation targetedNav = getTargetedNav(uiPortalApp, targetedUri);
if(targetedNav == null)
{
return;
}
String formerNavType = currentNav.getOwnerType();
String formerNavId = currentNav.getOwnerId();
String newNavType = targetedNav.getOwnerType();
String newNavId = targetedNav.getOwnerId();
String[] targetPath = targetedUri.split("/");
PageNode targetPageNode = getTargetedNode(targetedNav, targetPath);
List<PageNode> targetedPathNodes = findPath(targetedNav, targetPath);
if(formerNavType.equals(newNavType) && formerNavId.equals(newNavId))
{
//Case 1: Both navigation type and id are not changed, but current page node is changed
if(!currentUri.equals(targetedUri))
{
showedUIPortal.setSelectedNode(targetPageNode);
showedUIPortal.setSelectedPath(targetedPathNodes);
}
}
else
{
// Case 2: Either navigation type or id has been changed
// First, we try to find a cached UIPortal
uiWorkingWS.setRenderedChild(UIPortalApplication.UI_VIEWING_WS_ID);
uiPortalApp.setModeState(UIPortalApplication.NORMAL_MODE);
showedUIPortal = uiPortalApp.getCachedUIPortal(newNavType, newNavId);
if (showedUIPortal != null)
{
showedUIPortal.setSelectedNode(targetPageNode);
showedUIPortal.setSelectedPath(targetedPathNodes);
uiPortalApp.setShowedUIPortal(showedUIPortal);
//Temporary solution to fix edit inline error while switching between navigations
DataStorage storageService = uiPortalApp.getApplicationComponent(DataStorage.class);
PortalConfig associatedPortalConfig = storageService.getPortalConfig(newNavType, newNavId);
UserPortalConfig userPortalConfig = uiPortalApp.getUserPortalConfig();
//Update layout-related data on UserPortalConfig
userPortalConfig.setPortal(associatedPortalConfig);
//Update selected navigation on UserPortalConfig, that is mandatory as at the moment the PortalConfig
//does not hold any navigation data.
userPortalConfig.updateSelectedNavigation(newNavType, newNavId);
}
else
{
showedUIPortal = buildUIPortal(targetedNav, uiPortalApp, uiPortalApp.getUserPortalConfig());
if(showedUIPortal == null)
{
return;
}
showedUIPortal.setSelectedNode(targetPageNode);
showedUIPortal.setSelectedPath(targetedPathNodes);
uiPortalApp.setShowedUIPortal(showedUIPortal);
uiPortalApp.putCachedUIPortal(showedUIPortal);
}
}
showedUIPortal.refreshUIPage();
}