001 /* 002 * Copyright 2002-2004 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 005 * use this file except in compliance with the License. You may obtain a copy of 006 * 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, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations under 014 * the License. 015 */ 016 package org.springframework.binding.value; 017 018 import java.util.Iterator; 019 020 import org.springframework.richclient.util.EventListenerListHelper; 021 022 /** 023 * A class that can be used to trigger an event on a group of objects. Mainly 024 * intended to be used to trigger flush/revert in 025 * <code>BufferedValueModel</code> but is useful in general. 026 * 027 * @author Keith Donald 028 * @author Oliver Hutchison 029 */ 030 public class CommitTrigger { 031 032 private final EventListenerListHelper listeners = new EventListenerListHelper(CommitTriggerListener.class); 033 034 /** 035 * Constructs a <code>CommitTrigger</code>. 036 */ 037 public CommitTrigger() { 038 } 039 040 /** 041 * Triggers a commit event. 042 */ 043 public void commit() { 044 for (Iterator i = listeners.iterator(); i.hasNext();) { 045 ((CommitTriggerListener) i.next()).commit(); 046 } 047 } 048 049 /** 050 * Triggers a revert event. 051 */ 052 public void revert() { 053 for (Iterator i = listeners.iterator(); i.hasNext();) { 054 ((CommitTriggerListener) i.next()).revert(); 055 } 056 } 057 058 /** 059 * Adds the provided listener to the list of listeners that will be notified 060 * whenever a commit or revert event is fired. 061 * 062 * @param listener the <code>CommitTriggerListener</code> to add 063 */ 064 public void addCommitTriggerListener(CommitTriggerListener listener) { 065 listeners.add(listener); 066 } 067 068 /** 069 * Removed the provided listener to the list of listeners that will be 070 * notified whenever a commit or revert event is fired. 071 * 072 * @param listener the <code>CommitTriggerListener</code> to remove 073 */ 074 public void removeCommitTriggerListener(CommitTriggerListener listener) { 075 listeners.remove(listener); 076 } 077 }