public void loadView(Event<? extends UIComponent> event) throws Exception {
   UISpaceNavigationNodeSelector uiNodeSelector = getChild(UISpaceNavigationNodeSelector.class);
   UITree uiTree = uiNodeSelector.getChild(UITree.class);
   uiTree
       .createEvent("ChangeNode", event.getExecutionPhase(), event.getRequestContext())
       .broadcast();
 }
 @Override
 public void execute(Event<UISpaceNavigationManagement> event) throws Exception {
   UISpaceNavigationManagement uiManagement = event.getSource();
   UISpaceNavigationNodeSelector uiNodeSelector =
       uiManagement.getChild(UISpaceNavigationNodeSelector.class);
   UIRightClickPopupMenu menu = uiNodeSelector.getChild(UIRightClickPopupMenu.class);
   menu.createEvent("AddNode", Phase.PROCESS, event.getRequestContext()).broadcast();
 }
    public void execute(Event<UISpaceNavigationManagement> event) throws Exception {
      //
      UISpaceNavigationManagement uiSNM = event.getSource();
      UISpaceNavigationNodeSelector uiNodeSelector =
          uiSNM.getChild(UISpaceNavigationNodeSelector.class);

      String nodeID = event.getRequestContext().getRequestParameter(OBJECTID);
      TreeNode node = uiNodeSelector.findNode(nodeID);
      uiNodeSelector.selectNode(node);
      event.getRequestContext().addUIComponentToUpdateByAjax(uiNodeSelector.getParent());
    }
    public void execute(Event<UISpaceNavigationManagement> event) throws Exception {
      PortalRequestContext prContext = Util.getPortalRequestContext();
      UISpaceNavigationManagement uiManagement = event.getSource();
      UISpaceNavigationNodeSelector uiNodeSelector =
          uiManagement.getChild(UISpaceNavigationNodeSelector.class);
      UserPortalConfigService portalConfigService =
          uiManagement.getApplicationComponent(UserPortalConfigService.class);

      UIPortalApplication uiPortalApp = (UIPortalApplication) prContext.getUIApplication();
      UIWorkingWorkspace uiWorkingWS =
          uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
      prContext.addUIComponentToUpdateByAjax(uiWorkingWS);
      prContext.ignoreAJAXUpdateOnPortlets(true);

      UserNavigation navigation = uiNodeSelector.getEdittedNavigation();
      SiteKey siteKey = navigation.getKey();
      String editedOwnerId = siteKey.getName();

      // Check existed
      UserPortalConfig userPortalConfig;
      if (SiteType.PORTAL.equals(siteKey.getType())) {
        userPortalConfig =
            portalConfigService.getUserPortalConfig(
                editedOwnerId, event.getRequestContext().getRemoteUser());
        if (userPortalConfig == null) {
          prContext
              .getUIApplication()
              .addMessage(
                  new ApplicationMessage(
                      "UIPortalForm.msg.notExistAnymore", null, ApplicationMessage.ERROR));
          return;
        }
      } else {
        userPortalConfig =
            portalConfigService.getUserPortalConfig(
                prContext.getPortalOwner(), event.getRequestContext().getRemoteUser());
      }

      UserNavigation persistNavigation = userPortalConfig.getUserPortal().getNavigation(siteKey);
      if (persistNavigation == null) {
        prContext
            .getUIApplication()
            .addMessage(
                new ApplicationMessage(
                    "UINavigationManagement.msg.NavigationNotExistAnymore",
                    null,
                    ApplicationMessage.ERROR));
        return;
      }

      uiNodeSelector.save();
    }
 @Override
 public void execute(Event<UIPopupWindow> event) throws Exception {
   UIPopupWindow uiPopup = event.getSource();
   UISpaceNavigationManagement uiSpaceNavManagement =
       uiPopup.getAncestorOfType(UISpaceNavigationManagement.class);
   UISpaceNavigationNodeSelector selector =
       uiSpaceNavManagement.getChild(UISpaceNavigationNodeSelector.class);
   UserNavigation contextNavigation = selector.getEdittedNavigation();
   uiPopup.setShow(false);
   uiSpaceNavManagement.setOwner(contextNavigation.getKey().getName());
   uiSpaceNavManagement.setOwnerType(contextNavigation.getKey().getTypeName());
   selector.setEdittedNavigation(contextNavigation);
   selector.initTreeData();
   event.getRequestContext().addUIComponentToUpdateByAjax(uiSpaceNavManagement);
 }
  public void reloadTreeData() throws Exception {
    UserPortal userPortal = Util.getUIPortalApplication().getUserPortalConfig().getUserPortal();
    SpaceService spaceService = getApplicationComponent(SpaceService.class);
    String spaceUrl = Utils.getSpaceUrlByContext();
    Space space = spaceService.getSpaceByUrl(spaceUrl);

    UserNavigation groupNav = SpaceUtils.getGroupNavigation(space.getGroupId());

    setOwner(groupNav.getKey().getName());
    setOwnerType(groupNav.getKey().getTypeName());

    UISpaceNavigationNodeSelector selector = getChild(UISpaceNavigationNodeSelector.class);
    selector.setEdittedNavigation(groupNav);
    selector.setUserPortal(userPortal);
    selector.initTreeData();
  }
  protected String getBreadcrumb() throws Exception {
    UISpaceNavigationNodeSelector selector = getChild(UISpaceNavigationNodeSelector.class);
    UITree uiTree = selector.getChild(UITree.class);
    TreeNode selectedNode = uiTree.getSelected();
    TreeNode rootNode = selector.getRootNode();
    List<TreeNode> nodes = new ArrayList<TreeNode>();

    while (selectedNode.getId() != rootNode.getId()) {
      nodes.add(selectedNode);
      selectedNode = selectedNode.getParent();
    }

    StringBuffer sb = new StringBuffer();
    sb.append("<li>");
    sb.append("<a href='javascript:void(0);'>").append(SPACE_LABEL).append("</a>");
    sb.append("</li>");

    for (int idx = nodes.size() - 1; idx >= 0; idx--) {
      String nodeLabel = nodes.get(idx).getResolvedLabel();
      nodeLabel = StringEscapeUtils.escapeHtml(nodeLabel);
      sb.append("<li>");
      sb.append("<span class='uiIconMiniArrowRight'>&nbsp;</span>");
      sb.append("</li>");
      if (idx == 0) {
        sb.append("<li class=\"active\">");
      } else {
        sb.append("<li>");
      }
      sb.append("<a href=\"javascript:void(0);\" onclick=\"")
          .append(this.event("SelectNode", nodes.get(idx).getId()))
          .append("\"");
      sb.append(">").append(nodeLabel).append("</a>");
      sb.append("</li>");
    }

    return sb.toString();
  }