001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.extensions.breadcrumb; 018 019import java.util.ArrayList; 020import java.util.List; 021 022import org.apache.wicket.util.io.IClusterable; 023import org.apache.wicket.util.lang.Args; 024 025 026/** 027 * Utility class for working with {@link IBreadCrumbModelListener bread crumb model listeners}. 028 * 029 * @author Eelco Hillenius 030 */ 031public final class BreadCrumbModelListenerSupport implements IClusterable 032{ 033 private static final long serialVersionUID = 1L; 034 035 /** listeners for bread crumb events. */ 036 private final List<IBreadCrumbModelListener> listeners = new ArrayList<IBreadCrumbModelListener>( 037 1); 038 039 /** 040 * Adds a bread crumb model listener. 041 * 042 * @param listener 043 * The listener to add 044 */ 045 public final void addListener(final IBreadCrumbModelListener listener) 046 { 047 Args.notNull(listener, "listener"); 048 listeners.add(listener); 049 } 050 051 /** 052 * Notifies all listeners that a bread crumb was activated. 053 * 054 * @param previousParticipant 055 * The previously active participant 056 * 057 * @param breadCrumbParticipant 058 * The activated bread crumb 059 */ 060 public final void fireBreadCrumbActivated(final IBreadCrumbParticipant previousParticipant, 061 final IBreadCrumbParticipant breadCrumbParticipant) 062 { 063 for (IBreadCrumbModelListener listener : listeners) 064 { 065 listener.breadCrumbActivated(previousParticipant, breadCrumbParticipant); 066 } 067 } 068 069 /** 070 * Notifies all listeners that a new bread crumb was added. 071 * 072 * @param breadCrumbParticipant 073 * The newly added bread crumb 074 */ 075 public final void fireBreadCrumbAdded(final IBreadCrumbParticipant breadCrumbParticipant) 076 { 077 for (IBreadCrumbModelListener listener : listeners) 078 { 079 listener.breadCrumbAdded(breadCrumbParticipant); 080 } 081 } 082 083 /** 084 * Notifies all listeners that a bread crumb was removed. 085 * 086 * @param breadCrumbParticipant 087 * The removed bread crumb 088 */ 089 public final void fireBreadCrumbRemoved(final IBreadCrumbParticipant breadCrumbParticipant) 090 { 091 for (IBreadCrumbModelListener listener : listeners) 092 { 093 listener.breadCrumbRemoved(breadCrumbParticipant); 094 } 095 } 096 097 /** 098 * Removes a bread crumb model listener. 099 * 100 * @param listener 101 * The listener to remove 102 */ 103 public final void removeListener(final IBreadCrumbModelListener listener) 104 { 105 if (listener != null) 106 { 107 listeners.remove(listener); 108 } 109 } 110}