Search in sources :

Example 1 with IRepoBreadcrumbHandler

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

the class BrowseBean method updateUILocation.

/**
 * Refresh the UI after a Space selection change. Adds the selected space to the breadcrumb
 * location path and also updates the list components in the UI.
 *
 * @param ref     NodeRef of the selected space
 */
public void updateUILocation(NodeRef ref) {
    // get the current breadcrumb location and append a new handler to it
    // our handler know the ID of the selected node and the display label for it
    List<IBreadcrumbHandler> location = this.navigator.getLocation();
    if (location.size() != 0) {
        // attempt to find the ID - if it's already in the breadcrumb then we
        // navigate directly to that node - rather than add duplication to the breadcrumb path
        boolean foundNode = false;
        for (int i = 0; i < location.size(); i++) {
            IBreadcrumbHandler element = location.get(i);
            if (element instanceof IRepoBreadcrumbHandler) {
                NodeRef nodeRef = ((IRepoBreadcrumbHandler) element).getNodeRef();
                if (ref.equals(nodeRef) == true) {
                    // TODO: we should be able to do this - but the UIBreadcrumb component modifies
                    // it's own internal value when clicked - then uses that from then on!
                    // the other ops are using the same List object and modding it directly.
                    // List<IBreadcrumbHandler> newLocation = new ArrayList<IBreadcrumbHandler>(i+1);
                    // newLocation.addAll(location.subList(0, i + 1));
                    // this.navigator.setLocation(newLocation);
                    // TODO: but instead for now we do this:
                    int count = location.size();
                    for (int n = i + 1; n < count; n++) {
                        location.remove(i + 1);
                    }
                    foundNode = true;
                    break;
                }
            }
        }
        // add new node to the end of the existing breadcrumb
        if (foundNode == false) {
            FacesContext context = FacesContext.getCurrentInstance();
            String breadcrumbMode = Application.getClientConfig(context).getBreadcrumbMode();
            if (ClientConfigElement.BREADCRUMB_LOCATION.equals(breadcrumbMode)) {
                // if the breadcrumb is in "location" mode set the breadcrumb
                // to the full path to the node
                // TODO: check the end of the current breadcrumb, if the given
                // node is a child then we can shortcut the build of the
                // whole path.
                Repository.setupBreadcrumbLocation(context, this.navigator, location, ref);
            } else {
                // if the breadcrum is in "path" mode just add the given item to the end
                String name = Repository.getNameForNode(this.getNodeService(), ref);
                location.add(new BrowseBreadcrumbHandler(ref, name));
            }
        }
    } else {
        // special case to add first item to the location
        String name = Repository.getNameForNode(this.getNodeService(), ref);
        location.add(new BrowseBreadcrumbHandler(ref, name));
    }
    if (logger.isDebugEnabled())
        logger.debug("Updated breadcrumb: " + location);
    // set the current node Id ready for page refresh
    this.navigator.setCurrentNodeId(ref.getId());
    // set up the dispatch context for the navigation handler
    this.navigator.setupDispatchContext(new Node(ref));
    // inform any listeners that the current space has changed
    UIContextService.getInstance(FacesContext.getCurrentInstance()).spaceChanged();
    navigateBrowseScreen();
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) FacesContext(javax.faces.context.FacesContext) IBreadcrumbHandler(org.alfresco.web.ui.common.component.IBreadcrumbHandler) Node(org.alfresco.web.bean.repository.Node) MapNode(org.alfresco.web.bean.repository.MapNode) IRepoBreadcrumbHandler(org.alfresco.web.ui.repo.component.IRepoBreadcrumbHandler)

Example 2 with IRepoBreadcrumbHandler

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

the class BrowseBean method removeSpaceFromBreadcrumb.

/**
 * Removes the given node from the breadcrumb i.e. following a delete
 *
 * @param node The space to remove from the breadcrumb
 */
public void removeSpaceFromBreadcrumb(Node node) {
    List<IBreadcrumbHandler> location = navigator.getLocation();
    IBreadcrumbHandler handler = location.get(location.size() - 1);
    if (handler instanceof IRepoBreadcrumbHandler) {
        // see if the current breadcrumb location is our node
        if (((IRepoBreadcrumbHandler) handler).getNodeRef().equals(node.getNodeRef()) == true) {
            location.remove(location.size() - 1);
            // now work out which node to set the list to refresh against
            if (location.size() != 0) {
                handler = location.get(location.size() - 1);
                if (handler instanceof IRepoBreadcrumbHandler) {
                    // change the current node Id
                    navigator.setCurrentNodeId(((IRepoBreadcrumbHandler) handler).getNodeRef().getId());
                } else {
                    // if we don't have access to the NodeRef to go to next then go to the home space
                    navigator.processToolbarLocation(NavigationBean.LOCATION_HOME, false);
                }
            } else {
                // if there is no breadcrumb left go to the user's home space
                navigator.processToolbarLocation(NavigationBean.LOCATION_HOME, false);
            }
        }
    }
}
Also used : IBreadcrumbHandler(org.alfresco.web.ui.common.component.IBreadcrumbHandler) IRepoBreadcrumbHandler(org.alfresco.web.ui.repo.component.IRepoBreadcrumbHandler)

Aggregations

IBreadcrumbHandler (org.alfresco.web.ui.common.component.IBreadcrumbHandler)2 IRepoBreadcrumbHandler (org.alfresco.web.ui.repo.component.IRepoBreadcrumbHandler)2 FacesContext (javax.faces.context.FacesContext)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 MapNode (org.alfresco.web.bean.repository.MapNode)1 Node (org.alfresco.web.bean.repository.Node)1