001/* 002 * (C) Copyright 2012 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 * Anahide Tchertchian 018 */ 019package org.nuxeo.ecm.platform.forms.layout.service; 020 021import java.util.Collection; 022import java.util.Collections; 023import java.util.LinkedHashMap; 024import java.util.Map; 025 026import org.nuxeo.runtime.model.ContributionFragmentRegistry; 027 028/** 029 * Registry for {@link DisabledPropertyRefDescriptor} instances 030 * <p> 031 * Only supports merging of contributions on "enabled" information. 032 * <p> 033 * Stores contribution in the registration order, in case some conflicting criteria are found, the first one matching 034 * will apply. 035 * 036 * @since 5.6 037 */ 038public class DisabledPropertyRefRegistry extends ContributionFragmentRegistry<DisabledPropertyRefDescriptor> { 039 040 protected final Map<String, DisabledPropertyRefDescriptor> refs; 041 042 public DisabledPropertyRefRegistry() { 043 super(); 044 // use linked has map since there is no ordering support, not make sure 045 this.refs = new LinkedHashMap<String, DisabledPropertyRefDescriptor>(); 046 } 047 048 @Override 049 public String getContributionId(DisabledPropertyRefDescriptor contrib) { 050 return contrib.getId(); 051 } 052 053 @Override 054 public void contributionUpdated(String id, DisabledPropertyRefDescriptor contrib, 055 DisabledPropertyRefDescriptor newOrigContrib) { 056 refs.put(id, contrib); 057 } 058 059 @Override 060 public void contributionRemoved(String id, DisabledPropertyRefDescriptor origContrib) { 061 refs.remove(id); 062 } 063 064 @Override 065 public boolean isSupportingMerge() { 066 return true; 067 } 068 069 @Override 070 public DisabledPropertyRefDescriptor clone(DisabledPropertyRefDescriptor orig) { 071 return orig.clone(); 072 } 073 074 @Override 075 public void merge(DisabledPropertyRefDescriptor source, DisabledPropertyRefDescriptor dest) { 076 if (source.getEnabled() != dest.getEnabled()) { 077 dest.setEnabled(source.getEnabled()); 078 } 079 } 080 081 public Collection<DisabledPropertyRefDescriptor> getDisabledPropertyRefs() { 082 return Collections.unmodifiableCollection(refs.values()); 083 } 084 085}