1 11 package org.eclipse.team.internal.core.subscribers; 12 13 import java.util.*; 14 15 import org.eclipse.core.internal.runtime.ListenerList; 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.core.runtime.ISafeRunnable; 18 import org.eclipse.core.runtime.Platform; 19 import org.eclipse.team.core.synchronize.ISyncInfoSetChangeListener; 20 import org.eclipse.team.core.synchronize.SyncInfoSet; 21 22 28 public abstract class ChangeSetCollector { 29 30 private ListenerList listeners = new ListenerList(); 31 private Set sets = new HashSet(); 32 33 private Object [] getListeners() { 34 return listeners.getListeners(); 35 } 36 37 42 protected void fireNameChangedEvent(final ChangeSet set) { 43 if (contains(set)) { 44 Object [] listeners = getListeners(); 45 for (int i = 0; i < listeners.length; i++) { 46 final IChangeSetChangeListener listener = (IChangeSetChangeListener)listeners[i]; 47 Platform.run(new ISafeRunnable() { 48 public void handleException(Throwable exception) { 49 } 51 public void run() throws Exception { 52 listener.nameChanged(set); 53 } 54 }); 55 } 56 } 57 } 58 59 65 protected void fireDefaultChangedEvent(final ChangeSet oldSet, final ChangeSet defaultSet) { 66 Object [] listeners = getListeners(); 67 for (int i = 0; i < listeners.length; i++) { 68 final IChangeSetChangeListener listener = (IChangeSetChangeListener)listeners[i]; 69 Platform.run(new ISafeRunnable() { 70 public void handleException(Throwable exception) { 71 } 73 public void run() throws Exception { 74 listener.defaultSetChanged(oldSet, defaultSet); 75 } 76 }); 77 } 78 } 79 80 84 public void add(final ChangeSet set) { 85 if (!contains(set)) { 86 sets.add(set); 87 set.getSyncInfoSet().addSyncSetChangedListener(getChangeSetChangeListener()); 88 Object [] listeners = getListeners(); 89 for (int i = 0; i < listeners.length; i++) { 90 final IChangeSetChangeListener listener = (IChangeSetChangeListener)listeners[i]; 91 Platform.run(new ISafeRunnable() { 92 public void handleException(Throwable exception) { 93 } 95 public void run() throws Exception { 96 listener.setAdded(set); 97 } 98 }); 99 } 100 } 101 } 102 103 107 public void remove(final ChangeSet set) { 108 if (contains(set)) { 109 set.getSyncInfoSet().removeSyncSetChangedListener(getChangeSetChangeListener()); 110 sets.remove(set); 111 Object [] listeners = getListeners(); 112 for (int i = 0; i < listeners.length; i++) { 113 final IChangeSetChangeListener listener = (IChangeSetChangeListener)listeners[i]; 114 Platform.run(new ISafeRunnable() { 115 public void handleException(Throwable exception) { 116 } 118 public void run() throws Exception { 119 listener.setRemoved(set); 120 } 121 }); 122 } 123 } 124 } 125 126 134 protected abstract ISyncInfoSetChangeListener getChangeSetChangeListener(); 135 136 141 public boolean contains(ChangeSet set) { 142 return sets.contains(set); 143 } 144 145 149 public void addListener(IChangeSetChangeListener listener) { 150 listeners.add(listener); 151 } 152 153 157 public void removeListener(IChangeSetChangeListener listener) { 158 listeners.remove(listener); 159 } 160 161 165 public ChangeSet[] getSets() { 166 return (ChangeSet[]) sets.toArray(new ChangeSet[sets.size()]); 167 } 168 169 172 public void dispose() { 173 } 175 176 180 protected void fireResourcesChangedEvent(final ChangeSet changeSet, final IResource[] allAffectedResources) { 181 Object [] listeners = getListeners(); 182 for (int i = 0; i < listeners.length; i++) { 183 final IChangeSetChangeListener listener = (IChangeSetChangeListener)listeners[i]; 184 Platform.run(new ISafeRunnable() { 185 public void handleException(Throwable exception) { 186 } 188 public void run() throws Exception { 189 listener.resourcesChanged(changeSet, allAffectedResources); 190 } 191 }); 192 } 193 } 194 195 201 protected ChangeSet getChangeSet(SyncInfoSet set) { 202 for (Iterator iter = sets.iterator(); iter.hasNext();) { 203 ChangeSet changeSet = (ChangeSet) iter.next(); 204 if (changeSet.getSyncInfoSet() == set) { 205 return changeSet; 206 } 207 } 208 return null; 209 } 210 } 211 | Popular Tags |