Project

General

Profile

Download (75.9 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.taxeditor.ui.element;
5

    
6
import java.net.URI;
7
import java.util.ArrayList;
8
import java.util.HashSet;
9
import java.util.List;
10
import java.util.Map;
11
import java.util.Set;
12

    
13
import org.eclipse.jface.util.IPropertyChangeListener;
14
import org.eclipse.jface.viewers.ISelection;
15
import org.eclipse.jface.viewers.ISelectionProvider;
16
import org.eclipse.jface.window.Window;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.custom.StyledText;
19
import org.eclipse.swt.events.FocusAdapter;
20
import org.eclipse.swt.events.FocusEvent;
21
import org.eclipse.swt.events.FocusListener;
22
import org.eclipse.swt.events.MouseAdapter;
23
import org.eclipse.swt.events.MouseEvent;
24
import org.eclipse.swt.events.MouseListener;
25
import org.eclipse.swt.events.SelectionEvent;
26
import org.eclipse.swt.events.SelectionListener;
27
import org.eclipse.swt.events.TypedEvent;
28
import org.eclipse.swt.graphics.Color;
29
import org.eclipse.swt.graphics.Font;
30
import org.eclipse.swt.widgets.Composite;
31
import org.eclipse.swt.widgets.Control;
32
import org.eclipse.swt.widgets.Display;
33
import org.eclipse.swt.widgets.Event;
34
import org.eclipse.swt.widgets.Label;
35
import org.eclipse.ui.forms.IFormColors;
36
import org.eclipse.ui.forms.widgets.FormToolkit;
37
import org.eclipse.ui.forms.widgets.Section;
38
import org.eclipse.ui.internal.forms.widgets.FormFonts;
39
import org.joda.time.Partial;
40
import org.springframework.security.core.GrantedAuthority;
41

    
42
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
43
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
44
import eu.etaxonomy.cdm.model.agent.Person;
45
import eu.etaxonomy.cdm.model.agent.Team;
46
import eu.etaxonomy.cdm.model.common.Annotation;
47
import eu.etaxonomy.cdm.model.common.CdmBase;
48
import eu.etaxonomy.cdm.model.common.Credit;
49
import eu.etaxonomy.cdm.model.common.DefinedTerm;
50
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
51
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
52
import eu.etaxonomy.cdm.model.common.Extension;
53
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
54
import eu.etaxonomy.cdm.model.common.Group;
55
import eu.etaxonomy.cdm.model.common.ICdmBase;
56
import eu.etaxonomy.cdm.model.common.IDefinedTerm;
57
import eu.etaxonomy.cdm.model.common.IEnumTerm;
58
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
59
import eu.etaxonomy.cdm.model.common.Language;
60
import eu.etaxonomy.cdm.model.common.LanguageString;
61
import eu.etaxonomy.cdm.model.common.Marker;
62
import eu.etaxonomy.cdm.model.common.TermType;
63
import eu.etaxonomy.cdm.model.common.TimePeriod;
64
import eu.etaxonomy.cdm.model.common.User;
65
import eu.etaxonomy.cdm.model.common.VersionableEntity;
66
import eu.etaxonomy.cdm.model.description.CategoricalData;
67
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
68
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
69
import eu.etaxonomy.cdm.model.description.Distribution;
70
import eu.etaxonomy.cdm.model.description.Feature;
71
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
72
import eu.etaxonomy.cdm.model.description.KeyStatement;
73
import eu.etaxonomy.cdm.model.description.QuantitativeData;
74
import eu.etaxonomy.cdm.model.description.StateData;
75
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
76
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
77
import eu.etaxonomy.cdm.model.description.TextData;
78
import eu.etaxonomy.cdm.model.location.NamedArea;
79
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
80
import eu.etaxonomy.cdm.model.location.Point;
81
import eu.etaxonomy.cdm.model.media.ImageFile;
82
import eu.etaxonomy.cdm.model.media.Media;
83
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
84
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
85
import eu.etaxonomy.cdm.model.media.Rights;
86
import eu.etaxonomy.cdm.model.name.NameRelationship;
87
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
88
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
89
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
90
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
91
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
92
import eu.etaxonomy.cdm.model.reference.Reference;
93
import eu.etaxonomy.cdm.model.taxon.Taxon;
94
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
95
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
96
import eu.etaxonomy.taxeditor.store.StoreUtil;
97
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
98
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
99
import eu.etaxonomy.taxeditor.ui.openurl.IOpenUrlEnabled;
100
import eu.etaxonomy.taxeditor.ui.openurl.OpenUrlSelectorElement;
101
import eu.etaxonomy.taxeditor.ui.password.EditPasswordElement;
102
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
103
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
104
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
105
import eu.etaxonomy.taxeditor.ui.section.EmptyElement;
106
import eu.etaxonomy.taxeditor.ui.section.agent.InstitutionDetailElement;
107
import eu.etaxonomy.taxeditor.ui.section.agent.InstitutionDetailSection;
108
import eu.etaxonomy.taxeditor.ui.section.agent.PersonDetailElement;
109
import eu.etaxonomy.taxeditor.ui.section.agent.PersonDetailSection;
110
import eu.etaxonomy.taxeditor.ui.section.agent.TeamDetailElement;
111
import eu.etaxonomy.taxeditor.ui.section.agent.TeamDetailSection;
112
import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberElement;
113
import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberSection;
114
import eu.etaxonomy.taxeditor.ui.section.agent.TeamOrPersonBaseDetailSection;
115
import eu.etaxonomy.taxeditor.ui.section.classification.ClassificationDetailElement;
116
import eu.etaxonomy.taxeditor.ui.section.classification.ClassificationDetailSection;
117
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailElement;
118
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailSection;
119
import eu.etaxonomy.taxeditor.ui.section.common.ReferencedEntityDetailSection;
120
import eu.etaxonomy.taxeditor.ui.section.common.RefereneEntityDetailElement;
121
import eu.etaxonomy.taxeditor.ui.section.description.DerivedUnitElement;
122
import eu.etaxonomy.taxeditor.ui.section.description.DescribedSpecimenSection;
123
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionDetailElement;
124
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionDetailSection;
125
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementDetailElement;
126
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementDetailSection;
127
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementMediaSection;
128
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementSourceElement;
129
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementSourceSection;
130
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionSourceElement;
131
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionSourceSection;
132
import eu.etaxonomy.taxeditor.ui.section.description.ModifierElement;
133
import eu.etaxonomy.taxeditor.ui.section.description.ModifierSection;
134
import eu.etaxonomy.taxeditor.ui.section.description.NaturalLanguageDetailElement;
135
import eu.etaxonomy.taxeditor.ui.section.description.NaturalLanguageSection;
136
import eu.etaxonomy.taxeditor.ui.section.description.ScopeElement;
137
import eu.etaxonomy.taxeditor.ui.section.description.ScopeSection;
138
import eu.etaxonomy.taxeditor.ui.section.description.StateDataElement;
139
import eu.etaxonomy.taxeditor.ui.section.description.StateDataSection;
140
import eu.etaxonomy.taxeditor.ui.section.description.StatisticalMeasurementValueElement;
141
import eu.etaxonomy.taxeditor.ui.section.description.StatisticalMeasurementValueSection;
142
import eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement;
143
import eu.etaxonomy.taxeditor.ui.section.description.detail.CategoricalDataDetailElement;
144
import eu.etaxonomy.taxeditor.ui.section.description.detail.CommonNameDetailElement;
145
import eu.etaxonomy.taxeditor.ui.section.description.detail.DistributionDetailElement;
146
import eu.etaxonomy.taxeditor.ui.section.description.detail.IndividualsAssociationDetailElement;
147
import eu.etaxonomy.taxeditor.ui.section.description.detail.QuantitativeDataDetailElement;
148
import eu.etaxonomy.taxeditor.ui.section.description.detail.TaxonInteractionDetailElement;
149
import eu.etaxonomy.taxeditor.ui.section.description.detail.TextDataDetailElement;
150
import eu.etaxonomy.taxeditor.ui.section.feature.FeatureDistributionDetailElement;
151
import eu.etaxonomy.taxeditor.ui.section.feature.FeatureDistributionDetailSection;
152
import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityCollectionElement;
153
import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityDetailElement;
154
import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityDetailSection;
155
import eu.etaxonomy.taxeditor.ui.section.group.GroupDetailElement;
156
import eu.etaxonomy.taxeditor.ui.section.group.GroupDetailSection;
157
import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailElement;
158
import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailSection;
159
import eu.etaxonomy.taxeditor.ui.section.key.GeographicalScopeDetailSection;
160
import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyDetailElement;
161
import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyDetailSection;
162
import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyNodeDetailElement;
163
import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyNodeDetailSection;
164
import eu.etaxonomy.taxeditor.ui.section.key.ScopeRestrictionSection;
165
import eu.etaxonomy.taxeditor.ui.section.key.TaxonomicScopeSection;
166
import eu.etaxonomy.taxeditor.ui.section.media.ImageFileElement;
167
import eu.etaxonomy.taxeditor.ui.section.media.MediaElement;
168
import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationElement;
169
import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationPartElement;
170
import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationPartSection;
171
import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationSection;
172
import eu.etaxonomy.taxeditor.ui.section.media.MediaSection;
173
import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailElement;
174
import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailSection;
175
import eu.etaxonomy.taxeditor.ui.section.name.HybridDetailElement;
176
import eu.etaxonomy.taxeditor.ui.section.name.HybridDetailSection;
177
import eu.etaxonomy.taxeditor.ui.section.name.NameDetailElement;
178
import eu.etaxonomy.taxeditor.ui.section.name.NameDetailSection;
179
import eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailElement;
180
import eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailSection;
181
import eu.etaxonomy.taxeditor.ui.section.name.NameTypeDesignationElement;
182
import eu.etaxonomy.taxeditor.ui.section.name.NomenclaturalStatusElement;
183
import eu.etaxonomy.taxeditor.ui.section.name.NomenclaturalStatusSection;
184
import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameDetailElement;
185
import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameDetailSection;
186
import eu.etaxonomy.taxeditor.ui.section.name.ProtologueElement;
187
import eu.etaxonomy.taxeditor.ui.section.name.ProtologueSection;
188
import eu.etaxonomy.taxeditor.ui.section.name.SpecimenTypeDesignationElement;
189
import eu.etaxonomy.taxeditor.ui.section.name.TypeDesignationSection;
190
import eu.etaxonomy.taxeditor.ui.section.occurrence.CollectingAreasDetailSection;
191
import eu.etaxonomy.taxeditor.ui.section.occurrence.CollectionDetailElement;
192
import eu.etaxonomy.taxeditor.ui.section.occurrence.CurrentDeterminationDetailSection;
193
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseDetailElement;
194
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseDetailSection;
195
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitFacadeDetailElement;
196
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitFacadeDetailSection;
197
import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationDetailElement;
198
import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationDetailSection;
199
import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationEventDetailElement;
200
import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationHistoryDetailSection;
201
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldObservationDetailElement;
202
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldObservationDetailSection;
203
import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventDetailElement;
204
import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventDetailSection;
205
import eu.etaxonomy.taxeditor.ui.section.occurrence.GeneralDetailElement;
206
import eu.etaxonomy.taxeditor.ui.section.occurrence.GeneralDetailSection;
207
import eu.etaxonomy.taxeditor.ui.section.occurrence.NamedAreaDetailElement;
208
import eu.etaxonomy.taxeditor.ui.section.occurrence.SourceCollectionDetailSection;
209
import eu.etaxonomy.taxeditor.ui.section.occurrence.SpecimenCollectionDetailElement;
210
import eu.etaxonomy.taxeditor.ui.section.occurrence.SpecimenCollectionDetailSection;
211
import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailElement;
212
import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailSection;
213
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailElement;
214
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailSection;
215
import eu.etaxonomy.taxeditor.ui.section.supplemental.AnnotationElement;
216
import eu.etaxonomy.taxeditor.ui.section.supplemental.AnnotationSection;
217
import eu.etaxonomy.taxeditor.ui.section.supplemental.CdmBaseElement;
218
import eu.etaxonomy.taxeditor.ui.section.supplemental.CdmBaseSection;
219
import eu.etaxonomy.taxeditor.ui.section.supplemental.CreditElement;
220
import eu.etaxonomy.taxeditor.ui.section.supplemental.CreditSection;
221
import eu.etaxonomy.taxeditor.ui.section.supplemental.ExtensionElement;
222
import eu.etaxonomy.taxeditor.ui.section.supplemental.ExtensionSection;
223
import eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection;
224
import eu.etaxonomy.taxeditor.ui.section.supplemental.IdentifiableSourceElement;
225
import eu.etaxonomy.taxeditor.ui.section.supplemental.MarkerElement;
226
import eu.etaxonomy.taxeditor.ui.section.supplemental.MarkerSection;
227
import eu.etaxonomy.taxeditor.ui.section.supplemental.RightsElement;
228
import eu.etaxonomy.taxeditor.ui.section.supplemental.RightsSection;
229
import eu.etaxonomy.taxeditor.ui.section.supplemental.SourceSection;
230
import eu.etaxonomy.taxeditor.ui.section.supplemental.VersionElement;
231
import eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection;
232
import eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessageElement;
233
import eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessagesSection;
234
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonBaseDetailElement;
235
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonBaseDetailSection;
236
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonDetailElement;
237
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonRelationshipDetailElement;
238
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonRelationshipDetailSection;
239
import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailElement;
240
import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailSection;
241
import eu.etaxonomy.taxeditor.ui.section.user.UserDetailElement;
242
import eu.etaxonomy.taxeditor.ui.section.user.UserDetailSection;
243
import eu.etaxonomy.taxeditor.ui.section.userecords.UseRecordDetailElement;
244
import eu.etaxonomy.taxeditor.ui.section.userecords.UseRecordDetailSection;
245
import eu.etaxonomy.taxeditor.ui.section.vocabulary.DefinedTermDetailElement;
246
import eu.etaxonomy.taxeditor.ui.section.vocabulary.DefinedTermDetailSection;
247
import eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailSection;
248
import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermVocabularyDetailElement;
249
import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermVocabularyDetailSection;
250
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
251
import eu.etaxonomy.taxeditor.ui.selection.NomenclaturalAuthorTeamSelectionElement;
252
import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
253

    
254
/**
255
 * <p>
256
 * CdmFormFactory class.
257
 * </p>
258
 * 
259
 * @author n.hoffmann
260
 * @created Feb 24, 2010
261
 * @version 1.0
262
 */
263
public class CdmFormFactory extends FormToolkit {
264

    
265
	private BoldFontHolder2 boldFontHolder2;
266
	private MouseListener selectionMouseHandler;
267
	private FocusListener selectionFocusHandler;
268

    
269
	private final Set selectionListenerList = new HashSet();
270

    
271
	private final List<IPropertyChangeListener> propertyChangeListeners = new ArrayList<IPropertyChangeListener>();
272

    
273
	private final int orientation = Window.getDefaultOrientation();
274
	private ISelectionProvider selectionProvider;
275

    
276
	/** Constant <code>EMPTY_SELECTION</code> */
277
	public static ISelection EMPTY_SELECTION = new ISelection() {
278
		@Override
279
		public boolean isEmpty() {
280
			return true;
281
		}
282
	};
283
	
284
	/**
285
	 * 
286
	 * @author n.hoffmann
287
	 * @date Jan 25, 2010
288
	 *
289
	 */
290
	private class SelectionMouseHandler extends MouseAdapter {
291
		@Override
292
		public void mouseDown(MouseEvent e) {
293
			notifySelectionListeners(e);
294
		}
295
	}
296

    
297
	/**
298
	 * 
299
	 * @author n.hoffmann
300
	 * @date Jan 25, 2010
301
	 *
302
	 */
303
	private class SelectionFocusHandler extends FocusAdapter {
304
		@Override
305
		public void focusGained(FocusEvent e) {
306
			notifySelectionListeners(e);
307
		}
308
	}
309

    
310
	private void notifySelectionListeners(TypedEvent e) {
311
		Event event = new Event();
312
		event.widget = e.widget;
313
		SelectionEvent selectionEvent = new SelectionEvent(event);
314

    
315
		for (Object listener : selectionListenerList) {
316
			((SelectionListener) listener).widgetSelected(selectionEvent);
317
		}
318
	}
319

    
320
	/**
321
	 * <p>
322
	 * Constructor for CdmFormFactory.
323
	 * </p>
324
	 * 
325
	 * @param display
326
	 *            a {@link org.eclipse.swt.widgets.Display} object.
327
	 * @param selectionProvider
328
	 *            a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
329
	 */
330
	public CdmFormFactory(Display display, ISelectionProvider selectionProvider) {
331
		super(display);
332
		this.selectionProvider = selectionProvider;
333
		init();
334
	}
335

    
336
	/**
337
	 * <p>
338
	 * Constructor for CdmFormFactory.
339
	 * </p>
340
	 * 
341
	 * @param display
342
	 *            a {@link org.eclipse.swt.widgets.Display} object.
343
	 */
344
	public CdmFormFactory(Display display) {
345
		super(display);
346
		init();
347
	}
348

    
349
	/**
350
	 * 
351
	 */
352
	private void init() {
353
		boldFontHolder2 = new BoldFontHolder2();
354
		selectionMouseHandler = new SelectionMouseHandler();
355
		selectionFocusHandler = new SelectionFocusHandler();
356
	}
357

    
358
	/**
359
	 * Creates an instance initialized with the correct selectionProvider
360
	 * 
361
	 * Make sure to remove the instance when the entityComposite disposes via
362
	 * destroySelectionArbitrator(..)
363
	 * 
364
	 * @param entityElement
365
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.IEntityElement}
366
	 *            object.
367
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator}
368
	 *         object.
369
	 */
370
	public SelectionArbitrator createSelectionArbitrator(
371
			IEntityElement entityElement) {
372
		SelectionArbitrator selectionArbitrator = new SelectionArbitrator(
373
				entityElement);
374
		selectionArbitrator.addSelectionProvider(selectionProvider);
375
		selectionProvider.addSelectionChangedListener(selectionArbitrator);
376
		addSelectionListener(selectionArbitrator);
377
		return selectionArbitrator;
378
	}
379

    
380
	/**
381
	 * <p>
382
	 * destroySelectionArbitrator
383
	 * </p>
384
	 * 
385
	 * @param selectionArbitrator
386
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator}
387
	 *            object.
388
	 */
389
	public void destroySelectionArbitrator(
390
			SelectionArbitrator selectionArbitrator) {
391
		removeSelectionListener(selectionArbitrator);
392
		if (selectionProvider != null) {
393
			selectionProvider
394
					.removeSelectionChangedListener(selectionArbitrator);
395
		} else {
396
			StoreUtil
397
					.error(this.getClass(),
398
							"Tried to destroy a selection listener from this factories listeners but was null",
399
							null);
400
		}
401
	}
402

    
403
	/** {@inheritDoc} */
404
	@Override
405
	public void adapt(Composite composite) {
406
		composite.addMouseListener(selectionMouseHandler);
407
		super.adapt(composite);
408
	}
409

    
410
	/**
411
	 * <p>
412
	 * adapt
413
	 * </p>
414
	 * 
415
	 * @param formElement
416
	 *            a
417
	 *            {@link eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement}
418
	 *            object.
419
	 */
420
	public void adapt(AbstractCdmFormElement formElement) {
421
		formElement.setPropertyChangeListeners(propertyChangeListeners);
422
	}
423

    
424
	/** {@inheritDoc} */
425
	@Override
426
	public void adapt(Control control, boolean trackFocus, boolean trackKeyboard) {
427
		if (trackFocus) {
428
			control.addFocusListener(selectionFocusHandler);
429
		}
430
		super.adapt(control, trackFocus, trackKeyboard);
431
	}
432

    
433
	/**
434
	 * <p>
435
	 * destroyElement
436
	 * </p>
437
	 * 
438
	 * @param formElement
439
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
440
	 *            object.
441
	 */
442
	public void destroyElement(ICdmFormElement formElement) {
443
		// return if element was not initialized
444
		if (formElement == null) {
445
			return;
446
		}
447
		// destroy selection arbitrator, if any
448
		if (formElement instanceof ISelectableElement) {
449
			destroySelectionArbitrator(((ISelectableElement) formElement)
450
					.getSelectionArbitrator());
451
		}
452
		// remove this element form its parents list of elements
453
		// ICdmFormElement parentElement = formElement.getParentElement();
454
		// if(parentElement != null){
455
		// parentElement.removeElement(formElement);
456
		// }
457
		// call destroy on child elements recursively
458
		for (ICdmFormElement childElement : formElement.getElements()) {
459
			destroyElement(childElement);
460
		}
461
		// dispose of the controls
462
		for (Control control : formElement.getControls()) {
463
			// we added the layoutComposite of the parental element as the
464
			// layout composite to this formElement
465
			// but we do not want to destroy it.
466
			if (control.equals(formElement.getLayoutComposite())) {
467
				continue;
468
			} else {
469
				control.dispose();
470
				control = null;
471
			}
472
		}
473
	}
474

    
475
	/**
476
	 * <p>
477
	 * createEmptyCell
478
	 * </p>
479
	 * 
480
	 * @param parent
481
	 *            a {@link org.eclipse.swt.widgets.Composite} object.
482
	 * @return a {@link org.eclipse.swt.widgets.Label} object.
483
	 */
484
	public Label createEmptyCell(Composite parent) {
485
		return this.createLabel(parent, null);
486
	}
487

    
488
	/**
489
	 * <p>
490
	 * createMultilineTextWithLabel
491
	 * </p>
492
	 * 
493
	 * @param labelString
494
	 *            a {@link java.lang.String} object.
495
	 * @param textHeight
496
	 *            a int.
497
	 * @param style
498
	 *            a int.
499
	 * @param parentElement
500
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
501
	 *            object.
502
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
503
	 *         object.
504
	 */
505
	public TextWithLabelElement createMultilineTextWithLabel(
506
			ICdmFormElement parentElement, String labelString, int textHeight,
507
			int style) {
508
		TextWithLabelElement element = new TextWithLabelElement(this,
509
				parentElement, labelString, "", textHeight, style);
510
		adapt(element);
511
		parentElement.addElement(element);
512
		return element;
513
	}
514

    
515
	/**
516
	 * <p>
517
	 * createMultiLanguageTextElement
518
	 * </p>
519
	 * 
520
	 * @param parentElement
521
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
522
	 *            object.
523
	 * @param labelString
524
	 *            a {@link java.lang.String} object.
525
	 * @param multilanguageText
526
	 *            a {@link java.util.Map} object.
527
	 * @param textHeight
528
	 *            a int.
529
	 * @param style
530
	 *            a int.
531
	 * @return a
532
	 *         {@link eu.etaxonomy.taxeditor.ui.element.MultilanguageTextElement}
533
	 *         object.
534
	 */
535
	public MultilanguageTextElement createMultiLanguageTextElement(
536
			ICdmFormElement parentElement, String labelString,
537
			Map<Language, LanguageString> multilanguageText, int textHeight,
538
			int style) {
539
		MultilanguageTextElement element = new MultilanguageTextElement(this,
540
				parentElement, labelString, multilanguageText, textHeight,
541
				style);
542
		adapt(element);
543
		parentElement.addElement(element);
544
		return element;
545
	}
546

    
547
	public KeyStatementElement createKeyStatementElement(
548
			ICdmFormElement parentElement, String labelString,
549
			KeyStatement keyStatement, int textHeight, int style) {
550
		KeyStatementElement element = new KeyStatementElement(this,
551
				parentElement, labelString, keyStatement, textHeight, style);
552
		adapt(element);
553
		parentElement.addElement(element);
554
		return element;
555
	}
556

    
557
	/**
558
	 * <p>
559
	 * createTextWithLabelElement
560
	 * </p>
561
	 * 
562
	 * @param labelString
563
	 *            a {@link java.lang.String} object.
564
	 * @param initialText
565
	 *            a {@link java.lang.String} object.
566
	 * @param style
567
	 *            a int.
568
	 * @param parentElement
569
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
570
	 *            object.
571
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
572
	 *         object.
573
	 */
574
	public TextWithLabelElement createTextWithLabelElement(
575
			ICdmFormElement parentElement, String labelString,
576
			String initialText, int style) {
577
		TextWithLabelElement element = new TextWithLabelElement(this,
578
				parentElement, labelString, initialText, null, style);
579
		adapt(element);
580
		parentElement.addElement(element);
581
		return element;
582
	}
583

    
584
	public UriWithLabelElement createUriWithLabelElement(
585
			ICdmFormElement parentElement, String labelString, URI initialUri,
586
			int style) {
587
		UriWithLabelElement element = new UriWithLabelElement(this,
588
				parentElement, labelString, initialUri, null, style);
589
		adapt(element);
590
		parentElement.addElement(element);
591
		return element;
592
	}
593

    
594
	/**
595
	 * @param element
596
	 * @param string
597
	 * @param uri
598
	 * @param style
599
	 * @return
600
	 */
601
	public OpenUrlSelectorElement createOpenUrlSelectorElement(
602
			ICdmFormElement parentElement, String labelString,
603
			IOpenUrlEnabled openUrlEnabled, int style) {
604
		OpenUrlSelectorElement element = new OpenUrlSelectorElement(this,
605
				parentElement, labelString, openUrlEnabled, style);
606
		adapt(element);
607
		parentElement.addElement(element);
608
		return element;
609
	}
610

    
611
	/**
612
	 * 
613
	 * @param parentElement
614
	 * @param labelString
615
	 * @param conversationEnabled
616
	 * @param user
617
	 * @param style
618
	 * @return
619
	 */
620
	public EditPasswordElement createEditPasswordElement(
621
			ICdmFormElement parentElement, String labelString,
622
			ConversationHolder conversation, User user, int style) {
623
		EditPasswordElement element = new EditPasswordElement(this,
624
				parentElement, labelString, user, conversation);
625
		adapt(element);
626
		parentElement.addElement(element);
627
		return element;
628
	}
629

    
630
	/**
631
	 * <p>
632
	 * createIntegerTextWithLabelElement
633
	 * </p>
634
	 * 
635
	 * @param parentElement
636
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
637
	 *            object.
638
	 * @param labelString
639
	 *            a {@link java.lang.String} object.
640
	 * @param initialInteger
641
	 *            a {@link java.lang.Integer} object.
642
	 * @param style
643
	 *            a int.
644
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement}
645
	 *         object.
646
	 */
647
	public NumberWithLabelElement createNumberTextWithLabelElement(
648
			ICdmFormElement parentElement, String labelString,
649
			Number initialNumber, int style) {
650
		NumberWithLabelElement element = new NumberWithLabelElement(this,
651
				parentElement, labelString, initialNumber, style);
652
		adapt(element);
653
		parentElement.addElement(element);
654
		return element;
655
	}
656

    
657

    
658
	/**
659
	 * <p>
660
	 * createLanguageStringWithLabelElement
661
	 * </p>
662
	 * 
663
	 * @param parentElement
664
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
665
	 *            object.
666
	 * @param labelString
667
	 *            a {@link java.lang.String} object.
668
	 * @param languageString
669
	 *            a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
670
	 * @param style
671
	 *            a int.
672
	 * @return a
673
	 *         {@link eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement}
674
	 *         object.
675
	 */
676
	public LanguageStringWithLabelElement createLanguageStringWithLabelElement(
677
			ICdmFormElement parentElement, String labelString,
678
			LanguageString languageString, int style) {
679
		LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(
680
				this, parentElement, labelString, languageString, style);
681
		adapt(element);
682
		parentElement.addElement(element);
683
		return element;
684
	}
685

    
686
	/**
687
	 * <p>
688
	 * createLanguageStringWithLabelElement
689
	 * </p>
690
	 * 
691
	 * @param parentElement
692
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
693
	 *            object.
694
	 * @param labelString
695
	 *            a {@link java.lang.String} object.
696
	 * @param languageString
697
	 *            a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
698
	 * @param height
699
	 *            a int.
700
	 * @param style
701
	 *            a int.
702
	 * @return a
703
	 *         {@link eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement}
704
	 *         object.
705
	 */
706
	public LanguageStringWithLabelElement createLanguageStringWithLabelElement(
707
			ICdmFormElement parentElement, String labelString,
708
			LanguageString languageString, int height, int style) {
709
		LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(
710
				this, parentElement, labelString, languageString, height, style);
711
		adapt(element);
712
		parentElement.addElement(element);
713
		return element;
714
	}
715

    
716
	/**
717
	 * <p>
718
	 * createTextElement
719
	 * </p>
720
	 * 
721
	 * @param parentElement
722
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
723
	 *            object.
724
	 * @param initialText
725
	 *            a {@link java.lang.String} object.
726
	 * @param style
727
	 *            a int.
728
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
729
	 *         object.
730
	 */
731
	public TextWithLabelElement createTextElement(
732
			ICdmFormElement parentElement, String initialText, int style) {
733
		TextWithLabelElement element = new TextWithLabelElement(this,
734
				parentElement, null, initialText, null, style);
735
		adapt(element);
736
		parentElement.addElement(element);
737
		return element;
738
	}
739

    
740
	/**
741
	 * <p>
742
	 * createKeyValueViewerElement
743
	 * </p>
744
	 * 
745
	 * @param parentElement
746
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
747
	 *            object.
748
	 * @param keyHeading
749
	 *            a {@link java.lang.String} object.
750
	 * @param valueHeading
751
	 *            a {@link java.lang.String} object.
752
	 * @param map
753
	 *            a {@link java.util.Map} object.
754
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.KeyValueViewerElement}
755
	 *         object.
756
	 */
757
	public KeyValueViewerElement createKeyValueViewerElement(
758
			ICdmFormElement parentElement, String keyHeading,
759
			String valueHeading, Map<Object, Object> map) {
760
		KeyValueViewerElement element = new KeyValueViewerElement(this,
761
				parentElement, keyHeading, valueHeading, map);
762
		adapt(element);
763
		parentElement.addElement(element);
764
		return element;
765
	}
766

    
767
	/**
768
	 * <p>
769
	 * createTermComboElement
770
	 * </p>
771
	 * 
772
	 * @param termComboType
773
	 *            a
774
	 *            {@link eu.eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.TermComboType}
775
	 *            object.
776
	 * @param parentElement
777
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
778
	 *            object.
779
	 * @param labelString
780
	 *            a {@link java.lang.String} object.
781
	 * @param selection
782
	 *            a {@link eu.etaxonomy.cdm.model.common.DefinedTermBase}
783
	 *            object.
784
	 * @param style
785
	 *            a int.
786
	 * @return a {@link eu.etaxonomy.taxeditor.ui.combo.TermComboElement}
787
	 *         object.
788
	 */
789
	
790
	public <T extends DefinedTermBase> TermComboElement<T> createTermComboElement(
791
			Class<T> termComboType, ICdmFormElement parentElement,
792
			String labelString, T selection, int style) {
793
		TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termComboType, labelString, selection, style);
794
		adapt(element);
795
		parentElement.addElement(element);
796
		return element;
797
	}
798

    
799
	/**
800
	 * <p>
801
	 * createEnumComboElement
802
	 * </p>
803
	 * 
804
	 * @param enumComboType
805
	 *            a
806
	 *            {@link eu.eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.EnumComboType}
807
	 *            object.
808
	 * @param parentElement
809
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
810
	 *            object.
811
	 * @param style
812
	 *            a int.
813
	 * @return a {@link eu.etaxonomy.taxeditor.ui.term.AbstractEnumComboElement}
814
	 *         object.
815
	 */
816
	public <T extends IEnumTerm> EnumComboElement<T> createEnumComboElement(
817
			Class<T> enumComboType, ICdmFormElement parentElement,
818
			int style) {
819
		EnumComboElement<T> element = new EnumComboElement<T>(this, parentElement, enumComboType, style);
820
		adapt(element);
821
		parentElement.addElement(element);
822
		return element;
823
	}
824

    
825
	/**
826
	 * <p>
827
	 * createBrowserElement
828
	 * </p>
829
	 * 
830
	 * @param imageUri
831
	 *            a {@link java.net.URI} object.
832
	 * @param style
833
	 *            a int.
834
	 * @param parentElement
835
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
836
	 *            object.
837
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.BrowserElement} object.
838
	 */
839
	public BrowserElement createBrowserElement(ICdmFormElement parentElement,
840
			URI imageUri, int style) {
841
		BrowserElement element = new BrowserElement(this, parentElement,
842
				imageUri, style);
843
		adapt(element);
844
		parentElement.addElement(element);
845
		return element;
846
	}
847

    
848
	/**
849
	 * <p>
850
	 * createImageElement
851
	 * </p>
852
	 * 
853
	 * @param parentElement
854
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
855
	 *            object.
856
	 * @param imageUri
857
	 *            a {@link java.net.URI} object.
858
	 * @param style
859
	 *            a int.
860
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.ImageElement} object.
861
	 */
862
	public ImageElement createImageElement(ICdmFormElement parentElement,
863
			URI imageUri, int style) {
864
		ImageElement element = new ImageElement(this, parentElement, imageUri,
865
				style);
866
		adapt(element);
867
		parentElement.addElement(element);
868
		return element;
869
	}
870

    
871
	/**
872
	 * <p>
873
	 * createTextActionElement
874
	 * </p>
875
	 * 
876
	 * @param labelString
877
	 *            a {@link java.lang.String} object.
878
	 * @param initialText
879
	 *            a {@link java.lang.String} object.
880
	 * @param style
881
	 *            a int.
882
	 * @param parentElement
883
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
884
	 *            object.
885
	 * @param buttonLabel
886
	 *            a {@link java.lang.String} object.
887
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextActionElement}
888
	 *         object.
889
	 */
890
	public TextActionElement createTextActionElement(
891
			ICdmFormElement parentElement, String labelString,
892
			String buttonLabel, String initialText, int style) {
893
		TextActionElement element = new TextActionElement(this, parentElement,
894
				labelString, buttonLabel, initialText, style);
895
		adapt(element);
896
		parentElement.addElement(element);
897
		return element;
898
	}
899

    
900
	/**
901
	 * <p>
902
	 * createCheckbox
903
	 * </p>
904
	 * 
905
	 * @param parentElement
906
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
907
	 *            object.
908
	 * @param label
909
	 *            a {@link java.lang.String} object.
910
	 * @param initialState
911
	 *            a boolean.
912
	 * @param style
913
	 *            a int.
914
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.CheckboxElement} object.
915
	 */
916
	public CheckboxElement createCheckbox(ICdmFormElement parentElement,
917
			String label, boolean initialState, int style) {
918
		CheckboxElement element = new CheckboxElement(this, parentElement,
919
				label, initialState, style | orientation);
920
		adapt(element);
921
		parentElement.addElement(element);
922
		return element;
923
	}
924

    
925
	/**
926
	 * Creates a section as a part of the form.
927
	 * 
928
	 * @return the section widget
929
	 * @param section
930
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
931
	 *            object.
932
	 */
933
	public Section adapt(AbstractFormSection section) {
934
		section.setMenu(section.getLayoutComposite().getMenu());
935
		adapt(section, true, true);
936

    
937
		// handle focus and property change events for cdm use
938
		section.addFocusListener(selectionFocusHandler);
939
		section.setPropertyChangeListeners(propertyChangeListeners);
940

    
941
		if (section.getToggle() != null) {
942
			section.getToggle().setHoverDecorationColor(
943
					getColors().getColor(IFormColors.TB_TOGGLE_HOVER));
944
			section.getToggle().setDecorationColor(
945
					getColors().getColor(IFormColors.TB_TOGGLE));
946
		}
947

    
948
		section.setFont(boldFontHolder2.getBoldFont(section
949
				.getLayoutComposite().getFont()));
950

    
951
		if ((section.getStyle() & Section.TITLE_BAR) != 0
952
				|| (section.getStyle() & Section.SHORT_TITLE_BAR) != 0) {
953
			getColors().initializeSectionToolBarColors();
954
			section.setTitleBarBackground(getColors().getColor(
955
					IFormColors.TB_BG));
956
			section.setTitleBarBorderColor(getColors().getColor(
957
					IFormColors.TB_BORDER));
958
		}
959
		// call setTitleBarForeground regardless as it also sets the label color
960
		section.setTitleBarForeground(getColors().getColor(
961
				IFormColors.TB_TOGGLE));
962
		return section;
963
	}
964

    
965
	private class BoldFontHolder2 {
966
		private Font normalFont;
967

    
968
		private Font boldFont;
969

    
970
		public BoldFontHolder2() {
971
		}
972

    
973
		public Font getBoldFont(Font font) {
974
			createBoldFont(font);
975
			return boldFont;
976
		}
977

    
978
		private void createBoldFont(Font font) {
979
			if (normalFont == null || !normalFont.equals(font)) {
980
				normalFont = font;
981
				dispose();
982
			}
983
			if (boldFont == null) {
984
				boldFont = FormFonts.getInstance().getBoldFont(
985
						getColors().getDisplay(), normalFont);
986
			}
987
		}
988

    
989
		public void dispose() {
990
			if (boldFont != null) {
991
				FormFonts.getInstance().markFinished(boldFont,
992
						getColors().getDisplay());
993
				boldFont = null;
994
			}
995
		}
996
	}
997

    
998
	/**
999
	 * <p>
1000
	 * createToggleableTextField
1001
	 * </p>
1002
	 * 
1003
	 * @param parentElement
1004
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1005
	 *            object.
1006
	 * @param labelString
1007
	 *            a {@link java.lang.String} object.
1008
	 * @param initialText
1009
	 *            a {@link java.lang.String} object.
1010
	 * @param initialState
1011
	 *            a boolean.
1012
	 * @param style
1013
	 *            a int.
1014
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement}
1015
	 *         object.
1016
	 */
1017
	public ToggleableTextElement createToggleableTextField(
1018
			ICdmFormElement parentElement, String labelString,
1019
			String initialText, boolean initialState, int style) {
1020
		ToggleableTextElement element = new ToggleableTextElement(this,
1021
				parentElement, labelString, initialText, initialState, style
1022
						| orientation);
1023
		adapt(element);
1024
		parentElement.addElement(element);
1025
		return element;
1026
	}
1027

    
1028
	/**
1029
	 * <p>
1030
	 * createTimePeriodElement
1031
	 * </p>
1032
	 * 
1033
	 * @param parentElement
1034
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1035
	 *            object.
1036
	 * @param labelString
1037
	 *            a {@link java.lang.String} object.
1038
	 * @param timePeriod
1039
	 *            a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
1040
	 * @param style
1041
	 *            a int.
1042
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.TimePeriodElement}
1043
	 *         object.
1044
	 */
1045
	public TimePeriodElement createTimePeriodElement(
1046
			ICdmFormElement parentElement, String labelString,
1047
			TimePeriod timePeriod, int style) {
1048
		TimePeriodElement element = new TimePeriodElement(this, parentElement,
1049
				labelString, timePeriod, style);
1050
		adapt(element);
1051
		parentElement.addElement(element);
1052
		return element;
1053
	}
1054

    
1055
	/**
1056
	 * <p>
1057
	 * createPointElement
1058
	 * </p>
1059
	 * 
1060
	 * @param style
1061
	 *            a int.
1062
	 * @param parentElement
1063
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1064
	 *            object.
1065
	 * @param point
1066
	 *            a {@link eu.etaxonomy.cdm.model.location.Point} object.
1067
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.PointElement} object.
1068
	 */
1069
	public PointElement createPointElement(ICdmFormElement parentElement,
1070
			Point point, int style) {
1071
		PointElement element = new PointElement(this, parentElement, point,
1072
				style);
1073
		adapt(element);
1074
		parentElement.addElement(element);
1075
		return element;
1076
	}
1077

    
1078
	/**
1079
	 * <p>
1080
	 * createDateDetailSection
1081
	 * </p>
1082
	 * 
1083
	 * @param parentElement
1084
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1085
	 *            object.
1086
	 * @param style
1087
	 *            a int.
1088
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.DateDetailSection}
1089
	 *         object.
1090
	 */
1091
	public DateDetailSection createDateDetailSection(
1092
			ICdmFormElement parentElement, int style) {
1093
		DateDetailSection section = new DateDetailSection(this, parentElement,
1094
				style);
1095
		parentElement.addElement(section);
1096
		adapt(section);
1097
		return section;
1098
	}
1099

    
1100
	/**
1101
	 * <p>
1102
	 * createPartialElement
1103
	 * </p>
1104
	 * 
1105
	 * @param parentElement
1106
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1107
	 *            object.
1108
	 * @param labelString
1109
	 *            a {@link java.lang.String} object.
1110
	 * @param partial
1111
	 *            a {@link org.joda.time.Partial} object.
1112
	 * @param style
1113
	 *            a int.
1114
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.PartialElement} object.
1115
	 */
1116
	public PartialElement createPartialElement(ICdmFormElement parentElement,
1117
			String labelString, Partial partial, int style) {
1118
		PartialElement element = new PartialElement(this, parentElement,
1119
				labelString, style);
1120
		adapt(element);
1121
		parentElement.addElement(element);
1122
		return element;
1123
	}
1124

    
1125
	/**
1126
	 * <p>
1127
	 * addSelectionListener
1128
	 * </p>
1129
	 * 
1130
	 * @param listener
1131
	 *            a {@link org.eclipse.swt.events.SelectionListener} object.
1132
	 */
1133
	public void addSelectionListener(SelectionListener listener) {
1134
		selectionListenerList.add(listener);
1135
	}
1136

    
1137
	/**
1138
	 * <p>
1139
	 * removeSelectionListener
1140
	 * </p>
1141
	 * 
1142
	 * @param listener
1143
	 *            a {@link org.eclipse.swt.events.SelectionListener} object.
1144
	 */
1145
	public void removeSelectionListener(SelectionListener listener) {
1146
		if (listener == null) {
1147
			StoreUtil
1148
					.error(this.getClass(),
1149
							"Tried to remove a selection listener from this factories listeners but was null",
1150
							null);
1151
		} else {
1152
			selectionListenerList.remove(listener);
1153
		}
1154
	}
1155

    
1156
	/**
1157
	 * <p>
1158
	 * addPropertyChangeListener
1159
	 * </p>
1160
	 * 
1161
	 * @param listener
1162
	 *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1163
	 *            object.
1164
	 */
1165
	public void addPropertyChangeListener(IPropertyChangeListener listener) {
1166
		if(propertyChangeListeners.contains(listener)){
1167
			return;
1168
		}
1169
		propertyChangeListeners.add(0, listener);
1170
	}
1171

    
1172
	/**
1173
	 * <p>
1174
	 * removePropertyChangeListener
1175
	 * </p>
1176
	 * 
1177
	 * @param listener
1178
	 *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1179
	 *            object.
1180
	 */
1181
	public void removePropertyChangeListener(IPropertyChangeListener listener) {
1182
		propertyChangeListeners.remove(listener);
1183
	}
1184

    
1185
	/**
1186
	 * <p>
1187
	 * createHorizontalSeparator
1188
	 * </p>
1189
	 * 
1190
	 * @param parentElement
1191
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1192
	 *            object.
1193
	 * @param style
1194
	 *            a int.
1195
	 * @return a {@link org.eclipse.swt.widgets.Label} object.
1196
	 */
1197
	public Label createHorizontalSeparator(ICdmFormElement parentElement,
1198
			int style) {
1199
		Label separator = this.createSeparator(
1200
				parentElement.getLayoutComposite(), SWT.HORIZONTAL | style);
1201
		separator.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
1202
		return separator;
1203
	}
1204

    
1205
	/**
1206
	 * <p>
1207
	 * createVersionElement
1208
	 * </p>
1209
	 * 
1210
	 * @param parentElement
1211
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1212
	 *            object.
1213
	 * @param entity
1214
	 *            a {@link eu.etaxonomy.cdm.model.common.VersionableEntity}
1215
	 *            object.
1216
	 * @param style
1217
	 *            a int.
1218
	 * @return a
1219
	 *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionElement}
1220
	 *         object.
1221
	 */
1222
	public VersionElement createVersionElement(ICdmFormElement parentElement,
1223
			VersionableEntity entity, int style) {
1224
		VersionElement element = new VersionElement(this, parentElement,
1225
				entity, style);
1226
		adapt(element);
1227
		parentElement.addElement(element);
1228
		return element;
1229
	}
1230
	
1231
	/**
1232
	 * @param cdmBaseSection
1233
	 * @param object
1234
	 * @param style
1235
	 * @return
1236
	 */
1237
	public CdmBaseElement createCdmBaseElement(ICdmFormElement parentElement,
1238
			CdmBase entity, int style) {
1239
		CdmBaseElement element = new CdmBaseElement(this, parentElement,
1240
				entity, style);
1241
		adapt(element);
1242
		parentElement.addElement(element);
1243
		return element;
1244
	}
1245

    
1246

    
1247
	/**
1248
	 * <p>
1249
	 * createVersionSection
1250
	 * </p>
1251
	 * 
1252
	 * @param parentElement
1253
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1254
	 *            object.
1255
	 * @param style
1256
	 *            a int.
1257
	 * @return a
1258
	 *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection}
1259
	 *         object.
1260
	 */
1261
	public VersionSection createVersionSection(ICdmFormElement parentElement,
1262
			int style) {
1263
		VersionSection section = new VersionSection(this, parentElement, style);
1264
		parentElement.addElement(section);
1265
		adapt(section);
1266
		return section;
1267
	}
1268
	
1269
	/**
1270
	 * @param parent
1271
	 * @param i
1272
	 * @return
1273
	 */
1274
	public CdmBaseSection createCdmBaseSection(ICdmFormElement parentElement, int style) {
1275
		CdmBaseSection section = new CdmBaseSection(this, parentElement, style);
1276
		parentElement.addElement(section);
1277
		adapt(section);
1278
		return section;
1279
	}
1280

    
1281
	/**
1282
	 * <p>
1283
	 * createEmptyElement
1284
	 * </p>
1285
	 * 
1286
	 * @param parentElement
1287
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1288
	 *            object.
1289
	 * @return a {@link eu.etaxonomy.taxeditor.ui.section.EmptyElement} object.
1290
	 */
1291
	public EmptyElement createEmptyElement(ICdmFormElement parentElement) {
1292
		EmptyElement element = new EmptyElement(this, parentElement, null,
1293
				SWT.NULL);
1294
		adapt(element);
1295
		parentElement.addElement(element);
1296
		return element;
1297
	}
1298

    
1299
	/**
1300
	 * <p>
1301
	 * createHeadlineSection
1302
	 * </p>
1303
	 * 
1304
	 * @param parentElement
1305
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1306
	 *            object.
1307
	 * @return a
1308
	 *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection}
1309
	 *         object.
1310
	 */
1311
	public HeadlineSection createHeadlineSection(ICdmFormElement parentElement) {
1312
		HeadlineSection section = new HeadlineSection(this, parentElement,
1313
				SWT.NULL);
1314
		parentElement.addElement(section);
1315
		adapt(section);
1316
		return section;
1317
	}
1318

    
1319
	/**
1320
	 * <p>
1321
	 * createParsingMessageElement
1322
	 * </p>
1323
	 * 
1324
	 * @param parentElement
1325
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1326
	 *            object.
1327
	 * @param parserProblem
1328
	 *            a {@link eu.etaxonomy.cdm.strategy.parser.ParserProblem}
1329
	 *            object.
1330
	 * @param style
1331
	 *            a int.
1332
	 * @return a
1333
	 *         {@link eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessageElement}
1334
	 *         object.
1335
	 */
1336
	public ParsingMessageElement createParsingMessageElement(
1337
			ICdmFormElement parentElement, ParserProblem parserProblem,
1338
			int style) {
1339
		ParsingMessageElement element = new ParsingMessageElement(this,
1340
				parentElement, parserProblem, style);
1341
		adapt(element);
1342
		parentElement.addElement(element);
1343
		return element;
1344
	}
1345

    
1346
	// SIMPLIFY
1347

    
1348
	/**
1349
	 * 
1350
	 */
1351
	public static enum DetailType {
1352
		AUTHORSHIP, 
1353
		CLASSIFICATION, 
1354
		COLLECTION, 
1355
		DERIVED_UNIT, 
1356
		DERIVED_UNIT_FACADE, 
1357
		DERIVED_UNIT_GENERAL, 
1358
		DESCRIPTION, 
1359
		DESCRIPTIONELEMENT, 
1360
		DETERMINATION, 
1361
		FEATURE_DISTRIBUTION, 
1362
		FIELD_OBSERVATION, 
1363
		GATHERING_EVENT, 
1364
		GRANTEDAUTHORITY,
1365
		GROUP, 
1366
		HYBRID, 
1367
		INSTITUTION, 
1368
		MEDIA, 
1369
		NAMED_AREA, 
1370
		NAMED_AREA_LEVEL, 
1371
		NAMERELATIONSHIP, 
1372
		NATURAL_LANGUAGE, 
1373
		NOMENCLATURALREFERENCE, 
1374
		NONVIRALNAME, 
1375
		PARSINGMESSAGE, 
1376
		PERSON, 
1377
		POLYTOMOUS_KEY, 
1378
		POLYTOMOUS_KEY_NODE, 
1379
		REFERENCEBASE, 
1380
		REFERENCED_ENTITY, 
1381
		SCIENTIFICNAME, 
1382
		TAXON_NODE, 
1383
		TAXON_RELATIONSHIP, 
1384
		TAXONBASE, 
1385
		TEAM, 
1386
		TEAMORPERSONBASE, 
1387
		TERM_VOCABULARY,
1388
		USE_RECORD,
1389
		USER
1390
	}
1391
	
1392
	public AbstractFormSection createDefinedTermDetailSection(Class definedTermClass,
1393
			ConversationHolder conversation, ICdmFormElement parentElement,
1394
			ISelectionProvider selectionProvider, int style) {
1395
		
1396
		AbstractFormSection section = new DefinedTermDetailSection(this, definedTermClass, conversation, parentElement, selectionProvider, style);
1397
			
1398
		parentElement.addElement(section);
1399
		adapt(section);
1400
		return section;
1401
		
1402
	}
1403
	
1404
	/**
1405
	 * @param definedTermClass
1406
	 * @param formElement
1407
	 * @param style
1408
	 * @return
1409
	 */
1410
	public AbstractCdmDetailElement createDefinedTermDetailElement(
1411
			Class definedTermClass, AbstractCdmDetailSection parentElement,
1412
			int style) {
1413
		AbstractCdmDetailElement element = null;
1414
		
1415
		if (NamedArea.class.isAssignableFrom(definedTermClass)){
1416
			element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
1417
		}
1418
		else {
1419
			element = new DefinedTermDetailElement(this, parentElement);
1420
		}
1421
		
1422
		adapt(element);
1423
		parentElement.addElement(element);
1424
		return element;
1425
	}
1426

    
1427
	/**
1428
	 * <p>
1429
	 * createCdmDetailSection
1430
	 * </p>
1431
	 * 
1432
	 * @param detailType
1433
	 *            a
1434
	 *            {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType}
1435
	 *            object.
1436
	 * @param parentElement
1437
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1438
	 *            object.
1439
	 * @param selectionProvider
1440
	 *            a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
1441
	 * @param style
1442
	 *            a int.
1443
	 * @param conversation
1444
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1445
	 *            object.
1446
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1447
	 *         object.
1448
	 */
1449
	public AbstractFormSection createCdmDetailSection(DetailType detailType,
1450
			ConversationHolder conversation, ICdmFormElement parentElement,
1451
			ISelectionProvider selectionProvider, int style) {
1452
		AbstractFormSection section = null;
1453

    
1454
		switch (detailType) {
1455
		case SCIENTIFICNAME:
1456
			section = new NameDetailSection(this, conversation, parentElement,
1457
					selectionProvider, style);
1458
			break;
1459
		case REFERENCEBASE:
1460
			section = new ReferenceDetailSection(this, conversation,
1461
					parentElement, selectionProvider, style);
1462
			break;
1463
		case NOMENCLATURALREFERENCE:
1464
			section = new NomenclaturalReferenceDetailSection(this,
1465
					conversation, parentElement, selectionProvider, style);
1466
			break;
1467
		case TAXONBASE:
1468
			section = new TaxonBaseDetailSection(this, conversation,
1469
					parentElement, selectionProvider, style);
1470
			break;
1471
		case AUTHORSHIP:
1472
			section = new AuthorshipDetailSection(this, conversation,
1473
					parentElement, selectionProvider, style);
1474
			break;
1475
		case TEAMORPERSONBASE:
1476
			section = new TeamOrPersonBaseDetailSection(this, conversation,
1477
					parentElement, selectionProvider, style);
1478
			break;
1479
		case TEAM:
1480
			section = new TeamDetailSection(this, conversation, parentElement,
1481
					null, style);
1482
			break;
1483
		case PERSON:
1484
			section = new PersonDetailSection(this, conversation,
1485
					parentElement, null, style);
1486
			break;
1487
		case DESCRIPTION:
1488
			section = new DescriptionDetailSection(this, conversation,
1489
					parentElement, selectionProvider, style);
1490
			break;
1491
		case DESCRIPTIONELEMENT:
1492
			section = new DescriptionElementDetailSection(this, conversation,
1493
					parentElement, selectionProvider, style);
1494
			break;
1495
		case PARSINGMESSAGE:
1496
			section = new ParsingMessagesSection(this, conversation,
1497
					parentElement, selectionProvider, style);
1498
			break;
1499
		case NONVIRALNAME:
1500
			section = new NonViralNameDetailSection(this, conversation,
1501
					parentElement, selectionProvider, style);
1502
			break;
1503
		case MEDIA:
1504
			section = new eu.etaxonomy.taxeditor.ui.section.description.MediaDetailsSection(
1505
					this, conversation, parentElement, selectionProvider, style);
1506
			break;
1507
		case DERIVED_UNIT_FACADE:
1508
			section = new DerivedUnitFacadeDetailSection(this, conversation,
1509
					parentElement, selectionProvider, style);
1510
			break;
1511
		case FIELD_OBSERVATION:
1512
			section = new FieldObservationDetailSection(this, conversation,
1513
					parentElement, selectionProvider, style);
1514
			break;
1515
		case GATHERING_EVENT:
1516
			section = new GatheringEventDetailSection(this, conversation,
1517
					parentElement, selectionProvider, style);
1518
			break;
1519
		case DERIVED_UNIT:
1520
			section = new DerivedUnitBaseDetailSection(this, conversation,
1521
					parentElement, selectionProvider, style);
1522
			break;
1523
		case NATURAL_LANGUAGE:
1524
			section = new NaturalLanguageSection(this, conversation,
1525
					parentElement, selectionProvider, style);
1526
			break;
1527
		case FEATURE_DISTRIBUTION:
1528
			section = new FeatureDistributionDetailSection(this, conversation,
1529
					parentElement, selectionProvider, style);
1530
			break;
1531
		case CLASSIFICATION:
1532
			section = new ClassificationDetailSection(this, conversation,
1533
					parentElement, selectionProvider, style);
1534
			break;
1535
		case TAXON_NODE:
1536
			section = new TaxonNodeDetailSection(this, conversation,
1537
					parentElement, selectionProvider, style);
1538
			break;
1539
		case POLYTOMOUS_KEY:
1540
			section = new PolytomousKeyDetailSection(this, conversation,
1541
					parentElement, selectionProvider, style);
1542
			break;
1543
		case POLYTOMOUS_KEY_NODE:
1544
			section = new PolytomousKeyNodeDetailSection(this, conversation,
1545
					parentElement, selectionProvider, style);
1546
			break;
1547
		case INSTITUTION:
1548
			section = new InstitutionDetailSection(this, conversation,
1549
					parentElement, selectionProvider, style);
1550
			break;
1551
		case DERIVED_UNIT_GENERAL:
1552
			section = new GeneralDetailSection(this, conversation,
1553
					parentElement, selectionProvider, style);
1554
			break;
1555
		case HYBRID:
1556
			section = new HybridDetailSection(this, conversation,
1557
					parentElement, selectionProvider, style);
1558
			break;
1559
		case USER:
1560
			section = new UserDetailSection(this, conversation, parentElement,
1561
					selectionProvider, style);
1562
			break;
1563
		case GROUP:
1564
			section = new GroupDetailSection(this, conversation, parentElement,
1565
					selectionProvider, style);
1566
			break;
1567
		case DETERMINATION:
1568
			section = new DeterminationDetailSection(this, conversation, parentElement,
1569
					selectionProvider, style);
1570
			break;
1571
		case TAXON_RELATIONSHIP:
1572
			section = new TaxonRelationshipDetailSection(this, conversation, parentElement, 
1573
					selectionProvider, style);
1574
			break;
1575
		case REFERENCED_ENTITY:
1576
			section = new ReferencedEntityDetailSection(this, conversation, parentElement, 
1577
					selectionProvider, style);
1578
			break;
1579
		case TERM_VOCABULARY:
1580
			section = new TermVocabularyDetailSection(this, conversation, parentElement, 
1581
					selectionProvider, style);
1582
			break;
1583
		case NAMED_AREA:
1584
			section = new NamedAreaDetailSection(this, conversation, parentElement, 
1585
					selectionProvider, style);
1586
			break;
1587
		case USE_RECORD:
1588
			section = new UseRecordDetailSection(this, conversation, parentElement,
1589
					selectionProvider, style);
1590
			break;
1591
		}
1592
		
1593

    
1594
		if (section == null) {
1595
			throw new RuntimeException(
1596
					"You tried to create a cdm detail section that is not implemented yet.");
1597
		}
1598

    
1599
		parentElement.addElement(section);
1600
		adapt(section);
1601
		return section;
1602
	}
1603

    
1604
	
1605
	
1606
	/**
1607
	 * <p>
1608
	 * createCdmDetailElement
1609
	 * </p>
1610
	 * 
1611
	 * @param detailType
1612
	 *            a
1613
	 *            {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType}
1614
	 *            object.
1615
	 * @param style
1616
	 *            a int.
1617
	 * @param parentElement
1618
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1619
	 *            object.
1620
	 * @return a
1621
	 *         {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
1622
	 *         object.
1623
	 */
1624
	public AbstractCdmDetailElement createCdmDetailElement(
1625
			DetailType detailType, ICdmFormElement parentElement, int style) {
1626
		AbstractCdmDetailElement element = null;
1627

    
1628
		switch (detailType) {
1629
		case SCIENTIFICNAME:
1630
			element = new NameDetailElement(this, parentElement, style);
1631
			break;
1632
		case REFERENCEBASE:
1633
			element = new ReferenceDetailElement(this, parentElement, style);
1634
			break;
1635
		case NOMENCLATURALREFERENCE:
1636
			element = new NomenclaturalReferenceDetailElement(this,
1637
					parentElement, style);
1638
			break;
1639
		case TAXONBASE:
1640
			element = new TaxonBaseDetailElement(this, parentElement, style);
1641
			break;
1642
		case AUTHORSHIP:
1643
			element = new AuthorshipDetailElement(this, parentElement, style);
1644
			break;
1645
		case TEAM:
1646
			element = new TeamDetailElement(this, parentElement, style);
1647
			break;
1648
		case PERSON:
1649
			element = new PersonDetailElement(this, parentElement, style);
1650
			break;
1651
		case DESCRIPTION:
1652
			element = new DescriptionDetailElement(this, parentElement, style);
1653
			break;
1654
		case DESCRIPTIONELEMENT:
1655
			element = new DescriptionElementDetailElement(this, parentElement,
1656
					style);
1657
			break;
1658
		case NONVIRALNAME:
1659
			element = new NonViralNameDetailElement(this, parentElement);
1660
			break;
1661
		case DERIVED_UNIT_FACADE:
1662
			element = new DerivedUnitFacadeDetailElement(this, parentElement);
1663
			break;
1664
		case FIELD_OBSERVATION:
1665
			element = new FieldObservationDetailElement(this, parentElement);
1666
			break;
1667
		case GATHERING_EVENT:
1668
			element = new GatheringEventDetailElement(this, parentElement);
1669
			break;
1670
		case DERIVED_UNIT:
1671
			element = new DerivedUnitBaseDetailElement(this, parentElement);
1672
			break;
1673
		case NATURAL_LANGUAGE:
1674
			element = new NaturalLanguageDetailElement(this, parentElement);
1675
			break;
1676
		case FEATURE_DISTRIBUTION:
1677
			element = new FeatureDistributionDetailElement(this, parentElement);
1678
			break;
1679
		case CLASSIFICATION:
1680
			element = new ClassificationDetailElement(this, parentElement);
1681
			break;
1682
		case TAXON_NODE:
1683
			element = new TaxonNodeDetailElement(this, parentElement);
1684
			break;
1685
		case COLLECTION:
1686
			element = new CollectionDetailElement(this, parentElement);
1687
			break;
1688
		case POLYTOMOUS_KEY:
1689
			element = new PolytomousKeyDetailElement(this, parentElement);
1690
			break;
1691
		case POLYTOMOUS_KEY_NODE:
1692
			element = new PolytomousKeyNodeDetailElement(this, parentElement);
1693
			break;
1694
		case INSTITUTION:
1695
			element = new InstitutionDetailElement(this, parentElement);
1696
			break;
1697
		case DERIVED_UNIT_GENERAL:
1698
			element = new GeneralDetailElement(this, parentElement);
1699
			break;
1700
		case HYBRID:
1701
			element = new HybridDetailElement(this, parentElement);
1702
			break;
1703
		case USER:
1704
			element = new UserDetailElement(this, parentElement);
1705
			break;
1706
		case GROUP:
1707
			element = new GroupDetailElement(this, parentElement);
1708
			break;
1709
		case GRANTEDAUTHORITY:
1710
			element = new GrantedAuthorityDetailElement(this, parentElement);
1711
			break;
1712
		case DETERMINATION:
1713
			element = new DeterminationDetailElement(this, parentElement);
1714
			break;
1715
		case TAXON_RELATIONSHIP:
1716
			element = new TaxonRelationshipDetailElement(this, parentElement);
1717
			break;
1718
		case REFERENCED_ENTITY:
1719
			element = new RefereneEntityDetailElement(this, parentElement);
1720
			break;
1721
		case TERM_VOCABULARY:
1722
			element = new TermVocabularyDetailElement(this, parentElement);
1723
			break;
1724
		case NAMED_AREA:
1725
			element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
1726
			break;
1727
		case NAMED_AREA_LEVEL:
1728
			element = new DefinedTermDetailElement<NamedAreaLevel>(this, parentElement);
1729
			break;
1730
		case USE_RECORD:
1731
			//element = new UseRecordDetailElement(this, parentElement, style);
1732
			element = new UseRecordDetailElement(this, parentElement);
1733
			break;
1734
		}
1735

    
1736
		if (element == null) {
1737
			StoreUtil
1738
					.error(this.getClass(),
1739
							"Detail element was not created. Seems like the case was not implemented for the requested detail type: "
1740
									+ detailType, null);
1741
		}
1742

    
1743
		adapt(element);
1744
		parentElement.addElement(element);
1745
		return element;
1746
	}
1747

    
1748
	/**
1749
	 * 
1750
	 * @author n.hoffmann
1751
	 * @created Mar 5, 2010
1752
	 * @version 1.0
1753
	 */
1754
	public static enum EntityDetailType {
1755
		TEAM, 
1756
		TEAMMEMBER, 
1757
		ANNOTATION, 
1758
		CREDIT, 
1759
		DESCRIPTIONELEMENTSOURCE, 
1760
		EXTENSION, 
1761
		MARKER, 
1762
		MEDIA, 
1763
		DESCRIPTIONELEMENTMEDIA, 
1764
		MEDIAREPRESENTATION, 
1765
		MEDIAREPRESENTATIONPART, 
1766
		MODIFIER, 
1767
		NOMENCLATURALSTATUS, 
1768
		NAME_RELATIONSHIP, 
1769
		PROTOLOG, 
1770
		RIGHTS, 
1771
		SOURCE, 
1772
		SCOPE, 
1773
		DESCRIPTIONSOURCE, 
1774
		TYPEDESIGNATION, 
1775
		STATE_DATA, 
1776
		STATISTICAL_MEASUREMENT_VALUE, 
1777
		DESCRIBED_SPECIMEN, 
1778
		COLLECTING_AREA, 
1779
		DETERMINATION_EVENT, 
1780
		SPECIMEN_COLLECTION, 
1781
		IDENTIFIABLE_SOURCE_COLLECTION, 
1782
		GEOGRAPHICAL_SCOPE, 
1783
		SCOPE_RESTRICTION, 
1784
		MEMBER, 
1785
		GRANTED_AUTHORITY, 
1786
		GROUPS_BY_USER, 
1787
		TAXONOMIC_SCOPE, 
1788
		DETERMINATION_CURRENT, 
1789
		DETERMINATION_HISTORY
1790
	}
1791

    
1792
	/**
1793
	 * <p>
1794
	 * createEntityDetailSection
1795
	 * </p>
1796
	 * 
1797
	 * @param entityDetailType
1798
	 *            a
1799
	 *            {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.EntityDetailType}
1800
	 *            object.
1801
	 * @param style
1802
	 *            a int.
1803
	 * @param conversation
1804
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1805
	 *            object.
1806
	 * @param parentElement
1807
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1808
	 *            object.
1809
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1810
	 *         object.
1811
	 */
1812
	public AbstractFormSection createEntityDetailSection(
1813
			EntityDetailType entityDetailType, ConversationHolder conversation,
1814
			ICdmFormElement parentElement, int style) {
1815
		AbstractFormSection section = null;
1816

    
1817
		switch (entityDetailType) {
1818
		case TEAM:
1819
			section = new TeamDetailSection(this, conversation, parentElement,
1820
					null, style);
1821
			break;
1822
		case TEAMMEMBER:
1823
			section = new TeamMemberSection(this, conversation, parentElement,
1824
					style);
1825
			break;
1826
		case ANNOTATION:
1827
			section = new AnnotationSection(this, conversation, parentElement,
1828
					style);
1829
			break;
1830
		case CREDIT:
1831
			section = new CreditSection(this, conversation, parentElement,
1832
					style);
1833
			break;
1834
		case DESCRIPTIONELEMENTSOURCE:
1835
			section = new DescriptionElementSourceSection(this, conversation,
1836
					parentElement, style);
1837
			break;
1838
		case EXTENSION:
1839
			section = new ExtensionSection(this, conversation, parentElement,
1840
					style);
1841
			break;
1842
		case MARKER:
1843
			section = new MarkerSection(this, conversation, parentElement,
1844
					style);
1845
			break;
1846
		case MEDIA:
1847
			section = new MediaSection(this, conversation, parentElement, style);
1848
			break;
1849
		case DESCRIPTIONELEMENTMEDIA:
1850
			section = new DescriptionElementMediaSection(this, conversation,
1851
					parentElement, style);
1852
			break;
1853
		case MEDIAREPRESENTATION:
1854
			section = new MediaRepresentationSection(this, conversation,
1855
					parentElement, style);
1856
			break;
1857
		case MEDIAREPRESENTATIONPART:
1858
			section = new MediaRepresentationPartSection(this, conversation,
1859
					parentElement, style);
1860
			break;
1861
		case MODIFIER:
1862
			section = new ModifierSection(this, conversation, parentElement,
1863
					style);
1864
			break;
1865
		case NOMENCLATURALSTATUS:
1866
			section = new NomenclaturalStatusSection(this, conversation,
1867
					parentElement, style);
1868
			break;
1869
		case NAME_RELATIONSHIP:
1870
			section = new NameRelationshipDetailSection(this, conversation,
1871
					parentElement, style);
1872
			break;
1873
		case PROTOLOG:
1874
			section = new ProtologueSection(this, conversation, parentElement,
1875
					style);
1876
			break;
1877
		case RIGHTS:
1878
			section = new RightsSection(this, conversation, parentElement,
1879
					style);
1880
			break;
1881
		case SOURCE:
1882
			section = new SourceSection(this, conversation, parentElement,
1883
					style);
1884
			break;
1885
		case SCOPE:
1886
			section = new ScopeSection(this, conversation, parentElement, style);
1887
			break;
1888
		case DESCRIPTIONSOURCE:
1889
			section = new DescriptionSourceSection(this, conversation,
1890
					parentElement, style);
1891
			break;
1892
		case TYPEDESIGNATION:
1893
			section = new TypeDesignationSection(this, conversation,
1894
					parentElement, style);
1895
			break;
1896
		case STATE_DATA:
1897
			section = new StateDataSection(this, conversation, parentElement,
1898
					style);
1899
			break;
1900
		case STATISTICAL_MEASUREMENT_VALUE:
1901
			section = new StatisticalMeasurementValueSection(this,
1902
					conversation, parentElement, style);
1903
			break;
1904
		case DESCRIBED_SPECIMEN:
1905
			section = new DescribedSpecimenSection(this, conversation,
1906
					parentElement, style);
1907
			break;
1908
		case COLLECTING_AREA:
1909
			section = new CollectingAreasDetailSection(this, conversation,
1910
					parentElement, style);
1911
			break;
1912
		case DETERMINATION_CURRENT:
1913
			section = new CurrentDeterminationDetailSection(this, conversation,
1914
					parentElement, style);
1915
			break;
1916
		case DETERMINATION_HISTORY:
1917
			section = new DeterminationHistoryDetailSection(this, conversation,
1918
					parentElement, style);
1919
			break;
1920
		case SPECIMEN_COLLECTION:
1921
			section = new SpecimenCollectionDetailSection(this, conversation,
1922
					parentElement, style);
1923
			break;
1924
		case IDENTIFIABLE_SOURCE_COLLECTION:
1925
			section = new SourceCollectionDetailSection(this, conversation,
1926
					parentElement, style);
1927
			break;
1928
		case GEOGRAPHICAL_SCOPE:
1929
			section = new GeographicalScopeDetailSection(this, conversation,
1930
					parentElement, style);
1931
			break;
1932
		case SCOPE_RESTRICTION:
1933
			section = new ScopeRestrictionSection(this, conversation,
1934
					parentElement, style);
1935
			break;
1936
		case MEMBER:
1937
			section = new MemberDetailSection(this, conversation,
1938
					parentElement, style);
1939
			break;
1940
		case GRANTED_AUTHORITY:
1941
			section = new GrantedAuthorityDetailSection(this, conversation,
1942
					parentElement, style);
1943
			break;
1944
		case GROUPS_BY_USER:
1945
			section = new GroupsByUserDetailSection(this, conversation,
1946
					parentElement, style);
1947
			break;
1948
		case TAXONOMIC_SCOPE:
1949
			section = new TaxonomicScopeSection(this, conversation,
1950
					parentElement, style);
1951
			break;
1952
		}
1953
		parentElement.addElement(section);
1954
		adapt(section);
1955
		return section;
1956
	}
1957

    
1958
	/**
1959
	 * <p>
1960
	 * createEntityCollectionElement
1961
	 * </p>
1962
	 * 
1963
	 * @param removeListener
1964
	 *            a {@link org.eclipse.swt.events.SelectionListener} object.
1965
	 * @param style
1966
	 *            a int.
1967
	 * @param parentElement
1968
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1969
	 *            object.
1970
	 * @param versionableEntity
1971
	 *            a {@link eu.etaxonomy.cdm.model.common.IVersionableEntity}
1972
	 *            object.
1973
	 * @param backgroundColor
1974
	 *            a {@link org.eclipse.swt.graphics.Color} object.
1975
	 * @return a
1976
	 *         {@link eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement}
1977
	 *         object.
1978
	 */
1979
	public AbstractEntityCollectionElement createEntityCollectionElement(
1980
			AbstractFormSection parentElement, Object versionableEntity,
1981
			SelectionListener removeListener, Color backgroundColor, int style) {
1982
		AbstractEntityCollectionElement element = null;
1983

    
1984
		Object entity = HibernateProxyHelper.deproxy(versionableEntity);
1985

    
1986
		if (entity instanceof Annotation) {
1987
			element = new AnnotationElement(this, parentElement,
1988
					(Annotation) entity, removeListener, style);
1989
		} else if (entity instanceof Person) {
1990
			element = new TeamMemberElement(this, parentElement,
1991
					(Person) entity, removeListener, style);
1992
		} else if (entity instanceof Credit) {
1993
			element = new CreditElement(this, parentElement, (Credit) entity,
1994
					removeListener, style);
1995
		} else if (entity instanceof Extension) {
1996
			element = new ExtensionElement(this, parentElement,
1997
					(Extension) entity, removeListener, style);
1998
		} else if (entity instanceof Marker) {
1999
			element = new MarkerElement(this, parentElement, (Marker) entity,
2000
					removeListener, style);
2001
		} else if (entity instanceof Media) {
2002
			element = new MediaElement(this, parentElement, (Media) entity,
2003
					removeListener, style);
2004
		} else if (entity instanceof MediaRepresentation) {
2005
			element = new MediaRepresentationElement(this, parentElement,
2006
					(MediaRepresentation) entity, removeListener, style);
2007
		} else if (entity instanceof ImageFile) {
2008
			element = new ImageFileElement(this, parentElement,
2009
					(ImageFile) entity, removeListener, style);
2010
		} else if (entity instanceof MediaRepresentationPart){
2011
			element = new MediaRepresentationPartElement(this, parentElement, 
2012
					(MediaRepresentationPart) entity, removeListener, style);			
2013
		} else if (entity instanceof NomenclaturalStatus) {
2014
			element = new NomenclaturalStatusElement(this, parentElement,
2015
					(NomenclaturalStatus) entity, removeListener, style);
2016
		} else if (entity instanceof Rights) {
2017
			element = new RightsElement(this, parentElement, (Rights) entity,
2018
					removeListener, style);
2019
		} else if (entity instanceof DescriptionElementSource) {
2020
			element = new DescriptionElementSourceElement(this, parentElement,
2021
					(DescriptionElementSource) entity, removeListener, style);
2022
		} else if (entity instanceof IdentifiableSource) {
2023
			element = new IdentifiableSourceElement(this, parentElement,
2024
					(IdentifiableSource) entity, removeListener, style);
2025
		} else if (entity instanceof DefinedTerm) {
2026
			switch(((DefinedTerm)entity).getTermType()) {
2027
				case Scope:
2028
					element = new ScopeElement(this, 
2029
							parentElement, 
2030
							(DefinedTerm) entity,
2031
							removeListener, 
2032
							style);
2033
					break;
2034
				case Modifier:
2035
					element = new ModifierElement(this, 
2036
							parentElement,
2037
							(DefinedTerm) entity, 
2038
							removeListener, 
2039
							style);
2040
					break;
2041
				default:
2042
					//FIXME : Actually we should through an exception here
2043
					element = null;
2044
					break;
2045
			
2046
			}
2047
		} else if (entity instanceof Reference) {
2048
			element = new DescriptionSourceElement(this, parentElement,
2049
					(Reference) entity, removeListener, style);
2050
		} else if (entity instanceof NameTypeDesignation) {
2051
			element = new NameTypeDesignationElement(this, parentElement,
2052
					(NameTypeDesignation) entity, removeListener, style);
2053
		} else if (entity instanceof NameRelationship) {
2054
			element = new NameRelationshipDetailElement(this, parentElement,
2055
					(NameRelationship) entity, removeListener, style);
2056
		} else if (entity instanceof SpecimenTypeDesignation) {
2057
			element = new SpecimenTypeDesignationElement(this, parentElement,
2058
					(SpecimenTypeDesignation) entity, removeListener, style);
2059
		} else if (entity instanceof StateData) {
2060
			element = new StateDataElement(this, parentElement,
2061
					(StateData) entity, removeListener, style);
2062
		} else if (entity instanceof StatisticalMeasurementValue) {
2063
			element = new StatisticalMeasurementValueElement(this,
2064
					parentElement, (StatisticalMeasurementValue) entity,
2065
					removeListener, style);
2066
		} else if (entity instanceof DerivedUnit) {
2067
			switch(((DerivedUnit)entity).getRecordBasis()) {
2068
				case LivingSpecimen:
2069
				case PreservedSpecimen:
2070
				case OtherSpecimen:
2071
					element = new SpecimenCollectionDetailElement(this, 
2072
								parentElement,
2073
								(DerivedUnit) entity, 
2074
								removeListener, 
2075
								style);
2076
					break;
2077
				default:
2078
					element = new DerivedUnitElement(this, 
2079
								parentElement,
2080
								(DerivedUnit) entity, 
2081
								removeListener, 
2082
								style);
2083
			}			
2084

    
2085
		} else if (entity instanceof NamedArea) {
2086
			element = new NamedAreaDetailElement(this, parentElement,
2087
					(NamedArea) entity, removeListener, style);
2088
		} else if (entity instanceof DeterminationEvent) {
2089
			element = new DeterminationEventDetailElement(this, parentElement,
2090
					(DeterminationEvent) entity, removeListener, style);			
2091
		} else if (entity instanceof User) {
2092
			element = new MemberDetailElement(this, parentElement,
2093
					(User) entity, removeListener, style);
2094
		} else if (entity instanceof GrantedAuthority) {
2095
			element = new GrantedAuthorityCollectionElement(this, parentElement,
2096
					(GrantedAuthorityImpl) entity, removeListener, style);
2097
		} else if (entity instanceof Group) {
2098
			element = new GroupsByUserDetailElement(this, parentElement,
2099
					(Group) entity, removeListener, style);
2100
		} else if (entity instanceof Taxon) {
2101
			element = new TaxonDetailElement(this, parentElement,
2102
					(Taxon) entity, removeListener, style);
2103
		} else if (entity instanceof DescriptionElementBase) {
2104
			// this is the special case for protologs, maybe we can do this
2105
			// differently when API improves
2106
			DescriptionElementBase descriptionElement = (DescriptionElementBase) entity;
2107
			if (descriptionElement.getFeature().equals(Feature.PROTOLOGUE())) {
2108
				element = new ProtologueElement(this, parentElement,
2109
						descriptionElement, removeListener, style);
2110
			}
2111
		}
2112

    
2113
		if (element == null) {
2114
			StoreUtil
2115
					.errorDialog(
2116
							"No element for entity",
2117
							this,
2118
							"Could not generate element for entity. "
2119
									+ "Looks like the case is not handled already. Check implementation. Entity: "
2120
									+ entity, null);
2121

    
2122
		}
2123

    
2124
		if (backgroundColor != null && !backgroundColor.isDisposed()) {
2125
			element.setPersistentBackground(backgroundColor);
2126
		}
2127

    
2128
		adapt(element);
2129
		parentElement.addElement(element);
2130
		return element;
2131
	}
2132

    
2133
	/**
2134
	 * <p>
2135
	 * Creates a selection element for the given type T.
2136
	 * </p>
2137
	 * <p>
2138
	 * 	<strong>Selection elements not handled by this method:</strong>
2139
	 * 	<ul>
2140
	 * 		<li>{@link TaxonNodeSelectionElement} see {@link #createTaxonNodeSelectionElement(ConversationHolder, ICdmFormElement, String, TaxonNode, int, int)}</li>
2141
	 * 		<li>{@link NomenclaturalAuthorTeamSelectionElement} see {@link #createNomenclaturalAuthorTeamSelectionElement(ConversationHolder, ICdmFormElement, String, Team, int, int)}</li>
2142
	 * 	</ul>	
2143
	 * </p>
2144
	 * 
2145
	 * @param clazz
2146
	 * 			  a {@link Class} object of the type that you want the selection element to handle
2147
	 * @param parentElement
2148
	 *            a {@link ICdmFormElement}
2149
	 *            object.
2150
	 * @param labelString
2151
	 *            a {@link String} object.
2152
	 * @param selectionType
2153
	 * @param selection
2154
	 *            a {@link ICdmBase} object.
2155
	 * @param style
2156
	 *            a int.
2157
	 * @param conversation
2158
	 *            a {@link ConversationHolder} object.
2159
	 * @return a
2160
	 *         {@link EntitySelectionElement}
2161
	 *         object.
2162
	 */
2163
	public <T extends ICdmBase> EntitySelectionElement<T> createSelectionElement(
2164
			Class<T> clazz, ConversationHolder conversation,
2165
			ICdmFormElement parentElement, String labelString,
2166
			T selection, int mode, int style) {
2167
		EntitySelectionElement<T> element = new EntitySelectionElement<T>(this, conversation, parentElement, clazz, labelString, selection, mode, style);
2168
		adapt(element);
2169
		parentElement.addElement(element);
2170
		return element;
2171
	}
2172
	
2173
	public TaxonNodeSelectionElement createTaxonNodeSelectionElement(
2174
			ConversationHolder conversation,
2175
			ICdmFormElement parentElement, String labelString,
2176
			TaxonNode selection, int mode, int style) {
2177
		TaxonNodeSelectionElement element = new TaxonNodeSelectionElement(this, conversation, parentElement, labelString, selection, mode, style);
2178
		adapt(element);
2179
		parentElement.addElement(element);
2180
		return element;
2181
	}
2182
	
2183
	public NomenclaturalAuthorTeamSelectionElement createNomenclaturalAuthorTeamSelectionElement(
2184
			ConversationHolder conversation,
2185
			ICdmFormElement parentElement, String labelString,
2186
			Team selection, int mode, int style) {
2187
		NomenclaturalAuthorTeamSelectionElement element = new NomenclaturalAuthorTeamSelectionElement(this, conversation, parentElement, labelString, selection, mode, style);
2188
		adapt(element);
2189
		parentElement.addElement(element);
2190
		return element;
2191
	}
2192
	
2193
	
2194
	/** {@inheritDoc} */
2195
	public LabelElement createLabel(ICdmFormElement parentElement, String text) {
2196
		LabelElement labelElement = new LabelElement(this, parentElement, text);
2197
		adapt(labelElement);
2198
		parentElement.addElement(labelElement);
2199
		return labelElement;
2200
	}
2201

    
2202
	/**
2203
	 * <p>
2204
	 * Getter for the field <code>selectionProvider</code>.
2205
	 * </p>
2206
	 * 
2207
	 * @return a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
2208
	 */
2209
	public ISelectionProvider getSelectionProvider() {
2210
		return selectionProvider;
2211
	}
2212

    
2213
	/**
2214
	 * <p>
2215
	 * createDetailedDescriptionDetailElement
2216
	 * </p>
2217
	 * 
2218
	 * @param parentElement
2219
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
2220
	 *            object.
2221
	 * @param entity
2222
	 *            a
2223
	 *            {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase}
2224
	 *            object.
2225
	 * @param style
2226
	 *            a int.
2227
	 * @return a
2228
	 *         {@link eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement}
2229
	 *         object.
2230
	 */
2231
	public AbstractDetailedDescriptionDetailElement createDetailedDescriptionDetailElement(
2232
			ICdmFormElement parentElement, DescriptionElementBase entity,
2233
			int style) {
2234
		AbstractDetailedDescriptionDetailElement detailedDescriptionElement = null;
2235

    
2236
		if (entity instanceof CategoricalData) {
2237
			detailedDescriptionElement = new CategoricalDataDetailElement(this,
2238
					parentElement, (CategoricalData) entity, style);
2239
		} else if (entity instanceof CommonTaxonName) {
2240
			detailedDescriptionElement = new CommonNameDetailElement(this,
2241
					parentElement, (CommonTaxonName) entity, style);
2242
		} else if (entity instanceof Distribution) {
2243
			detailedDescriptionElement = new DistributionDetailElement(this,
2244
					parentElement, (Distribution) entity, style);
2245
		} else if (entity instanceof IndividualsAssociation) {
2246
			detailedDescriptionElement = new IndividualsAssociationDetailElement(
2247
					this, parentElement, (IndividualsAssociation) entity, style);
2248
		} else if (entity instanceof QuantitativeData) {
2249
			detailedDescriptionElement = new QuantitativeDataDetailElement(
2250
					this, parentElement, (QuantitativeData) entity, style);
2251
		} else if (entity instanceof TaxonInteraction) {
2252
			detailedDescriptionElement = new TaxonInteractionDetailElement(
2253
					this, parentElement, (TaxonInteraction) entity, style);
2254
		} else if (entity instanceof TextData) {
2255
			detailedDescriptionElement = new TextDataDetailElement(this,
2256
					parentElement, (TextData) entity, style);
2257
		} else {
2258
			throw new IllegalStateException(
2259
					"There is no interface for the given description element");
2260
		}
2261
		adapt(detailedDescriptionElement);
2262
		parentElement.addElement(detailedDescriptionElement);
2263
		return detailedDescriptionElement;
2264

    
2265
	}
2266

    
2267
	/**
2268
	 * Creates a styled text as a part of the form.
2269
	 * 
2270
	 * @param parent
2271
	 *            the text parent
2272
	 * @param value
2273
	 *            the text initial value
2274
	 * @param style
2275
	 *            the text style
2276
	 * @return the text widget
2277
	 */
2278
	public StyledText createStyledText(Composite parent, String value, int style) {
2279
		StyledText text = new StyledText(parent, getBorderStyle() | style
2280
				| getOrientation());
2281
		if (value != null)
2282
			text.setText(value);
2283
		text.setForeground(getColors().getForeground());
2284
		text.setBackground(getColors().getBackground());
2285
		// text.addFocusListener(visibilityHandler);
2286
		return text;
2287
	}
2288

    
2289

    
2290

    
2291

    
2292

    
2293

    
2294
}
(6-6/36)