1 19 package org.netbeans.mdr.handlers; 20 21 import java.util.*; 22 import org.netbeans.api.mdr.events.AttributeEvent; 23 import org.netbeans.mdr.util.EventNotifier; 24 25 29 public final class AttrListWrapper extends AttrCollWrapper implements List { 30 31 32 public AttrListWrapper(FeaturedHandler source, int attrIndex, String attrName) { 33 super(source, attrIndex, attrName); 34 } 35 36 public AttrListWrapper(FeaturedHandler source, Collection inner) { 37 super(source, inner); 38 } 39 40 public List getInnerList() { 41 return (List) getInnerCollection(); 42 } 43 44 public Object remove(int param) { 45 boolean fail = true; 46 lock(true); 47 try { 48 if (storage.eventsEnabled()) { 49 AttributeEvent event = new AttributeEvent( 50 source, 51 isStatic ? AttributeEvent.EVENT_CLASSATTR_REMOVE : AttributeEvent.EVENT_ATTRIBUTE_REMOVE, 52 attrName, 53 get(param), null, 54 param); 55 notifier.firePlannedChange(source, event); 56 } 57 Object result = getInnerList().remove(param); 58 fail = false; 59 return result; 60 } finally { 61 unlock(fail); 62 } 63 } 64 65 public ListIterator listIterator(int param) { 66 lock(false); 67 try { 68 return new AttrListIteratorWrapper(getInnerList().listIterator(param)); 69 } finally { 70 unlock(); 71 } 72 } 73 74 public void add(int param, Object obj) { 75 boolean fail = true; 76 lock(true); 77 try { 78 if (storage.eventsEnabled()) { 79 AttributeEvent event = new AttributeEvent( 80 source, 81 isStatic ? AttributeEvent.EVENT_CLASSATTR_ADD : AttributeEvent.EVENT_ATTRIBUTE_ADD, 82 attrName, 83 null, obj, 84 param); 85 notifier.firePlannedChange(source, event); 86 } 87 getInnerList().add(param, obj); 88 fail = false; 89 } finally { 90 unlock(fail); 91 } 92 } 93 94 public int indexOf(Object obj) { 95 lock(false); 96 try { 97 return getInnerList().indexOf(obj); 98 } finally { 99 unlock(); 100 } 101 } 102 103 public int lastIndexOf(Object obj) { 104 lock(false); 105 try { 106 return getInnerList().lastIndexOf(obj); 107 } finally { 108 unlock(); 109 } 110 } 111 112 public Object get(int param) { 113 lock(false); 114 try { 115 return getInnerList().get(param); 116 } finally { 117 unlock(); 118 } 119 } 120 121 public Object set(int param, Object obj) { 122 boolean fail = true; 123 lock(true); 124 try { 125 if (storage.eventsEnabled()) { 126 AttributeEvent event = new AttributeEvent( 127 source, 128 isStatic ? AttributeEvent.EVENT_CLASSATTR_SET : AttributeEvent.EVENT_ATTRIBUTE_SET, 129 attrName, 130 get(param), obj, 131 param); 132 notifier.firePlannedChange(source, event); 133 } 134 Object result = getInnerList().set(param, obj); 135 fail = false; 136 return result; 137 } finally { 138 unlock(fail); 139 } 140 } 141 142 public boolean addAll(int param, Collection collection) { 143 boolean fail = true; 144 lock(true); 145 try { 146 for (Iterator it = collection.iterator(); it.hasNext();) { 147 add(param++, it.next()); 148 } 149 fail = false; 150 return true; 151 } finally { 152 unlock(fail); 153 } 154 } 155 156 public ListIterator listIterator() { 157 lock(false); 158 try { 159 return new AttrListIteratorWrapper(getInnerList().listIterator()); 160 } finally { 161 unlock(); 162 } 163 } 164 165 public List subList(int param, int param1) { 166 lock(false); 167 try { 168 AttrListWrapper result = new AttrListWrapper(source, getInnerList().subList(param, param1)); 169 result.setAttrName(attrName); 170 return result; 171 } finally { 172 unlock(); 173 } 174 } 175 176 public boolean equals(Object object) { 177 if (object instanceof List) { 178 return super.equals(object); 179 } else { 180 return false; 181 } 182 } 183 184 private final class AttrListIteratorWrapper extends AttrIteratorWrapper implements ListIterator { 185 private final ListIterator innerListIterator; 186 protected int lastReadIndex = 0; 187 188 AttrListIteratorWrapper(ListIterator innerIterator) { 189 super(innerIterator); 190 this.innerListIterator = innerIterator; 191 } 192 193 public int previousIndex() { 194 lock(false); 195 try { 196 return innerListIterator.previousIndex(); 197 } finally { 198 unlock(); 199 } 200 } 201 202 public void set(Object obj) { 203 boolean fail = true; 204 lock(true); 205 try { 206 if (storage.eventsEnabled()) { 207 AttributeEvent event = new AttributeEvent( 208 source, 209 isStatic ? AttributeEvent.EVENT_CLASSATTR_SET : AttributeEvent.EVENT_ATTRIBUTE_SET, 210 attrName, 211 lastRead, obj, 212 lastReadIndex); 213 notifier.firePlannedChange(source, event); 214 } 215 innerListIterator.set(obj); 216 fail = false; 217 } finally { 218 unlock(fail); 219 } 220 } 221 222 public int nextIndex() { 223 lock(false); 224 try { 225 return innerListIterator.nextIndex(); 226 } finally { 227 unlock(); 228 } 229 } 230 231 public boolean hasPrevious() { 232 lock(false); 233 try { 234 return innerListIterator.hasPrevious(); 235 } finally { 236 unlock(); 237 } 238 } 239 240 public void add(Object obj) { 241 boolean fail = true; 242 lock(true); 243 try { 244 if (storage.eventsEnabled()) { 245 AttributeEvent event = new AttributeEvent( 246 source, 247 isStatic ? AttributeEvent.EVENT_CLASSATTR_ADD : AttributeEvent.EVENT_ATTRIBUTE_ADD, 248 attrName, 249 null, obj, 250 nextIndex()); 251 notifier.firePlannedChange(source, event); 252 } 253 innerListIterator.add(obj); 254 fail = false; 255 } finally { 256 unlock(fail); 257 } 258 } 259 260 public final void remove() { 261 boolean fail = true; 262 lock(true); 263 try { 264 if (storage.eventsEnabled()) { 265 AttributeEvent event = new AttributeEvent( 266 source, 267 isStatic ? AttributeEvent.EVENT_CLASSATTR_REMOVE : AttributeEvent.EVENT_ATTRIBUTE_REMOVE, 268 attrName, 269 lastRead, null, 270 lastReadIndex); 271 notifier.firePlannedChange(source, event); 272 } 273 innerIterator.remove(); 274 fail = false; 275 } finally { 276 unlock(fail); 277 } 278 } 279 280 public Object previous() { 281 lock(false); 282 try { 283 lastReadIndex = previousIndex(); 284 return (lastRead = innerListIterator.previous()); 285 } finally { 286 unlock(); 287 } 288 } 289 290 public Object next() { 291 lock(false); 292 try { 293 lastReadIndex = nextIndex(); 294 return super.next(); 295 } finally { 296 unlock(); 297 } 298 } 299 } 300 } 301 | Popular Tags |