Repository: wicket Updated Branches: refs/heads/wicket-6.x ae76a350f -> 4bec79ffc
WICKET-5778 Pass the IModifiable to the IChangeListener in ModificationWatcher Introduce temporary interface IChangeListener2 that can be used when one needs the changed object as a parameter (cherry picked from commit 2637c1243d061f5d99f0cf10cd3b547359ced187) Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/4bec79ff Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/4bec79ff Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/4bec79ff Branch: refs/heads/wicket-6.x Commit: 4bec79ffc44b0a39471cf6c026cf6017ca21caf4 Parents: ae76a35 Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Thu Nov 27 15:45:17 2014 +0100 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Thu Nov 27 16:14:31 2014 +0100 ---------------------------------------------------------------------- .../wicket/util/listener/ChangeListenerSet.java | 21 ++++++++++++ .../wicket/util/listener/IChangeListener2.java | 34 ++++++++++++++++++++ .../wicket/util/watch/ModificationWatcher.java | 2 +- 3 files changed, 56 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/4bec79ff/wicket-util/src/main/java/org/apache/wicket/util/listener/ChangeListenerSet.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/main/java/org/apache/wicket/util/listener/ChangeListenerSet.java b/wicket-util/src/main/java/org/apache/wicket/util/listener/ChangeListenerSet.java index 651ec60..f69c0fe 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/listener/ChangeListenerSet.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/listener/ChangeListenerSet.java @@ -16,6 +16,8 @@ */ package org.apache.wicket.util.listener; +import org.apache.wicket.util.watch.IModifiable; + /** * Holds a set of IChangeListeners. * @@ -46,4 +48,23 @@ public final class ChangeListenerSet extends ListenerCollection<IChangeListener> } }); } + + public void notifyListeners(final IModifiable modifiable) + { + notify(new INotifier<IChangeListener>() + { + @Override + public void notify(final IChangeListener listener) + { + if (listener instanceof IChangeListener2) + { + ((IChangeListener2) listener).onChange(modifiable); + } + else + { + listener.onChange(); + } + } + }); + } } http://git-wip-us.apache.org/repos/asf/wicket/blob/4bec79ff/wicket-util/src/main/java/org/apache/wicket/util/listener/IChangeListener2.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/main/java/org/apache/wicket/util/listener/IChangeListener2.java b/wicket-util/src/main/java/org/apache/wicket/util/listener/IChangeListener2.java new file mode 100644 index 0000000..d6ffa35 --- /dev/null +++ b/wicket-util/src/main/java/org/apache/wicket/util/listener/IChangeListener2.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.wicket.util.listener; + +import org.apache.wicket.util.watch.IModifiable; + +/** + * Generic "something changed" listener interface that also provides the + * changed object as an argument. + */ +// TODO Wicket 8: Rename to IChangeListener and remove the old one +public interface IChangeListener2<T extends IModifiable> extends IChangeListener +{ + /** + * Client method that is called to indicate that something changed. + * + * @param modifiable The object that has changed + */ + void onChange(T modifiable); +} http://git-wip-us.apache.org/repos/asf/wicket/blob/4bec79ff/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java ---------------------------------------------------------------------- diff --git a/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java b/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java index 8af963d..4f260fa 100644 --- a/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java +++ b/wicket-util/src/main/java/org/apache/wicket/util/watch/ModificationWatcher.java @@ -159,7 +159,7 @@ public class ModificationWatcher implements IModificationWatcher modifiableLastModified.after(entry.lastModifiedTime)) { // Notify all listeners that the modifiable was modified - entry.listeners.notifyListeners(); + entry.listeners.notifyListeners(entry.modifiable); // Update timestamp entry.lastModifiedTime = modifiableLastModified;
