Search in sources :

Example 16 with QuickSort

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

the class CreateContentWizard method getCreateMimeTypes.

/**
 * @return Returns a list of mime types to allow the user to select from
 */
public List<SelectItem> getCreateMimeTypes() {
    if ((this.createMimeTypes == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        FacesContext context = FacesContext.getCurrentInstance();
        // add the well known object type to start with
        this.createMimeTypes = new ArrayList<SelectItem>(5);
        // add the configured create mime types to the list
        ConfigService svc = Application.getConfigService(context);
        Config wizardCfg = svc.getConfig("Content Wizards");
        if (wizardCfg != null) {
            ConfigElement typesCfg = wizardCfg.getConfigElement("create-mime-types");
            if (typesCfg != null) {
                for (ConfigElement child : typesCfg.getChildren()) {
                    String currentMimeType = child.getAttribute("name");
                    if (currentMimeType != null) {
                        String label = getSummaryMimeType(currentMimeType);
                        this.createMimeTypes.add(new SelectItem(currentMimeType, label));
                    }
                }
                // 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 'create-mime-types' configuration element");
            }
        } else {
            logger.warn("Could not find 'Content Wizards' configuration section");
        }
    }
    return this.createMimeTypes;
}
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)

Example 17 with QuickSort

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

the class NavigatorPluginBean method retrieveChildren.

// ------------------------------------------------------------------------------
// AJAX handler methods
/**
 * Retrieves the child folders for the noderef given in the
 * 'noderef' parameter and caches the nodes against the area in
 * the 'area' parameter.
 */
public void retrieveChildren() throws IOException {
    FacesContext context = FacesContext.getCurrentInstance();
    ResponseWriter out = context.getResponseWriter();
    UserTransaction tx = null;
    try {
        tx = Repository.getUserTransaction(context, true);
        tx.begin();
        Map params = context.getExternalContext().getRequestParameterMap();
        String nodeRefStr = (String) params.get("nodeRef");
        String area = (String) params.get("area");
        if (logger.isDebugEnabled())
            logger.debug("retrieveChildren: area = " + area + ", nodeRef = " + nodeRefStr);
        // work out which list to cache the nodes in
        Map<String, TreeNode> currentNodes = getNodesMapForArea(area);
        if (nodeRefStr != null && currentNodes != null) {
            // get the given node's details
            NodeRef parentNodeRef = new NodeRef(nodeRefStr);
            TreeNode parentNode = currentNodes.get(parentNodeRef.toString());
            parentNode.setExpanded(true);
            if (logger.isDebugEnabled())
                logger.debug("retrieving children for noderef: " + parentNodeRef);
            // remove any existing children as the latest ones will be added below
            parentNode.removeChildren();
            // get all the child folder objects for the parent
            List<ChildAssociationRef> childRefs = this.getNodeService().getChildAssocs(parentNodeRef, ContentModel.ASSOC_CONTAINS, RegexQNamePattern.MATCH_ALL);
            List<TreeNode> sortedNodes = new ArrayList<TreeNode>();
            for (ChildAssociationRef ref : childRefs) {
                NodeRef nodeRef = ref.getChildRef();
                if (isAddableChild(nodeRef)) {
                    // build the XML representation of the child node
                    TreeNode childNode = createTreeNode(nodeRef);
                    parentNode.addChild(childNode);
                    currentNodes.put(childNode.getNodeRef(), childNode);
                    sortedNodes.add(childNode);
                }
            }
            // order the tree nodes by the tree label
            if (sortedNodes.size() > 1) {
                QuickSort sorter = new QuickSort(sortedNodes, "name", true, IDataContainer.SORT_CASEINSENSITIVE);
                sorter.sort();
            }
            // generate the XML representation
            StringBuilder xml = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?><nodes>");
            for (TreeNode childNode : sortedNodes) {
                xml.append(childNode.toXML());
            }
            xml.append("</nodes>");
            // send the generated XML back to the tree
            out.write(xml.toString());
            if (logger.isDebugEnabled())
                logger.debug("returning XML: " + xml.toString());
        }
        // commit the transaction
        tx.commit();
    } catch (Throwable err) {
        try {
            if (tx != null) {
                tx.rollback();
            }
        } catch (Exception tex) {
        }
    }
}
Also used : UserTransaction(javax.transaction.UserTransaction) FacesContext(javax.faces.context.FacesContext) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) IOException(java.io.IOException) NodeRef(org.alfresco.service.cmr.repository.NodeRef) QuickSort(org.alfresco.web.data.QuickSort) ResponseWriter(javax.faces.context.ResponseWriter) TreeNode(org.alfresco.web.ui.repo.component.UITree.TreeNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with QuickSort

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

the class BaseActionWizard method getActions.

/**
 * @return Returns the list of selectable actions
 */
public List<SelectItem> getActions() {
    if (this.actions == null) {
        List<ActionDefinition> ruleActions = this.getActionService().getActionDefinitions();
        this.actions = new ArrayList<SelectItem>();
        for (ActionDefinition ruleActionDef : ruleActions) {
            String title = ruleActionDef.getTitle();
            if (title == null || title.length() == 0) {
                title = ruleActionDef.getName();
            }
            this.actions.add(new SelectItem(ruleActionDef.getName(), title));
        }
        // make sure the list is sorted by the label
        QuickSort sorter = new QuickSort(this.actions, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
        sorter.sort();
        // add the select an action item at the start of the list
        this.actions.add(0, new SelectItem("null", Application.getMessage(FacesContext.getCurrentInstance(), "select_an_action")));
    }
    return this.actions;
}
Also used : QuickSort(org.alfresco.web.data.QuickSort) SelectItem(javax.faces.model.SelectItem) ActionDefinition(org.alfresco.service.cmr.action.ActionDefinition)

Example 19 with QuickSort

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

the class BaseActionWizard method getImageTransformers.

/**
 * Returns the image transformers that are available
 *
 * @return List of SelectItem objects representing the available image transformers
 */
public List<SelectItem> getImageTransformers() {
    if ((this.imageTransformers == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config wizardCfg = svc.getConfig("Action Wizards");
        if (wizardCfg != null) {
            ConfigElement transformersCfg = wizardCfg.getConfigElement("image-transformers");
            if (transformersCfg != null) {
                FacesContext context = FacesContext.getCurrentInstance();
                Map<String, String> mimeTypes = this.getMimetypeService().getDisplaysByMimetype();
                this.imageTransformers = new ArrayList<SelectItem>();
                for (ConfigElement child : transformersCfg.getChildren()) {
                    String id = child.getAttribute("name");
                    // try and get the display label from config
                    String label = Utils.getDisplayLabel(context, child);
                    // if there wasn't a client based label get it from the mime type service
                    if (label == null) {
                        label = mimeTypes.get(id);
                    }
                    // if there is still no label use the raw mimetype
                    if (label == null) {
                        label = id;
                    }
                    this.imageTransformers.add(new SelectItem(id, label));
                }
                // make sure the list is sorted by the label
                QuickSort sorter = new QuickSort(this.imageTransformers, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
                sorter.sort();
            } else {
                logger.warn("Could not find 'image-transformers' configuration element");
            }
        } else {
            logger.warn("Could not find 'Action Wizards' configuration section");
        }
    }
    return this.imageTransformers;
}
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) Config(org.springframework.extensions.config.Config) SelectItem(javax.faces.model.SelectItem)

Example 20 with QuickSort

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

the class BaseActionWizard method getAddableAspects.

/**
 * Returns a list of aspects that can be added
 *
 * @return List of SelectItem objects representing the aspects that can be added
 */
public List<SelectItem> getAddableAspects() {
    if ((this.addableAspects == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        // get the list of common aspects
        this.addableAspects = new ArrayList<SelectItem>();
        this.addableAspects.addAll(getCommonAspects());
        // get those aspects configured to appear only in the remove aspect action
        ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config wizardCfg = svc.getConfig("Action Wizards");
        if (wizardCfg != null) {
            ConfigElement aspectsCfg = wizardCfg.getConfigElement("aspects-add");
            if (aspectsCfg != null) {
                List<SelectItem> aspects = readAspectsConfig(FacesContext.getCurrentInstance(), aspectsCfg);
                this.addableAspects.addAll(aspects);
            } else {
                logger.warn("Could not find 'aspects-add' configuration element");
            }
        } else {
            logger.warn("Could not find 'Action Wizards' configuration section");
        }
        // make sure the list is sorted by the label
        QuickSort sorter = new QuickSort(this.addableAspects, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
        sorter.sort();
    }
    return this.addableAspects;
}
Also used : 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)

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