001/*
002 *  Copyright 2024 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 */
016package org.ametys.cms.properties;
017
018import java.util.List;
019import java.util.Map;
020
021import org.apache.avalon.framework.configuration.Configuration;
022import org.apache.avalon.framework.configuration.ConfigurationException;
023import org.apache.avalon.framework.service.ServiceException;
024import org.apache.avalon.framework.service.ServiceManager;
025
026import org.ametys.cms.properties.tab.PropertiesTab;
027import org.ametys.cms.properties.tab.PropertiesTabExtensionPoint;
028import org.ametys.core.ui.StaticClientSideElement;
029
030/**
031 * Client side element to get configuration of the properties tool.
032 */
033public class PropertiesToolClientSideElement extends StaticClientSideElement
034{
035    private PropertiesTabExtensionPoint _propertiesTabEP;
036
037    @Override
038    public void service(ServiceManager smanager) throws ServiceException
039    {
040        super.service(smanager);
041        _propertiesTabEP = (PropertiesTabExtensionPoint) smanager.lookup(PropertiesTabExtensionPoint.ROLE);
042    }
043    
044    @Override
045    protected Map<String, Object> configureInitialParameters(Configuration configuration) throws ConfigurationException
046    {
047        Map<String, Object> initialParameters = super.configureInitialParameters(configuration);
048        
049        // Get the configuration of each tab of the tool
050        List<Map<String, Object>> propertiesTabParameters = _propertiesTabEP.getExtensionsIds()
051            .stream()
052            .map(_propertiesTabEP::getExtension)
053            .map(PropertiesTab::getConfiguration)
054            .toList();
055        initialParameters.put("propertiesTab", propertiesTabParameters);
056        
057        return initialParameters;
058    }
059}