1 11 package org.eclipse.jface.viewers.deferred; 12 13 import java.util.Collection ; 14 import java.util.HashSet ; 15 16 import org.eclipse.core.runtime.Assert; 17 18 19 27 public class SetModel extends AbstractConcurrentModel { 28 29 private HashSet data = new HashSet (); 30 31 36 public Object [] getElements() { 37 return data.toArray(); 38 } 39 40 45 public void set(Object [] newContents) { 46 Assert.isNotNull(newContents); 47 data.clear(); 48 for (int i = 0; i < newContents.length; i++) { 49 Object object = newContents[i]; 50 51 data.add(object); 52 } 53 54 IConcurrentModelListener[] listeners = getListeners(); 55 for (int i = 0; i < listeners.length; i++) { 56 IConcurrentModelListener listener = listeners[i]; 57 58 listener.setContents(newContents); 59 } 60 } 61 62 65 public void clear() { 66 Object [] removed = data.toArray(); 67 data.clear(); 68 fireRemove(removed); 69 } 70 71 76 public void addAll(Object [] toAdd) { 77 Assert.isNotNull(toAdd); 78 for (int i = 0; i < toAdd.length; i++) { 79 Object object = toAdd[i]; 80 81 data.add(object); 82 } 83 84 fireAdd(toAdd); 85 } 86 87 92 public void addAll(Collection toAdd) { 93 Assert.isNotNull(toAdd); 94 addAll(toAdd.toArray()); 95 } 96 97 102 public void changeAll(Object [] changed) { 103 Assert.isNotNull(changed); 104 fireUpdate(changed); 105 } 106 107 112 public void removeAll(Object [] toRemove) { 113 Assert.isNotNull(toRemove); 114 for (int i = 0; i < toRemove.length; i++) { 115 Object object = toRemove[i]; 116 117 data.remove(object); 118 } 119 120 fireRemove(toRemove); 121 } 122 123 126 public void requestUpdate(IConcurrentModelListener listener) { 127 Assert.isNotNull(listener); 128 listener.setContents(getElements()); 129 } 130 } 131 | Popular Tags |