1 19 20 package org.netbeans; 21 22 import java.util.logging.Level ; 23 import org.openide.util.Utilities; 24 import java.util.*; 25 26 35 final class ChangeFirer { 36 37 private final ModuleManager mgr; 38 private final Set<Change> changes = new LinkedHashSet<Change>(100); 40 private final Set<Module> modulesCreated = new HashSet<Module>(100); 41 private final Set<Module> modulesDeleted = new HashSet<Module>(10); 42 43 46 public ChangeFirer(ModuleManager mgr) { 47 this.mgr = mgr; 48 } 49 50 53 public void change(Change c) { 54 changes.add(c); 55 } 56 57 60 public void created(Module m) { 61 modulesCreated.add(m); 62 } 63 64 68 public void deleted(Module m) { 69 if (! modulesCreated.remove(m)) { 72 modulesDeleted.add(m); 73 } 74 } 75 76 80 public void fire() { 81 mgr.readOnly(true); 82 try { 83 for (Change c: changes) { 84 if (c.source instanceof Module) { 85 ((Module) c.source).firePropertyChange0(c.prop, c.old, c.nue); 86 } else if (c.source == mgr) { 87 mgr.firePropertyChange(c.prop, c.old, c.nue); 88 } else { 89 throw new IllegalStateException ("Strange source: " + c.source); } 91 } 92 changes.clear(); 93 if (! modulesCreated.isEmpty() || ! modulesDeleted.isEmpty()) { 94 mgr.fireModulesCreatedDeleted(modulesCreated, modulesDeleted); 95 } 96 modulesCreated.clear(); 97 modulesDeleted.clear(); 98 } catch (RuntimeException e) { 99 Util.err.log(Level.SEVERE, null, e); 101 } finally { 102 mgr.readOnly(false); 103 } 104 } 105 106 109 public static final class Change { 110 public final String prop; 111 public final Object source, old, nue; 112 public Change(Object source, String prop, Object old, Object nue) { 113 this.source = source; 114 this.prop = prop; 115 this.old = old; 116 this.nue = nue; 117 } 118 public boolean equals(Object o) { 120 if (! (o instanceof Change)) return false; 121 Change c = (Change) o; 122 return Utilities.compareObjects(prop, c.prop) && 123 Utilities.compareObjects(source, c.source) && 124 Utilities.compareObjects(old, c.old) && 125 Utilities.compareObjects(nue, c.nue); 126 } 127 public int hashCode() { 128 return source.hashCode() ^ (prop == null ? 0 : prop.hashCode()); 129 } 130 public String toString() { 131 return "Change[" + source + ":" + prop + ";" + old + "->" + nue + "]"; } 133 } 134 135 } 136 | Popular Tags |