Revision 8800 org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/operations/DefaultOperationList.java

View differences:

DefaultOperationList.java
45 45
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory.Applicable;
46 46
import org.gvsig.raster.lib.buffer.api.operations.OperationList;
47 47
import org.gvsig.raster.lib.buffer.api.operations.OperationListEntry;
48
import org.gvsig.raster.lib.buffer.api.operations.OperationListNotification;
48 49
import org.gvsig.tools.ToolsLocator;
49 50
import org.gvsig.tools.dynobject.DynClass;
50 51
import org.gvsig.tools.dynobject.DynField;
51 52
import org.gvsig.tools.dynobject.DynField_v2;
52 53
import org.gvsig.tools.dynobject.DynObject;
53 54
import org.gvsig.tools.dynobject.DynStruct;
55
import org.gvsig.tools.observer.impl.BaseWeakReferencingObservable;
54 56
import org.gvsig.tools.persistence.PersistenceManager;
55 57
import org.gvsig.tools.persistence.PersistentState;
56 58
import org.gvsig.tools.persistence.exception.PersistenceException;
57
import org.gvsig.tools.lang.Cloneable;
58 59

  
59 60

  
60 61
/**
61 62
 * @author fdiaz
62 63
 *
63 64
 */
64
public class DefaultOperationList implements OperationList {
65
public class DefaultOperationList extends BaseWeakReferencingObservable implements OperationList {
65 66

  
66 67
    private static final Logger LOG = LoggerFactory.getLogger(DefaultOperationList.class);
67 68

  
......
120 121

  
121 122
    @Override
122 123
    public boolean add(OperationListEntry e) {
123
        return this.operations.add(e);
124
        ArrayList<OperationListEntry> oldOperations = this.cloneOperations();
125
        boolean result = this.operations.add(e);
126
        this.notifyObservers(new DefaultOperationListNotification(OperationListNotification.ADDED_ENTRY, new Object[] {
127
            oldOperations, this.operations }));
128

  
129
        return result;
124 130
    }
125 131

  
126 132
    @Override
127 133
    public boolean remove(Object o) {
128
        return this.operations.remove(o);
134
        ArrayList<OperationListEntry> oldOperations = this.cloneOperations();
135
        boolean result = this.operations.remove(o);
136
        this.notifyObservers(new DefaultOperationListNotification(OperationListNotification.REMOVED_ENTRY, new Object[] {
137
            oldOperations, this.operations }));
138
        return result;
129 139
    }
130 140

  
131 141
    @Override
......
135 145

  
136 146
    @Override
137 147
    public boolean addAll(Collection<? extends OperationListEntry> c) {
138
        return this.operations.addAll(c);
148
        ArrayList<OperationListEntry> oldOperations = this.cloneOperations();
149
        boolean result = this.operations.addAll(c);
150
        this.notifyObservers(new DefaultOperationListNotification(OperationListNotification.ADDED_ENTRIES, new Object[] {
151
            oldOperations, this.operations }));
152
        return result;
139 153
    }
140 154

  
141 155
    @Override
142 156
    public boolean addAll(int index, Collection<? extends OperationListEntry> c) {
143
        return this.operations.addAll(index, c);
157
        ArrayList<OperationListEntry> oldOperations = this.cloneOperations();
158
        boolean result = this.operations.addAll(index, c);
159
        this.notifyObservers(new DefaultOperationListNotification(OperationListNotification.ADDED_ENTRIES, new Object[] {
160
            oldOperations, this.operations }));
161
        return result;
144 162
    }
145 163

  
146 164
    @Override
147 165
    public boolean removeAll(Collection<?> c) {
148
        return this.operations.removeAll(c);
166
        ArrayList<OperationListEntry> oldOperations = this.cloneOperations();
167
        boolean result = this.operations.removeAll(c);
168
        this.notifyObservers(new DefaultOperationListNotification(OperationListNotification.REMOVED_ENTRIES, new Object[] {
169
            oldOperations, this.operations }));
170
        return result;
149 171
    }
150 172

  
151 173
    @Override
152 174
    public boolean retainAll(Collection<?> c) {
153
        return this.operations.retainAll(c);
175
        ArrayList<OperationListEntry> oldOperations = this.cloneOperations();
176
        boolean result = this.operations.retainAll(c);
177
        this.notifyObservers(new DefaultOperationListNotification(OperationListNotification.RETAINED_ENTRIES, new Object[] {
178
            oldOperations, this.operations }));
179
        return result;
154 180
    }
155 181

  
156 182
    @Override
157 183
    public void clear() {
184
        ArrayList<OperationListEntry> oldOperations = this.cloneOperations();
158 185
        this.operations.clear();
186
        this.notifyObservers(new DefaultOperationListNotification(OperationListNotification.CLEAR_ENTRIES, new Object[] {
187
            oldOperations, this.operations }));
159 188
    }
160 189

  
161 190
    @Override
......
165 194

  
166 195
    @Override
167 196
    public OperationListEntry set(int index, OperationListEntry element) {
168
        return this.operations.set(index, element);
197
        ArrayList<OperationListEntry> oldOperations = this.cloneOperations();
198
        OperationListEntry result = this.operations.set(index, element);
199
        this.notifyObservers(new DefaultOperationListNotification(OperationListNotification.SETTED_ENTRY, new Object[] {
200
            oldOperations, this.operations }));
201
        return result;
169 202
    }
170 203

  
171 204
    @Override
172 205
    public void add(int index, OperationListEntry element) {
206
        ArrayList<OperationListEntry> oldOperations = this.cloneOperations();
173 207
        if(index<0){
174 208
            index = this.operations.size()+index;
175 209
        }
176 210
        this.operations.add(index, element);
211
        this.notifyObservers(new DefaultOperationListNotification(OperationListNotification.ADDED_ENTRY, new Object[] {
212
            oldOperations, this.operations }));
177 213
    }
178 214

  
179 215
    @Override
180 216
    public OperationListEntry remove(int index) {
181
        return this.operations.remove(index);
217
        ArrayList<OperationListEntry> oldOperations = this.cloneOperations();
218
        OperationListEntry result = this.operations.remove(index);
219
        this.notifyObservers(new DefaultOperationListNotification(OperationListNotification.REMOVED_ENTRY, new Object[] {
220
            oldOperations, this.operations }));
221
        return result;
182 222
    }
183 223

  
184 224
    @Override
......
240 280

  
241 281
    @Override
242 282
    public void add(Operation operation, DynObject parameters) {
283
        ArrayList<OperationListEntry> oldOperations = this.cloneOperations();
243 284
        OperationManager operationManager = ((OperationManager)BufferLocator.getBufferManager());
244 285
        OperationListEntry entry = operationManager.createOperationListEntry(operation, parameters);
245 286
        this.operations.add(entry);
287
        this.notifyObservers(new DefaultOperationListNotification(OperationListNotification.ADDED_ENTRY, new Object[] {
288
            oldOperations, this.operations }));
246 289
    }
247 290

  
248 291
    @Override
249 292
    public void add(int index, Operation operation, DynObject parameters) {
293
        ArrayList<OperationListEntry> oldOperations = this.cloneOperations();
250 294
        OperationManager operationManager = ((OperationManager)BufferLocator.getBufferManager());
251 295
        OperationListEntry entry = operationManager.createOperationListEntry(operation, parameters);
252 296
        this.operations.add(index, entry);
297
        this.notifyObservers(new DefaultOperationListNotification(OperationListNotification.ADDED_ENTRY, new Object[] {
298
            oldOperations, this.operations }));
253 299
    }
254 300

  
255 301
    @Override
......
374 420
        return;
375 421
    }
376 422

  
423
    private ArrayList<OperationListEntry> cloneOperations() {
424
        ArrayList<OperationListEntry> clonedOperations = null;
425
        if (operations != null) {
426
            try {
427
                clonedOperations = new ArrayList(operations.size());
428
                for (int i = 0; i < operations.size(); i++) {
429
                    clonedOperations.add((OperationListEntry) operations.get(i).clone());
430
                }
431
            } catch (CloneNotSupportedException e) {
432
                LOG.warn("Can't clone operation list", e);
433
            }
434
        }
435
        return clonedOperations;
436
    }
437

  
377 438
    @Override
378 439
    public Object clone() throws CloneNotSupportedException {
379 440
        OperationList cloned = new DefaultOperationList();
380 441

  
381 442
        if (operations != null) {
382
            ArrayList<OperationListEntry> cloneOperations = new ArrayList(operations.size());
383 443
            for (int i = 0; i < operations.size(); i++) {
384 444
                cloned.add((OperationListEntry) operations.get(i).clone());
385 445
            }

Also available in: Unified diff