1 11 package org.eclipse.ui.internal; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 21 public class Model { 22 23 26 private Object state; 27 28 31 private List views = new ArrayList (1); 32 33 38 public Model(Object initialState) { 39 state = initialState; 40 } 41 42 47 public Object getState() { 48 return state; 49 } 50 51 58 public void setState(Object newState, IChangeListener toOmit) { 59 if (areEqual(newState, state)) { 60 return; 61 } 62 63 state = newState; 64 65 Iterator iter = views.iterator(); 66 while (iter.hasNext()) { 67 IChangeListener next = (IChangeListener) iter.next(); 68 69 if (next != toOmit) { 70 next.update(true); 71 } 72 } 73 } 74 75 private boolean areEqual(Object o1, Object o2) { 76 if (o1 == null) { 77 return o2 == null; 78 } 79 if (o2 == null) { 80 return false; 81 } 82 83 return o1.equals(o2); 84 } 85 86 92 public void addChangeListener(IChangeListener changeListener) { 93 changeListener.update(false); 94 views.add(changeListener); 95 } 96 97 102 public void removeChangeListener(IChangeListener changeListener) { 103 views.remove(changeListener); 104 } 105 106 } 107 | Popular Tags |