Search in sources :

Example 1 with UIBreadcrumb

use of org.alfresco.web.ui.common.component.UIBreadcrumb in project acs-community-packaging by Alfresco.

the class NavigationBean method processToolbarLocation.

/**
 * Process the selected toolbar location. Setup the breadcrumb with initial value and
 * setup the current node ID. This method can also perform the navigatin setup if requested.
 *
 * @param location      Toolbar location constant
 * @param navigate      True to perform navigation, false otherwise
 */
@SuppressWarnings("serial")
public void processToolbarLocation(String location, boolean navigate) {
    this.toolbarLocation = location;
    FacesContext context = FacesContext.getCurrentInstance();
    if (LOCATION_COMPANY.equals(location)) {
        List<IBreadcrumbHandler> elements = new ArrayList<IBreadcrumbHandler>(1);
        Node companyHome = getCompanyHomeNode();
        elements.add(new NavigationBreadcrumbHandler(companyHome.getNodeRef(), companyHome.getName()));
        setLocation(elements);
        setCurrentNodeId(companyHome.getId());
        if (s_logger.isDebugEnabled())
            s_logger.debug("Created breadcrumb for companyhome: " + elements);
        // inform registered beans that the current area has changed
        UIContextService.getInstance(FacesContext.getCurrentInstance()).areaChanged();
        // we need to force a navigation to refresh the browse screen breadcrumb
        if (navigate) {
            context.getApplication().getNavigationHandler().handleNavigation(context, null, OUTCOME_BROWSE);
        }
    } else if (LOCATION_HOME.equals(location)) {
        List<IBreadcrumbHandler> elements = new ArrayList<IBreadcrumbHandler>(1);
        String homeSpaceId = Application.getCurrentUser(context).getHomeSpaceId();
        NodeRef homeSpaceRef = new NodeRef(Repository.getStoreRef(), homeSpaceId);
        if (this.clientConfig.getBreadcrumbMode().equals(ClientConfigElement.BREADCRUMB_LOCATION)) {
            Repository.setupBreadcrumbLocation(context, this, elements, homeSpaceRef);
            if (s_logger.isDebugEnabled())
                s_logger.debug("Created breadcrumb location for userhome: " + elements);
        } else {
            String homeSpaceName = Repository.getNameForNode(this.getNodeService(), homeSpaceRef);
            elements.add(new NavigationBreadcrumbHandler(homeSpaceRef, homeSpaceName));
            if (s_logger.isDebugEnabled())
                s_logger.debug("Created breadcrumb path for userhome: " + elements);
        }
        setLocation(elements);
        setCurrentNodeId(homeSpaceRef.getId());
        // inform registered beans that the current area has changed
        UIContextService.getInstance(FacesContext.getCurrentInstance()).areaChanged();
        // we need to force a navigation to refresh the browse screen breadcrumb
        if (navigate) {
            context.getApplication().getNavigationHandler().handleNavigation(context, null, OUTCOME_BROWSE);
        }
    } else if (LOCATION_GUEST.equals(location)) {
        List<IBreadcrumbHandler> elements = new ArrayList<IBreadcrumbHandler>(1);
        Node guestHome = getGuestHomeNode();
        if (this.clientConfig.getBreadcrumbMode().equals(ClientConfigElement.BREADCRUMB_LOCATION)) {
            Repository.setupBreadcrumbLocation(context, this, elements, guestHome.getNodeRef());
            if (s_logger.isDebugEnabled())
                s_logger.debug("Created breadcrumb location for guesthome: " + elements);
        } else {
            elements.add(new NavigationBreadcrumbHandler(guestHome.getNodeRef(), guestHome.getName()));
            if (s_logger.isDebugEnabled())
                s_logger.debug("Created breadcrumb path for guesthome: " + elements);
        }
        setLocation(elements);
        setCurrentNodeId(guestHome.getId());
        // inform registered beans that the current area has changed
        UIContextService.getInstance(FacesContext.getCurrentInstance()).areaChanged();
        // we need to force a navigation to refresh the browse screen breadcrumb
        if (navigate) {
            context.getApplication().getNavigationHandler().handleNavigation(context, null, OUTCOME_BROWSE);
        }
    } else if (LOCATION_MYALFRESCO.equals(location)) {
        // make sure we set a current node ID as some screens expect this
        if (getCurrentNodeId() == null) {
            String homeSpaceId = Application.getCurrentUser(context).getHomeSpaceId();
            NodeRef homeSpaceRef = new NodeRef(Repository.getStoreRef(), homeSpaceId);
            setCurrentNodeId(homeSpaceRef.getId());
        }
        // create a breadcrumb handler for this special case location (not a node)
        List<IBreadcrumbHandler> elements = new ArrayList<IBreadcrumbHandler>(1);
        elements.add(new IBreadcrumbHandler() {

            @SuppressWarnings("unchecked")
            public String navigationOutcome(UIBreadcrumb breadcrumb) {
                setLocation((List) breadcrumb.getValue());
                return OUTCOME_MYALFRESCO;
            }

            public String toString() {
                return Application.getMessage(FacesContext.getCurrentInstance(), MSG_MYALFRESCO);
            }
        });
        if (s_logger.isDebugEnabled())
            s_logger.debug("Created breadcrumb for myalfresco: " + elements);
        setLocation(elements);
        // inform registered beans that the current area has changed
        UIContextService.getInstance(FacesContext.getCurrentInstance()).areaChanged();
        // we need to force a navigation to refresh the browse screen breadcrumb
        if (navigate) {
            context.getApplication().getNavigationHandler().handleNavigation(context, null, OUTCOME_MYALFRESCO);
        }
    } else {
        // handle outcomes to any other custom location
        context.getApplication().getNavigationHandler().handleNavigation(context, null, location);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) IBreadcrumbHandler(org.alfresco.web.ui.common.component.IBreadcrumbHandler) Node(org.alfresco.web.bean.repository.Node) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) UIModeList(org.alfresco.web.ui.common.component.UIModeList) UIBreadcrumb(org.alfresco.web.ui.common.component.UIBreadcrumb)

Example 2 with UIBreadcrumb

use of org.alfresco.web.ui.common.component.UIBreadcrumb in project acs-community-packaging by Alfresco.

the class BreadcrumbRenderer method encodeBegin.

/**
 * @see javax.faces.render.Renderer#encodeBegin(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
 */
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
    // always check for this flag - as per the spec
    if (component.isRendered() == true) {
        Writer out = context.getResponseWriter();
        UIBreadcrumb breadcrumb = (UIBreadcrumb) component;
        // get the List of IBreadcrumbHandler elements from the component
        List<IBreadcrumbHandler> elements = (List) breadcrumb.getValue();
        boolean first = true;
        for (int index = 0; index < elements.size(); index++) {
            IBreadcrumbHandler element = elements.get(index);
            // handle not optionally hiding the root part
            if (index != 0 || breadcrumb.getShowRoot() == true) {
                out.write(renderBreadcrumb(context, breadcrumb, element.toString(), index, first));
                first = false;
            }
        }
    }
}
Also used : IBreadcrumbHandler(org.alfresco.web.ui.common.component.IBreadcrumbHandler) List(java.util.List) UIBreadcrumb(org.alfresco.web.ui.common.component.UIBreadcrumb) Writer(java.io.Writer)

Aggregations

List (java.util.List)2 IBreadcrumbHandler (org.alfresco.web.ui.common.component.IBreadcrumbHandler)2 UIBreadcrumb (org.alfresco.web.ui.common.component.UIBreadcrumb)2 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 FacesContext (javax.faces.context.FacesContext)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 Node (org.alfresco.web.bean.repository.Node)1 UIModeList (org.alfresco.web.ui.common.component.UIModeList)1