Search in sources :

Example 1 with IBreadcrumbHandler

use of org.alfresco.web.ui.common.component.IBreadcrumbHandler 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 IBreadcrumbHandler

use of org.alfresco.web.ui.common.component.IBreadcrumbHandler 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)

Example 3 with IBreadcrumbHandler

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

the class DeleteCategoryDialog method finishDelete.

public String finishDelete() {
    String outcome = DEFAULT_OUTCOME;
    if (getActionCategory() != null) {
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            RetryingTransactionHelper txnHelper = Repository.getRetryingTransactionHelper(context);
            RetryingTransactionCallback<NodeRef> callback = new RetryingTransactionCallback<NodeRef>() {

                @SuppressWarnings("unchecked")
                public NodeRef execute() throws Throwable {
                    // delete the category node using the nodeservice
                    NodeRef categoryNodeRef = getActionCategory().getNodeRef();
                    getCategoryService().deleteCategory(categoryNodeRef);
                    // all the associations to the category should be removed too
                    if (getMembers() != null && getMembers().size() > 0) {
                        for (ChildAssociationRef childRef : getMembers()) {
                            List<NodeRef> list = new ArrayList<NodeRef>(getMembers().size());
                            NodeRef member = childRef.getChildRef();
                            Collection<NodeRef> categories = (Collection<NodeRef>) getNodeService().getProperty(member, ContentModel.PROP_CATEGORIES);
                            for (NodeRef category : categories) {
                                if (category.equals(categoryNodeRef) == false) {
                                    list.add(category);
                                }
                            }
                            // persist the list back to the repository
                            getNodeService().setProperty(member, ContentModel.PROP_CATEGORIES, (Serializable) list);
                        }
                    }
                    return categoryNodeRef;
                }
            };
            NodeRef categoryNodeRef = txnHelper.doInTransaction(callback);
            // Figure out if the deletion is made by an icon or by a list of actions
            CategoriesDialog categoriesDialog = (CategoriesDialog) UIContextService.getInstance(FacesContext.getCurrentInstance()).getRegisteredBean(CategoriesDialog.CATEGORIES_DIALOG_CLASS_NAME);
            setLocation(categoriesDialog.getLocation());
            List<IBreadcrumbHandler> location = getLocation();
            CategoryBreadcrumbHandler handler = (CategoryBreadcrumbHandler) location.get(location.size() - 1);
            setCategoryFlag(!handler.toString().equals(getCategory().getName()));
            // clear action context
            setActionCategory(null);
        } catch (Throwable err) {
            Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
            outcome = null;
            ReportedException.throwIfNecessary(err);
        }
    }
    return outcome;
}
Also used : FacesContext(javax.faces.context.FacesContext) RetryingTransactionHelper(org.alfresco.repo.transaction.RetryingTransactionHelper) IBreadcrumbHandler(org.alfresco.web.ui.common.component.IBreadcrumbHandler) ArrayList(java.util.ArrayList) CategoryBreadcrumbHandler(org.alfresco.web.bean.categories.CategoriesDialog.CategoryBreadcrumbHandler) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RetryingTransactionCallback(org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback) Collection(java.util.Collection)

Example 4 with IBreadcrumbHandler

use of org.alfresco.web.ui.common.component.IBreadcrumbHandler 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 5 with IBreadcrumbHandler

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

the class EditCategoryDialog method finishEdit.

public String finishEdit() {
    String outcome = DEFAULT_OUTCOME;
    try {
        // update the category node
        NodeRef nodeRef = getActionCategory().getNodeRef();
        getNodeService().setProperty(nodeRef, ContentModel.PROP_NAME, getName());
        // ALF-1788 Need to rename the association
        ChildAssociationRef assocRef = getNodeService().getPrimaryParent(nodeRef);
        QName qname = QName.createQName(assocRef.getQName().getNamespaceURI(), QName.createValidLocalName(name));
        getNodeService().moveNode(assocRef.getChildRef(), assocRef.getParentRef(), assocRef.getTypeQName(), qname);
        // apply the titled aspect - for description
        if (getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_TITLED) == false) {
            Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(1, 1.0f);
            titledProps.put(ContentModel.PROP_DESCRIPTION, getDescription());
            getNodeService().addAspect(nodeRef, ContentModel.ASPECT_TITLED, titledProps);
        } else {
            getNodeService().setProperty(nodeRef, ContentModel.PROP_DESCRIPTION, getDescription());
        }
        // Figure out if the editing is made by an icon or by a list of actions
        CategoriesDialog categoriesDialog = (CategoriesDialog) UIContextService.getInstance(FacesContext.getCurrentInstance()).getRegisteredBean(CategoriesDialog.CATEGORIES_DIALOG_CLASS_NAME);
        setLocation(categoriesDialog.getLocation());
        List<IBreadcrumbHandler> location = getLocation();
        CategoryBreadcrumbHandler handler = (CategoryBreadcrumbHandler) location.get(location.size() - 1);
        if (!handler.toString().equals(getCategory().getName())) {
            setCategoryFlag(true);
        } else {
            setCategoryFlag(false);
        }
        Node categoryNode = new Node(nodeRef);
        setCategory(categoryNode);
    } catch (Throwable err) {
        Utils.addErrorMessage(MessageFormat.format(Application.getMessage(FacesContext.getCurrentInstance(), Repository.ERROR_GENERIC), err.getMessage()), err);
        outcome = null;
        ReportedException.throwIfNecessary(err);
    }
    return outcome;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) IBreadcrumbHandler(org.alfresco.web.ui.common.component.IBreadcrumbHandler) Node(org.alfresco.web.bean.repository.Node) CategoryBreadcrumbHandler(org.alfresco.web.bean.categories.CategoriesDialog.CategoryBreadcrumbHandler) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Aggregations

IBreadcrumbHandler (org.alfresco.web.ui.common.component.IBreadcrumbHandler)6 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 FacesContext (javax.faces.context.FacesContext)3 Node (org.alfresco.web.bean.repository.Node)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)2 CategoryBreadcrumbHandler (org.alfresco.web.bean.categories.CategoriesDialog.CategoryBreadcrumbHandler)2 UIBreadcrumb (org.alfresco.web.ui.common.component.UIBreadcrumb)2 IRepoBreadcrumbHandler (org.alfresco.web.ui.repo.component.IRepoBreadcrumbHandler)2 Serializable (java.io.Serializable)1 Writer (java.io.Writer)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 RetryingTransactionHelper (org.alfresco.repo.transaction.RetryingTransactionHelper)1 RetryingTransactionCallback (org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback)1 QName (org.alfresco.service.namespace.QName)1 MapNode (org.alfresco.web.bean.repository.MapNode)1 UIModeList (org.alfresco.web.ui.common.component.UIModeList)1