001package fr.ifremer.adagio.core.config; 002 003/* 004 * #%L 005 * Tutti :: Persistence 006 * $Id: TuttiConfigurationProvider.java 1418 2013-12-01 21:18:22Z tchemit $ 007 * $HeadURL: http://svn.forge.codelutin.com/svn/tutti/trunk/tutti-persistence/src/main/java/fr/ifremer/tutti/TuttiConfigurationProvider.java $ 008 * %% 009 * Copyright (C) 2012 - 2013 Ifremer 010 * %% 011 * This program is free software: you can redistribute it and/or modify 012 * it under the terms of the GNU Affero General Public License as published by 013 * the Free Software Foundation, either version 3 of the License, or 014 * (at your option) any later version. 015 * 016 * This program is distributed in the hope that it will be useful, 017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 019 * GNU General Public License for more details. 020 * 021 * You should have received a copy of the GNU Affero General Public License 022 * along with this program. If not, see <http://www.gnu.org/licenses/>. 023 * #L% 024 */ 025 026import static org.nuiton.i18n.I18n.l; 027 028import java.util.List; 029import java.util.Locale; 030 031import org.nuiton.config.ApplicationConfigProvider; 032import org.nuiton.config.ConfigActionDef; 033import org.nuiton.config.ConfigOptionDef; 034 035import com.google.common.collect.Lists; 036 037import fr.ifremer.adagio.core.dao.technical.AdagioEnumerationDef; 038 039/** 040 * Allegro config provider (for site generation). 041 * 042 * @author Benoit Lavenier <benoit.lavenier@e-is.pro> 043 * @since 3.5.0 044 */ 045public class AdagioConfigurationModelEnumProvider implements ApplicationConfigProvider { 046 047 @Override 048 public String getName() { 049 return "adagio-db-enumerations"; 050 } 051 052 @Override 053 public String getDescription(Locale locale) { 054 return l(locale, "adagio-db-enumerations.config"); 055 } 056 057 @Override 058 public ConfigOptionDef[] getOptions() { 059 List<ConfigOptionDef> options = Lists.newArrayList(); 060 061 // Add options from model enumerations 062 List<AdagioEnumerationDef<?>> enumDefs = AdagioEnumerationHelper.getAllModelEnumerations(); 063 for(AdagioEnumerationDef<?> enumDef: enumDefs) { 064 AdagioEnumerationOption option = new AdagioEnumerationOption(enumDef); 065 options.add(option); 066 } 067 068 return (ConfigOptionDef[]) options.toArray(new ConfigOptionDef[options.size()]); 069 } 070 071 @Override 072 public ConfigActionDef[] getActions() { 073 return new ConfigActionDef[0]; 074 } 075 076 class AdagioEnumerationOption implements ConfigOptionDef { 077 078 private static final long serialVersionUID = -5720186783497571417L; 079 080 private AdagioEnumerationDef<?> delegatedEnum; 081 082 public AdagioEnumerationOption(AdagioEnumerationDef<?> delegatedEnum) { 083 this.delegatedEnum = delegatedEnum; 084 } 085 086 @Override 087 public boolean isFinal() { 088 return false; 089 } 090 091 @Override 092 public boolean isTransient() { 093 return false; 094 } 095 096 @Override 097 public String getDefaultValue() { 098 return delegatedEnum.getValueAsString(); 099 } 100 101 @Override 102 public String getDescription() { 103 return delegatedEnum.getDescription(); 104 } 105 106 @Override 107 public String getKey() { 108 return delegatedEnum.getKey(); 109 } 110 111 @Override 112 public Class getType() { 113 return delegatedEnum.getType(); 114 } 115 116 @Override 117 public void setDefaultValue(String defaultValue) { 118 //not used 119 } 120 121 @Override 122 public void setTransient(boolean isTransient) { 123 // not used 124 } 125 126 @Override 127 public void setFinal(boolean isFinal) { 128 // not used 129 } 130 } 131}