Search in sources :

Example 11 with QuickSort

use of org.alfresco.web.data.QuickSort in project acs-community-packaging by Alfresco.

the class CreateSpaceWizard method getTemplateSpaces.

/**
 * @return Returns a list of template spaces currently in the system
 */
public List<SelectItem> getTemplateSpaces() {
    if (this.templates == null) {
        this.templates = new ArrayList<SelectItem>();
        FacesContext context = FacesContext.getCurrentInstance();
        String xpath = Application.getRootPath(context) + "/" + Application.getGlossaryFolderName(context) + "/" + Application.getSpaceTemplatesFolderName(context) + "/*";
        NodeRef rootNodeRef = this.getNodeService().getRootNode(Repository.getStoreRef());
        List<NodeRef> results = this.getSearchService().selectNodes(rootNodeRef, xpath, null, this.getNamespaceService(), false);
        if (results.size() != 0) {
            // show templates of the type relating to the space we are creating
            QName spaceType = QName.createQName(this.spaceType);
            for (NodeRef assocRef : results) {
                Node childNode = new Node(assocRef);
                if (this.getDictionaryService().isSubClass(childNode.getType(), spaceType)) {
                    this.templates.add(new SelectItem(childNode.getId(), childNode.getName()));
                }
            }
            // make sure the list is sorted by the label
            QuickSort sorter = new QuickSort(this.templates, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
            sorter.sort();
        }
        // add an entry (at the start) to instruct the user to select a template
        this.templates.add(0, new SelectItem("none", Application.getMessage(FacesContext.getCurrentInstance(), "select_a_template")));
    }
    return this.templates;
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) QuickSort(org.alfresco.web.data.QuickSort) SelectItem(javax.faces.model.SelectItem) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.web.bean.repository.Node)

Example 12 with QuickSort

use of org.alfresco.web.data.QuickSort in project acs-community-packaging by Alfresco.

the class BaseContentWizard method getObjectTypesImpl.

private List<SelectItem> getObjectTypesImpl() {
    if ((this.objectTypes == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        FacesContext context = FacesContext.getCurrentInstance();
        // add the well known object type to start with
        this.objectTypes = new ArrayList<SelectItem>(5);
        ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config wizardCfg = svc.getConfig("Content Wizards");
        if (wizardCfg != null) {
            ConfigElement defaultTypesCfg = wizardCfg.getConfigElement("default-content-type");
            String parentLabel = "";
            if (defaultTypesCfg != null) {
                // Get the default content-type to apply
                ConfigElement typeElement = defaultTypesCfg.getChildren().get(0);
                QName parentQName = Repository.resolveToQName(typeElement.getAttribute("name"));
                TypeDefinition parentType = null;
                if (parentQName != null) {
                    parentType = this.getDictionaryService().getType(parentQName);
                    if (parentType == null) {
                        // If no default content type is defined default to content
                        parentQName = ContentModel.TYPE_CONTENT;
                        parentType = this.getDictionaryService().getType(ContentModel.TYPE_CONTENT);
                        this.objectTypes.add(new SelectItem(ContentModel.TYPE_CONTENT.toString(), Application.getMessage(context, "content")));
                        logger.warn("Configured default content type not found in dictionary: " + parentQName);
                    } else {
                        // try and get the display label from config
                        parentLabel = Utils.getDisplayLabel(context, typeElement);
                        // if there wasn't a client based label try and get it from the dictionary
                        if (parentLabel == null) {
                            parentLabel = parentType.getTitle(this.getDictionaryService());
                        }
                        // finally, just use the localname
                        if (parentLabel == null) {
                            parentLabel = parentQName.getLocalName();
                        }
                    }
                }
                // Get all content types defined
                ConfigElement typesCfg = wizardCfg.getConfigElement("content-types");
                if (typesCfg != null) {
                    for (ConfigElement child : typesCfg.getChildren()) {
                        QName idQName = Repository.resolveToQName(child.getAttribute("name"));
                        if (idQName != null) {
                            TypeDefinition typeDef = this.getDictionaryService().getType(idQName);
                            if (typeDef != null) {
                                // for each type check if it is a subtype of the default content type
                                if (this.getDictionaryService().isSubClass(typeDef.getName(), parentType.getName())) {
                                    // try and get the display label from config
                                    String label = Utils.getDisplayLabel(context, child);
                                    // if there wasn't a client based label try and get it from the dictionary
                                    if (label == null) {
                                        label = typeDef.getTitle(this.getDictionaryService());
                                    }
                                    // finally, just use the localname
                                    if (label == null) {
                                        label = idQName.getLocalName();
                                    }
                                    this.objectTypes.add(new SelectItem(idQName.toString(), label));
                                } else {
                                    logger.warn("Failed to add '" + child.getAttribute("name") + "' to the list of content types - it is not a subtype of " + parentQName);
                                }
                            }
                        } else {
                            logger.warn("Failed to add '" + child.getAttribute("name") + "' to the list of content types as the type is not recognised");
                        }
                    }
                }
                // Case when no type is defined - we add the default content type to the list of available types
                if (this.objectTypes.isEmpty()) {
                    // add default content type to the list of available types
                    this.objectTypes.add(new SelectItem(parentQName.toString(), parentLabel));
                }
                // make sure the list is sorted by the label
                QuickSort sorter = new QuickSort(this.objectTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
                sorter.sort();
            } else {
                logger.warn("Could not find 'content-types' configuration element");
            }
        } else {
            logger.warn("Could not find 'Content Wizards' configuration section");
        }
    }
    return this.objectTypes;
}
Also used : FacesContext(javax.faces.context.FacesContext) QuickSort(org.alfresco.web.data.QuickSort) ConfigService(org.springframework.extensions.config.ConfigService) ConfigElement(org.springframework.extensions.config.ConfigElement) SelectItem(javax.faces.model.SelectItem) Config(org.springframework.extensions.config.Config) QName(org.alfresco.service.namespace.QName) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 13 with QuickSort

use of org.alfresco.web.data.QuickSort in project acs-community-packaging by Alfresco.

the class DocumentPropertiesDialog method getContentTypes.

/**
 * @return Returns a list of content types to allow the user to select from
 */
public List<SelectItem> getContentTypes() {
    if (this.contentTypes == null) {
        this.contentTypes = new ArrayList<SelectItem>(80);
        ServiceRegistry registry = Repository.getServiceRegistry(FacesContext.getCurrentInstance());
        MimetypeService mimetypeService = registry.getMimetypeService();
        // get the mime type display names
        Map<String, String> mimeTypes = mimetypeService.getDisplaysByMimetype();
        for (String mimeType : mimeTypes.keySet()) {
            this.contentTypes.add(new SelectItem(mimeType, mimeTypes.get(mimeType)));
        }
        // make sure the list is sorted by the values
        QuickSort sorter = new QuickSort(this.contentTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
        sorter.sort();
    }
    return this.contentTypes;
}
Also used : QuickSort(org.alfresco.web.data.QuickSort) SelectItem(javax.faces.model.SelectItem) MimetypeService(org.alfresco.service.cmr.repository.MimetypeService) ServiceRegistry(org.alfresco.service.ServiceRegistry)

Example 14 with QuickSort

use of org.alfresco.web.data.QuickSort in project acs-community-packaging by Alfresco.

the class GridListDataModel method sort.

/**
 * Sort the data set using the specified sort parameters
 *
 * @param column        Column to sort
 * @param descending    True for descending sort, false for ascending
 * @param mode          Sort mode to use (see IDataContainer constants)
 */
public void sort(String column, boolean descending, String mode) {
    try {
        QuickSort sorter = new QuickSort(this.data, column, !descending, mode);
        sorter.sort();
    } catch (Exception err) {
        throw new RuntimeException("Failed to sort data: " + err.getMessage(), err);
    }
}
Also used : QuickSort(org.alfresco.web.data.QuickSort)

Example 15 with QuickSort

use of org.alfresco.web.data.QuickSort in project acs-community-packaging by Alfresco.

the class NodeDescendantsLinkRenderer method encodeEnd.

/**
 * @see javax.faces.render.Renderer#encodeEnd(javax.faces.context.FacesContext, javax.faces.component.UIComponent)
 */
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
    // always check for this flag - as per the spec
    if (component.isRendered() == true) {
        Writer out = context.getResponseWriter();
        UINodeDescendants control = (UINodeDescendants) component;
        // make sure we have a NodeRef from the 'value' property ValueBinding
        Object val = control.getValue();
        if (val instanceof NodeRef == false) {
            throw new IllegalArgumentException("UINodeDescendants component 'value' property must resolve to a NodeRef!");
        }
        NodeRef parentRef = (NodeRef) val;
        // use Spring JSF integration to get the node service bean
        NodeService service = getNodeService(context);
        DictionaryService dd = getDictionaryService(context);
        UserTransaction tx = null;
        try {
            tx = Repository.getUserTransaction(FacesContext.getCurrentInstance(), true);
            tx.begin();
            // TODO: need a comparator to sort node refs (based on childref qname)
            // as currently the list is returned in a random order per request!
            String separator = (String) component.getAttributes().get("separator");
            if (separator == null) {
                separator = DEFAULT_SEPARATOR;
            }
            // calculate the number of displayed child refs
            if (service.exists(parentRef) == true) {
                List<ChildAssociationRef> childRefs = service.getChildAssocs(parentRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
                List<Node> nodes = new ArrayList<Node>(childRefs.size());
                for (int index = 0; index < childRefs.size(); index++) {
                    ChildAssociationRef ref = childRefs.get(index);
                    QName type = service.getType(ref.getChildRef());
                    TypeDefinition typeDef = dd.getType(type);
                    if (typeDef != null && dd.isSubClass(type, ContentModel.TYPE_FOLDER) && dd.isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                        nodes.add(new Node(ref.getChildRef()));
                    }
                }
                QuickSort sorter = new QuickSort(nodes, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
                sorter.sort();
                // walk each child ref and output a descendant link control for each item
                int total = 0;
                int maximum = nodes.size() > control.getMaxChildren() ? control.getMaxChildren() : nodes.size();
                for (int index = 0; index < maximum; index++) {
                    Node node = nodes.get(index);
                    QName type = service.getType(node.getNodeRef());
                    TypeDefinition typeDef = dd.getType(type);
                    if (typeDef != null && dd.isSubClass(type, ContentModel.TYPE_FOLDER) && dd.isSubClass(type, ContentModel.TYPE_SYSTEM_FOLDER) == false) {
                        // output separator if appropriate
                        if (total > 0) {
                            out.write(separator);
                        }
                        out.write(renderDescendant(context, control, node.getNodeRef(), false));
                        total++;
                    }
                }
                // do we need to render ellipses to indicate more items than the maximum
                if (control.getShowEllipses() == true && nodes.size() > maximum) {
                    out.write(separator);
                    // TODO: is this the correct way to get the information we need?
                    // e.g. primary parent may not be the correct path? how do we make sure we find
                    // the correct parent and more importantly the correct Display Name value!
                    out.write(renderDescendant(context, control, service.getPrimaryParent(parentRef).getChildRef(), true));
                }
            }
            tx.commit();
        } catch (Throwable err) {
            try {
                if (tx != null) {
                    tx.rollback();
                }
            } catch (Exception tex) {
            }
            throw new RuntimeException(err);
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) QName(org.alfresco.service.namespace.QName) NodeService(org.alfresco.service.cmr.repository.NodeService) Node(org.alfresco.web.bean.repository.Node) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) UINodeDescendants(org.alfresco.web.ui.repo.component.UINodeDescendants) IOException(java.io.IOException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) NodeRef(org.alfresco.service.cmr.repository.NodeRef) DictionaryService(org.alfresco.service.cmr.dictionary.DictionaryService) QuickSort(org.alfresco.web.data.QuickSort) Writer(java.io.Writer)

Aggregations

QuickSort (org.alfresco.web.data.QuickSort)30 SelectItem (javax.faces.model.SelectItem)22 FacesContext (javax.faces.context.FacesContext)11 Config (org.springframework.extensions.config.Config)9 ConfigElement (org.springframework.extensions.config.ConfigElement)9 ConfigService (org.springframework.extensions.config.ConfigService)9 NodeRef (org.alfresco.service.cmr.repository.NodeRef)8 Node (org.alfresco.web.bean.repository.Node)6 ArrayList (java.util.ArrayList)5 QName (org.alfresco.service.namespace.QName)5 TreeNode (org.alfresco.web.ui.repo.component.UITree.TreeNode)5 ResponseWriter (javax.faces.context.ResponseWriter)4 ServiceRegistry (org.alfresco.service.ServiceRegistry)4 DictionaryService (org.alfresco.service.cmr.dictionary.DictionaryService)4 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)4 IOException (java.io.IOException)3 UserTransaction (javax.transaction.UserTransaction)3 MimetypeService (org.alfresco.service.cmr.repository.MimetypeService)3 HashMap (java.util.HashMap)2