001/*
002 * (C) Copyright 2006-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 *     Thomas Roger <troger@nuxeo.com>
018 */
019
020package org.nuxeo.ecm.activity;
021
022import java.util.HashMap;
023import java.util.Map;
024
025import org.nuxeo.runtime.model.ContributionFragmentRegistry;
026
027/**
028 * Registry for activity verbs, handling merge of registered {@link org.nuxeo.ecm.activity.ActivityVerb} elements.
029 *
030 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
031 * @since 5.6
032 */
033public class ActivityVerbRegistry extends ContributionFragmentRegistry<ActivityVerb> {
034
035    protected Map<String, ActivityVerb> activityVerbs = new HashMap<String, ActivityVerb>();
036
037    public ActivityVerb get(String name) {
038        return activityVerbs.get(name);
039    }
040
041    @Override
042    public String getContributionId(ActivityVerb contrib) {
043        return contrib.getVerb();
044    }
045
046    @Override
047    public void contributionUpdated(String id, ActivityVerb contrib, ActivityVerb newOrigContrib) {
048        activityVerbs.put(id, contrib);
049    }
050
051    @Override
052    public void contributionRemoved(String id, ActivityVerb origContrib) {
053        activityVerbs.remove(id);
054    }
055
056    @Override
057    public ActivityVerb clone(ActivityVerb orig) {
058        return orig.clone();
059    }
060
061    @Override
062    public void merge(ActivityVerb src, ActivityVerb dst) {
063        String labelKey = src.getLabelKey();
064        if (labelKey != null) {
065            dst.setLabelKey(labelKey);
066        }
067        String icon = src.getIcon();
068        if (icon != null) {
069            dst.setIcon(icon);
070        }
071    }
072}