001/* 002 * (C) Copyright 2006-2007 Nuxeo SA (http://nuxeo.com/) and others. 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 * Contributors: 017 * Jean-Marc Orliaguet, Chalmers 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.theme.themes; 023 024import java.util.ArrayList; 025import java.util.HashMap; 026import java.util.List; 027import java.util.Map; 028 029import org.nuxeo.common.xmap.annotation.XNode; 030import org.nuxeo.common.xmap.annotation.XNodeMap; 031import org.nuxeo.common.xmap.annotation.XObject; 032import org.nuxeo.theme.types.Type; 033import org.nuxeo.theme.types.TypeFamily; 034 035@XObject("themeset") 036public class ThemeSet implements Type { 037 038 @XNode("@name") 039 public String name; 040 041 @XNodeMap(value = "theme", key = "@name", type = HashMap.class, componentType = ThemeSetEntry.class) 042 public Map<String, ThemeSetEntry> themes; 043 044 public ThemeSet() { 045 } 046 047 public TypeFamily getTypeFamily() { 048 return TypeFamily.THEMESET; 049 } 050 051 public String getTypeName() { 052 return name; 053 } 054 055 public String getName() { 056 return name; 057 } 058 059 /* 060 * Theme entries 061 */ 062 public void setTheme(ThemeSetEntry theme) { 063 themes.put(theme.getName(), theme); 064 } 065 066 public ThemeSetEntry getTheme(String themeName) { 067 return themes.get(themeName); 068 } 069 070 public List<ThemeSetEntry> getThemes() { 071 return new ArrayList<ThemeSetEntry>(themes.values()); 072 } 073 074 /* 075 * Features 076 */ 077 public String getThemeForFeature(String feature) { 078 for (ThemeSetEntry theme : getThemes()) { 079 if (theme.getFeatures().contains(feature)) { 080 return theme.getName(); 081 } 082 } 083 return null; 084 } 085 086 public void addFeatureToTheme(String themeName, String feature) { 087 for (ThemeSetEntry theme : getThemes()) { 088 if (theme.getName().equals(themeName)) { 089 theme.addFeature(feature); 090 } else { 091 theme.removeFeature(feature); 092 } 093 } 094 } 095 096}