View | Details | Raw Unified | Return to bug 199476 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/tests/databinding/observable/set/ObservableSetRealmTest.java (+3 lines)
Lines 23-28 Link Here
23
 */
23
 */
24
public class ObservableSetRealmTest extends AbstractObservableSetRealmTestCase {	
24
public class ObservableSetRealmTest extends AbstractObservableSetRealmTestCase {	
25
	/* package */ class ObservableSetStub extends ObservableSet {
25
	/* package */ class ObservableSetStub extends ObservableSet {
26
		
27
		private static final long serialVersionUID = 4242495692676164527L;
28
26
		/**
29
		/**
27
		 * @param wrappedSet
30
		 * @param wrappedSet
28
		 * @param elementType
31
		 * @param elementType
(-)src/org/eclipse/core/tests/databinding/observable/set/AbstractObservableSetRealmTest.java (+2 lines)
Lines 23-28 Link Here
23
 */
23
 */
24
public class AbstractObservableSetRealmTest extends AbstractObservableSetRealmTestCase {
24
public class AbstractObservableSetRealmTest extends AbstractObservableSetRealmTestCase {
25
	/* package */static class ObservableSetStub extends AbstractObservableSet {
25
	/* package */static class ObservableSetStub extends AbstractObservableSet {
26
		
27
		private static final long serialVersionUID = 6971607995821086519L;
26
		private Set set;
28
		private Set set;
27
29
28
		/* package */ObservableSetStub(Set set) {
30
		/* package */ObservableSetStub(Set set) {
(-)src/org/eclipse/core/tests/databinding/observable/set/WritableSetRealmTest.java (+5 lines)
Lines 31-36 Link Here
31
	}
31
	}
32
	
32
	
33
	private static class WritableSetStub extends WritableSet {
33
	private static class WritableSetStub extends WritableSet {
34
		/**
35
		 * 
36
		 */
37
		private static final long serialVersionUID = -8269348320374796053L;
38
34
		public void getterCalled() {
39
		public void getterCalled() {
35
			super.getterCalled();
40
			super.getterCalled();
36
		}
41
		}
(-)src/org/eclipse/core/tests/databinding/observable/ObservablesTest.java (+3 lines)
Lines 35-40 Link Here
35
	}
35
	}
36
	
36
	
37
	private static class ObservableListStub extends ObservableList {
37
	private static class ObservableListStub extends ObservableList {
38
		
39
		private static final long serialVersionUID = 8982246761243009342L;
40
38
		/**
41
		/**
39
		 * @param wrappedList
42
		 * @param wrappedList
40
		 * @param elementType
43
		 * @param elementType
(-)src/org/eclipse/core/tests/databinding/observable/value/AbstractObservableValueTest.java (+6 lines)
Lines 66-71 Link Here
66
	}
66
	}
67
67
68
	private static class ObservableValueStub extends AbstractObservableValue {
68
	private static class ObservableValueStub extends AbstractObservableValue {
69
		
70
		/**
71
		 * 
72
		 */
73
		private static final long serialVersionUID = -7608277757427191L;
74
		
69
		ObservableValueStub() {
75
		ObservableValueStub() {
70
			super(Realm.getDefault());
76
			super(Realm.getDefault());
71
		}
77
		}
(-)src/org/eclipse/core/tests/internal/databinding/observable/UnmodifiableObservableListTest.java (+3 lines)
Lines 155-160 Link Here
155
	}
155
	}
156
	
156
	
157
	private static class MutableObservableList extends ObservableList {
157
	private static class MutableObservableList extends ObservableList {
158
		
159
		private static final long serialVersionUID = -812319905879339953L;
160
158
		/**
161
		/**
159
		 * @param wrappedList
162
		 * @param wrappedList
160
		 * @param elementType
163
		 * @param elementType
(-)src/org/eclipse/core/tests/databinding/observable/list/ObservableListTest.java (+3 lines)
Lines 110-115 Link Here
110
	}
110
	}
111
111
112
	static class ObservableListStub extends ObservableList {
112
	static class ObservableListStub extends ObservableList {
113
		
114
		private static final long serialVersionUID = 2924018673816795605L;
115
113
		protected ObservableListStub(List wrappedList, Object elementType) {
116
		protected ObservableListStub(List wrappedList, Object elementType) {
114
			super(wrappedList, elementType);
117
			super(wrappedList, elementType);
115
		}
118
		}
(-)src/org/eclipse/core/tests/databinding/observable/list/AbstractObservableListTest.java (+3 lines)
Lines 89-94 Link Here
89
	}
89
	}
90
90
91
	static class AbstractObservableListStub extends AbstractObservableList {
91
	static class AbstractObservableListStub extends AbstractObservableList {
92
		
93
		private static final long serialVersionUID = -6824068597959148550L;
94
92
		protected int doGetSize() {
95
		protected int doGetSize() {
93
			return 0;
96
			return 0;
94
		}
97
		}
(-)src/org/eclipse/core/tests/databinding/SerializableTest.java (+81 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.core.tests.databinding;
13
14
import java.io.ByteArrayInputStream;
15
import java.io.ByteArrayOutputStream;
16
import java.io.IOException;
17
import java.io.ObjectInputStream;
18
import java.io.ObjectOutputStream;
19
import java.io.Serializable;
20
import java.util.ArrayList;
21
import java.util.HashSet;
22
23
import junit.framework.Assert;
24
25
import org.eclipse.core.databinding.observable.list.WritableList;
26
import org.eclipse.core.databinding.observable.set.WritableSet;
27
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
28
29
/**
30
 * @since 3.2
31
 *
32
 */
33
public class SerializableTest extends AbstractDefaultRealmTestCase{
34
	
35
	
36
	
37
	public void testWritableList() throws Exception{
38
		
39
		try{
40
		WritableList list = new WritableList(new ArrayList(), Object.class);
41
		Object obj = doSerializationTest(list);
42
		Assert.assertNotNull(obj);
43
		}catch (Exception x){
44
			x.printStackTrace();
45
			throw x;
46
		}
47
	}
48
	public void testWritableSet() throws Exception{
49
		
50
		try{
51
		WritableSet set = new WritableSet(new HashSet(), Object.class);
52
		Object obj = doSerializationTest(set);
53
		Assert.assertNotNull(obj);
54
		}catch (Exception x){
55
			x.printStackTrace();
56
			throw x;
57
		}
58
	}
59
	private Object doSerializationTest(Serializable s) throws Exception{
60
		byte[] bytes = serialize(s);
61
		Object obj = deserialize(bytes);
62
		return obj;
63
	}
64
	
65
	private byte[] serialize( Serializable s) throws IOException{
66
		ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
67
        ObjectOutputStream out = new ObjectOutputStream(bos) ;
68
        out.writeObject(s);
69
        out.close();
70
        return bos.toByteArray();
71
	}
72
	
73
	private Object deserialize( byte [] bytes) throws IOException,ClassNotFoundException{
74
		ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
75
		ObjectInputStream in = new ObjectInputStream(bis);
76
		Object result = in.readObject();
77
		in.close();
78
		return result;
79
	}
80
81
}
(-)src/org/eclipse/core/databinding/observable/set/WritableSet.java (-1 / +9 lines)
Lines 12-17 Link Here
12
12
13
package org.eclipse.core.databinding.observable.set;
13
package org.eclipse.core.databinding.observable.set;
14
14
15
import java.io.Serializable;
15
import java.util.Collection;
16
import java.util.Collection;
16
import java.util.Collections;
17
import java.util.Collections;
17
import java.util.HashSet;
18
import java.util.HashSet;
Lines 32-38 Link Here
32
 * 
33
 * 
33
 * @since 1.0
34
 * @since 1.0
34
 */
35
 */
35
public class WritableSet extends ObservableSet {
36
public class WritableSet extends ObservableSet implements Serializable{
37
38
	/**
39
	 * 
40
	 */
41
	private static final long serialVersionUID = 1L;
36
42
37
	/**
43
	/**
38
	 * Constructs a new instance with the default realm, empty list, and a
44
	 * Constructs a new instance with the default realm, empty list, and a
Lines 75-80 Link Here
75
		super(realm, new HashSet(c), elementType);
81
		super(realm, new HashSet(c), elementType);
76
		this.elementType = elementType;
82
		this.elementType = elementType;
77
	}
83
	}
84
	
85
	
78
86
79
	public boolean add(Object o) {
87
	public boolean add(Object o) {
80
		checkRealm();
88
		checkRealm();
(-)src/org/eclipse/core/databinding/observable/set/ObservableSet.java (+6 lines)
Lines 40-45 Link Here
40
	private boolean stale = false;
40
	private boolean stale = false;
41
41
42
	protected Object elementType;
42
	protected Object elementType;
43
	
44
	/** necessary for deserialization */
45
	protected ObservableSet(){
46
		super(Realm.getDefault());
47
		
48
	}
43
49
44
	protected ObservableSet(Set wrappedSet, Object elementType) {
50
	protected ObservableSet(Set wrappedSet, Object elementType) {
45
		this(Realm.getDefault(), wrappedSet, elementType);
51
		this(Realm.getDefault(), wrappedSet, elementType);
(-)src/org/eclipse/core/databinding/observable/ChangeManager.java (-1 / +6 lines)
Lines 25-31 Link Here
25
25
26
	ListenerList[] listenerLists = null;
26
	ListenerList[] listenerLists = null;
27
	Object listenerTypes[] = null;
27
	Object listenerTypes[] = null;
28
	private Realm realm;
28
	// this is not to be serialized
29
	private transient Realm realm;
30
	
31
	
29
32
30
	/**
33
	/**
31
	 * @param realm 
34
	 * @param realm 
Lines 35-40 Link Here
35
		Assert.isNotNull(realm);
38
		Assert.isNotNull(realm);
36
		this.realm = realm;
39
		this.realm = realm;
37
	}
40
	}
41
	
42
	
38
43
39
	/**
44
	/**
40
	 * @param listenerType
45
	 * @param listenerType
(-)src/org/eclipse/core/databinding/observable/list/WritableList.java (-1 / +10 lines)
Lines 14-19 Link Here
14
 *******************************************************************************/
14
 *******************************************************************************/
15
package org.eclipse.core.databinding.observable.list;
15
package org.eclipse.core.databinding.observable.list;
16
16
17
import java.io.Serializable;
17
import java.util.ArrayList;
18
import java.util.ArrayList;
18
import java.util.Collection;
19
import java.util.Collection;
19
import java.util.Iterator;
20
import java.util.Iterator;
Lines 33-39 Link Here
33
 * 
34
 * 
34
 * @since 1.0
35
 * @since 1.0
35
 */
36
 */
36
public class WritableList extends ObservableList {
37
public class WritableList extends ObservableList implements Serializable{
38
39
	/**
40
	 * 
41
	 */
42
	private static final long serialVersionUID = 1L;
37
43
38
	/**
44
	/**
39
	 * Creates an empty writable list in the default realm with a
45
	 * Creates an empty writable list in the default realm with a
Lines 78-83 Link Here
78
		super(realm, toWrap, elementType);
84
		super(realm, toWrap, elementType);
79
	}
85
	}
80
86
87
	
88
89
81
	public Object set(int index, Object element) {
90
	public Object set(int index, Object element) {
82
		checkRealm();
91
		checkRealm();
83
		Object oldElement = wrappedList.set(index, element);
92
		Object oldElement = wrappedList.set(index, element);
(-)src/org/eclipse/core/databinding/observable/list/ObservableList.java (-46 / +58 lines)
Lines 25-36 Link Here
25
25
26
/**
26
/**
27
 * 
27
 * 
28
 * Abstract implementation of {@link IObservableList}, based on an underlying regular list. 
28
 * Abstract implementation of {@link IObservableList}, based on an underlying
29
 * regular list.
29
 * <p>
30
 * <p>
30
 * This class is thread safe. All state accessing methods must be invoked from
31
 * This class is thread safe. All state accessing methods must be invoked from
31
 * the {@link Realm#isCurrent() current realm}. Methods for adding and removing
32
 * the {@link Realm#isCurrent() current realm}. Methods for adding and removing
32
 * listeners may be invoked from any thread.
33
 * listeners may be invoked from any thread.
33
 * </p>
34
 * </p>
35
 * 
34
 * @since 1.0
36
 * @since 1.0
35
 * 
37
 * 
36
 */
38
 */
Lines 40-51 Link Here
40
	protected List wrappedList;
42
	protected List wrappedList;
41
43
42
	/**
44
	/**
43
	 * Stale state of the list.  Access must occur in the current realm.
45
	 * Stale state of the list. Access must occur in the current realm.
44
	 */
46
	 */
45
	private boolean stale = false;
47
	private boolean stale = false;
46
48
47
	private Object elementType;
49
	private Object elementType;
48
50
51
	/** 
52
	 * needed for deserialization 
53
	 */
54
	protected ObservableList() {
55
		super(Realm.getDefault());
56
	}
57
49
	protected ObservableList(List wrappedList, Object elementType) {
58
	protected ObservableList(List wrappedList, Object elementType) {
50
		this(Realm.getDefault(), wrappedList, elementType);
59
		this(Realm.getDefault(), wrappedList, elementType);
51
	}
60
	}
Lines 60-66 Link Here
60
		addListener(ListChangeEvent.TYPE, listener);
69
		addListener(ListChangeEvent.TYPE, listener);
61
	}
70
	}
62
71
63
	public synchronized void removeListChangeListener(IListChangeListener listener) {
72
	public synchronized void removeListChangeListener(
73
			IListChangeListener listener) {
64
		removeListener(ListChangeEvent.TYPE, listener);
74
		removeListener(ListChangeEvent.TYPE, listener);
65
	}
75
	}
66
76
Lines 69-75 Link Here
69
		super.fireChange();
79
		super.fireChange();
70
		fireEvent(new ListChangeEvent(this, diff));
80
		fireEvent(new ListChangeEvent(this, diff));
71
	}
81
	}
72
	
82
73
	public boolean contains(Object o) {
83
	public boolean contains(Object o) {
74
		getterCalled();
84
		getterCalled();
75
		return wrappedList.contains(o);
85
		return wrappedList.contains(o);
Lines 133-177 Link Here
133
		getterCalled();
143
		getterCalled();
134
		return wrappedList.toString();
144
		return wrappedList.toString();
135
	}
145
	}
136
	
146
137
	/**
147
	/**
138
	 * @TrackedGetter
148
	 * @TrackedGetter
139
	 */
149
	 */
140
    public Object get(int index) {
150
	public Object get(int index) {
141
    	getterCalled();
151
		getterCalled();
142
    	return wrappedList.get(index);
152
		return wrappedList.get(index);
143
    }
153
	}
144
154
145
	/**
155
	/**
146
	 * @TrackedGetter
156
	 * @TrackedGetter
147
	 */
157
	 */
148
    public int indexOf(Object o) {
158
	public int indexOf(Object o) {
149
    	getterCalled();
159
		getterCalled();
150
    	return wrappedList.indexOf(o);
160
		return wrappedList.indexOf(o);
151
    }
161
	}
152
162
153
	/**
163
	/**
154
	 * @TrackedGetter
164
	 * @TrackedGetter
155
	 */
165
	 */
156
    public int lastIndexOf(Object o) {
166
	public int lastIndexOf(Object o) {
157
    	getterCalled();
167
		getterCalled();
158
    	return wrappedList.lastIndexOf(o);
168
		return wrappedList.lastIndexOf(o);
159
    }
169
	}
160
170
161
    // List Iterators
171
	// List Iterators
162
172
163
	/**
173
	/**
164
	 * @TrackedGetter
174
	 * @TrackedGetter
165
	 */
175
	 */
166
    public ListIterator listIterator() {
176
	public ListIterator listIterator() {
167
    	return listIterator(0);
177
		return listIterator(0);
168
    }
178
	}
169
179
170
	/**
180
	/**
171
	 * @TrackedGetter
181
	 * @TrackedGetter
172
	 */
182
	 */
173
    public ListIterator listIterator(int index) {
183
	public ListIterator listIterator(int index) {
174
    	getterCalled();
184
		getterCalled();
175
		final ListIterator wrappedIterator = wrappedList.listIterator(index);
185
		final ListIterator wrappedIterator = wrappedList.listIterator(index);
176
		return new ListIterator() {
186
		return new ListIterator() {
177
187
Lines 211-235 Link Here
211
				throw new UnsupportedOperationException();
221
				throw new UnsupportedOperationException();
212
			}
222
			}
213
		};
223
		};
214
    }
224
	}
215
216
225
217
    public List subList(int fromIndex, int toIndex) {
226
	public List subList(int fromIndex, int toIndex) {
218
    	getterCalled();
227
		getterCalled();
219
    	return wrappedList.subList(fromIndex, toIndex);
228
		return wrappedList.subList(fromIndex, toIndex);
220
    }
229
	}
221
230
222
	protected void getterCalled() {
231
	protected void getterCalled() {
223
		ObservableTracker.getterCalled(this);
232
		ObservableTracker.getterCalled(this);
224
	}
233
	}
225
234
226
    public Object set(int index, Object element) {
235
	public Object set(int index, Object element) {
227
    	throw new UnsupportedOperationException();
236
		throw new UnsupportedOperationException();
228
    }
237
	}
229
238
230
    public Object remove(int index) {
239
	public Object remove(int index) {
231
    	throw new UnsupportedOperationException();
240
		throw new UnsupportedOperationException();
232
    }
241
	}
233
242
234
	public boolean add(Object o) {
243
	public boolean add(Object o) {
235
		throw new UnsupportedOperationException();
244
		throw new UnsupportedOperationException();
Lines 238-251 Link Here
238
	public void add(int index, Object element) {
247
	public void add(int index, Object element) {
239
		throw new UnsupportedOperationException();
248
		throw new UnsupportedOperationException();
240
	}
249
	}
241
	
250
242
	public boolean addAll(Collection c) {
251
	public boolean addAll(Collection c) {
243
		throw new UnsupportedOperationException();
252
		throw new UnsupportedOperationException();
244
	}
253
	}
245
254
246
    public boolean addAll(int index, Collection c) {
255
	public boolean addAll(int index, Collection c) {
247
    	throw new UnsupportedOperationException();
256
		throw new UnsupportedOperationException();
248
    }
257
	}
249
258
250
	public boolean remove(Object o) {
259
	public boolean remove(Object o) {
251
		throw new UnsupportedOperationException();
260
		throw new UnsupportedOperationException();
Lines 264-270 Link Here
264
	}
273
	}
265
274
266
	/**
275
	/**
267
	 * Returns the stale state.  Must be invoked from the current realm.
276
	 * Returns the stale state. Must be invoked from the current realm.
268
	 * 
277
	 * 
269
	 * @return stale state
278
	 * @return stale state
270
	 */
279
	 */
Lines 274-280 Link Here
274
	}
283
	}
275
284
276
	/**
285
	/**
277
	 * Sets the stale state.  Must be invoked from the current realm.
286
	 * Sets the stale state. Must be invoked from the current realm.
278
	 * 
287
	 * 
279
	 * @param stale
288
	 * @param stale
280
	 *            The stale state to list. This will fire a stale event if the
289
	 *            The stale state to list. This will fire a stale event if the
Lines 292-307 Link Here
292
	}
301
	}
293
302
294
	protected void fireChange() {
303
	protected void fireChange() {
295
		throw new RuntimeException("fireChange should not be called, use fireListChange() instead"); //$NON-NLS-1$
304
		throw new RuntimeException(
305
				"fireChange should not be called, use fireListChange() instead"); //$NON-NLS-1$
296
	}
306
	}
297
	
307
298
	/* (non-Javadoc)
308
	/*
309
	 * (non-Javadoc)
310
	 * 
299
	 * @see org.eclipse.jface.provisional.databinding.observable.AbstractObservable#dispose()
311
	 * @see org.eclipse.jface.provisional.databinding.observable.AbstractObservable#dispose()
300
	 */
312
	 */
301
	public synchronized void dispose() {
313
	public synchronized void dispose() {
302
		super.dispose();
314
		super.dispose();
303
	}
315
	}
304
	
316
305
	public Object getElementType() {
317
	public Object getElementType() {
306
		return elementType;
318
		return elementType;
307
	}
319
	}

Return to bug 199476