KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > viewers > deferred > AbstractConcurrentModel


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jface.viewers.deferred;
12
13 import org.eclipse.core.runtime.ListenerList;
14
15
16 /**
17  * Abstract base class for all IConcurrentModel implementations. Clients should
18  * subclass this class instead of implementing IConcurrentModel directly.
19  *
20  * @since 3.1
21  */

22 public abstract class AbstractConcurrentModel implements
23         IConcurrentModel {
24
25     private ListenerList listeners = new ListenerList();
26     
27     /* (non-Javadoc)
28      * @see org.eclipse.jface.viewers.deferred.IConcurrentContentProvider#addListener(org.eclipse.jface.viewers.deferred.IConcurrentContentProviderListener)
29      */

30     public void addListener(IConcurrentModelListener listener) {
31         listeners.add(listener);
32     }
33     
34     /**
35      * Fires an add notification to all listeners
36      *
37      * @param added objects added to the set
38      */

39     protected final void fireAdd(Object JavaDoc[] added) {
40         Object JavaDoc[] listenerArray = listeners.getListeners();
41         
42         for (int i = 0; i < listenerArray.length; i++) {
43             IConcurrentModelListener next = (IConcurrentModelListener) listenerArray[i];
44             
45             next.add(added);
46         }
47     }
48
49     /**
50      * Fires a remove notification to all listeners
51      *
52      * @param removed objects removed from the set
53      */

54     protected final void fireRemove(Object JavaDoc[] removed) {
55         Object JavaDoc[] listenerArray = listeners.getListeners();
56         
57         for (int i = 0; i < listenerArray.length; i++) {
58             IConcurrentModelListener next = (IConcurrentModelListener) listenerArray[i];
59             
60             next.remove(removed);
61         }
62     }
63     
64     /**
65      * Fires an update notification to all listeners
66      *
67      * @param updated objects that have changed
68      */

69     protected final void fireUpdate(Object JavaDoc[] updated) {
70         Object JavaDoc[] listenerArray = listeners.getListeners();
71         
72         for (int i = 0; i < listenerArray.length; i++) {
73             IConcurrentModelListener next = (IConcurrentModelListener) listenerArray[i];
74             
75             next.update(updated);
76         }
77     }
78     
79     /**
80      * Returns the array of listeners for this model
81      *
82      * @return the array of listeners for this model
83      */

84     protected final IConcurrentModelListener[] getListeners() {
85         Object JavaDoc[] l = listeners.getListeners();
86         IConcurrentModelListener[] result = new IConcurrentModelListener[l.length];
87         
88         for (int i = 0; i < l.length; i++) {
89             result[i] = (IConcurrentModelListener)l[i];
90         }
91         
92         return result;
93     }
94     
95     /* (non-Javadoc)
96      * @see org.eclipse.jface.viewers.deferred.IConcurrentContentProvider#removeListener(org.eclipse.jface.viewers.deferred.IConcurrentContentProviderListener)
97      */

98     public void removeListener(IConcurrentModelListener listener) {
99         listeners.remove(listener);
100     }
101 }
102
Popular Tags