Project

General

Profile

« Previous | Next » 

Revision c6a0dc85

Added by Pepe Ciardelli over 15 years ago

Fixed infinite loop bug caused by making a ProperySheet field editable while at the same time returning an IPropertySource with which its child fields are built.

View differences:

eclipseprojects/eu.etaxonomy.taxeditor/src/eu/etaxonomy/taxeditor/propertysheet/type/TypeCollectionPropertySource.java
27 27
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
28 28
import eu.etaxonomy.cdm.model.reference.Generic;
29 29
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
30
import eu.etaxonomy.taxeditor.model.CdmUtil;
31 30
import eu.etaxonomy.taxeditor.propertysheet.CollectionPropertySource;
32 31
import eu.etaxonomy.taxeditor.propertysheet.reference.ReferencePropertySource;
33 32

  
......
50 49
					new PropertyDescriptor(item, itemDisplayName));
51 50
		} else {
52 51
			
53
			// TextPropertyDescriptor expects its value to be set w/ a String and throws
54
			//	an Assert exception when this is not the case, i.e. when it is passed an 
55
			//	IPropertySource; hence, this override
52
			/* Two issues here, caused by making a ProperySheet field editable while at the same
53
			 *  time returning an IPropertySource with which its child fields are built.
54
			 *  
55
			 * First, TextPropertyDescriptor expects its value to be set w/ a String and 
56
			 *  throws an Assert exception when this is not the case, i.e. when it is passed an
57
			 *  IPropertySource; hence, the override of doSetValue().
58
			 *  
59
			 * Second, the super implementation of doGetValue() was causing the equality test in
60
			 *  PropertySheetEntry:140 to return false: it was comparing the IPropertySource with 
61
			 *  the CellEditor's text String, thereby triggering an infinite loop where the cell's
62
			 *  previous state would never equals the cell's current state. Hence, the 
63
			 *  IPropertySource is now saved in the field editorValue for comparison.
64
			 */
56 65
			descriptors.addElement(
57 66
					new TextPropertyDescriptor(item, itemDisplayName) {
58 67
					    public CellEditor createPropertyEditor(Composite parent) {
59 68
					        CellEditor editor = new TextCellEditor(parent) {
69
					        	Object editorValue;
60 70
					            protected void doSetValue(Object value) {
61 71
					            	if (value instanceof String) {
62 72
					            		super.doSetValue(value);
63 73
					            	} else {
74
					            		editorValue = value;
64 75
					            		super.doSetValue(value.toString());
65 76
					            	}				            		
66 77
					            }
78
					            protected Object doGetValue() {
79
					            	return editorValue;
80
					            }
67 81
					        };
68 82
					        if (getValidator() != null) {
69 83
								editor.setValidator(getValidator());
......
105 119

  
106 120
	@Override
107 121
	public Object getPropertyValue(Object id) {
108
		String str = "";
109 122
		
110 123
		if (id instanceof TypeDesignationBase) {
111
			
112
			final TypeDesignationBase typeDesignation = (TypeDesignationBase) id;
113
			
114
			return new IPropertySource() {
115

  
116
				@Override
117
				public Object getEditableValue() {
118
					return this;
119
				}
120

  
121
				@Override
122
				public IPropertyDescriptor[] getPropertyDescriptors() {
123
					return new IPropertyDescriptor[]{
124
							new PropertyDescriptor(
125
									typeDesignation, "Citation")
126
					};
127
				}
128

  
129
				@Override
130
				public Object getPropertyValue(Object id) {
131
					ReferenceBase reference = typeDesignation.getCitation();
132
					if (reference == null) {
133
						reference = Generic.NewInstance();
134
					}
135
					ReferencePropertySource referencePropertySource = new ReferencePropertySource(reference);
136
					referencePropertySource.addPropertyChangeListener(new PropertyChangeListener() {
137
						public void propertyChange(PropertyChangeEvent evt) {
138
							if (evt.getNewValue() instanceof ReferenceBase) {	
139
								typeDesignation.setCitation((ReferenceBase) evt.getNewValue());
140
							}
141
						}
142
					});
143
					return referencePropertySource;
144
				}
145

  
146
				@Override
147
				public boolean isPropertySet(Object id) {
148
					return false;
149
				}
150

  
151
				@Override
152
				public void resetPropertyValue(Object id) {}
153

  
154
				@Override
155
				public void setPropertyValue(Object id, Object value) {
156
				}
157
				
158
				public String toString() {
159
					if (typeDesignation instanceof SpecimenTypeDesignation) {
160
						return ((SpecimenTypeDesignation) typeDesignation).getTypeSpecimen().getTitleCache();
161
					}
162
					
163
					if (typeDesignation instanceof NameTypeDesignation) {
164
						if (((NameTypeDesignation) typeDesignation).getTypeName() != null) {
165
							return ((NameTypeDesignation) typeDesignation).getTypeName().getTitleCache();
166
						}
167
					}
168
					
169
					return null;
170
				}
171
			};
172
			
124
			return new TypeDesignationPropertySource((TypeDesignationBase) id);
173 125
		}
174
		return str;
126
		return null;
175 127
	}	
176 128
	
177 129
	@Override
......
195 147
	public String toString() {
196 148
		return "";
197 149
	}
150
	
151
	class TypeDesignationPropertySource implements IPropertySource {
152

  
153
		private TypeDesignationBase typeDesignation;
154

  
155
		TypeDesignationPropertySource(TypeDesignationBase typeDesignation) {
156
			this.typeDesignation = typeDesignation;
157
		}
158
		
159
		@Override
160
		public Object getEditableValue() {
161
			return this;
162
		}
163

  
164
		@Override
165
		public IPropertyDescriptor[] getPropertyDescriptors() {
166
			return new IPropertyDescriptor[]{
167
					new PropertyDescriptor(
168
							typeDesignation, "Citation")
169
			};
170
		}
171

  
172
		@Override
173
		public Object getPropertyValue(Object id) {
174
			ReferenceBase reference = typeDesignation.getCitation();
175
			if (reference == null) {
176
				reference = Generic.NewInstance();
177
			}
178
			ReferencePropertySource referencePropertySource = new ReferencePropertySource(reference);
179
			referencePropertySource.addPropertyChangeListener(new PropertyChangeListener() {
180
				public void propertyChange(PropertyChangeEvent evt) {
181
					if (evt.getNewValue() instanceof ReferenceBase) {	
182
						typeDesignation.setCitation((ReferenceBase) evt.getNewValue());
183
					}
184
				}
185
			});
186
			return referencePropertySource;
187
		}
188

  
189
		@Override
190
		public boolean isPropertySet(Object id) {
191
			return false;
192
		}
193

  
194
		@Override
195
		public void resetPropertyValue(Object id) {}
196

  
197
		@Override
198
		public void setPropertyValue(Object id, Object value) {
199
		}
200
		
201
		public String toString() {
202
			if (typeDesignation instanceof SpecimenTypeDesignation) {
203
				return ((SpecimenTypeDesignation) typeDesignation).getTypeSpecimen().getTitleCache();
204
			}
205
			
206
			if (typeDesignation instanceof NameTypeDesignation) {
207
				if (((NameTypeDesignation) typeDesignation).getTypeName() != null) {
208
					return ((NameTypeDesignation) typeDesignation).getTypeName().getTitleCache();
209
				}
210
			}
211
			
212
			return null;
213
		}
214
	}
198 215
}

Also available in: Unified diff