001/*
002 *  Copyright 2020 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016
017package org.ametys.plugins.odfpilotage.clientsideelement;
018
019import java.util.ArrayList;
020import java.util.List;
021
022import org.apache.avalon.framework.service.ServiceException;
023import org.apache.avalon.framework.service.ServiceManager;
024
025import org.ametys.odf.enumeration.OdfReferenceTableEntry;
026import org.ametys.odf.enumeration.OdfReferenceTableHelper;
027import org.ametys.plugins.contentstree.ui.TreeToolClientSideElement;
028
029/**
030 * Override the TreeTooClientSideElement to retrieve informations for the CostModeling 
031 */
032public class CostModelingClientSideElement extends TreeToolClientSideElement
033{
034    /** The Avalon role name */
035    public static final String ROLE = CostModelingClientSideElement.class.getName();
036    /** The ODF enumeration helper */
037    protected OdfReferenceTableHelper _refTableHelper;
038    
039    @Override
040    public void service(ServiceManager smanager) throws ServiceException
041    {
042        super.service(smanager);
043        _refTableHelper = (OdfReferenceTableHelper) smanager.lookup(OdfReferenceTableHelper.ROLE); 
044    }
045    
046    @Override
047    protected void _lazyConfigure()
048    {
049        super._lazyConfigure();
050        _script.getParameters().put("enseignement-nature", getEnseignementNature());
051    }
052    
053    /**
054     * Retrieve and get all teaching nature in a JSON map 
055     * @return a JSON map containing the grid structure for all teaching nature
056     */
057    public List<String> getEnseignementNature()
058    {
059        List<String> codesNatures = new ArrayList<>();
060        for (OdfReferenceTableEntry enseignementNature : _refTableHelper.getItems(OdfReferenceTableHelper.ENSEIGNEMENT_NATURE))
061        {
062            codesNatures.add(enseignementNature.getCode());
063            
064        }
065        return codesNatures;
066    }
067}