001/* 002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.platform.forms.layout.core.registries; 018 019import java.util.List; 020 021import org.nuxeo.ecm.platform.forms.layout.api.WidgetType; 022import org.nuxeo.runtime.model.SimpleContributionRegistry; 023 024/** 025 * Registry holding widget type instances for a given category. 026 * 027 * @since 5.5 028 */ 029public class WidgetTypeRegistry extends SimpleContributionRegistry<WidgetType> { 030 031 protected final String category; 032 033 public WidgetTypeRegistry(String category) { 034 super(); 035 this.category = category; 036 } 037 038 public String getCategory() { 039 return category; 040 } 041 042 @Override 043 public String getContributionId(WidgetType contrib) { 044 return contrib.getName(); 045 } 046 047 public WidgetType getWidgetType(String id) { 048 return getCurrentContribution(id); 049 } 050 051 @Override 052 // overridden to handle aliases 053 public synchronized void addContribution(WidgetType contrib) { 054 super.addContribution(contrib); 055 List<String> aliases = contrib.getAliases(); 056 if (aliases != null) { 057 for (String alias : aliases) { 058 FragmentList<WidgetType> head = addFragment(alias, contrib); 059 contributionUpdated(alias, head.merge(this), contrib); 060 } 061 } 062 } 063 064 /** 065 * Overridden to use equals method when removing elements. 066 * 067 * @since 7.2 068 */ 069 @Override 070 public synchronized void removeContribution(WidgetType contrib) { 071 removeContribution(contrib, true); 072 } 073 074 @Override 075 // overridden to handle aliases 076 public synchronized void removeContribution(WidgetType contrib, boolean useEqualsMethod) { 077 super.removeContribution(contrib, useEqualsMethod); 078 List<String> aliases = contrib.getAliases(); 079 if (aliases != null) { 080 for (String alias : aliases) { 081 FragmentList<WidgetType> head = removeFragment(alias, contrib, useEqualsMethod); 082 if (head != null) { 083 WidgetType result = head.merge(this); 084 if (result != null) { 085 contributionUpdated(alias, result, contrib); 086 } else { 087 contributionRemoved(alias, contrib); 088 } 089 } 090 } 091 } 092 } 093 094}