001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS <http://nuxeo.com> and others 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * Jean-Marc Orliaguet, Chalmers 011 * 012 * $Id$ 013 */ 014 015package org.nuxeo.theme.themes; 016 017import java.util.ArrayList; 018import java.util.HashMap; 019import java.util.List; 020import java.util.Map; 021 022import org.nuxeo.common.xmap.annotation.XNode; 023import org.nuxeo.common.xmap.annotation.XNodeMap; 024import org.nuxeo.common.xmap.annotation.XObject; 025import org.nuxeo.theme.types.Type; 026import org.nuxeo.theme.types.TypeFamily; 027 028@XObject("themeset") 029public class ThemeSet implements Type { 030 031 @XNode("@name") 032 public String name; 033 034 @XNodeMap(value = "theme", key = "@name", type = HashMap.class, componentType = ThemeSetEntry.class) 035 public Map<String, ThemeSetEntry> themes; 036 037 public ThemeSet() { 038 } 039 040 public TypeFamily getTypeFamily() { 041 return TypeFamily.THEMESET; 042 } 043 044 public String getTypeName() { 045 return name; 046 } 047 048 public String getName() { 049 return name; 050 } 051 052 /* 053 * Theme entries 054 */ 055 public void setTheme(ThemeSetEntry theme) { 056 themes.put(theme.getName(), theme); 057 } 058 059 public ThemeSetEntry getTheme(String themeName) { 060 return themes.get(themeName); 061 } 062 063 public List<ThemeSetEntry> getThemes() { 064 return new ArrayList<ThemeSetEntry>(themes.values()); 065 } 066 067 /* 068 * Features 069 */ 070 public String getThemeForFeature(String feature) { 071 for (ThemeSetEntry theme : getThemes()) { 072 if (theme.getFeatures().contains(feature)) { 073 return theme.getName(); 074 } 075 } 076 return null; 077 } 078 079 public void addFeatureToTheme(String themeName, String feature) { 080 for (ThemeSetEntry theme : getThemes()) { 081 if (theme.getName().equals(themeName)) { 082 theme.addFeature(feature); 083 } else { 084 theme.removeFeature(feature); 085 } 086 } 087 } 088 089}