1 17 package org.alfresco.web.ui.repo.component; 18 19 import java.util.ArrayList ; 20 import java.util.Collection ; 21 22 import javax.faces.context.FacesContext; 23 24 import org.alfresco.model.ContentModel; 25 import org.alfresco.service.cmr.dictionary.DictionaryService; 26 import org.alfresco.service.cmr.repository.ChildAssociationRef; 27 import org.alfresco.service.cmr.repository.NodeRef; 28 import org.alfresco.service.cmr.search.CategoryService; 29 import org.alfresco.service.cmr.search.CategoryService.Depth; 30 import org.alfresco.web.app.Application; 31 import org.alfresco.web.bean.repository.Node; 32 import org.alfresco.web.bean.repository.Repository; 33 import org.alfresco.web.ui.repo.WebResources; 34 35 40 public class UICategorySelector extends AbstractItemSelector 41 { 42 45 48 public String getFamily() 49 { 50 return "org.alfresco.faces.CategorySelector"; 51 } 52 53 57 public String getDefaultLabel() 58 { 59 return Application.getMessage(FacesContext.getCurrentInstance(), "select_category_prompt"); 60 } 61 62 69 private static CategoryService getCategoryService(FacesContext context) 70 { 71 CategoryService service = Repository.getServiceRegistry(context).getCategoryService(); 72 if (service == null) 73 { 74 throw new IllegalStateException ("Unable to obtain CategoryService bean reference."); 75 } 76 77 return service; 78 } 79 80 85 public String getParentNodeId(FacesContext context) 86 { 87 String id = null; 88 89 if (this.navigationId != null) 90 { 91 ChildAssociationRef parentRef = getNodeService(context).getPrimaryParent( 92 new NodeRef(Repository.getStoreRef(), this.navigationId)); 93 Node parentNode = new Node(parentRef.getParentRef()); 94 95 DictionaryService dd = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getDictionaryService(); 96 97 if (dd.isSubClass(parentNode.getType(), ContentModel.TYPE_CATEGORYROOT) == false) 98 { 99 id = parentRef.getParentRef().getId(); 100 } 101 } 102 103 return id; 104 } 105 106 111 public Collection <NodeRef> getChildrenForNode(FacesContext context) 112 { 113 NodeRef nodeRef = new NodeRef(Repository.getStoreRef(), this.navigationId); 114 115 Collection <ChildAssociationRef> childRefs = getCategoryService(context).getChildren(nodeRef, 116 CategoryService.Mode.SUB_CATEGORIES, CategoryService.Depth.IMMEDIATE); 117 Collection <NodeRef> refs = new ArrayList <NodeRef>(childRefs.size()); 118 for (ChildAssociationRef childRef : childRefs) 119 { 120 refs.add(childRef.getChildRef()); 121 } 122 123 return refs; 124 } 125 126 131 public Collection <NodeRef> getRootChildren(FacesContext context) 132 { 133 Collection <ChildAssociationRef> childRefs = getCategoryService(context).getCategories( 134 Repository.getStoreRef(), ContentModel.ASPECT_GEN_CLASSIFIABLE, Depth.IMMEDIATE); 135 Collection <NodeRef> refs = new ArrayList <NodeRef>(childRefs.size()); 136 for (ChildAssociationRef childRef : childRefs) 137 { 138 refs.add(childRef.getChildRef()); 139 } 140 141 return refs; 142 } 143 144 147 public String getItemIcon() 148 { 149 return WebResources.IMAGE_CATEGORY; 150 } 151 } 152 | Popular Tags |