Project

General

Profile

Download (84.1 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.taxeditor.ui.forms;
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.forms.widgets.TableWrapData;
39
import org.eclipse.ui.forms.widgets.TableWrapLayout;
40
import org.eclipse.ui.internal.forms.widgets.FormFonts;
41
import org.joda.time.Partial;
42
import org.springframework.security.core.GrantedAuthority;
43

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

    
291
/**
292
 * <p>
293
 * CdmFormFactory class.
294
 * </p>
295
 * 
296
 * @author n.hoffmann
297
 * @created Feb 24, 2010
298
 * @version 1.0
299
 */
300
public class CdmFormFactory extends FormToolkit {
301

    
302
	private BoldFontHolder2 boldFontHolder2;
303
	private MouseListener selectionMouseHandler;
304
	private FocusListener selectionFocusHandler;
305

    
306
	private final Set selectionListenerList = new HashSet();
307

    
308
	private final List<IPropertyChangeListener> propertyChangeListeners = new ArrayList<IPropertyChangeListener>();
309

    
310
	private final int orientation = Window.getDefaultOrientation();
311
	private ISelectionProvider selectionProvider;
312

    
313
	/**
314
	 * <p>
315
	 * LAYOUT
316
	 * </p>
317
	 * 
318
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapLayout} object.
319
	 */
320
	public static final TableWrapLayout LAYOUT() {
321
		return LAYOUT(1, false);
322
	}
323

    
324
	/**
325
	 * <p>
326
	 * LAYOUT
327
	 * </p>
328
	 * 
329
	 * @param columns
330
	 *            a int.
331
	 * @param equalWidth
332
	 *            a boolean.
333
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapLayout} object.
334
	 */
335
	public static final TableWrapLayout LAYOUT(int columns, boolean equalWidth) {
336
		TableWrapLayout layout = new TableWrapLayout();
337
		layout.topMargin = 0;
338
		layout.rightMargin = 0;
339
		layout.bottomMargin = 0;
340
		layout.leftMargin = 0;
341
		layout.numColumns = columns;
342
		layout.makeColumnsEqualWidth = equalWidth;
343
		layout.verticalSpacing = 0;
344
		layout.horizontalSpacing = 0;
345
		return layout;
346
	}
347

    
348
	/**
349
	 * <p>
350
	 * FILL
351
	 * </p>
352
	 * 
353
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
354
	 */
355
	public static final TableWrapData FILL() {
356
		return FILL(1, 1);
357
	}
358

    
359
	/**
360
	 * <p>
361
	 * FILL
362
	 * </p>
363
	 * 
364
	 * @param horizontalSpan
365
	 *            a int.
366
	 * @param verticalSpan
367
	 *            a int.
368
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
369
	 */
370
	public static final TableWrapData FILL(int horizontalSpan, int verticalSpan) {
371
		TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB,
372
				TableWrapData.FILL_GRAB);
373
		layoutData.colspan = horizontalSpan;
374
		layoutData.rowspan = verticalSpan;
375
		return layoutData;
376
	}
377

    
378
	/**
379
	 * <p>
380
	 * LEFT
381
	 * </p>
382
	 * 
383
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
384
	 */
385
	public static final TableWrapData LEFT() {
386
		return new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP);
387
	}
388

    
389
	/**
390
	 * <p>
391
	 * RIGHT
392
	 * </p>
393
	 * 
394
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
395
	 */
396
	public static final TableWrapData RIGHT() {
397
		return new TableWrapData(TableWrapData.RIGHT, TableWrapData.TOP);
398
	}
399

    
400
	/**
401
	 * <p>
402
	 * FILL_HORIZONTALLY
403
	 * </p>
404
	 * 
405
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
406
	 */
407
	public static final TableWrapData FILL_HORIZONTALLY() {
408
		return FILL_HORIZONTALLY(1, 1);
409
	}
410

    
411
	/**
412
	 * <p>
413
	 * FILL_HORIZONTALLY
414
	 * </p>
415
	 * 
416
	 * @param horizontalSpan
417
	 *            a int.
418
	 * @param verticalSpan
419
	 *            a int.
420
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
421
	 */
422
	public static final TableWrapData FILL_HORIZONTALLY(int horizontalSpan,
423
			int verticalSpan) {
424
		TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB,
425
				TableWrapData.TOP);
426
		layoutData.colspan = horizontalSpan;
427
		layoutData.rowspan = verticalSpan;
428
		return layoutData;
429
	}
430

    
431
	/** Constant <code>EMPTY_SELECTION</code> */
432
	public static ISelection EMPTY_SELECTION = new ISelection() {
433
		@Override
434
		public boolean isEmpty() {
435
			return true;
436
		}
437
	};
438

    
439
	private class SelectionMouseHandler extends MouseAdapter {
440
		@Override
441
		public void mouseDown(MouseEvent e) {
442
			notifySelectionListeners(e);
443
		}
444
	}
445

    
446
	private class SelectionFocusHandler extends FocusAdapter {
447
		@Override
448
		public void focusGained(FocusEvent e) {
449
			notifySelectionListeners(e);
450
		}
451
	}
452

    
453
	private void notifySelectionListeners(TypedEvent e) {
454
		Event event = new Event();
455
		event.widget = e.widget;
456
		SelectionEvent selectionEvent = new SelectionEvent(event);
457

    
458
		for (Object listener : selectionListenerList) {
459
			((SelectionListener) listener).widgetSelected(selectionEvent);
460
		}
461
	}
462

    
463
	/**
464
	 * <p>
465
	 * Constructor for CdmFormFactory.
466
	 * </p>
467
	 * 
468
	 * @param display
469
	 *            a {@link org.eclipse.swt.widgets.Display} object.
470
	 * @param selectionProvider
471
	 *            a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
472
	 */
473
	public CdmFormFactory(Display display, ISelectionProvider selectionProvider) {
474
		super(display);
475
		this.selectionProvider = selectionProvider;
476
		init();
477
	}
478

    
479
	/**
480
	 * <p>
481
	 * Constructor for CdmFormFactory.
482
	 * </p>
483
	 * 
484
	 * @param display
485
	 *            a {@link org.eclipse.swt.widgets.Display} object.
486
	 */
487
	public CdmFormFactory(Display display) {
488
		super(display);
489
		init();
490
	}
491

    
492
	/**
493
	 * 
494
	 */
495
	private void init() {
496
		boldFontHolder2 = new BoldFontHolder2();
497
		selectionMouseHandler = new SelectionMouseHandler();
498
		selectionFocusHandler = new SelectionFocusHandler();
499
	}
500

    
501
	/**
502
	 * Creates an instance initialized with the correct selectionProvider
503
	 * 
504
	 * Make sure to remove the instance when the entityComposite disposes via
505
	 * destroySelectionArbitrator(..)
506
	 * 
507
	 * @param entityElement
508
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.IEntityElement}
509
	 *            object.
510
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.SelectionArbitrator}
511
	 *         object.
512
	 */
513
	public SelectionArbitrator createSelectionArbitrator(
514
			IEntityElement entityElement) {
515
		SelectionArbitrator selectionArbitrator = new SelectionArbitrator(
516
				entityElement);
517
		selectionArbitrator.addSelectionProvider(selectionProvider);
518
		selectionProvider.addSelectionChangedListener(selectionArbitrator);
519
		addSelectionListener(selectionArbitrator);
520
		return selectionArbitrator;
521
	}
522

    
523
	/**
524
	 * <p>
525
	 * destroySelectionArbitrator
526
	 * </p>
527
	 * 
528
	 * @param selectionArbitrator
529
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.SelectionArbitrator}
530
	 *            object.
531
	 */
532
	public void destroySelectionArbitrator(
533
			SelectionArbitrator selectionArbitrator) {
534
		removeSelectionListener(selectionArbitrator);
535
		if (selectionProvider != null) {
536
			selectionProvider
537
					.removeSelectionChangedListener(selectionArbitrator);
538
		} else {
539
			StoreUtil
540
					.error(this.getClass(),
541
							"Tried to destroy a selection listener from this factories listeners but was null",
542
							null);
543
		}
544
	}
545

    
546
	/** {@inheritDoc} */
547
	@Override
548
	public void adapt(Composite composite) {
549
		composite.addMouseListener(selectionMouseHandler);
550
		super.adapt(composite);
551
	}
552

    
553
	/**
554
	 * <p>
555
	 * adapt
556
	 * </p>
557
	 * 
558
	 * @param formElement
559
	 *            a
560
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.AbstractCdmFormElement}
561
	 *            object.
562
	 */
563
	public void adapt(AbstractCdmFormElement formElement) {
564
		formElement.setPropertyChangeListeners(propertyChangeListeners);
565
	}
566

    
567
	/** {@inheritDoc} */
568
	@Override
569
	public void adapt(Control control, boolean trackFocus, boolean trackKeyboard) {
570
		if (trackFocus) {
571
			control.addFocusListener(selectionFocusHandler);
572
		}
573
		super.adapt(control, trackFocus, trackKeyboard);
574
	}
575

    
576
	/**
577
	 * <p>
578
	 * destroyElement
579
	 * </p>
580
	 * 
581
	 * @param formElement
582
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
583
	 *            object.
584
	 */
585
	public void destroyElement(ICdmFormElement formElement) {
586
		// return if element was not initialized
587
		if (formElement == null) {
588
			return;
589
		}
590
		// destroy selection arbitrator, if any
591
		if (formElement instanceof ISelectableElement) {
592
			destroySelectionArbitrator(((ISelectableElement) formElement)
593
					.getSelectionArbitrator());
594
		}
595
		// remove this element form its parents list of elements
596
		// ICdmFormElement parentElement = formElement.getParentElement();
597
		// if(parentElement != null){
598
		// parentElement.removeElement(formElement);
599
		// }
600
		// call destroy on child elements recursively
601
		for (ICdmFormElement childElement : formElement.getElements()) {
602
			destroyElement(childElement);
603
		}
604
		// dispose of the controls
605
		for (Control control : formElement.getControls()) {
606
			// we added the layoutComposite of the parental element as the
607
			// layout composite to this formElement
608
			// but we do not want to destroy it.
609
			if (control.equals(formElement.getLayoutComposite())) {
610
				continue;
611
			} else {
612
				control.dispose();
613
				control = null;
614
			}
615
		}
616
	}
617

    
618
	/**
619
	 * <p>
620
	 * createEmptyCell
621
	 * </p>
622
	 * 
623
	 * @param parent
624
	 *            a {@link org.eclipse.swt.widgets.Composite} object.
625
	 * @return a {@link org.eclipse.swt.widgets.Label} object.
626
	 */
627
	public Label createEmptyCell(Composite parent) {
628
		return this.createLabel(parent, null);
629
	}
630

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

    
658
	/**
659
	 * <p>
660
	 * createMultiLanguageTextElement
661
	 * </p>
662
	 * 
663
	 * @param parentElement
664
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
665
	 *            object.
666
	 * @param labelString
667
	 *            a {@link java.lang.String} object.
668
	 * @param multilanguageText
669
	 *            a {@link java.util.Map} object.
670
	 * @param textHeight
671
	 *            a int.
672
	 * @param style
673
	 *            a int.
674
	 * @return a
675
	 *         {@link eu.etaxonomy.taxeditor.ui.forms.MultilanguageTextElement}
676
	 *         object.
677
	 */
678
	public MultilanguageTextElement createMultiLanguageTextElement(
679
			ICdmFormElement parentElement, String labelString,
680
			Map<Language, LanguageString> multilanguageText, int textHeight,
681
			int style) {
682
		MultilanguageTextElement element = new MultilanguageTextElement(this,
683
				parentElement, labelString, multilanguageText, textHeight,
684
				style);
685
		adapt(element);
686
		parentElement.addElement(element);
687
		return element;
688
	}
689

    
690
	public KeyStatementElement createKeyStatementElement(
691
			ICdmFormElement parentElement, String labelString,
692
			KeyStatement keyStatement, int textHeight, int style) {
693
		KeyStatementElement element = new KeyStatementElement(this,
694
				parentElement, labelString, keyStatement, textHeight, style);
695
		adapt(element);
696
		parentElement.addElement(element);
697
		return element;
698
	}
699

    
700
	/**
701
	 * <p>
702
	 * createTextWithLabelElement
703
	 * </p>
704
	 * 
705
	 * @param labelString
706
	 *            a {@link java.lang.String} object.
707
	 * @param initialText
708
	 *            a {@link java.lang.String} object.
709
	 * @param style
710
	 *            a int.
711
	 * @param parentElement
712
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
713
	 *            object.
714
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement}
715
	 *         object.
716
	 */
717
	public TextWithLabelElement createTextWithLabelElement(
718
			ICdmFormElement parentElement, String labelString,
719
			String initialText, int style) {
720
		TextWithLabelElement element = new TextWithLabelElement(this,
721
				parentElement, labelString, initialText, null, style);
722
		adapt(element);
723
		parentElement.addElement(element);
724
		return element;
725
	}
726

    
727
	public UriWithLabelElement createUriWithLabelElement(
728
			ICdmFormElement parentElement, String labelString, URI initialUri,
729
			int style) {
730
		UriWithLabelElement element = new UriWithLabelElement(this,
731
				parentElement, labelString, initialUri, null, style);
732
		adapt(element);
733
		parentElement.addElement(element);
734
		return element;
735
	}
736

    
737
	/**
738
	 * @param element
739
	 * @param string
740
	 * @param uri
741
	 * @param style
742
	 * @return
743
	 */
744
	public OpenUrlSelectorElement createOpenUrlSelectorElement(
745
			ICdmFormElement parentElement, String labelString,
746
			IOpenUrlEnabled openUrlEnabled, int style) {
747
		OpenUrlSelectorElement element = new OpenUrlSelectorElement(this,
748
				parentElement, labelString, openUrlEnabled, style);
749
		adapt(element);
750
		parentElement.addElement(element);
751
		return element;
752
	}
753

    
754
	/**
755
	 * 
756
	 * @param parentElement
757
	 * @param labelString
758
	 * @param conversationEnabled
759
	 * @param user
760
	 * @param style
761
	 * @return
762
	 */
763
	public EditPasswordElement createEditPasswordElement(
764
			ICdmFormElement parentElement, String labelString,
765
			ConversationHolder conversation, User user, int style) {
766
		EditPasswordElement element = new EditPasswordElement(this,
767
				parentElement, labelString, user, conversation);
768
		adapt(element);
769
		parentElement.addElement(element);
770
		return element;
771
	}
772

    
773
	/**
774
	 * <p>
775
	 * createIntegerTextWithLabelElement
776
	 * </p>
777
	 * 
778
	 * @param parentElement
779
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
780
	 *            object.
781
	 * @param labelString
782
	 *            a {@link java.lang.String} object.
783
	 * @param initialInteger
784
	 *            a {@link java.lang.Integer} object.
785
	 * @param style
786
	 *            a int.
787
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElement}
788
	 *         object.
789
	 */
790
	public NumberWithLabelElement createIntegerTextWithLabelElement(
791
			ICdmFormElement parentElement, String labelString,
792
			Integer initialInteger, int style) {
793
		NumberWithLabelElement element = new NumberWithLabelElement(this,
794
				parentElement, labelString, initialInteger, style);
795
		adapt(element);
796
		parentElement.addElement(element);
797
		return element;
798
	}
799

    
800
	/**
801
	 * <p>
802
	 * createFloatTextWithLabelElement
803
	 * </p>
804
	 * 
805
	 * @param parentElement
806
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
807
	 *            object.
808
	 * @param labelString
809
	 *            a {@link java.lang.String} object.
810
	 * @param initialFloat
811
	 *            a float.
812
	 * @param style
813
	 *            a int.
814
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElement}
815
	 *         object.
816
	 */
817
	public NumberWithLabelElement createFloatTextWithLabelElement(
818
			ICdmFormElement parentElement, String labelString,
819
			float initialFloat, int style) {
820
		NumberWithLabelElement element = new NumberWithLabelElement(this,
821
				parentElement, labelString, initialFloat, style);
822
		adapt(element);
823
		parentElement.addElement(element);
824
		return element;
825
	}
826

    
827
	/**
828
	 * <p>
829
	 * createLanguageStringWithLabelElement
830
	 * </p>
831
	 * 
832
	 * @param parentElement
833
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
834
	 *            object.
835
	 * @param labelString
836
	 *            a {@link java.lang.String} object.
837
	 * @param languageString
838
	 *            a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
839
	 * @param style
840
	 *            a int.
841
	 * @return a
842
	 *         {@link eu.etaxonomy.taxeditor.ui.forms.LanguageStringWithLabelElement}
843
	 *         object.
844
	 */
845
	public LanguageStringWithLabelElement createLanguageStringWithLabelElement(
846
			ICdmFormElement parentElement, String labelString,
847
			LanguageString languageString, int style) {
848
		LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(
849
				this, parentElement, labelString, languageString, style);
850
		adapt(element);
851
		parentElement.addElement(element);
852
		return element;
853
	}
854

    
855
	/**
856
	 * <p>
857
	 * createLanguageStringWithLabelElement
858
	 * </p>
859
	 * 
860
	 * @param parentElement
861
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
862
	 *            object.
863
	 * @param labelString
864
	 *            a {@link java.lang.String} object.
865
	 * @param languageString
866
	 *            a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
867
	 * @param height
868
	 *            a int.
869
	 * @param style
870
	 *            a int.
871
	 * @return a
872
	 *         {@link eu.etaxonomy.taxeditor.ui.forms.LanguageStringWithLabelElement}
873
	 *         object.
874
	 */
875
	public LanguageStringWithLabelElement createLanguageStringWithLabelElement(
876
			ICdmFormElement parentElement, String labelString,
877
			LanguageString languageString, int height, int style) {
878
		LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(
879
				this, parentElement, labelString, languageString, height, style);
880
		adapt(element);
881
		parentElement.addElement(element);
882
		return element;
883
	}
884

    
885
	/**
886
	 * <p>
887
	 * createTextElement
888
	 * </p>
889
	 * 
890
	 * @param parentElement
891
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
892
	 *            object.
893
	 * @param initialText
894
	 *            a {@link java.lang.String} object.
895
	 * @param style
896
	 *            a int.
897
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement}
898
	 *         object.
899
	 */
900
	public TextWithLabelElement createTextElement(
901
			ICdmFormElement parentElement, String initialText, int style) {
902
		TextWithLabelElement element = new TextWithLabelElement(this,
903
				parentElement, null, initialText, null, style);
904
		adapt(element);
905
		parentElement.addElement(element);
906
		return element;
907
	}
908

    
909
	/**
910
	 * <p>
911
	 * createKeyValueViewerElement
912
	 * </p>
913
	 * 
914
	 * @param parentElement
915
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
916
	 *            object.
917
	 * @param keyHeading
918
	 *            a {@link java.lang.String} object.
919
	 * @param valueHeading
920
	 *            a {@link java.lang.String} object.
921
	 * @param map
922
	 *            a {@link java.util.Map} object.
923
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.KeyValueViewerElement}
924
	 *         object.
925
	 */
926
	public KeyValueViewerElement createKeyValueViewerElement(
927
			ICdmFormElement parentElement, String keyHeading,
928
			String valueHeading, Map<Object, Object> map) {
929
		KeyValueViewerElement element = new KeyValueViewerElement(this,
930
				parentElement, keyHeading, valueHeading, map);
931
		adapt(element);
932
		parentElement.addElement(element);
933
		return element;
934
	}
935

    
936
	/**
937
	 * <p>
938
	 * createTermComboElement
939
	 * </p>
940
	 * 
941
	 * @param termComboType
942
	 *            a
943
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.TermComboType}
944
	 *            object.
945
	 * @param parentElement
946
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
947
	 *            object.
948
	 * @param labelString
949
	 *            a {@link java.lang.String} object.
950
	 * @param selection
951
	 *            a {@link eu.etaxonomy.cdm.model.common.DefinedTermBase}
952
	 *            object.
953
	 * @param style
954
	 *            a int.
955
	 * @return a {@link eu.etaxonomy.taxeditor.ui.combo.TermComboElement}
956
	 *         object.
957
	 */
958

    
959
	public <T extends DefinedTermBase> TermComboElement createTermComboElement(
960
			Class<T> termComboType, ICdmFormElement parentElement,
961
			String labelString, T selection, int style) {
962
		TermComboElement element = new TermComboElement<T>(this, parentElement,
963
				termComboType, labelString, selection, style);
964
		adapt(element);
965
		parentElement.addElement(element);
966
		return element;
967
	}
968

    
969
	/**
970
	 * <p>
971
	 * createEnumComboElement
972
	 * </p>
973
	 * 
974
	 * @param enumComboType
975
	 *            a
976
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EnumComboType}
977
	 *            object.
978
	 * @param parentElement
979
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
980
	 *            object.
981
	 * @param style
982
	 *            a int.
983
	 * @return a {@link eu.etaxonomy.taxeditor.ui.term.AbstractEnumComboElement}
984
	 *         object.
985
	 */
986
	public <T extends IDefinedTerm> EnumComboElement<T> createEnumComboElement(
987
			Class<T> enumComboType, ICdmFormElement parentElement, int style) {
988
		EnumComboElement<T> element = new EnumComboElement<T>(this,
989
				parentElement, enumComboType, style);
990
		adapt(element);
991
		parentElement.addElement(element);
992
		return element;
993
	}
994

    
995
	/**
996
	 * <p>
997
	 * createBrowserElement
998
	 * </p>
999
	 * 
1000
	 * @param imageUri
1001
	 *            a {@link java.net.URI} object.
1002
	 * @param style
1003
	 *            a int.
1004
	 * @param parentElement
1005
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1006
	 *            object.
1007
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.BrowserElement} object.
1008
	 */
1009
	public BrowserElement createBrowserElement(ICdmFormElement parentElement,
1010
			URI imageUri, int style) {
1011
		BrowserElement element = new BrowserElement(this, parentElement,
1012
				imageUri, style);
1013
		adapt(element);
1014
		parentElement.addElement(element);
1015
		return element;
1016
	}
1017

    
1018
	/**
1019
	 * <p>
1020
	 * createImageElement
1021
	 * </p>
1022
	 * 
1023
	 * @param parentElement
1024
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1025
	 *            object.
1026
	 * @param imageUri
1027
	 *            a {@link java.net.URI} object.
1028
	 * @param style
1029
	 *            a int.
1030
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.ImageElement} object.
1031
	 */
1032
	public ImageElement createImageElement(ICdmFormElement parentElement,
1033
			URI imageUri, int style) {
1034
		ImageElement element = new ImageElement(this, parentElement, imageUri,
1035
				style);
1036
		adapt(element);
1037
		parentElement.addElement(element);
1038
		return element;
1039
	}
1040

    
1041
	/**
1042
	 * <p>
1043
	 * createTextActionElement
1044
	 * </p>
1045
	 * 
1046
	 * @param labelString
1047
	 *            a {@link java.lang.String} object.
1048
	 * @param initialText
1049
	 *            a {@link java.lang.String} object.
1050
	 * @param style
1051
	 *            a int.
1052
	 * @param parentElement
1053
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1054
	 *            object.
1055
	 * @param buttonLabel
1056
	 *            a {@link java.lang.String} object.
1057
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TextActionElement}
1058
	 *         object.
1059
	 */
1060
	public TextActionElement createTextActionElement(
1061
			ICdmFormElement parentElement, String labelString,
1062
			String buttonLabel, String initialText, int style) {
1063
		TextActionElement element = new TextActionElement(this, parentElement,
1064
				labelString, buttonLabel, initialText, style);
1065
		adapt(element);
1066
		parentElement.addElement(element);
1067
		return element;
1068
	}
1069

    
1070
	/**
1071
	 * 
1072
	 * @author n.hoffmann
1073
	 * @created Mar 5, 2010
1074
	 * @version 1.0
1075
	 */
1076
	public static enum SelectionType {
1077
		AGENT, INSTITUTION, NAME, REFERENCE, TAXON_BASE, TAXON, SYNONYM, TEAM, AUTHOR_TEAM, PERSON, DERIVED_UNIT, FIELD_OBSERVATION, FEATURE_TREE, CLASSIFICATION, TAXON_NODE, COLLECTION, FEATURE, POLYTOMOUS_KEY, POLYTOMOUS_KEY_NODE, USER, GROUP
1078
	}
1079

    
1080
	/**
1081
	 * <p>
1082
	 * createCheckbox
1083
	 * </p>
1084
	 * 
1085
	 * @param parentElement
1086
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1087
	 *            object.
1088
	 * @param label
1089
	 *            a {@link java.lang.String} object.
1090
	 * @param initialState
1091
	 *            a boolean.
1092
	 * @param style
1093
	 *            a int.
1094
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.CheckboxElement} object.
1095
	 */
1096
	public CheckboxElement createCheckbox(ICdmFormElement parentElement,
1097
			String label, boolean initialState, int style) {
1098
		CheckboxElement element = new CheckboxElement(this, parentElement,
1099
				label, initialState, style | orientation);
1100
		adapt(element);
1101
		parentElement.addElement(element);
1102
		return element;
1103
	}
1104

    
1105
	/**
1106
	 * Creates a section as a part of the form.
1107
	 * 
1108
	 * @return the section widget
1109
	 * @param section
1110
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
1111
	 *            object.
1112
	 */
1113
	public Section adapt(AbstractFormSection section) {
1114
		section.setMenu(section.getLayoutComposite().getMenu());
1115
		adapt(section, true, true);
1116

    
1117
		// handle focus and property change events for cdm use
1118
		section.addFocusListener(selectionFocusHandler);
1119
		section.setPropertyChangeListeners(propertyChangeListeners);
1120

    
1121
		if (section.getToggle() != null) {
1122
			section.getToggle().setHoverDecorationColor(
1123
					getColors().getColor(IFormColors.TB_TOGGLE_HOVER));
1124
			section.getToggle().setDecorationColor(
1125
					getColors().getColor(IFormColors.TB_TOGGLE));
1126
		}
1127

    
1128
		section.setFont(boldFontHolder2.getBoldFont(section
1129
				.getLayoutComposite().getFont()));
1130

    
1131
		if ((section.getStyle() & Section.TITLE_BAR) != 0
1132
				|| (section.getStyle() & Section.SHORT_TITLE_BAR) != 0) {
1133
			getColors().initializeSectionToolBarColors();
1134
			section.setTitleBarBackground(getColors().getColor(
1135
					IFormColors.TB_BG));
1136
			section.setTitleBarBorderColor(getColors().getColor(
1137
					IFormColors.TB_BORDER));
1138
		}
1139
		// call setTitleBarForeground regardless as it also sets the label color
1140
		section.setTitleBarForeground(getColors().getColor(
1141
				IFormColors.TB_TOGGLE));
1142
		return section;
1143
	}
1144

    
1145
	private class BoldFontHolder2 {
1146
		private Font normalFont;
1147

    
1148
		private Font boldFont;
1149

    
1150
		public BoldFontHolder2() {
1151
		}
1152

    
1153
		public Font getBoldFont(Font font) {
1154
			createBoldFont(font);
1155
			return boldFont;
1156
		}
1157

    
1158
		private void createBoldFont(Font font) {
1159
			if (normalFont == null || !normalFont.equals(font)) {
1160
				normalFont = font;
1161
				dispose();
1162
			}
1163
			if (boldFont == null) {
1164
				boldFont = FormFonts.getInstance().getBoldFont(
1165
						getColors().getDisplay(), normalFont);
1166
			}
1167
		}
1168

    
1169
		public void dispose() {
1170
			if (boldFont != null) {
1171
				FormFonts.getInstance().markFinished(boldFont,
1172
						getColors().getDisplay());
1173
				boldFont = null;
1174
			}
1175
		}
1176
	}
1177

    
1178
	/**
1179
	 * <p>
1180
	 * createToggleableTextField
1181
	 * </p>
1182
	 * 
1183
	 * @param parentElement
1184
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1185
	 *            object.
1186
	 * @param labelString
1187
	 *            a {@link java.lang.String} object.
1188
	 * @param initialText
1189
	 *            a {@link java.lang.String} object.
1190
	 * @param initialState
1191
	 *            a boolean.
1192
	 * @param style
1193
	 *            a int.
1194
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.ToggleableTextElement}
1195
	 *         object.
1196
	 */
1197
	public ToggleableTextElement createToggleableTextField(
1198
			ICdmFormElement parentElement, String labelString,
1199
			String initialText, boolean initialState, int style) {
1200
		ToggleableTextElement element = new ToggleableTextElement(this,
1201
				parentElement, labelString, initialText, initialState, style
1202
						| orientation);
1203
		adapt(element);
1204
		parentElement.addElement(element);
1205
		return element;
1206
	}
1207

    
1208
	/**
1209
	 * <p>
1210
	 * createTimePeriodElement
1211
	 * </p>
1212
	 * 
1213
	 * @param parentElement
1214
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1215
	 *            object.
1216
	 * @param labelString
1217
	 *            a {@link java.lang.String} object.
1218
	 * @param timePeriod
1219
	 *            a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
1220
	 * @param style
1221
	 *            a int.
1222
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TimePeriodElement}
1223
	 *         object.
1224
	 */
1225
	public TimePeriodElement createTimePeriodElement(
1226
			ICdmFormElement parentElement, String labelString,
1227
			TimePeriod timePeriod, int style) {
1228
		TimePeriodElement element = new TimePeriodElement(this, parentElement,
1229
				labelString, timePeriod, style);
1230
		adapt(element);
1231
		parentElement.addElement(element);
1232
		return element;
1233
	}
1234

    
1235
	/**
1236
	 * <p>
1237
	 * createPointElement
1238
	 * </p>
1239
	 * 
1240
	 * @param style
1241
	 *            a int.
1242
	 * @param parentElement
1243
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1244
	 *            object.
1245
	 * @param point
1246
	 *            a {@link eu.etaxonomy.cdm.model.location.Point} object.
1247
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.PointElement} object.
1248
	 */
1249
	public PointElement createPointElement(ICdmFormElement parentElement,
1250
			Point point, int style) {
1251
		PointElement element = new PointElement(this, parentElement, point,
1252
				style);
1253
		adapt(element);
1254
		parentElement.addElement(element);
1255
		return element;
1256
	}
1257

    
1258
	/**
1259
	 * <p>
1260
	 * createDateDetailSection
1261
	 * </p>
1262
	 * 
1263
	 * @param parentElement
1264
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1265
	 *            object.
1266
	 * @param style
1267
	 *            a int.
1268
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.DateDetailSection}
1269
	 *         object.
1270
	 */
1271
	public DateDetailSection createDateDetailSection(
1272
			ICdmFormElement parentElement, int style) {
1273
		DateDetailSection section = new DateDetailSection(this, parentElement,
1274
				style);
1275
		parentElement.addElement(section);
1276
		adapt(section);
1277
		return section;
1278
	}
1279

    
1280
	/**
1281
	 * <p>
1282
	 * createPartialElement
1283
	 * </p>
1284
	 * 
1285
	 * @param parentElement
1286
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1287
	 *            object.
1288
	 * @param labelString
1289
	 *            a {@link java.lang.String} object.
1290
	 * @param partial
1291
	 *            a {@link org.joda.time.Partial} object.
1292
	 * @param style
1293
	 *            a int.
1294
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.PartialElement} object.
1295
	 */
1296
	public PartialElement createPartialElement(ICdmFormElement parentElement,
1297
			String labelString, Partial partial, int style) {
1298
		PartialElement element = new PartialElement(this, parentElement,
1299
				labelString, style);
1300
		adapt(element);
1301
		parentElement.addElement(element);
1302
		return element;
1303
	}
1304

    
1305
	/**
1306
	 * <p>
1307
	 * addSelectionListener
1308
	 * </p>
1309
	 * 
1310
	 * @param listener
1311
	 *            a {@link org.eclipse.swt.events.SelectionListener} object.
1312
	 */
1313
	public void addSelectionListener(SelectionListener listener) {
1314
		selectionListenerList.add(listener);
1315
	}
1316

    
1317
	/**
1318
	 * <p>
1319
	 * removeSelectionListener
1320
	 * </p>
1321
	 * 
1322
	 * @param listener
1323
	 *            a {@link org.eclipse.swt.events.SelectionListener} object.
1324
	 */
1325
	public void removeSelectionListener(SelectionListener listener) {
1326
		if (listener == null) {
1327
			StoreUtil
1328
					.error(this.getClass(),
1329
							"Tried to remove a selection listener from this factories listeners but was null",
1330
							null);
1331
		} else {
1332
			selectionListenerList.remove(listener);
1333
		}
1334
	}
1335

    
1336
	/**
1337
	 * <p>
1338
	 * addPropertyChangeListener
1339
	 * </p>
1340
	 * 
1341
	 * @param listener
1342
	 *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1343
	 *            object.
1344
	 */
1345
	public void addPropertyChangeListener(IPropertyChangeListener listener) {
1346
		if (propertyChangeListeners.contains(listener)) {
1347
			return;
1348
		}
1349
		propertyChangeListeners.add(0, listener);
1350
	}
1351

    
1352
	/**
1353
	 * <p>
1354
	 * removePropertyChangeListener
1355
	 * </p>
1356
	 * 
1357
	 * @param listener
1358
	 *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1359
	 *            object.
1360
	 */
1361
	public void removePropertyChangeListener(IPropertyChangeListener listener) {
1362
		propertyChangeListeners.remove(listener);
1363
	}
1364

    
1365
	/**
1366
	 * <p>
1367
	 * createHorizontalSeparator
1368
	 * </p>
1369
	 * 
1370
	 * @param parentElement
1371
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1372
	 *            object.
1373
	 * @param style
1374
	 *            a int.
1375
	 * @return a {@link org.eclipse.swt.widgets.Label} object.
1376
	 */
1377
	public Label createHorizontalSeparator(ICdmFormElement parentElement,
1378
			int style) {
1379
		Label separator = this.createSeparator(
1380
				parentElement.getLayoutComposite(), SWT.HORIZONTAL | style);
1381
		separator.setLayoutData(FILL_HORIZONTALLY());
1382
		return separator;
1383
	}
1384

    
1385
	/**
1386
	 * <p>
1387
	 * createVersionElement
1388
	 * </p>
1389
	 * 
1390
	 * @param parentElement
1391
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1392
	 *            object.
1393
	 * @param entity
1394
	 *            a {@link eu.etaxonomy.cdm.model.common.VersionableEntity}
1395
	 *            object.
1396
	 * @param style
1397
	 *            a int.
1398
	 * @return a
1399
	 *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionElement}
1400
	 *         object.
1401
	 */
1402
	public VersionElement createVersionElement(ICdmFormElement parentElement,
1403
			VersionableEntity entity, int style) {
1404
		VersionElement element = new VersionElement(this, parentElement,
1405
				entity, style);
1406
		adapt(element);
1407
		parentElement.addElement(element);
1408
		return element;
1409
	}
1410

    
1411
	/**
1412
	 * <p>
1413
	 * createVersionSection
1414
	 * </p>
1415
	 * 
1416
	 * @param parentElement
1417
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1418
	 *            object.
1419
	 * @param style
1420
	 *            a int.
1421
	 * @return a
1422
	 *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection}
1423
	 *         object.
1424
	 */
1425
	public VersionSection createVersionSection(ICdmFormElement parentElement,
1426
			int style) {
1427
		VersionSection section = new VersionSection(this, parentElement, style);
1428
		parentElement.addElement(section);
1429
		adapt(section);
1430
		return section;
1431
	}
1432

    
1433
	/**
1434
	 * <p>
1435
	 * createEmptyElement
1436
	 * </p>
1437
	 * 
1438
	 * @param parentElement
1439
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1440
	 *            object.
1441
	 * @return a {@link eu.etaxonomy.taxeditor.ui.section.EmptyElement} object.
1442
	 */
1443
	public EmptyElement createEmptyElement(ICdmFormElement parentElement) {
1444
		EmptyElement element = new EmptyElement(this, parentElement, null,
1445
				SWT.NULL);
1446
		adapt(element);
1447
		parentElement.addElement(element);
1448
		return element;
1449
	}
1450

    
1451
	/**
1452
	 * <p>
1453
	 * createHeadlineSection
1454
	 * </p>
1455
	 * 
1456
	 * @param parentElement
1457
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1458
	 *            object.
1459
	 * @return a
1460
	 *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection}
1461
	 *         object.
1462
	 */
1463
	public HeadlineSection createHeadlineSection(ICdmFormElement parentElement) {
1464
		HeadlineSection section = new HeadlineSection(this, parentElement,
1465
				SWT.NULL);
1466
		parentElement.addElement(section);
1467
		adapt(section);
1468
		return section;
1469
	}
1470

    
1471
	/**
1472
	 * <p>
1473
	 * createParsingMessageElement
1474
	 * </p>
1475
	 * 
1476
	 * @param parentElement
1477
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1478
	 *            object.
1479
	 * @param parserProblem
1480
	 *            a {@link eu.etaxonomy.cdm.strategy.parser.ParserProblem}
1481
	 *            object.
1482
	 * @param style
1483
	 *            a int.
1484
	 * @return a
1485
	 *         {@link eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessageElement}
1486
	 *         object.
1487
	 */
1488
	public ParsingMessageElement createParsingMessageElement(
1489
			ICdmFormElement parentElement, ParserProblem parserProblem,
1490
			int style) {
1491
		ParsingMessageElement element = new ParsingMessageElement(this,
1492
				parentElement, parserProblem, style);
1493
		adapt(element);
1494
		parentElement.addElement(element);
1495
		return element;
1496
	}
1497

    
1498
	// SIMPLIFY
1499

    
1500
	/**
1501
	 * 
1502
	 */
1503
	public static enum DetailType {
1504
		NONVIRALNAME, SCIENTIFICNAME, REFERENCEBASE, NOMENCLATURALREFERENCE, TAXONBASE, AUTHORSHIP, TEAM, PERSON, DESCRIPTION, DESCRIPTIONELEMENT, PARSINGMESSAGE, NAMERELATIONSHIP, TEAMORPERSONBASE, MEDIA, FIELD_OBSERVATION, DERIVED_UNIT_FACADE, GATHERING_EVENT, DERIVED_UNIT, NATURAL_LANGUAGE, FEATURE_DISTRIBUTION, CLASSIFICATION, TAXON_NODE, COLLECTION, POLYTOMOUS_KEY, POLYTOMOUS_KEY_NODE, INSTITUTION, DERIVED_UNIT_GENERAL, HYBRID, USER, GROUP, DETERMINATION, TAXON_RELATIONSHIP, REFERENCED_ENTITY, TERM_VOCABULARY, NAMED_AREA, NAMED_AREA_LEVEL, USE_RECORD
1505
	}
1506

    
1507
	public AbstractFormSection createDefinedTermDetailSection(
1508
			Class definedTermClass, ConversationHolder conversation,
1509
			ICdmFormElement parentElement,
1510
			ISelectionProvider selectionProvider, int style) {
1511

    
1512
		AbstractFormSection section = new DefinedTermDetailSection(this,
1513
				definedTermClass, conversation, parentElement,
1514
				selectionProvider, style);
1515

    
1516
		parentElement.addElement(section);
1517
		adapt(section);
1518
		return section;
1519

    
1520
	}
1521

    
1522
	/**
1523
	 * @param definedTermClass
1524
	 * @param formElement
1525
	 * @param style
1526
	 * @return
1527
	 */
1528
	public AbstractCdmDetailElement createDefinedTermDetailElement(
1529
			Class definedTermClass, AbstractCdmDetailSection parentElement,
1530
			int style) {
1531
		AbstractCdmDetailElement element = null;
1532

    
1533
		if (NamedArea.class.isAssignableFrom(definedTermClass)) {
1534
			element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(
1535
					this, parentElement);
1536
		} else {
1537
			element = new DefinedTermDetailElement(this, parentElement);
1538
		}
1539

    
1540
		adapt(element);
1541
		parentElement.addElement(element);
1542
		return element;
1543
	}
1544

    
1545
	/**
1546
	 * <p>
1547
	 * createCdmDetailSection
1548
	 * </p>
1549
	 * 
1550
	 * @param detailType
1551
	 *            a
1552
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType}
1553
	 *            object.
1554
	 * @param parentElement
1555
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1556
	 *            object.
1557
	 * @param selectionProvider
1558
	 *            a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
1559
	 * @param style
1560
	 *            a int.
1561
	 * @param conversation
1562
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1563
	 *            object.
1564
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
1565
	 *         object.
1566
	 */
1567
	public AbstractFormSection createCdmDetailSection(DetailType detailType,
1568
			ConversationHolder conversation, ICdmFormElement parentElement,
1569
			ISelectionProvider selectionProvider, int style) {
1570
		AbstractFormSection section = null;
1571

    
1572
		switch (detailType) {
1573
		case SCIENTIFICNAME:
1574
			section = new NameDetailSection(this, conversation, parentElement,
1575
					selectionProvider, style);
1576
			break;
1577
		case REFERENCEBASE:
1578
			section = new ReferenceDetailSection(this, conversation,
1579
					parentElement, selectionProvider, style);
1580
			break;
1581
		case NOMENCLATURALREFERENCE:
1582
			section = new NomenclaturalReferenceDetailSection(this,
1583
					conversation, parentElement, selectionProvider, style);
1584
			break;
1585
		case TAXONBASE:
1586
			section = new TaxonBaseDetailSection(this, conversation,
1587
					parentElement, selectionProvider, style);
1588
			break;
1589
		case AUTHORSHIP:
1590
			section = new AuthorshipDetailSection(this, conversation,
1591
					parentElement, selectionProvider, style);
1592
			break;
1593
		case TEAMORPERSONBASE:
1594
			section = new TeamOrPersonBaseDetailSection(this, conversation,
1595
					parentElement, selectionProvider, style);
1596
			break;
1597
		case TEAM:
1598
			section = new TeamDetailSection(this, conversation, parentElement,
1599
					null, style);
1600
			break;
1601
		case PERSON:
1602
			section = new PersonDetailSection(this, conversation,
1603
					parentElement, null, style);
1604
			break;
1605
		case DESCRIPTION:
1606
			section = new DescriptionDetailSection(this, conversation,
1607
					parentElement, selectionProvider, style);
1608
			break;
1609
		case DESCRIPTIONELEMENT:
1610
			section = new DescriptionElementDetailSection(this, conversation,
1611
					parentElement, selectionProvider, style);
1612
			break;
1613
		case PARSINGMESSAGE:
1614
			section = new ParsingMessagesSection(this, conversation,
1615
					parentElement, selectionProvider, style);
1616
			break;
1617
		case NONVIRALNAME:
1618
			section = new NonViralNameDetailSection(this, conversation,
1619
					parentElement, selectionProvider, style);
1620
			break;
1621
		case MEDIA:
1622
			section = new eu.etaxonomy.taxeditor.ui.section.description.MediaDetailsSection(
1623
					this, conversation, parentElement, selectionProvider, style);
1624
			break;
1625
		case DERIVED_UNIT_FACADE:
1626
			section = new DerivedUnitFacadeDetailSection(this, conversation,
1627
					parentElement, selectionProvider, style);
1628
			break;
1629
		case FIELD_OBSERVATION:
1630
			section = new FieldObservationDetailSection(this, conversation,
1631
					parentElement, selectionProvider, style);
1632
			break;
1633
		case GATHERING_EVENT:
1634
			section = new GatheringEventDetailSection(this, conversation,
1635
					parentElement, selectionProvider, style);
1636
			break;
1637
		case DERIVED_UNIT:
1638
			section = new DerivedUnitBaseDetailSection(this, conversation,
1639
					parentElement, selectionProvider, style);
1640
			break;
1641
		case NATURAL_LANGUAGE:
1642
			section = new NaturalLanguageSection(this, conversation,
1643
					parentElement, selectionProvider, style);
1644
			break;
1645
		case FEATURE_DISTRIBUTION:
1646
			section = new FeatureDistributionDetailSection(this, conversation,
1647
					parentElement, selectionProvider, style);
1648
			break;
1649
		case CLASSIFICATION:
1650
			section = new ClassificationDetailSection(this, conversation,
1651
					parentElement, selectionProvider, style);
1652
			break;
1653
		case TAXON_NODE:
1654
			section = new TaxonNodeDetailSection(this, conversation,
1655
					parentElement, selectionProvider, style);
1656
			break;
1657
		case POLYTOMOUS_KEY:
1658
			section = new PolytomousKeyDetailSection(this, conversation,
1659
					parentElement, selectionProvider, style);
1660
			break;
1661
		case POLYTOMOUS_KEY_NODE:
1662
			section = new PolytomousKeyNodeDetailSection(this, conversation,
1663
					parentElement, selectionProvider, style);
1664
			break;
1665
		case INSTITUTION:
1666
			section = new InstitutionDetailSection(this, conversation,
1667
					parentElement, selectionProvider, style);
1668
			break;
1669
		case DERIVED_UNIT_GENERAL:
1670
			section = new GeneralDetailSection(this, conversation,
1671
					parentElement, selectionProvider, style);
1672
			break;
1673
		case HYBRID:
1674
			section = new HybridDetailSection(this, conversation,
1675
					parentElement, selectionProvider, style);
1676
			break;
1677
		case USER:
1678
			section = new UserDetailSection(this, conversation, parentElement,
1679
					selectionProvider, style);
1680
			break;
1681
		case GROUP:
1682
			section = new GroupDetailSection(this, conversation, parentElement,
1683
					selectionProvider, style);
1684
			break;
1685
		case DETERMINATION:
1686
			section = new DeterminationDetailSection(this, conversation,
1687
					parentElement, selectionProvider, style);
1688
			break;
1689
		case TAXON_RELATIONSHIP:
1690
			section = new TaxonRelationshipDetailSection(this, conversation,
1691
					parentElement, selectionProvider, style);
1692
			break;
1693
		case REFERENCED_ENTITY:
1694
			section = new ReferencedEntityDetailSection(this, conversation,
1695
					parentElement, selectionProvider, style);
1696
			break;
1697
		case TERM_VOCABULARY:
1698
			section = new TermVocabularyDetailSection(this, conversation,
1699
					parentElement, selectionProvider, style);
1700
			break;
1701
		case NAMED_AREA:
1702
			section = new NamedAreaDetailSection(this, conversation,
1703
					parentElement, selectionProvider, style);
1704
			break;
1705
		case USE_RECORD:
1706
			section = new UseRecordDetailSection(this, conversation,
1707
					parentElement, selectionProvider, style);
1708
			break;
1709
		}
1710

    
1711
		if (section == null) {
1712
			throw new RuntimeException(
1713
					"You tried to create a cdm detail section that is not implemented yet.");
1714
		}
1715

    
1716
		parentElement.addElement(section);
1717
		adapt(section);
1718
		return section;
1719
	}
1720

    
1721
	/**
1722
	 * <p>
1723
	 * createCdmDetailElement
1724
	 * </p>
1725
	 * 
1726
	 * @param detailType
1727
	 *            a
1728
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType}
1729
	 *            object.
1730
	 * @param style
1731
	 *            a int.
1732
	 * @param parentElement
1733
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1734
	 *            object.
1735
	 * @return a
1736
	 *         {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
1737
	 *         object.
1738
	 */
1739
	public AbstractCdmDetailElement createCdmDetailElement(
1740
			DetailType detailType, ICdmFormElement parentElement, int style) {
1741
		AbstractCdmDetailElement element = null;
1742

    
1743
		switch (detailType) {
1744
		case SCIENTIFICNAME:
1745
			element = new NameDetailElement(this, parentElement, style);
1746
			break;
1747
		case REFERENCEBASE:
1748
			element = new ReferenceDetailElement(this, parentElement, style);
1749
			break;
1750
		case NOMENCLATURALREFERENCE:
1751
			element = new NomenclaturalReferenceDetailElement(this,
1752
					parentElement, style);
1753
			break;
1754
		case TAXONBASE:
1755
			element = new TaxonBaseDetailElement(this, parentElement, style);
1756
			break;
1757
		case AUTHORSHIP:
1758
			element = new AuthorshipDetailElement(this, parentElement, style);
1759
			break;
1760
		case TEAM:
1761
			element = new TeamDetailElement(this, parentElement, style);
1762
			break;
1763
		case PERSON:
1764
			element = new PersonDetailElement(this, parentElement, style);
1765
			break;
1766
		case DESCRIPTION:
1767
			element = new DescriptionDetailElement(this, parentElement, style);
1768
			break;
1769
		case DESCRIPTIONELEMENT:
1770
			element = new DescriptionElementDetailElement(this, parentElement,
1771
					style);
1772
			break;
1773
		case NONVIRALNAME:
1774
			element = new NonViralNameDetailElement(this, parentElement);
1775
			break;
1776
		case DERIVED_UNIT_FACADE:
1777
			element = new DerivedUnitFacadeDetailElement(this, parentElement);
1778
			break;
1779
		case FIELD_OBSERVATION:
1780
			element = new FieldObservationDetailElement(this, parentElement);
1781
			break;
1782
		case GATHERING_EVENT:
1783
			element = new GatheringEventDetailElement(this, parentElement);
1784
			break;
1785
		case DERIVED_UNIT:
1786
			element = new DerivedUnitBaseDetailElement(this, parentElement);
1787
			break;
1788
		case NATURAL_LANGUAGE:
1789
			element = new NaturalLanguageDetailElement(this, parentElement);
1790
			break;
1791
		case FEATURE_DISTRIBUTION:
1792
			element = new FeatureDistributionDetailElement(this, parentElement);
1793
			break;
1794
		case CLASSIFICATION:
1795
			element = new ClassificationDetailElement(this, parentElement);
1796
			break;
1797
		case TAXON_NODE:
1798
			element = new TaxonNodeDetailElement(this, parentElement);
1799
			break;
1800
		case COLLECTION:
1801
			element = new CollectionDetailElement(this, parentElement);
1802
			break;
1803
		case POLYTOMOUS_KEY:
1804
			element = new PolytomousKeyDetailElement(this, parentElement);
1805
			break;
1806
		case POLYTOMOUS_KEY_NODE:
1807
			element = new PolytomousKeyNodeDetailElement(this, parentElement);
1808
			break;
1809
		case INSTITUTION:
1810
			element = new InstitutionDetailElement(this, parentElement);
1811
			break;
1812
		case DERIVED_UNIT_GENERAL:
1813
			element = new GeneralDetailElement(this, parentElement);
1814
			break;
1815
		case HYBRID:
1816
			element = new HybridDetailElement(this, parentElement);
1817
			break;
1818
		case USER:
1819
			element = new UserDetailElement(this, parentElement);
1820
			break;
1821
		case GROUP:
1822
			element = new GroupDetailElement(this, parentElement);
1823
			break;
1824
		case DETERMINATION:
1825
			element = new DeterminationDetailElement(this, parentElement);
1826
			break;
1827
		case TAXON_RELATIONSHIP:
1828
			element = new TaxonRelationshipDetailElement(this, parentElement);
1829
			break;
1830
		case REFERENCED_ENTITY:
1831
			element = new RefereneEntityDetailElement(this, parentElement);
1832
			break;
1833
		case TERM_VOCABULARY:
1834
			element = new TermVocabularyDetailElement(this, parentElement);
1835
			break;
1836
		case NAMED_AREA:
1837
			element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(
1838
					this, parentElement);
1839
			break;
1840
		case NAMED_AREA_LEVEL:
1841
			element = new DefinedTermDetailElement<NamedAreaLevel>(this,
1842
					parentElement);
1843
			break;
1844
		/*case USE_RECORD:
1845
			element = new UseRecordDetailElement(this, parentElement, style);
1846
			break;*/
1847
		}
1848

    
1849
		if (element == null) {
1850
			StoreUtil
1851
					.error(this.getClass(),
1852
							"Detail element was not created. Seems like the case was not implemented for the requested detail type: "
1853
									+ detailType, null);
1854
		}
1855

    
1856
		adapt(element);
1857
		parentElement.addElement(element);
1858
		return element;
1859
	}
1860

    
1861
	/**
1862
	 * 
1863
	 * @author n.hoffmann
1864
	 * @created Mar 5, 2010
1865
	 * @version 1.0
1866
	 */
1867
	public static enum EntityDetailType {
1868
		TEAM, TEAMMEMBER, ANNOTATION, CREDIT, DESCRIPTIONELEMENTSOURCE, EXTENSION, MARKER, MEDIA, DESCRIPTIONELEMENTMEDIA, MEDIAREPRESENTATION, MEDIAREPRESENTATIONPART, MODIFIER, NOMENCLATURALSTATUS, NAME_RELATIONSHIP, PROTOLOG, RIGHTS, SOURCE, SCOPE, DESCRIPTIONSOURCE, TYPEDESIGNATION, STATE_DATA, STATISTICAL_MEASUREMENT_VALUE, DESCRIBED_SPECIMEN, COLLECTING_AREA, DETERMINATION_EVENT, SPECIMEN_COLLECTION, IDENTIFIABLE_SOURCE_COLLECTION, GEOGRAPHICAL_SCOPE, SCOPE_RESTRICTION, MEMBER, GRANTED_AUTHORITY, GROUPS_BY_USER, TAXONOMIC_SCOPE, DETERMINATION_CURRENT, DETERMINATION_HISTORY
1869
	}
1870

    
1871
	/**
1872
	 * <p>
1873
	 * createEntityDetailSection
1874
	 * </p>
1875
	 * 
1876
	 * @param entityDetailType
1877
	 *            a
1878
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EntityDetailType}
1879
	 *            object.
1880
	 * @param style
1881
	 *            a int.
1882
	 * @param conversation
1883
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1884
	 *            object.
1885
	 * @param parentElement
1886
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1887
	 *            object.
1888
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
1889
	 *         object.
1890
	 */
1891
	public AbstractFormSection createEntityDetailSection(
1892
			EntityDetailType entityDetailType, ConversationHolder conversation,
1893
			ICdmFormElement parentElement, int style) {
1894
		AbstractFormSection section = null;
1895

    
1896
		switch (entityDetailType) {
1897
		case TEAM:
1898
			section = new TeamDetailSection(this, conversation, parentElement,
1899
					null, style);
1900
			break;
1901
		case TEAMMEMBER:
1902
			section = new TeamMemberSection(this, conversation, parentElement,
1903
					style);
1904
			break;
1905
		case ANNOTATION:
1906
			section = new AnnotationSection(this, conversation, parentElement,
1907
					style);
1908
			break;
1909
		case CREDIT:
1910
			section = new CreditSection(this, conversation, parentElement,
1911
					style);
1912
			break;
1913
		case DESCRIPTIONELEMENTSOURCE:
1914
			section = new DescriptionElementSourceSection(this, conversation,
1915
					parentElement, style);
1916
			break;
1917
		case EXTENSION:
1918
			section = new ExtensionSection(this, conversation, parentElement,
1919
					style);
1920
			break;
1921
		case MARKER:
1922
			section = new MarkerSection(this, conversation, parentElement,
1923
					style);
1924
			break;
1925
		case MEDIA:
1926
			section = new MediaSection(this, conversation, parentElement, style);
1927
			break;
1928
		case DESCRIPTIONELEMENTMEDIA:
1929
			section = new DescriptionElementMediaSection(this, conversation,
1930
					parentElement, style);
1931
			break;
1932
		case MEDIAREPRESENTATION:
1933
			section = new MediaRepresentationSection(this, conversation,
1934
					parentElement, style);
1935
			break;
1936
		case MEDIAREPRESENTATIONPART:
1937
			section = new MediaRepresentationPartSection(this, conversation,
1938
					parentElement, style);
1939
			break;
1940
		case MODIFIER:
1941
			section = new ModifierSection(this, conversation, parentElement,
1942
					style);
1943
			break;
1944
		case NOMENCLATURALSTATUS:
1945
			section = new NomenclaturalStatusSection(this, conversation,
1946
					parentElement, style);
1947
			break;
1948
		case NAME_RELATIONSHIP:
1949
			section = new NameRelationshipDetailSection(this, conversation,
1950
					parentElement, style);
1951
			break;
1952
		case PROTOLOG:
1953
			section = new ProtologueSection(this, conversation, parentElement,
1954
					style);
1955
			break;
1956
		case RIGHTS:
1957
			section = new RightsSection(this, conversation, parentElement,
1958
					style);
1959
			break;
1960
		case SOURCE:
1961
			section = new SourceSection(this, conversation, parentElement,
1962
					style);
1963
			break;
1964
		case SCOPE:
1965
			section = new ScopeSection(this, conversation, parentElement, style);
1966
			break;
1967
		case DESCRIPTIONSOURCE:
1968
			section = new DescriptionSourceSection(this, conversation,
1969
					parentElement, style);
1970
			break;
1971
		case TYPEDESIGNATION:
1972
			section = new TypeDesignationSection(this, conversation,
1973
					parentElement, style);
1974
			break;
1975
		case STATE_DATA:
1976
			section = new StateDataSection(this, conversation, parentElement,
1977
					style);
1978
			break;
1979
		case STATISTICAL_MEASUREMENT_VALUE:
1980
			section = new StatisticalMeasurementValueSection(this,
1981
					conversation, parentElement, style);
1982
			break;
1983
		case DESCRIBED_SPECIMEN:
1984
			section = new DescribedSpecimenSection(this, conversation,
1985
					parentElement, style);
1986
			break;
1987
		case COLLECTING_AREA:
1988
			section = new CollectingAreasDetailSection(this, conversation,
1989
					parentElement, style);
1990
			break;
1991
		case DETERMINATION_CURRENT:
1992
			section = new CurrentDeterminationDetailSection(this, conversation,
1993
					parentElement, style);
1994
			break;
1995
		case DETERMINATION_HISTORY:
1996
			section = new DeterminationHistoryDetailSection(this, conversation,
1997
					parentElement, style);
1998
			break;
1999
		case SPECIMEN_COLLECTION:
2000
			section = new SpecimenCollectionDetailSection(this, conversation,
2001
					parentElement, style);
2002
			break;
2003
		case IDENTIFIABLE_SOURCE_COLLECTION:
2004
			section = new SourceCollectionDetailSection(this, conversation,
2005
					parentElement, style);
2006
			break;
2007
		case GEOGRAPHICAL_SCOPE:
2008
			section = new GeographicalScopeDetailSection(this, conversation,
2009
					parentElement, style);
2010
			break;
2011
		case SCOPE_RESTRICTION:
2012
			section = new ScopeRestrictionSection(this, conversation,
2013
					parentElement, style);
2014
			break;
2015
		case MEMBER:
2016
			section = new MemberDetailSection(this, conversation,
2017
					parentElement, style);
2018
			break;
2019
		case GRANTED_AUTHORITY:
2020
			section = new GrantedAuthorityDetailSection(this, conversation,
2021
					parentElement, style);
2022
			break;
2023
		case GROUPS_BY_USER:
2024
			section = new GroupsByUserDetailSection(this, conversation,
2025
					parentElement, style);
2026
			break;
2027
		case TAXONOMIC_SCOPE:
2028
			section = new TaxonomicScopeSection(this, conversation,
2029
					parentElement, style);
2030
			break;
2031
		}
2032
		parentElement.addElement(section);
2033
		adapt(section);
2034
		return section;
2035
	}
2036

    
2037
	/**
2038
	 * <p>
2039
	 * createEntityCollectionElement
2040
	 * </p>
2041
	 * 
2042
	 * @param removeListener
2043
	 *            a {@link org.eclipse.swt.events.SelectionListener} object.
2044
	 * @param style
2045
	 *            a int.
2046
	 * @param parentElement
2047
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
2048
	 *            object.
2049
	 * @param versionableEntity
2050
	 *            a {@link eu.etaxonomy.cdm.model.common.IVersionableEntity}
2051
	 *            object.
2052
	 * @param backgroundColor
2053
	 *            a {@link org.eclipse.swt.graphics.Color} object.
2054
	 * @return a
2055
	 *         {@link eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement}
2056
	 *         object.
2057
	 */
2058
	public AbstractEntityCollectionElement createEntityCollectionElement(
2059
			AbstractFormSection parentElement, Object versionableEntity,
2060
			SelectionListener removeListener, Color backgroundColor, int style) {
2061
		AbstractEntityCollectionElement element = null;
2062

    
2063
		Object entity = HibernateProxyHelper.deproxy(versionableEntity);
2064

    
2065
		if (entity instanceof Annotation) {
2066
			element = new AnnotationElement(this, parentElement,
2067
					(Annotation) entity, removeListener, style);
2068
		} else if (entity instanceof Person) {
2069
			element = new TeamMemberElement(this, parentElement,
2070
					(Person) entity, removeListener, style);
2071
		} else if (entity instanceof Credit) {
2072
			element = new CreditElement(this, parentElement, (Credit) entity,
2073
					removeListener, style);
2074
		} else if (entity instanceof Extension) {
2075
			element = new ExtensionElement(this, parentElement,
2076
					(Extension) entity, removeListener, style);
2077
		} else if (entity instanceof Marker) {
2078
			element = new MarkerElement(this, parentElement, (Marker) entity,
2079
					removeListener, style);
2080
		} else if (entity instanceof Media) {
2081
			element = new MediaElement(this, parentElement, (Media) entity,
2082
					removeListener, style);
2083
		} else if (entity instanceof MediaRepresentation) {
2084
			element = new MediaRepresentationElement(this, parentElement,
2085
					(MediaRepresentation) entity, removeListener, style);
2086
		} else if (entity instanceof ImageFile) {
2087
			element = new ImageFileElement(this, parentElement,
2088
					(ImageFile) entity, removeListener, style);
2089
		} else if (entity instanceof MediaRepresentationPart) {
2090
			element = new MediaRepresentationPartElement(this, parentElement,
2091
					(MediaRepresentationPart) entity, removeListener, style);
2092
		} else if (entity instanceof NomenclaturalStatus) {
2093
			element = new NomenclaturalStatusElement(this, parentElement,
2094
					(NomenclaturalStatus) entity, removeListener, style);
2095
		} else if (entity instanceof Rights) {
2096
			element = new RightsElement(this, parentElement, (Rights) entity,
2097
					removeListener, style);
2098
		} else if (entity instanceof DescriptionElementSource) {
2099
			element = new DescriptionElementSourceElement(this, parentElement,
2100
					(DescriptionElementSource) entity, removeListener, style);
2101
		} else if (entity instanceof IdentifiableSource) {
2102
			element = new IdentifiableSourceElement(this, parentElement,
2103
					(IdentifiableSource) entity, removeListener, style);
2104
		} else if (entity instanceof Scope) {
2105
			element = new ScopeElement(this, parentElement, (Scope) entity,
2106
					removeListener, style);
2107
		} else if (entity instanceof Modifier) {
2108
			element = new ModifierElement(this, parentElement,
2109
					(Modifier) entity, removeListener, style);
2110
		} else if (entity instanceof Reference) {
2111
			element = new DescriptionSourceElement(this, parentElement,
2112
					(Reference) entity, removeListener, style);
2113
		} else if (entity instanceof NameTypeDesignation) {
2114
			element = new NameTypeDesignationElement(this, parentElement,
2115
					(NameTypeDesignation) entity, removeListener, style);
2116
		} else if (entity instanceof NameRelationship) {
2117
			element = new NameRelationshipDetailElement(this, parentElement,
2118
					(NameRelationship) entity, removeListener, style);
2119
		} else if (entity instanceof SpecimenTypeDesignation) {
2120
			element = new SpecimenTypeDesignationElement(this, parentElement,
2121
					(SpecimenTypeDesignation) entity, removeListener, style);
2122
		} else if (entity instanceof StateData) {
2123
			element = new StateDataElement(this, parentElement,
2124
					(StateData) entity, removeListener, style);
2125
		} else if (entity instanceof StatisticalMeasurementValue) {
2126
			element = new StatisticalMeasurementValueElement(this,
2127
					parentElement, (StatisticalMeasurementValue) entity,
2128
					removeListener, style);
2129
		} else if (entity instanceof DerivedUnit) {
2130
			element = new DerivedUnitElement(this, parentElement,
2131
					(DerivedUnit) entity, removeListener, style);
2132
		} else if (entity instanceof NamedArea) {
2133
			element = new NamedAreaDetailElement(this, parentElement,
2134
					(NamedArea) entity, removeListener, style);
2135
		} else if (entity instanceof DeterminationEvent) {
2136
			element = new DeterminationEventDetailElement(this, parentElement,
2137
					(DeterminationEvent) entity, removeListener, style);
2138
		} else if (entity instanceof Specimen) {
2139
			element = new SpecimenCollectionDetailElement(this, parentElement,
2140
					(Specimen) entity, removeListener, style);
2141
		} else if (entity instanceof User) {
2142
			element = new MemberDetailElement(this, parentElement,
2143
					(User) entity, removeListener, style);
2144
		} else if (entity instanceof GrantedAuthority) {
2145
			element = new GrantedAuthorityDetailElement(this, parentElement,
2146
					(GrantedAuthority) entity, removeListener, style);
2147
		} else if (entity instanceof Group) {
2148
			element = new GroupsByUserDetailElement(this, parentElement,
2149
					(Group) entity, removeListener, style);
2150
		} else if (entity instanceof Taxon) {
2151
			element = new TaxonDetailElement(this, parentElement,
2152
					(Taxon) entity, removeListener, style);
2153
		} else if (entity instanceof DescriptionElementBase) {
2154
			// this is the special case for protologs, maybe we can do this
2155
			// differently when API improves
2156
			DescriptionElementBase descriptionElement = (DescriptionElementBase) entity;
2157
			if (descriptionElement.getFeature().equals(Feature.PROTOLOGUE())) {
2158
				element = new ProtologueElement(this, parentElement,
2159
						descriptionElement, removeListener, style);
2160
			}
2161
		}
2162

    
2163
		if (element == null) {
2164
			StoreUtil
2165
					.errorDialog(
2166
							"No element for entity",
2167
							this,
2168
							"Could not generate element for entity. "
2169
									+ "Looks like the case is not handled already. Check implementation. Entity: "
2170
									+ entity, null);
2171

    
2172
		}
2173

    
2174
		if (backgroundColor != null && !backgroundColor.isDisposed()) {
2175
			element.setPersistentBackground(backgroundColor);
2176
		}
2177

    
2178
		adapt(element);
2179
		parentElement.addElement(element);
2180
		return element;
2181
	}
2182

    
2183
	/**
2184
	 * <p>
2185
	 * createSelectionElement
2186
	 * </p>
2187
	 * 
2188
	 * @param selectionType
2189
	 *            a
2190
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.SelectionType}
2191
	 *            object.
2192
	 * @param parentElement
2193
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
2194
	 *            object.
2195
	 * @param labelString
2196
	 *            a {@link java.lang.String} object.
2197
	 * @param selectionType
2198
	 * @param selection
2199
	 *            a {@link eu.etaxonomy.cdm.model.common.IAnnotatableEntity}
2200
	 *            object.
2201
	 * @param style
2202
	 *            a int.
2203
	 * @param conversation
2204
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
2205
	 *            object.
2206
	 * @return a
2207
	 *         {@link eu.etaxonomy.taxeditor.ui.selection.AbstractSelectionElement}
2208
	 *         object.
2209
	 */
2210
	public AbstractSelectionElement createSelectionElement(
2211
			SelectionType selectionType, ConversationHolder conversation,
2212
			ICdmFormElement parentElement, String labelString,
2213
			ICdmBase selection, int mode, int style) {
2214
		AbstractSelectionElement element = null;
2215

    
2216
		IAnnotatableEntity entity = (IAnnotatableEntity) HibernateProxyHelper
2217
				.deproxy(selection);
2218

    
2219
		switch (selectionType) {
2220
		case AGENT:
2221
			element = new AgentSelectionElement(this, conversation,
2222
					parentElement, labelString, (TeamOrPersonBase) entity,
2223
					mode, style);
2224
			break;
2225
		case PERSON:
2226
			element = new PersonSelectionElement(this, conversation,
2227
					parentElement, labelString, (Person) entity, mode, style);
2228
			break;
2229
		case TEAM:
2230
			element = new TeamSelectionElement(this, conversation,
2231
					parentElement, labelString, (Team) entity, mode, style);
2232
			break;
2233
		case AUTHOR_TEAM:
2234
			element = new NomenclaturalAuthorTeamSelectionElement(this,
2235
					conversation, parentElement, labelString, (Team) entity,
2236
					mode, style);
2237
			break;
2238
		case INSTITUTION:
2239
			element = new InstitutionSelectionElement(this, conversation,
2240
					parentElement, labelString, (Institution) entity, mode,
2241
					style);
2242
			break;
2243
		case NAME:
2244
			element = new NameSelectionElement(this, conversation,
2245
					parentElement, labelString, (TaxonNameBase) entity, mode,
2246
					style);
2247
			break;
2248
		case REFERENCE:
2249
			element = new ReferenceSelectionElement(this, conversation,
2250
					parentElement, labelString, (Reference) entity, mode, style);
2251
			break;
2252
		case TAXON_BASE:
2253
			element = new TaxonBaseSelectionElement(this, conversation,
2254
					parentElement, labelString, (TaxonBase) entity, mode, style);
2255
			break;
2256
		case TAXON:
2257
			element = new TaxonSelectionElement(this, conversation,
2258
					parentElement, labelString, (Taxon) entity, mode, style);
2259
			break;
2260
		case SYNONYM:
2261
			element = new SynonymSelectionElement(this, conversation,
2262
					parentElement, labelString, (Synonym) entity, mode, style);
2263
			break;
2264
		case DERIVED_UNIT:
2265
			element = new DerivedUnitBaseSelectionElement(this, conversation,
2266
					parentElement, labelString, (DerivedUnitBase) entity, mode,
2267
					style);
2268
			break;
2269
		case FIELD_OBSERVATION:
2270
			element = new FieldObservationSelectionElement(this, conversation,
2271
					parentElement, labelString, (FieldObservation) entity,
2272
					mode, style);
2273
			break;
2274
		case FEATURE_TREE:
2275
			element = new FeatureTreeSelectionElement(this, conversation,
2276
					parentElement, labelString, (FeatureTree) entity, mode,
2277
					style);
2278
			break;
2279
		case CLASSIFICATION:
2280
			element = new ClassificationSelectionElement(this, conversation,
2281
					parentElement, labelString, (Classification) entity, mode,
2282
					style);
2283
			break;
2284
		case TAXON_NODE:
2285
			element = new TaxonNodeSelectionElement(this, conversation,
2286
					parentElement, labelString, (TaxonNode) entity, mode, style);
2287
			break;
2288
		case COLLECTION:
2289
			element = new CollectionSelectionElement(this, conversation,
2290
					parentElement, labelString, (Collection) entity, mode,
2291
					style);
2292
			break;
2293
		case FEATURE:
2294
			element = new FeatureSelectionElement(this, conversation,
2295
					parentElement, labelString, (Feature) entity, mode, style);
2296
			break;
2297
		case POLYTOMOUS_KEY:
2298
			element = new PolytomousKeySelectionElement(this, conversation,
2299
					parentElement, labelString, (PolytomousKey) entity, mode,
2300
					style);
2301
			break;
2302
		case POLYTOMOUS_KEY_NODE:
2303
			element = new PolytomousKeyNodeSelectionElement(this, conversation,
2304
					parentElement, labelString, (PolytomousKeyNode) entity,
2305
					mode, style);
2306
			break;
2307
		case USER:
2308
			element = new UserSelectionElement(this, conversation,
2309
					parentElement, labelString, (User) entity, mode, style);
2310
			break;
2311
		case GROUP:
2312
			element = new GroupSelectionElement(this, conversation,
2313
					parentElement, labelString, (Group) entity, mode, style);
2314
			break;
2315
		default:
2316
			new RuntimeException(
2317
					"There is no selection composite for the desired selection type.");
2318
			break;
2319
		}
2320

    
2321
		adapt(element);
2322
		parentElement.addElement(element);
2323
		return element;
2324
	}
2325

    
2326
	/**
2327
	 * <p>
2328
	 * createNamedAreaSelectionElement
2329
	 * </p>
2330
	 * 
2331
	 * @param parentElement
2332
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
2333
	 *            object.
2334
	 * @param conversation
2335
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
2336
	 *            object.
2337
	 * @param labelString
2338
	 *            a {@link java.lang.String} object.
2339
	 * @param selection
2340
	 *            a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
2341
	 * @param style
2342
	 *            a int.
2343
	 * @return a
2344
	 *         {@link eu.etaxonomy.taxeditor.ui.selection.NamedAreaSelectionElement}
2345
	 *         object.
2346
	 */
2347
	public NamedAreaSelectionElement createNamedAreaSelectionElement(
2348
			ICdmFormElement parentElement, ConversationHolder conversation,
2349
			String labelString, NamedArea selection, int style) {
2350
		NamedAreaSelectionElement element = new NamedAreaSelectionElement(this,
2351
				conversation, parentElement, labelString, selection,
2352
				AbstractSelectionElement.NOTHING, style);
2353
		adapt(element);
2354
		parentElement.addElement(element);
2355
		return element;
2356
	}
2357

    
2358
	/** {@inheritDoc} */
2359
	public LabelElement createLabel(ICdmFormElement parentElement, String text) {
2360
		LabelElement labelElement = new LabelElement(this, parentElement, text);
2361
		adapt(labelElement);
2362
		parentElement.addElement(labelElement);
2363
		return labelElement;
2364
	}
2365

    
2366
	/**
2367
	 * <p>
2368
	 * Getter for the field <code>selectionProvider</code>.
2369
	 * </p>
2370
	 * 
2371
	 * @return a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
2372
	 */
2373
	public ISelectionProvider getSelectionProvider() {
2374
		return selectionProvider;
2375
	}
2376

    
2377
	/**
2378
	 * <p>
2379
	 * createDetailedDescriptionDetailElement
2380
	 * </p>
2381
	 * 
2382
	 * @param parentElement
2383
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
2384
	 *            object.
2385
	 * @param entity
2386
	 *            a
2387
	 *            {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase}
2388
	 *            object.
2389
	 * @param style
2390
	 *            a int.
2391
	 * @return a
2392
	 *         {@link eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement}
2393
	 *         object.
2394
	 */
2395
	public AbstractDetailedDescriptionDetailElement createDetailedDescriptionDetailElement(
2396
			ICdmFormElement parentElement, DescriptionElementBase entity,
2397
			int style) {
2398
		AbstractDetailedDescriptionDetailElement detailedDescriptionElement = null;
2399

    
2400
		if (entity instanceof CategoricalData) {
2401
			detailedDescriptionElement = new CategoricalDataDetailElement(this,
2402
					parentElement, (CategoricalData) entity, style);
2403
		} else if (entity instanceof CommonTaxonName) {
2404
			detailedDescriptionElement = new CommonNameDetailElement(this,
2405
					parentElement, (CommonTaxonName) entity, style);
2406
		} else if (entity instanceof Distribution) {
2407
			detailedDescriptionElement = new DistributionDetailElement(this,
2408
					parentElement, (Distribution) entity, style);
2409
		} else if (entity instanceof IndividualsAssociation) {
2410
			detailedDescriptionElement = new IndividualsAssociationDetailElement(
2411
					this, parentElement, (IndividualsAssociation) entity, style);
2412
		} else if (entity instanceof QuantitativeData) {
2413
			detailedDescriptionElement = new QuantitativeDataDetailElement(
2414
					this, parentElement, (QuantitativeData) entity, style);
2415
		} else if (entity instanceof TaxonInteraction) {
2416
			detailedDescriptionElement = new TaxonInteractionDetailElement(
2417
					this, parentElement, (TaxonInteraction) entity, style);
2418
		} else if (entity instanceof TextData) {
2419
			detailedDescriptionElement = new TextDataDetailElement(this,
2420
					parentElement, (TextData) entity, style);
2421
		} else {
2422
			throw new IllegalStateException(
2423
					"There is no interface for the given description element");
2424
		}
2425
		adapt(detailedDescriptionElement);
2426
		parentElement.addElement(detailedDescriptionElement);
2427
		return detailedDescriptionElement;
2428

    
2429
	}
2430

    
2431
	public AbstractDetailedDescriptionDetailElement createUseRecordDetailElement(
2432
			ICdmFormElement parentElement, DescriptionElementBase entity,
2433
			int style) {
2434
		AbstractDetailedDescriptionDetailElement useRecordElement = null;
2435
		if (entity instanceof CategoricalData) {
2436
			useRecordElement = new UseRecordDetailElement(this,
2437
					parentElement, (CategoricalData) entity, style);
2438
		} else {
2439
			throw new IllegalStateException(
2440
					"There is no interface for the given description element");
2441
		}
2442
		adapt(useRecordElement);
2443
		parentElement.addElement(useRecordElement);
2444
		return useRecordElement;
2445
	}
2446

    
2447
	/**
2448
	 * Creates a styled text as a part of the form.
2449
	 * 
2450
	 * @param parent
2451
	 *            the text parent
2452
	 * @param value
2453
	 *            the text initial value
2454
	 * @param style
2455
	 *            the text style
2456
	 * @return the text widget
2457
	 */
2458
	public StyledText createStyledText(Composite parent, String value, int style) {
2459
		StyledText text = new StyledText(parent, getBorderStyle() | style
2460
				| getOrientation());
2461
		if (value != null)
2462
			text.setText(value);
2463
		text.setForeground(getColors().getForeground());
2464
		text.setBackground(getColors().getBackground());
2465
		// text.addFocusListener(visibilityHandler);
2466
		return text;
2467
	}
2468

    
2469
}
(6-6/35)