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.HashMap; 020import java.util.Map; 021 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024 025import org.ametys.cms.languages.Language; 026import org.ametys.cms.languages.LanguagesManager; 027import org.ametys.plugins.contentstree.ui.OpenTreeControllerClientSideElement; 028import org.ametys.runtime.i18n.I18nizableText; 029 030/** 031 * Override the TreeTooClientSideElement to retrieve informations for the CostModeling 032 */ 033public class CostModelingButtonClientSideElement extends OpenTreeControllerClientSideElement 034{ 035 /** The Avalon role name */ 036 public static final String ROLE = CostModelingButtonClientSideElement.class.getName(); 037 /** The ODF enumeration helper */ 038 protected LanguagesManager _languagesManager; 039 040 @Override 041 public void service(ServiceManager smanager) throws ServiceException 042 { 043 super.service(smanager); 044 _languagesManager = (LanguagesManager) smanager.lookup(LanguagesManager.ROLE); 045 } 046 047 @Override 048 protected void _lazyConfigure() 049 { 050 super._lazyConfigure(); 051 _script.getParameters().put("languages", getLanguages()); 052 } 053 054 /** 055 * Retrieve and get all languages in a JSON map 056 * @return a JSON map containing the grid structure for all languages 057 */ 058 public Map<String, I18nizableText> getLanguages() 059 { 060 Map<String, I18nizableText> languages = new HashMap<>(); 061 for (Language lang : _languagesManager.getAvailableLanguages().values()) 062 { 063 languages.put(lang.getCode(), lang.getLabel()); 064 065 } 066 return languages; 067 } 068}