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: */
017: package org.apache.wicket.extensions.breadcrumb;
018:
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import org.apache.wicket.IClusterable;
024:
025: /**
026: * Utility class for working with
027: * {@link IBreadCrumbModelListener bread crumb model listeners}.
028: *
029: * @author Eelco Hillenius
030: */
031: public final class BreadCrumbModelListenerSupport implements
032: IClusterable {
033: private static final long serialVersionUID = 1L;
034:
035: /** listeners for bread crumb events. */
036: private final List listeners = new ArrayList(1);
037:
038: /**
039: * Adds a bread crumb model listener.
040: *
041: * @param listener
042: * The listener to add
043: */
044: public final void addListener(IBreadCrumbModelListener listener) {
045: if (listener == null) {
046: throw new IllegalArgumentException(
047: "argument listener must be not null");
048: }
049: listeners.add(listener);
050: }
051:
052: /**
053: * Notifies all listeners that a bread crumb was activated.
054: *
055: * @param previousParticipant
056: * The previously active participant
057: *
058: * @param breadCrumbParticipant
059: * The activated bread crumb
060: */
061: public final void fireBreadCrumbActivated(
062: IBreadCrumbParticipant previousParticipant,
063: IBreadCrumbParticipant breadCrumbParticipant) {
064: for (Iterator i = listeners.iterator(); i.hasNext();) {
065: IBreadCrumbModelListener listener = (IBreadCrumbModelListener) i
066: .next();
067: listener.breadCrumbActivated(previousParticipant,
068: breadCrumbParticipant);
069: }
070: }
071:
072: /**
073: * Notifies all listeners that a new bread crumb was added.
074: *
075: * @param breadCrumbParticipant
076: * The newly added bread crumb
077: */
078: public final void fireBreadCrumbAdded(
079: IBreadCrumbParticipant breadCrumbParticipant) {
080: for (Iterator i = listeners.iterator(); i.hasNext();) {
081: IBreadCrumbModelListener listener = (IBreadCrumbModelListener) i
082: .next();
083: listener.breadCrumbAdded(breadCrumbParticipant);
084: }
085: }
086:
087: /**
088: * Notifies all listeners that a bread crumb was removed.
089: *
090: * @param breadCrumbParticipant
091: * The removed bread crumb
092: */
093: public final void fireBreadCrumbRemoved(
094: IBreadCrumbParticipant breadCrumbParticipant) {
095: for (Iterator i = listeners.iterator(); i.hasNext();) {
096: IBreadCrumbModelListener listener = (IBreadCrumbModelListener) i
097: .next();
098: listener.breadCrumbRemoved(breadCrumbParticipant);
099: }
100: }
101:
102: /**
103: * Removes a bread crumb model listener.
104: *
105: * @param listener
106: * The listener to remove
107: */
108: public final void removeListener(IBreadCrumbModelListener listener) {
109: if (listener != null) {
110: listeners.remove(listener);
111: }
112: }
113: }
|