KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > edit > provider > ChangeNotifier


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2002-2004 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: ChangeNotifier.java,v 1.2 2005/06/08 06:17:05 nickb Exp $
16  */

17 package org.eclipse.emf.edit.provider;
18
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 import org.eclipse.emf.common.notify.Notification;
24
25
26 /**
27  * This is a simple and obvious implementation of {@link IChangeNotifier} as an extension of an ArrayList, for flexibility.
28  */

29 public class ChangeNotifier extends ArrayList JavaDoc implements IChangeNotifier
30 {
31   public ChangeNotifier()
32   {
33   }
34
35   /**
36    * This calls {@link org.eclipse.emf.edit.provider.INotifyChangedListener#notifyChanged notifyChanged} for each listener.
37    */

38   public void fireNotifyChanged(Notification notification)
39   {
40     for (Iterator JavaDoc listeners = new ArrayList JavaDoc(this).iterator(); listeners.hasNext(); )
41     {
42       INotifyChangedListener notifyChangedListener = (INotifyChangedListener)listeners.next();
43       if (this.contains(notifyChangedListener))
44       {
45         notifyChangedListener.notifyChanged(notification);
46       }
47     }
48   }
49
50   /**
51    * This adds another listener.
52    */

53   public void addListener(INotifyChangedListener notifyChangedListener)
54   {
55     add(notifyChangedListener);
56   }
57
58   /**
59    * This removes a listener.
60    */

61   public void removeListener(INotifyChangedListener notifyChangedListener)
62   {
63     remove(notifyChangedListener);
64   }
65 }
66
Popular Tags