KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > base > entitylist > EntityManagementTightComposite


1 /*
2  * Created on Jun 12, 2005
3  *
4  */

5 package com.nightlabs.base.entitylist;
6
7 import java.util.HashSet JavaDoc;
8 import java.util.Iterator JavaDoc;
9 import java.util.Set JavaDoc;
10
11 import org.eclipse.swt.widgets.Composite;
12
13 import com.nightlabs.rcp.composite.TightWrapperComposite;
14
15
16 /**
17  * @author Niklas Schiffler <nick@nightlabs.de>
18  *
19  */

20 public abstract class EntityManagementTightComposite extends TightWrapperComposite implements EntityManager
21 {
22     protected Set JavaDoc dataChangedListeners;
23     
24     public EntityManagementTightComposite(Composite parent, int style)
25     {
26         this(parent, style, false);
27     }
28
29     public EntityManagementTightComposite(Composite parent, int style, boolean doSetLayoutData)
30     {
31         super(parent, style, doSetLayoutData);
32         dataChangedListeners = new HashSet JavaDoc();
33     }
34
35     /**
36    * Call this when you modified the entity object.
37    *
38    */

39   public void notifyDataChangedListeners()
40   {
41     Iterator JavaDoc i = dataChangedListeners.iterator();
42     while(i.hasNext())
43         ((EntityDataChangedListener)i.next()).entityDataChanged(this);
44   }
45
46   /**
47    * Listen for modifications of the entity object
48    * @param listener your listener
49    */

50   public void addDataChangedListener(EntityDataChangedListener listener)
51   {
52     if(!dataChangedListeners.contains(listener))
53         dataChangedListeners.add(listener);
54   }
55
56   /**
57    * Remove a listener
58    * @param listener the listener
59    */

60   public void removeDataChangedListener(EntityDataChangedListener listener)
61   {
62     if(dataChangedListeners.contains(listener))
63         dataChangedListeners.remove(listener);
64   }
65     
66     private boolean changed = false;
67     
68     public void setChanged(boolean changed) {
69         this.changed = changed;
70         if (changed)
71             notifyDataChangedListeners();
72     }
73     
74     public boolean isChanged() {
75         return changed;
76     }
77     
78   public void dispose()
79   {
80     super.dispose();
81     dataChangedListeners.clear();
82     dataChangedListeners = null;
83   }
84
85 }
86
Popular Tags