Project

General

Profile

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

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

    
14
import javax.inject.Inject;
15

    
16
import org.eclipse.e4.core.contexts.IEclipseContext;
17
import org.eclipse.jface.util.IPropertyChangeListener;
18
import org.eclipse.jface.viewers.ISelection;
19
import org.eclipse.jface.viewers.ISelectionProvider;
20
import org.eclipse.jface.window.Window;
21
//import org.eclipse.nebula.widgets.richtext.RichTextEditor;
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.custom.StyledText;
24
import org.eclipse.swt.events.FocusAdapter;
25
import org.eclipse.swt.events.FocusEvent;
26
import org.eclipse.swt.events.FocusListener;
27
import org.eclipse.swt.events.MouseAdapter;
28
import org.eclipse.swt.events.MouseEvent;
29
import org.eclipse.swt.events.MouseListener;
30
import org.eclipse.swt.events.SelectionEvent;
31
import org.eclipse.swt.events.SelectionListener;
32
import org.eclipse.swt.events.TypedEvent;
33
import org.eclipse.swt.graphics.Color;
34
import org.eclipse.swt.graphics.Font;
35
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Control;
37
import org.eclipse.swt.widgets.Display;
38
import org.eclipse.swt.widgets.Event;
39
import org.eclipse.swt.widgets.Label;
40
import org.eclipse.ui.forms.IFormColors;
41
import org.eclipse.ui.forms.widgets.ExpandableComposite;
42
import org.eclipse.ui.forms.widgets.FormToolkit;
43
import org.eclipse.ui.forms.widgets.Section;
44
import org.eclipse.ui.forms.widgets.TableWrapData;
45
import org.eclipse.ui.internal.forms.widgets.FormFonts;
46
import org.joda.time.DateTime;
47
import org.joda.time.Partial;
48
import org.springframework.security.core.GrantedAuthority;
49

    
50
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
51
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
52
import eu.etaxonomy.cdm.common.DOI;
53
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
54
import eu.etaxonomy.cdm.model.agent.Person;
55
import eu.etaxonomy.cdm.model.agent.Team;
56
import eu.etaxonomy.cdm.model.common.Annotation;
57
import eu.etaxonomy.cdm.model.common.CdmBase;
58
import eu.etaxonomy.cdm.model.common.Credit;
59
import eu.etaxonomy.cdm.model.common.Extension;
60
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
61
import eu.etaxonomy.cdm.model.common.Group;
62
import eu.etaxonomy.cdm.model.common.ICdmBase;
63
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
64
import eu.etaxonomy.cdm.model.common.Identifier;
65
import eu.etaxonomy.cdm.model.common.LSID;
66
import eu.etaxonomy.cdm.model.common.Language;
67
import eu.etaxonomy.cdm.model.common.LanguageString;
68
import eu.etaxonomy.cdm.model.common.Marker;
69
import eu.etaxonomy.cdm.model.common.TimePeriod;
70
import eu.etaxonomy.cdm.model.common.User;
71
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
72
import eu.etaxonomy.cdm.model.common.VersionableEntity;
73
import eu.etaxonomy.cdm.model.description.CategoricalData;
74
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
75
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
76
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
77
import eu.etaxonomy.cdm.model.description.Distribution;
78
import eu.etaxonomy.cdm.model.description.Feature;
79
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
80
import eu.etaxonomy.cdm.model.description.KeyStatement;
81
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
82
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
83
import eu.etaxonomy.cdm.model.description.QuantitativeData;
84
import eu.etaxonomy.cdm.model.description.State;
85
import eu.etaxonomy.cdm.model.description.StateData;
86
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
87
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
88
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
89
import eu.etaxonomy.cdm.model.description.TextData;
90
import eu.etaxonomy.cdm.model.location.NamedArea;
91
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
92
import eu.etaxonomy.cdm.model.location.Point;
93
import eu.etaxonomy.cdm.model.media.ExternalLink;
94
import eu.etaxonomy.cdm.model.media.ImageFile;
95
import eu.etaxonomy.cdm.model.media.Media;
96
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
97
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
98
import eu.etaxonomy.cdm.model.media.Rights;
99
import eu.etaxonomy.cdm.model.molecular.DnaSample;
100
import eu.etaxonomy.cdm.model.name.NameRelationship;
101
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
102
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
103
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
104
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
105
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
106
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
107
import eu.etaxonomy.cdm.model.reference.Reference;
108
import eu.etaxonomy.cdm.model.taxon.Taxon;
109
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
110
import eu.etaxonomy.cdm.model.taxon.TaxonNodeAgentRelation;
111
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
112
import eu.etaxonomy.cdm.model.term.DefinedTerm;
113
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
114
import eu.etaxonomy.cdm.model.term.IEnumTerm;
115
import eu.etaxonomy.cdm.model.term.Representation;
116
import eu.etaxonomy.cdm.model.term.TermBase;
117
import eu.etaxonomy.cdm.model.term.TermType;
118
import eu.etaxonomy.cdm.model.term.TermVocabulary;
119
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
120
import eu.etaxonomy.taxeditor.model.MessagingUtils;
121
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
122
import eu.etaxonomy.taxeditor.ui.combo.InverseTermWrapper;
123
import eu.etaxonomy.taxeditor.ui.combo.MisappliedRelationshipComboElement;
124
import eu.etaxonomy.taxeditor.ui.combo.NameRelationshipTypeCombo;
125
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
126
import eu.etaxonomy.taxeditor.ui.combo.VocabularyComboElement;
127
import eu.etaxonomy.taxeditor.ui.dialog.CloneClassificationDetailElement;
128
import eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection.UnitType;
129
import eu.etaxonomy.taxeditor.ui.mvc.element.DateElement;
130
import eu.etaxonomy.taxeditor.ui.openurl.IOpenUrlEnabled;
131
import eu.etaxonomy.taxeditor.ui.openurl.OpenUrlSelectorElement;
132
import eu.etaxonomy.taxeditor.ui.password.EditPasswordElement;
133
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
134
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
135
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
136
import eu.etaxonomy.taxeditor.ui.section.EmptyElement;
137
import eu.etaxonomy.taxeditor.ui.section.agent.InstitutionDetailElement;
138
import eu.etaxonomy.taxeditor.ui.section.agent.InstitutionDetailSection;
139
import eu.etaxonomy.taxeditor.ui.section.agent.PersonDetailElement;
140
import eu.etaxonomy.taxeditor.ui.section.agent.PersonDetailSection;
141
import eu.etaxonomy.taxeditor.ui.section.agent.TeamDetailElement;
142
import eu.etaxonomy.taxeditor.ui.section.agent.TeamDetailSection;
143
import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberElement;
144
import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberSection;
145
import eu.etaxonomy.taxeditor.ui.section.agent.TeamOrPersonBaseDetailSection;
146
import eu.etaxonomy.taxeditor.ui.section.classification.ClassificationDetailElement;
147
import eu.etaxonomy.taxeditor.ui.section.classification.ClassificationDetailSection;
148
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeAgentRelationCollectionElement;
149
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeAgentRelationCollectionSection;
150
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailElement;
151
import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailSection;
152
import eu.etaxonomy.taxeditor.ui.section.common.ExternalLinksElement;
153
import eu.etaxonomy.taxeditor.ui.section.common.ExternalLinksSection;
154
import eu.etaxonomy.taxeditor.ui.section.common.ReferenceEntityDetailElement;
155
import eu.etaxonomy.taxeditor.ui.section.common.ReferencedEntityDetailSection;
156
import eu.etaxonomy.taxeditor.ui.section.description.CommonNameSourceElement;
157
import eu.etaxonomy.taxeditor.ui.section.description.DerivedUnitElement;
158
import eu.etaxonomy.taxeditor.ui.section.description.DescribedSpecimenSection;
159
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionDetailElement;
160
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionDetailSection;
161
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementDetailElement;
162
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementDetailSection;
163
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementMediaSection;
164
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementSourceElement;
165
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementSourceSection;
166
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionSourceElement;
167
import eu.etaxonomy.taxeditor.ui.section.description.DescriptionSourceSection;
168
import eu.etaxonomy.taxeditor.ui.section.description.MediaDetailsSection;
169
import eu.etaxonomy.taxeditor.ui.section.description.ModifierElement;
170
import eu.etaxonomy.taxeditor.ui.section.description.ModifierSection;
171
import eu.etaxonomy.taxeditor.ui.section.description.NaturalLanguageDetailElement;
172
import eu.etaxonomy.taxeditor.ui.section.description.NaturalLanguageSection;
173
import eu.etaxonomy.taxeditor.ui.section.description.ScopeElement;
174
import eu.etaxonomy.taxeditor.ui.section.description.ScopeSection;
175
import eu.etaxonomy.taxeditor.ui.section.description.StateDataElement;
176
import eu.etaxonomy.taxeditor.ui.section.description.StateDataSection;
177
import eu.etaxonomy.taxeditor.ui.section.description.StatisticalMeasurementValueElement;
178
import eu.etaxonomy.taxeditor.ui.section.description.StatisticalMeasurementValueSection;
179
import eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement;
180
import eu.etaxonomy.taxeditor.ui.section.description.detail.CategoricalDataDetailElement;
181
import eu.etaxonomy.taxeditor.ui.section.description.detail.CommonNameDetailElement;
182
import eu.etaxonomy.taxeditor.ui.section.description.detail.DistributionDetailElement;
183
import eu.etaxonomy.taxeditor.ui.section.description.detail.IndividualsAssociationDetailElement;
184
import eu.etaxonomy.taxeditor.ui.section.description.detail.QuantitativeDataDetailElement;
185
import eu.etaxonomy.taxeditor.ui.section.description.detail.TaxonInteractionDetailElement;
186
import eu.etaxonomy.taxeditor.ui.section.description.detail.TextDataDetailElement;
187
import eu.etaxonomy.taxeditor.ui.section.feature.CharacterDetailElement;
188
import eu.etaxonomy.taxeditor.ui.section.feature.CharacterDetailSection;
189
import eu.etaxonomy.taxeditor.ui.section.feature.FeatureDistributionDetailElement;
190
import eu.etaxonomy.taxeditor.ui.section.feature.FeatureDistributionDetailSection;
191
import eu.etaxonomy.taxeditor.ui.section.feature.FeatureNodeDetailElement;
192
import eu.etaxonomy.taxeditor.ui.section.feature.FeatureNodeDetailSection;
193
import eu.etaxonomy.taxeditor.ui.section.feature.FeatureTreeDetailElement;
194
import eu.etaxonomy.taxeditor.ui.section.feature.FeatureTreeDetailSection;
195
import eu.etaxonomy.taxeditor.ui.section.feature.InapplicableIfCollectionElement;
196
import eu.etaxonomy.taxeditor.ui.section.feature.InapplicableIfEntityCollectionSection;
197
import eu.etaxonomy.taxeditor.ui.section.feature.OnlyApplicableIfCollectionElement;
198
import eu.etaxonomy.taxeditor.ui.section.feature.OnlyApplicableIfEntityCollectionSection;
199
import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityCollectionElement;
200
import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityDetailElement;
201
import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityDetailSection;
202
import eu.etaxonomy.taxeditor.ui.section.group.GroupDetailElement;
203
import eu.etaxonomy.taxeditor.ui.section.group.GroupDetailSection;
204
import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailElement;
205
import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailSection;
206
import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyDetailElement;
207
import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyDetailSection;
208
import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyNodeDetailElement;
209
import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyNodeDetailSection;
210
import eu.etaxonomy.taxeditor.ui.section.key.ScopeRestrictionSection;
211
import eu.etaxonomy.taxeditor.ui.section.key.TaxonomicScopeSection;
212
import eu.etaxonomy.taxeditor.ui.section.media.ImageFileElement;
213
import eu.etaxonomy.taxeditor.ui.section.media.MediaDetailElement;
214
import eu.etaxonomy.taxeditor.ui.section.media.MediaMetaElement;
215
import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationElement;
216
import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationPartElement;
217
import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationPartSection;
218
import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationSection;
219
import eu.etaxonomy.taxeditor.ui.section.media.MediaSection;
220
import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailElement;
221
import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailSection;
222
import eu.etaxonomy.taxeditor.ui.section.name.HybridDetailElement;
223
import eu.etaxonomy.taxeditor.ui.section.name.HybridDetailSection;
224
import eu.etaxonomy.taxeditor.ui.section.name.NameDetailElement;
225
import eu.etaxonomy.taxeditor.ui.section.name.NameDetailSection;
226
import eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailElement;
227
import eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailSection;
228
import eu.etaxonomy.taxeditor.ui.section.name.NameTypeDesignationElement;
229
import eu.etaxonomy.taxeditor.ui.section.name.NomenclaturalStatusElement;
230
import eu.etaxonomy.taxeditor.ui.section.name.NomenclaturalStatusSection;
231
import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameDetailElement;
232
import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameDetailSection;
233
import eu.etaxonomy.taxeditor.ui.section.name.ProtologueElement;
234
import eu.etaxonomy.taxeditor.ui.section.name.ProtologueSection;
235
import eu.etaxonomy.taxeditor.ui.section.name.SpecimenTypeDesignationElement;
236
import eu.etaxonomy.taxeditor.ui.section.name.TypeDesignationSection;
237
import eu.etaxonomy.taxeditor.ui.section.occurrence.CollectingAreaDetailElement;
238
import eu.etaxonomy.taxeditor.ui.section.occurrence.CollectingAreasDetailSection;
239
import eu.etaxonomy.taxeditor.ui.section.occurrence.CollectionDetailElement;
240
import eu.etaxonomy.taxeditor.ui.section.occurrence.CurrentDeterminationDetailSection;
241
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseDetailElement;
242
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseDetailSection;
243
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitGeneralDetailElement;
244
import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitGeneralDetailSection;
245
import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationDetailElement;
246
import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationDetailSection;
247
import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationEventDetailElement;
248
import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationHistoryDetailSection;
249
import eu.etaxonomy.taxeditor.ui.section.occurrence.EmptySection;
250
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitDetailElement;
251
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitDetailSection;
252
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitGeneralDetailElement;
253
import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitGeneralDetailSection;
254
import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventDetailElement;
255
import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventDetailSection;
256
import eu.etaxonomy.taxeditor.ui.section.occurrence.GeoScopeDetailSection;
257
import eu.etaxonomy.taxeditor.ui.section.occurrence.GeoScopePolyKeyDetailSection;
258
import eu.etaxonomy.taxeditor.ui.section.occurrence.OriginalLabelDataSection;
259
import eu.etaxonomy.taxeditor.ui.section.occurrence.SourceCollectionDetailSection;
260
import eu.etaxonomy.taxeditor.ui.section.occurrence.SpecimenCollectionDetailElement;
261
import eu.etaxonomy.taxeditor.ui.section.occurrence.SpecimenCollectionDetailSection;
262
import eu.etaxonomy.taxeditor.ui.section.occurrence.association.DerivedUnitTypeDesignationElement;
263
import eu.etaxonomy.taxeditor.ui.section.occurrence.association.DerivedUnitTypeDesignationSection;
264
import eu.etaxonomy.taxeditor.ui.section.occurrence.association.TaxonAssociationDetailElement;
265
import eu.etaxonomy.taxeditor.ui.section.occurrence.association.TaxonAssociationDetailSection;
266
import eu.etaxonomy.taxeditor.ui.section.occurrence.derivedUnit.PreservedSpecimenCurrentDeterminationDetailSection;
267
import eu.etaxonomy.taxeditor.ui.section.occurrence.derivedUnit.PreservedSpecimenDetailElement;
268
import eu.etaxonomy.taxeditor.ui.section.occurrence.derivedUnit.PreservedSpecimenDetailSection;
269
import eu.etaxonomy.taxeditor.ui.section.occurrence.derivedUnit.PreservedSpecimenGeneralDetailElement;
270
import eu.etaxonomy.taxeditor.ui.section.occurrence.derivedUnit.PreservedSpecimenGeneralDetailSection;
271
import eu.etaxonomy.taxeditor.ui.section.occurrence.derivedUnit.PreservedSpecimenSourceCollectionDetailSection;
272
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.AbstractSampleDesignationDetailSection;
273
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.AmplificationCloningDetailElement;
274
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.AmplificationCloningDetailSection;
275
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.AmplificationGelPhotoCollectionDetailSection;
276
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.AmplificationGelPhotoDetailElement;
277
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.AmplificationGeneralDetailElement;
278
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.AmplificationGeneralDetailSection;
279
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.AmplificationPrimerDetailElement;
280
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.AmplificationPrimerDetailSection;
281
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.CurrentSampleDesignationDetailSection;
282
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.DnaQualityDetailElement;
283
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.DnaQualityDetailSection;
284
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.DnaSampleGeneralDetailElement;
285
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.DnaSampleGeneralDetailSection;
286
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.DnaSamplePreparationPreservationDetailElement;
287
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.DnaSamplePreparationPreservationSection;
288
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.PrimerGeneralDetailElement;
289
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.SampleDesignationDetailElement;
290
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.SampleDesignationDetailSection;
291
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.SampleDesignationHistoryDetailSection;
292
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.SampleDesignationTextDetailElement;
293
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.SequenceContigFileCollectionDetailSection;
294
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.SequenceGeneralDetailElement;
295
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.SequenceGeneralDetailSection;
296
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.SequenceReferenceCollectionDetailElement;
297
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.SequenceReferenceCollectionDetailSection;
298
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.SingleReadGeneralDetailElement;
299
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.SingleReadGeneralDetailSection;
300
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.SingleReadPherogramCollectionDetailSection;
301
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.TissueSampleGeneralDetailElement;
302
import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.TissueSampleGeneralDetailSection;
303
import eu.etaxonomy.taxeditor.ui.section.occurrence.media.MediaSpecimenGeneralDetailElement;
304
import eu.etaxonomy.taxeditor.ui.section.occurrence.media.MediaSpecimenGeneralDetailSection;
305
import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailElement;
306
import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailSection;
307
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailElement;
308
import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailSection;
309
import eu.etaxonomy.taxeditor.ui.section.supplemental.AnnotationElement;
310
import eu.etaxonomy.taxeditor.ui.section.supplemental.AnnotationSection;
311
import eu.etaxonomy.taxeditor.ui.section.supplemental.CdmBaseElement;
312
import eu.etaxonomy.taxeditor.ui.section.supplemental.CdmBaseSection;
313
import eu.etaxonomy.taxeditor.ui.section.supplemental.CreditElement;
314
import eu.etaxonomy.taxeditor.ui.section.supplemental.CreditSection;
315
import eu.etaxonomy.taxeditor.ui.section.supplemental.ExtensionElement;
316
import eu.etaxonomy.taxeditor.ui.section.supplemental.ExtensionSection;
317
import eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection;
318
import eu.etaxonomy.taxeditor.ui.section.supplemental.IdentifiableSourceElement;
319
import eu.etaxonomy.taxeditor.ui.section.supplemental.MarkerElement;
320
import eu.etaxonomy.taxeditor.ui.section.supplemental.MarkerSection;
321
import eu.etaxonomy.taxeditor.ui.section.supplemental.RightsElement;
322
import eu.etaxonomy.taxeditor.ui.section.supplemental.RightsSection;
323
import eu.etaxonomy.taxeditor.ui.section.supplemental.SourceSection;
324
import eu.etaxonomy.taxeditor.ui.section.supplemental.VersionElement;
325
import eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection;
326
import eu.etaxonomy.taxeditor.ui.section.supplemental.identifier.DerivedUnitFacadeIdentifierSection;
327
import eu.etaxonomy.taxeditor.ui.section.supplemental.identifier.IdentifierElement;
328
import eu.etaxonomy.taxeditor.ui.section.supplemental.identifier.IdentifierSection;
329
import eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessageElement;
330
import eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessagesSection;
331
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonBaseDetailElement;
332
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonBaseDetailSection;
333
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonDetailElement;
334
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonDetailSection;
335
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonOfRelationshipElement;
336
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonRelationshipDetailElement;
337
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonRelationshipDetailSection;
338
import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailElement;
339
import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailSection;
340
import eu.etaxonomy.taxeditor.ui.section.user.UserDetailElement;
341
import eu.etaxonomy.taxeditor.ui.section.user.UserDetailSection;
342
import eu.etaxonomy.taxeditor.ui.section.userecords.UseRecordDetailElement;
343
import eu.etaxonomy.taxeditor.ui.section.userecords.UseRecordDetailSection;
344
import eu.etaxonomy.taxeditor.ui.section.vocabulary.DefinedTermDetailElement;
345
import eu.etaxonomy.taxeditor.ui.section.vocabulary.DefinedTermDetailSection;
346
import eu.etaxonomy.taxeditor.ui.section.vocabulary.FeatureDetailElement;
347
import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionElement;
348
import eu.etaxonomy.taxeditor.ui.section.vocabulary.MeasurementUnitCollectionSection;
349
import eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailSection;
350
import eu.etaxonomy.taxeditor.ui.section.vocabulary.PresenceAbsenceTermDetailElement;
351
import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesCollectionSection;
352
import eu.etaxonomy.taxeditor.ui.section.vocabulary.RecommendedModifierVocabulariesElement;
353
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StateVocabularyCollectionElement;
354
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StateVocabularyCollectionSection;
355
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StatisticalMeasureCollectionElement;
356
import eu.etaxonomy.taxeditor.ui.section.vocabulary.StatisticalMeasureCollectionSection;
357
import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermMediaSection;
358
import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermVocabularyDetailElement;
359
import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermVocabularyDetailSection;
360
import eu.etaxonomy.taxeditor.ui.selection.CommonNameReferenceSelectionElement;
361
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
362
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElementWithAbbreviatedTitle;
363
import eu.etaxonomy.taxeditor.ui.selection.NomenclaturalAuthorTeamSelectionElement;
364
import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
365

    
366
/**
367
 * <p>
368
 * CdmFormFactory class.
369
 * </p>
370
 *
371
 * @author n.hoffmann
372
 * @created Feb 24, 2010
373
 */
374
public class CdmFormFactory extends FormToolkit {
375

    
376
    private BoldFontHolder2 boldFontHolder2;
377
    private MouseListener selectionMouseHandler;
378
    private FocusListener selectionFocusHandler;
379

    
380
    @Inject
381
    private IEclipseContext context;
382

    
383
    private final Set<SelectionListener> selectionListenerList = new HashSet<SelectionListener>();
384

    
385
    private final List<IPropertyChangeListener> propertyChangeListeners = new ArrayList<IPropertyChangeListener>();
386

    
387
    private final int orientation = Window.getDefaultOrientation();
388
    private ISelectionProvider selectionProvider;
389

    
390
    /** Constant <code>EMPTY_SELECTION</code> */
391
    public static ISelection EMPTY_SELECTION = new ISelection() {
392
        @Override
393
        public boolean isEmpty() {
394
            return true;
395
        }
396
    };
397

    
398
    /**
399
     *
400
     * @author n.hoffmann
401
     * @date Jan 25, 2010
402
     *
403
     */
404
    private class SelectionMouseHandler extends MouseAdapter {
405
        @Override
406
        public void mouseDown(MouseEvent e) {
407
            notifySelectionListeners(e);
408
        }
409
    }
410

    
411
    /**
412
     *
413
     * @author n.hoffmann
414
     * @date Jan 25, 2010
415
     *
416
     */
417
    private class SelectionFocusHandler extends FocusAdapter {
418
        @Override
419
        public void focusGained(FocusEvent e) {
420
            notifySelectionListeners(e);
421
        }
422
    }
423

    
424
    private void notifySelectionListeners(TypedEvent e) {
425
        Event event = new Event();
426
        event.widget = e.widget;
427
        SelectionEvent selectionEvent = new SelectionEvent(event);
428

    
429
        for (SelectionListener listener : selectionListenerList) {
430
            listener.widgetSelected(selectionEvent);
431
        }
432
    }
433

    
434
    public CdmFormFactory(Display display) {
435
        this(display, null);
436
    }
437

    
438
    public CdmFormFactory(Display display, ISelectionProvider selectionProvider) {
439
        super(display);
440
        this.selectionProvider = selectionProvider;
441
        init();
442
    }
443

    
444
    private void init() {
445
        boldFontHolder2 = new BoldFontHolder2();
446
        selectionMouseHandler = new SelectionMouseHandler();
447
        selectionFocusHandler = new SelectionFocusHandler();
448
    }
449

    
450
    public IEclipseContext getContext() {
451
        return context;
452
    }
453

    
454
    /**
455
     * Creates an instance initialized with the correct selectionProvider
456
     *
457
     * Make sure to remove the instance when the entityComposite disposes via
458
     * destroySelectionArbitrator(..)
459
     *
460
     * @param entityElement
461
     *            a {@link eu.etaxonomy.taxeditor.ui.element.IEntityElement}
462
     *            object.
463
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator}
464
     *         object.
465
     */
466
    public SelectionArbitrator createSelectionArbitrator(IEntityElement entityElement) {
467
        SelectionArbitrator selectionArbitrator = new SelectionArbitrator(entityElement);
468
        selectionArbitrator.addSelectionProvider(selectionProvider);
469
        selectionProvider.addSelectionChangedListener(selectionArbitrator);
470
        addSelectionListener(selectionArbitrator);
471
        return selectionArbitrator;
472
    }
473

    
474
    /**
475
     * <p>
476
     * destroySelectionArbitrator
477
     * </p>
478
     *
479
     * @param selectionArbitrator
480
     *            a
481
     *            {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator}
482
     *            object.
483
     */
484
    public void destroySelectionArbitrator(SelectionArbitrator selectionArbitrator) {
485
        if(selectionArbitrator==null){
486
            return;
487
        }
488
        removeSelectionListener(selectionArbitrator);
489
        if (selectionProvider != null) {
490
            selectionProvider.removeSelectionChangedListener(selectionArbitrator);
491
        } else {
492
            MessagingUtils.error(this.getClass(),
493
                    "Tried to destroy a selection listener from this factories listeners but was null", null);
494
        }
495
    }
496

    
497
    /**
498
     * <p>
499
     * Adapts the {@link AbstractCdmFormElement}:<br>
500
     * - sets the {@link IPropertyChangeListener}s handled by this class
501
     * </p>
502
     *
503
     * @param formElement
504
     *            a
505
     *            {@link eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement}
506
     *            object.
507
     */
508
    public void adapt(ICdmFormElement formElement) {
509
        formElement.setPropertyChangeListeners(propertyChangeListeners);
510
    }
511

    
512
    /** {@inheritDoc} */
513
    @Override
514
    public void adapt(Control control, boolean trackFocus, boolean trackKeyboard) {
515
        if (trackFocus) {
516
            control.addFocusListener(selectionFocusHandler);
517
        }
518
        super.adapt(control, trackFocus, trackKeyboard);
519
    }
520

    
521
    /** {@inheritDoc} */
522
    @Override
523
    public void adapt(Composite composite) {
524
        composite.addMouseListener(selectionMouseHandler);
525

    
526
        super.adapt(composite);
527
    }
528

    
529
    /**
530
     * <p>
531
     * destroyElement
532
     * </p>
533
     *
534
     * @param formElement
535
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
536
     *            object.
537
     */
538
    public void destroyElement(ICdmFormElement formElement) {
539
        // return if element was not initialized
540
        if (formElement == null) {
541
            return;
542
        }
543
        // destroy selection arbitrator, if any
544
        if (formElement instanceof ISelectableElement) {
545
            destroySelectionArbitrator(((ISelectableElement) formElement).getSelectionArbitrator());
546
        }
547
        // remove this element form its parents list of elements
548
        // ICdmFormElement parentElement = formElement.getParentElement();
549
        // if(parentElement != null){
550
        // parentElement.removeElement(formElement);
551
        // }
552
        // call destroy on child elements recursively
553
        for (ICdmFormElement childElement : formElement.getElements()) {
554
            destroyElement(childElement);
555
        }
556
        // dispose of the controls
557
        for (Control control : formElement.getControls()) {
558
            // we added the layoutComposite of the parental element as the
559
            // layout composite to this formElement
560
            // but we do not want to destroy it.
561
            if (control.equals(formElement.getLayoutComposite())) {
562
                continue;
563
            } else {
564
                if (control != null && !control.isDisposed()){
565
                    control.dispose();
566
                }
567
                control = null;
568
            }
569
        }
570
    }
571

    
572
    /**
573
     * <p>
574
     * createEmptyCell
575
     * </p>
576
     *
577
     * @param parent
578
     *            a {@link org.eclipse.swt.widgets.Composite} object.
579
     * @return a {@link org.eclipse.swt.widgets.Label} object.
580
     */
581
    public Label createEmptyCell(Composite parent) {
582
        return this.createLabel(parent, null);
583
    }
584

    
585
    /**
586
     * <p>
587
     * createMultiLanguageTextElement
588
     * </p>
589
     *
590
     * @param parentElement
591
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
592
     *            object.
593
     * @param labelString
594
     *            a {@link java.lang.String} object.
595
     * @param multilanguageText
596
     *            a {@link java.util.Map} object.
597
     * @param textHeight
598
     *            a int.
599
     * @param style
600
     *            a int.
601
     * @return a
602
     *         {@link eu.etaxonomy.taxeditor.ui.element.MultilanguageTextElement}
603
     *         object.
604
     */
605
    public MultilanguageTextElement createMultiLanguageTextElement(ICdmFormElement parentElement, String labelString,
606
            Map<Language, LanguageString> multilanguageText, int textHeight, int style) {
607
        MultilanguageTextElement element = new MultilanguageTextElement(this, parentElement, labelString,
608
                multilanguageText, textHeight, style);
609
        adapt(element);
610
        parentElement.addElement(element);
611
        return element;
612
    }
613

    
614
    /**
615
     * <p>
616
     * createMultiLanguageTextElement
617
     * </p>
618
     *
619
     * @param parentElement
620
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
621
     *            object.
622
     *
623
     * @param Representation
624
     *            a {@link eu.etaxonomy.cdm.model.term.Representation} object.
625
     * @param textHeight
626
     *            a int.
627
     * @param style
628
     *            a int.
629
     * @return a
630
     *         {@link eu.etaxonomy.taxeditor.ui.element.RepresentationElement}
631
     *         object.
632
     */
633
    public RepresentationElement createRepresentationElement(ICdmFormElement parentElement, Representation representation, TermBase term,int textHeight, int style, boolean fillDetails) {
634
        RepresentationElement element = new RepresentationElement(this, parentElement, representation, term, textHeight, style, fillDetails);
635
        adapt(element);
636
        parentElement.addElement(element);
637
        return element;
638
    }
639

    
640
    /**
641
     * <p>
642
     * createMultiLanguageTextElement
643
     * </p>
644
     *
645
     * @param parentElement
646
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
647
     *            object.
648
     *
649
     * @param Representation
650
     *            a {@link eu.etaxonomy.cdm.model.term.Representation} object.
651
     * @param textHeight
652
     *            a int.
653
     * @param style
654
     *            a int.
655
     * @return a
656
     *         {@link eu.etaxonomy.taxeditor.ui.element.RepresentationElement}
657
     *         object.
658
     */
659
    public TranslatableRepresentationElement createTranslatableRepresentationElement(ICdmFormElement parentElement, Representation representation, TermBase term,int textHeight, int style, boolean fillDetails) {
660
        TranslatableRepresentationElement element = new TranslatableRepresentationElement(this, parentElement, representation, term, textHeight, style, fillDetails);
661
        adapt(element);
662
        parentElement.addElement(element);
663
        return element;
664
    }
665

    
666
    public KeyStatementElement createKeyStatementElement(ICdmFormElement parentElement, String labelString,
667
            KeyStatement keyStatement, int textHeight, int style) {
668
        KeyStatementElement element = new KeyStatementElement(this, parentElement, labelString, keyStatement,
669
                textHeight, style);
670
        adapt(element);
671
        parentElement.addElement(element);
672
        return element;
673
    }
674

    
675
    /**
676
     * Creates a text field with a label. The initial content will be the return value of the initalObject's {@link #toString()}
677
     * method.<br>
678
     * <b>Note</b>: if initialObject is <code>null</code> then an empty string is used.
679
     * @param parentElement the parent container
680
     * @param labelString the label name
681
     * @param initialObject the object from which the <code>toString()</code> method is called
682
     * @param style {@link SWT} style constant
683
     * @return the created textfield with label
684
     */
685
    public TextWithLabelElement createTextWithLabelElement(ICdmFormElement parentElement, String labelString,
686
            Object initialObject, int style) {
687
        return createTextWithLabelElement(parentElement, labelString, initialObject==null?"":initialObject.toString(), style);
688
    }
689

    
690
    /**
691
     * <p>
692
     * createTextWithLabelElement
693
     * </p>
694
     *
695
     * @param parentElement
696
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
697
     *            object.
698
     * @param labelString
699
     *            a {@link java.lang.String} object.
700
     * @param initialText
701
     *            a {@link java.lang.String} object.
702
     * @param style
703
     *            a int.
704
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
705
     *         object.
706
     */
707
    public TextWithLabelElement createTextWithLabelElement(ICdmFormElement parentElement, String labelString,
708
            String initialText, int style) {
709
        return createTextWithLabelElement(parentElement, labelString, initialText, null, style);
710
    }
711
    /**
712
     * <p>
713
     * createTextWithLabelElement
714
     * </p>
715
     *
716
     * @param parentElement
717
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
718
     *            object.
719
     * @param labelString
720
     *            a {@link java.lang.String} object.
721
     * @param initialText
722
     *            a {@link java.lang.String} object.
723
     * @param textLimit maximal number of characters allowed
724
     * @param style
725
     *            a int.
726
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
727
     *         object.
728
     */
729
    public TextWithLabelElement createTextWithLabelElement(ICdmFormElement parentElement, String labelString,
730
            String initialText, Integer textLimit, int style) {
731
        if(initialText==null){
732
            initialText = "";
733
        }
734

    
735
        TextWithLabelElement element = new TextWithLabelElement(this, parentElement, labelString, initialText, null,
736
                textLimit, style);
737
        adapt(element);
738
        parentElement.addElement(element);
739
        return element;
740
    }
741

    
742
    public TextWithLabelElement createMultiLineTextWithLabel(ICdmFormElement parentElement, String labelString,
743
            int textHeight, int style) {
744
        TextWithLabelElement element = new TextWithLabelElement(this, parentElement, labelString, "", textHeight, true, style);
745
        adapt(element);
746
        parentElement.addElement(element);
747
        return element;
748
    }
749

    
750
    public LsidWithExceptionLabelElement createLsidWithExceptionLabelElement(ICdmFormElement parentElement, String labelString,
751
            LSID initialLsid, int style) {
752
        LsidWithExceptionLabelElement element = new LsidWithExceptionLabelElement(this, parentElement, labelString, initialLsid, null, style);
753
        adapt(element);
754
        parentElement.addElement(element);
755
        return element;
756
    }
757

    
758
    public UriWithLabelElement createUriWithLabelElement(ICdmFormElement parentElement, String labelString,
759
            URI initialUri, int style) {
760
        UriWithLabelElement element = new UriWithLabelElement(this, parentElement, labelString, initialUri, null, style);
761
        adapt(element);
762
        parentElement.addElement(element);
763
        return element;
764
    }
765
    public UriWithLabelElement createUriWithLabelElement(ICdmFormElement parentElement, String labelString,
766
            URI initialUri,Integer textHeight, int style) {
767
        UriWithLabelElement element = new UriWithLabelElement(this, parentElement, labelString, initialUri, textHeight, style);
768
        adapt(element);
769
        parentElement.addElement(element);
770
        return element;
771
    }
772

    
773

    
774
    public DoiWithLabelElement createDoiWithLabelElement(ICdmFormElement parentElement, String labelString,
775
            DOI initialDoi, int style) {
776
        DoiWithLabelElement element = new DoiWithLabelElement(this, parentElement, labelString, initialDoi, null, style);
777
        adapt(element);
778
        parentElement.addElement(element);
779
        return element;
780
    }
781
    public DoiWithLabelElement createDoiWithLabelElement(ICdmFormElement parentElement, String labelString,
782
            DOI initialDoi,Integer textHeight, int style) {
783
        DoiWithLabelElement element = new DoiWithLabelElement(this, parentElement, labelString, initialDoi, textHeight, style);
784
        adapt(element);
785
        parentElement.addElement(element);
786
        return element;
787
    }
788

    
789
    /**
790
     * @param element
791
     * @param string
792
     * @param uri
793
     * @param style
794
     * @return
795
     */
796
    public OpenUrlSelectorElement createOpenUrlSelectorElement(ICdmFormElement parentElement, String labelString,
797
            IOpenUrlEnabled openUrlEnabled, int style) {
798
        OpenUrlSelectorElement element = new OpenUrlSelectorElement(this, parentElement, labelString, openUrlEnabled,
799
                style);
800
        adapt(element);
801
        parentElement.addElement(element);
802
        return element;
803
    }
804

    
805
    /**
806
     *
807
     * @param parentElement
808
     * @param labelString
809
     * @param conversationEnabled
810
     * @param user
811
     * @param style
812
     * @return
813
     */
814
    public EditPasswordElement createEditPasswordElement(ICdmFormElement parentElement, String labelString,
815
            ConversationHolder conversation, User user, int style) {
816
        EditPasswordElement element = new EditPasswordElement(this, parentElement, labelString, user, conversation);
817
        adapt(element);
818
        parentElement.addElement(element);
819
        return element;
820
    }
821

    
822
    /**
823
     * <p>
824
     * createIntegerTextWithLabelElement
825
     * </p>
826
     *
827
     * @param parentElement
828
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
829
     *            object.
830
     * @param labelString
831
     *            a {@link java.lang.String} object.
832
     * @param initialInteger
833
     *            a {@link java.lang.Integer} object.
834
     * @param style
835
     *            a int.
836
     * @return a
837
     *         {@link eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement}
838
     *         object.
839
     */
840
	public NumberWithLabelElement createNumberTextWithLabelElement(
841
			ICdmFormElement parentElement, String labelString,
842
			Number initialNumber, int style) {
843
		NumberWithLabelElement element = new NumberWithLabelElement(this,
844
				parentElement, labelString, initialNumber, style);
845
		adapt(element);
846
		parentElement.addElement(element);
847
		return element;
848
	}
849

    
850
    public LanguageStringWithLabelElement createLanguageStringWithLabelElement(ICdmFormElement parentElement,
851
            String labelString, LanguageString languageString, int style) {
852
        return createLanguageStringWithLabelElement(parentElement, labelString, languageString, null, false, style);
853
    }
854

    
855
    public LanguageStringWithLabelElement createLanguageStringWithLabelElement(ICdmFormElement parentElement,
856
            String labelString, LanguageString languageString, Integer height, boolean isMultiLine, int style) {
857
        LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(this, parentElement, labelString,
858
                languageString, height, isMultiLine, style);
859
        adapt(element);
860
        parentElement.addElement(element);
861
        return element;
862
    }
863

    
864
    /**
865
     * <p>
866
     * createKeyValueViewerElement
867
     * </p>
868
     *
869
     * @param parentElement
870
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
871
     *            object.
872
     * @param keyHeading
873
     *            a {@link java.lang.String} object.
874
     * @param valueHeading
875
     *            a {@link java.lang.String} object.
876
     * @param map
877
     *            a {@link java.util.Map} object.
878
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.KeyValueViewerElement}
879
     *         object.
880
     */
881
    public KeyValueViewerElement createKeyValueViewerElement(ICdmFormElement parentElement, String keyHeading,
882
            String valueHeading, Map<Object, Object> map) {
883
        KeyValueViewerElement element = new KeyValueViewerElement(this, parentElement, keyHeading, valueHeading, map);
884
        adapt(element);
885
        parentElement.addElement(element);
886
        return element;
887
    }
888
    /**
889
     * @deprecated Use {@link #createDefinedTermComboElement(TermType, ICdmFormElement, String, DefinedTermBase, int)} instead
890
     */
891
    @Deprecated
892
    public <T extends DefinedTermBase> TermComboElement<T> createTermComboElement(Class<T> termComboType,
893
            ICdmFormElement parentElement, String labelString, T selection, int style) {
894
        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termComboType, labelString, selection, true, style);
895
        adapt(element);
896
        parentElement.addElement(element);
897
        return element;
898
    }
899

    
900
    public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
901
            TermType termType,
902
            ICdmFormElement parentElement,
903
            String labelString,
904
            T selection,
905
            int style,
906
            Comparator<T> comparator) {
907
        return this.createDefinedTermComboElement(termType, null, null, parentElement, labelString, selection, true, style, false, comparator);
908
    }
909

    
910
    public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
911
			TermType termType,
912
			ICdmFormElement parentElement,
913
			String labelString,
914
			T selection,
915
			boolean addEmptyElement,
916
			int style) {
917
        return this.createDefinedTermComboElement(termType, null, null, parentElement, labelString, selection, addEmptyElement, style, false, null);
918
	}
919

    
920
	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
921
			TermType termType,
922
			ICdmFormElement parentElement,
923
			String labelString,
924
			T selection,
925
			int style) {
926
		return  this.createDefinedTermComboElement(termType, null, null, parentElement, labelString, selection, true, style, false, null);
927
	}
928

    
929
	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
930
            List<T> terms,
931
            ICdmFormElement parentElement,
932
            String labelString,
933
            T selection,
934
            int style) {
935
        return  this.createDefinedTermComboElement(null, null, terms, parentElement, labelString, selection, true, style, false, null);
936
    }
937
    public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
938
			TermType termType,
939
			ICdmFormElement parentElement,
940
			String labelString,
941
			T selection,
942
			boolean addEmptyElement,
943
			int style,
944
			boolean useAbbrevLabel) {
945
		return createDefinedTermComboElement(termType, null, null, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
946
	}
947

    
948

    
949
    public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
950
            TermVocabulary<?> termVocabulary,
951
            ICdmFormElement parentElement,
952
            String labelString,
953
            T selection,
954
            int style) {
955
        return this.createDefinedTermComboElement(null, termVocabulary, null, parentElement, labelString, selection, true, style, false, null);
956
    }
957

    
958
	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
959
	        TermVocabulary<?> termVocabulary,
960
	        ICdmFormElement parentElement,
961
	        String labelString,
962
	        T selection,
963
	        boolean addEmptyElement,
964
	        int style,
965
	        boolean useAbbrevLabel) {
966
	    return createDefinedTermComboElement(null, termVocabulary, null, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
967
	}
968

    
969
	private <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
970
	        TermType termType,
971
	        TermVocabulary<?> termVocabulary,
972
	        List<T> terms,
973
	        ICdmFormElement parentElement,
974
	        String labelString,
975
	        T selection,
976
	        boolean addEmptyElement,
977
	        int style,
978
	        boolean useAbbrevLabel,
979
	        Comparator<T> comparator) {
980
	    if(termType!=null){
981
	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termType, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
982
	        adapt(element);
983
	        parentElement.addElement(element);
984
	        return element;
985
	    }
986
	    else if(termVocabulary!=null){
987
	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termVocabulary, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
988
	        if (comparator!= null){
989
	        	element.setTermComparator(comparator);
990
	        }
991
	        adapt(element);
992
	        parentElement.addElement(element);
993
	        return element;
994
	    }else if (terms != null){
995

    
996
	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, terms, labelString, selection, addEmptyElement, style, useAbbrevLabel);
997
            if (comparator!= null){
998
                element.setTermComparator(comparator);
999
            }
1000
            adapt(element);
1001
            parentElement.addElement(element);
1002
            return element;
1003
	    }
1004
	    else {
1005
	        //this should never happen
1006
	        return null;
1007
	    }
1008
	}
1009

    
1010
	public NameRelationshipTypeCombo createNameRelationshipTypeCombo(ICdmFormElement parentElement,
1011
            String labelString,
1012
            int style,
1013
            boolean useAbbrevLabel,
1014
            Comparator<NameRelationshipType> comparator) {
1015

    
1016
        NameRelationshipTypeCombo<InverseTermWrapper> element = new NameRelationshipTypeCombo(this, parentElement, labelString, true, style, useAbbrevLabel, comparator);
1017
        adapt(element);
1018
        parentElement.addElement(element);
1019
        return element;
1020
    }
1021

    
1022
	public MisappliedRelationshipComboElement createMisappliedRelationshipComboElement(
1023
	        ICdmFormElement parentElement,
1024
            String labelString,
1025
            TaxonRelationshipType selection,
1026
            int style) {
1027
	    MisappliedRelationshipComboElement combo = new MisappliedRelationshipComboElement(this, parentElement, labelString, selection, false, style, false);
1028
	    adapt(combo);
1029
        parentElement.addElement(combo);
1030
        return combo;
1031
    }
1032

    
1033
	public <T extends IEnumTerm<T>> EnumComboElement<T> createEnumComboElement(
1034
	        Class<T> enumComboType, ICdmFormElement parentElement,
1035
	        int style) {
1036
	    return createEnumComboElement(enumComboType, parentElement, null, style);
1037
	}
1038

    
1039
	public <T extends IEnumTerm<T>> EnumComboElement<T> createEnumComboElement(
1040
			Class<T> enumComboType, ICdmFormElement parentElement, Comparator<T> comparator,
1041
			int style) {
1042
        EnumComboElement<T> element = new EnumComboElement<T>(this, parentElement, enumComboType, comparator, style);
1043
        adapt(element);
1044
        parentElement.addElement(element);
1045
        return element;
1046
    }
1047

    
1048
	public <TERM extends DefinedTermBase<TERM>, VOC extends TermVocabulary<TERM>> VocabularyComboElement<TERM, VOC> createVocabularyComboElement(
1049
	        TermType termType, String label, VOC selection, ICdmFormElement parentElement, int style) {
1050
	    VocabularyComboElement<TERM, VOC> element = new VocabularyComboElement<TERM, VOC>(this, parentElement, termType, label, selection, style);
1051
	    adapt(element);
1052
	    parentElement.addElement(element);
1053
	    return element;
1054
	}
1055

    
1056
    /**
1057
     * <p>
1058
     * createBrowserElement
1059
     * </p>
1060
     *
1061
     * @param imageUri
1062
     *            a {@link java.net.URI} object.
1063
     * @param style
1064
     *            a int.
1065
     * @param parentElement
1066
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1067
     *            object.
1068
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.BrowserElement}
1069
     *         object.
1070
     */
1071
    public BrowserElement createBrowserElement(ICdmFormElement parentElement, URI imageUri, int style) {
1072
        BrowserElement element = new BrowserElement(this, parentElement, imageUri, style);
1073
        adapt(element);
1074
        parentElement.addElement(element);
1075
        return element;
1076
    }
1077

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

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

    
1127
    /**
1128
     * <p>
1129
     * createCheckbox
1130
     * </p>
1131
     *
1132
     * @param parentElement
1133
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1134
     *            object.
1135
     * @param label
1136
     *            a {@link java.lang.String} object.
1137
     * @param initialState
1138
     *            a boolean.
1139
     * @param style
1140
     *            a int.
1141
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.CheckboxElement}
1142
     *         object.
1143
     */
1144
    public CheckboxElement createCheckbox(ICdmFormElement parentElement, String label, Boolean initialState, int style) {
1145
        if(initialState==null){
1146
            initialState = Boolean.FALSE;
1147
        }
1148
        CheckboxElement element = new CheckboxElement(this, parentElement, label, initialState, style | orientation);
1149
        adapt(element);
1150
        parentElement.addElement(element);
1151
        return element;
1152
    }
1153

    
1154
    /**
1155
     * Creates a section as a part of the form.
1156
     *
1157
     * @return the section widget
1158
     * @param section
1159
     *            a
1160
     *            {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1161
     *            object.
1162
     */
1163
    public Section adapt(AbstractFormSection section) {
1164
        section.setMenu(section.getLayoutComposite().getMenu());
1165
        adapt(section, true, true);
1166

    
1167
        // handle focus and property change events for cdm use
1168
        section.addFocusListener(selectionFocusHandler);
1169
        section.setPropertyChangeListeners(propertyChangeListeners);
1170

    
1171
        if (section.getToggle() != null) {
1172
            section.getToggle().setHoverDecorationColor(getColors().getColor(IFormColors.TB_TOGGLE_HOVER));
1173
            section.getToggle().setDecorationColor(getColors().getColor(IFormColors.TB_TOGGLE));
1174
        }
1175

    
1176
        section.setFont(boldFontHolder2.getBoldFont(section.getLayoutComposite().getFont()));
1177

    
1178
        if ((section.getStyle() & ExpandableComposite.TITLE_BAR) != 0
1179
                || (section.getStyle() & ExpandableComposite.SHORT_TITLE_BAR) != 0) {
1180
            getColors().initializeSectionToolBarColors();
1181
            section.setTitleBarBackground(getColors().getColor(IFormColors.TB_BG));
1182
            section.setTitleBarBorderColor(getColors().getColor(IFormColors.TB_BORDER));
1183
        }
1184
        // call setTitleBarForeground regardless as it also sets the label color
1185
        section.setTitleBarForeground(getColors().getColor(IFormColors.TB_TOGGLE));
1186
        return section;
1187
    }
1188

    
1189
    private class BoldFontHolder2 {
1190
        private Font normalFont;
1191

    
1192
        private Font boldFont;
1193

    
1194
        public BoldFontHolder2() {
1195
        }
1196

    
1197
        public Font getBoldFont(Font font) {
1198
            createBoldFont(font);
1199
            return boldFont;
1200
        }
1201

    
1202
        private void createBoldFont(Font font) {
1203
            if (normalFont == null || !normalFont.equals(font)) {
1204
                normalFont = font;
1205
                dispose();
1206
            }
1207
            if (boldFont == null) {
1208
                boldFont = FormFonts.getInstance().getBoldFont(getColors().getDisplay(), normalFont);
1209
            }
1210
        }
1211

    
1212
        public void dispose() {
1213
            if (boldFont != null) {
1214
                FormFonts.getInstance().markFinished(boldFont, getColors().getDisplay());
1215
                boldFont = null;
1216
            }
1217
        }
1218
    }
1219

    
1220
    /**
1221
     * <p>
1222
     * createToggleableTextField
1223
     * </p>
1224
     *
1225
     * @param parentElement
1226
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1227
     *            object.
1228
     * @param labelString
1229
     *            a {@link java.lang.String} object.
1230
     * @param initialText
1231
     *            a {@link java.lang.String} object.
1232
     * @param initialState
1233
     *            a boolean.
1234
     * @param style
1235
     *            a int.
1236
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement}
1237
     *         object.
1238
     */
1239
    public ToggleableTextElement createToggleableTextField(ICdmFormElement parentElement, String labelString,
1240
            String initialText, boolean initialState, int style) {
1241
        ToggleableTextElement element = new ToggleableTextElement(this, parentElement, labelString, initialText,
1242
                initialState, style | orientation);
1243

    
1244
        adapt(element);
1245
        parentElement.addElement(element);
1246
        return element;
1247
    }
1248

    
1249
    /**
1250
     * <p>
1251
     * createTimePeriodElement
1252
     * </p>
1253
     *
1254
     * @param parentElement
1255
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1256
     *            object.
1257
     * @param labelString
1258
     *            a {@link java.lang.String} object.
1259
     * @param timePeriod
1260
     *            a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
1261
     * @param style
1262
     *            a int.
1263
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.TimePeriodElement}
1264
     *         object.
1265
     */
1266
    public TimePeriodElement createTimePeriodElement(ICdmFormElement parentElement, String labelString,
1267
            TimePeriod timePeriod, int style) {
1268
        TimePeriodElement element = new TimePeriodElement(this, parentElement, labelString, timePeriod, style);
1269
        adapt(element);
1270
        parentElement.addElement(element);
1271
        return element;
1272
    }
1273

    
1274
    /**
1275
     * <p>
1276
     * createVerbatimTimePeriodElement
1277
     * </p>
1278
     *
1279
     * @param parentElement
1280
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1281
     *            object.
1282
     * @param labelString
1283
     *            a {@link java.lang.String} object.
1284
     * @param timePeriod
1285
     *            a {@link eu.etaxonomy.cdm.model.common.VerbatimTimePeriod} object.
1286
     * @param style
1287
     *            a int.
1288
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.VerbatimTimePeriodElement}
1289
     *         object.
1290
     */
1291
    public VerbatimTimePeriodElement createVerbatimTimePeriodElement(ICdmFormElement parentElement, String labelString,
1292
            VerbatimTimePeriod timePeriod, int style) {
1293
        VerbatimTimePeriodElement element = new VerbatimTimePeriodElement(this, parentElement, labelString, timePeriod, style);
1294
        adapt(element);
1295
        parentElement.addElement(element);
1296
        return element;
1297
    }
1298

    
1299

    
1300

    
1301
	/**
1302
	 * <p>
1303
	 * createGatheringEventUnitElement
1304
	 * </p>
1305
	 *
1306
	 * @param parentElement
1307
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1308
	 *            object.
1309
	 * @param labelString
1310
	 *            a {@link java.lang.String} object.
1311
	 * @param timePeriod
1312
	 *            a {@link eu.etaxonomy.cdm.model.common.GatheringEvent} object.
1313
	 * @param style
1314
	 *            a int.
1315
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.GatheringEventUnitElement}
1316
	 *         object.
1317
	 */
1318
	public GatheringEventUnitElement createGatheringEventUnitElement(
1319
			ICdmFormElement parentElement,
1320
			String labelString,
1321
			DerivedUnitFacade gatheringEvent,
1322
			MinMaxTextSection.UnitType unitType,
1323
			int style) {
1324
		GatheringEventUnitElement element = new GatheringEventUnitElement(this,
1325
				parentElement,
1326
				labelString,
1327
				gatheringEvent,
1328
				unitType,
1329
				style);
1330
		adapt(element);
1331
		parentElement.addElement(element);
1332
		return element;
1333
	}
1334

    
1335
    /**
1336
     * <p>
1337
     * createPointElement
1338
     * </p>
1339
     *
1340
     * @param style
1341
     *            a int.
1342
     * @param parentElement
1343
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1344
     *            object.
1345
     * @param point
1346
     *            a {@link eu.etaxonomy.cdm.model.location.Point} object.
1347
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.PointElement} object.
1348
     */
1349
    public PointElement createPointElement(ICdmFormElement parentElement, Point point, int style) {
1350
        PointElement element = new PointElement(this, parentElement, point, style);
1351
        adapt(element);
1352
        parentElement.addElement(element);
1353
        return element;
1354
    }
1355

    
1356
    /**
1357
     * Creates an empty section with the given message.<br>
1358
     * If message is <code>null</code> a default message will be displayed.
1359
     */
1360
    public EmptySection createEmptySection(String message, CdmFormFactory formFactory, ICdmFormElement parentElement, int style) {
1361
        EmptySection section = new EmptySection(message, formFactory, parentElement, style);
1362
        parentElement.addElement(section);
1363
        adapt(section);
1364
        return section;
1365
    }
1366

    
1367
    /**
1368
     * <p>
1369
     * createDateDetailSection
1370
     * </p>
1371
     *
1372
     * @param parentElement
1373
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1374
     *            object.
1375
     * @param style
1376
     *            a int.
1377
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.DateDetailSection}
1378
     *         object.
1379
     */
1380
    public DateDetailSection<TimePeriod> createDateDetailSection(ICdmFormElement parentElement, int style) {
1381
        DateDetailSection<TimePeriod> section = new DateDetailSection<TimePeriod>(this, parentElement, false, style);
1382
        parentElement.addElement(section);
1383
        adapt(section);
1384
        return section;
1385
    }
1386

    
1387
    /**
1388
     * <p>
1389
     * createVerbatimDateDetailSection
1390
     * </p>
1391
     *
1392
     * @param parentElement
1393
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1394
     *            object.
1395
     * @param style
1396
     *            a int.
1397
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.VerbatimDateDetailSection}
1398
     *         object.
1399
     */
1400
    public DateDetailSection<VerbatimTimePeriod> createVerbatimDateDetailSection(ICdmFormElement parentElement, int style) {
1401
        DateDetailSection<VerbatimTimePeriod> section
1402
        	= new DateDetailSection<VerbatimTimePeriod>(this, parentElement, true, style);
1403
        parentElement.addElement(section);
1404
        adapt(section);
1405
        return section;
1406
    }
1407

    
1408
	/**
1409
	 * <p>
1410
	 * createDateDetailSection
1411
	 * </p>
1412
	 *
1413
	 * @param parentElement
1414
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1415
	 *            object.
1416
	 * @param style
1417
	 *            a int.
1418
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection}
1419
	 *         object.
1420
	 */
1421
	public MinMaxTextSection createMinMaxTextSection(ICdmFormElement parentElement, UnitType unitType, int style) {
1422
		MinMaxTextSection section = new MinMaxTextSection(this, parentElement, unitType, style);
1423
		parentElement.addElement(section);
1424
		adapt(section);
1425
		return section;
1426
	}
1427

    
1428
    /**
1429
     * <p>
1430
     * createPartialElement
1431
     * </p>
1432
     *
1433
     * @param parentElement
1434
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1435
     *            object.
1436
     * @param labelString
1437
     *            a {@link java.lang.String} object.
1438
     * @param partial
1439
     *            a {@link org.joda.time.Partial} object.
1440
     * @param style
1441
     *            a int.
1442
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.PartialElement}
1443
     *         object.
1444
     */
1445
    public PartialElement createPartialElement(ICdmFormElement parentElement, String labelString, Partial partial,
1446
            int style) {
1447
        PartialElement element = new PartialElement(this, parentElement, labelString, style);
1448
        adapt(element);
1449
        parentElement.addElement(element);
1450
        return element;
1451
    }
1452

    
1453
    /**
1454
     * <p>
1455
     * addSelectionListener
1456
     * </p>
1457
     *
1458
     * @param listener
1459
     *            a {@link org.eclipse.swt.events.SelectionListener} object.
1460
     */
1461
    public void addSelectionListener(SelectionListener listener) {
1462
        selectionListenerList.add(listener);
1463
    }
1464

    
1465
    /**
1466
     * <p>
1467
     * removeSelectionListener
1468
     * </p>
1469
     *
1470
     * @param listener
1471
     *            a {@link org.eclipse.swt.events.SelectionListener} object.
1472
     */
1473
    public void removeSelectionListener(SelectionListener listener) {
1474
        if (listener == null) {
1475
            MessagingUtils.error(this.getClass(),
1476
                    "Tried to remove a selection listener from this factories listeners but was null", null);
1477
        } else {
1478
            selectionListenerList.remove(listener);
1479
        }
1480
    }
1481

    
1482
    /**
1483
     * <p>
1484
     * addPropertyChangeListener
1485
     * </p>
1486
     *
1487
     * @param listener
1488
     *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1489
     *            object.
1490
     */
1491
    public void addPropertyChangeListener(IPropertyChangeListener listener) {
1492
        if (propertyChangeListeners.contains(listener)) {
1493
            return;
1494
        }
1495
        propertyChangeListeners.add(0, listener);
1496
    }
1497

    
1498
    /**
1499
     * <p>
1500
     * removePropertyChangeListener
1501
     * </p>
1502
     *
1503
     * @param listener
1504
     *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1505
     *            object.
1506
     */
1507
    public void removePropertyChangeListener(IPropertyChangeListener listener) {
1508
        propertyChangeListeners.remove(listener);
1509
    }
1510

    
1511
    /**
1512
     * @return the propertyChangeListeners
1513
     */
1514
    public List<IPropertyChangeListener> getPropertyChangeListeners() {
1515
        return propertyChangeListeners;
1516
    }
1517

    
1518
    /**
1519
     * <p>
1520
     * createHorizontalSeparator
1521
     * </p>
1522
     *
1523
     * @param parentElement
1524
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1525
     *            object.
1526
     * @param style
1527
     *            a int.
1528
     * @return a {@link org.eclipse.swt.widgets.Label} object.
1529
     */
1530
    public Label createHorizontalSeparator(ICdmFormElement parentElement, int style) {
1531
        Label separator = this.createSeparator(parentElement.getLayoutComposite(), SWT.HORIZONTAL | style);
1532
        separator.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
1533
        return separator;
1534
    }
1535

    
1536
    /**
1537
     * <p>
1538
     * createVersionElement
1539
     * </p>
1540
     *
1541
     * @param parentElement
1542
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1543
     *            object.
1544
     * @param entity
1545
     *            a {@link eu.etaxonomy.cdm.model.common.VersionableEntity}
1546
     *            object.
1547
     * @param style
1548
     *            a int.
1549
     * @return a
1550
     *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionElement}
1551
     *         object.
1552
     */
1553
    public VersionElement createVersionElement(ICdmFormElement parentElement, VersionableEntity entity, int style) {
1554
        VersionElement element = new VersionElement(this, parentElement, entity, style);
1555
        adapt(element);
1556
        parentElement.addElement(element);
1557
        return element;
1558
    }
1559

    
1560
    /**
1561
     * @param cdmBaseSection
1562
     * @param object
1563
     * @param style
1564
     * @return
1565
     */
1566
    public CdmBaseElement createCdmBaseElement(ICdmFormElement parentElement, CdmBase entity, int style) {
1567
        CdmBaseElement element = new CdmBaseElement(this, parentElement, entity, style);
1568
        adapt(element);
1569
        parentElement.addElement(element);
1570
        return element;
1571
    }
1572

    
1573
    /**
1574
     * <p>
1575
     * createVersionSection
1576
     * </p>
1577
     *
1578
     * @param parentElement
1579
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1580
     *            object.
1581
     * @param style
1582
     *            a int.
1583
     * @return a
1584
     *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection}
1585
     *         object.
1586
     */
1587
    public VersionSection createVersionSection(ICdmFormElement parentElement, int style) {
1588
        VersionSection section = new VersionSection(this, parentElement, style);
1589
        parentElement.addElement(section);
1590
        adapt(section);
1591
        return section;
1592
    }
1593

    
1594
    /**
1595
     * @param parent
1596
     * @param i
1597
     * @return
1598
     */
1599
    public CdmBaseSection createCdmBaseSection(ICdmFormElement parentElement, int style) {
1600
        CdmBaseSection section = new CdmBaseSection(this, parentElement, style);
1601
        parentElement.addElement(section);
1602
        adapt(section);
1603
        return section;
1604
    }
1605

    
1606
    /**
1607
     * <p>
1608
     * createEmptyElement
1609
     * </p>
1610
     *
1611
     * @param parentElement
1612
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1613
     *            object.
1614
     * @return a {@link eu.etaxonomy.taxeditor.ui.section.EmptyElement} object.
1615
     */
1616
    public EmptyElement createEmptyElement(ICdmFormElement parentElement, String emptyText) {
1617
        EmptyElement element = new EmptyElement(this, parentElement, emptyText, SWT.NULL);
1618
        adapt(element);
1619
        parentElement.addElement(element);
1620
        return element;
1621
    }
1622

    
1623
    /**
1624
     * <p>
1625
     * createHeadlineSection
1626
     * </p>
1627
     *
1628
     * @param parentElement
1629
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1630
     *            object.
1631
     * @return a
1632
     *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection}
1633
     *         object.
1634
     */
1635
    public HeadlineSection createHeadlineSection(ICdmFormElement parentElement) {
1636
        HeadlineSection section = new HeadlineSection(this, parentElement, SWT.NULL);
1637
        parentElement.addElement(section);
1638
        adapt(section);
1639
        return section;
1640
    }
1641

    
1642
    /**
1643
     * <p>
1644
     * createParsingMessageElement
1645
     * </p>
1646
     *
1647
     * @param parentElement
1648
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1649
     *            object.
1650
     * @param parserProblem
1651
     *            a {@link eu.etaxonomy.cdm.strategy.parser.ParserProblem}
1652
     *            object.
1653
     * @param style
1654
     *            a int.
1655
     * @return a
1656
     *         {@link eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessageElement}
1657
     *         object.
1658
     */
1659
    public ParsingMessageElement createParsingMessageElement(ICdmFormElement parentElement,
1660
            ParserProblem parserProblem, int style) {
1661
        ParsingMessageElement element = new ParsingMessageElement(this, parentElement, parserProblem, style);
1662
        adapt(element);
1663
        parentElement.addElement(element);
1664
        return element;
1665
    }
1666

    
1667
    public DefinedTermDetailSection createDefinedTermDetailSection(Class definedTermClass, ConversationHolder conversation,
1668
            ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
1669

    
1670
        DefinedTermDetailSection section = new DefinedTermDetailSection(this, definedTermClass, conversation, parentElement,
1671
                selectionProvider, style);
1672

    
1673
        parentElement.addElement(section);
1674
        adapt(section);
1675
        return section;
1676

    
1677
    }
1678

    
1679
    public TermMediaSection createTermMediaSection(ConversationHolder conversation,
1680
            ICdmFormElement parentElement, int style) {
1681
        TermMediaSection section = new TermMediaSection(this, conversation, parentElement, style);
1682
        parentElement.addElement(section);
1683
        adapt(section);
1684
        return section;
1685

    
1686
    }
1687

    
1688
    /**
1689
     * @param definedTermClass
1690
     * @param formElement
1691
     * @param style
1692
     * @return
1693
     */
1694
    public AbstractCdmDetailElement createDefinedTermDetailElement(Class definedTermClass,
1695
            AbstractCdmDetailSection parentElement, int style) {
1696
        AbstractCdmDetailElement element = null;
1697

    
1698
        if (NamedArea.class.isAssignableFrom(definedTermClass)) {
1699
            element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
1700
        } else if (definedTermClass.equals(Feature.class)) {
1701
            element = new FeatureDetailElement(this, parentElement);
1702
        } else if(definedTermClass.equals(PresenceAbsenceTerm.class)){
1703
            element = new PresenceAbsenceTermDetailElement(this, parentElement);
1704
        } else {
1705
            element = new DefinedTermDetailElement(this, parentElement);
1706
        }
1707

    
1708

    
1709
        adapt(element);
1710
        parentElement.addElement(element);
1711
        return element;
1712
    }
1713

    
1714
    public CharacterDetailSection createCharacterDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1715
        CharacterDetailSection section = new CharacterDetailSection(this, conversation, parentElement, selectionProvider, style);
1716
        addAndAdaptSection(parentElement, section);
1717
        return section;
1718
    }
1719

    
1720
    public CharacterDetailElement createCharacterDetailElement(ICdmFormElement parentElement, int style){
1721
        CharacterDetailElement element = new CharacterDetailElement(this, parentElement);
1722
        addAndAdaptElement(parentElement, element);
1723
        return element;
1724
    }
1725

    
1726
    public FeatureTreeDetailElement createFeatureTreeDetailElement(ICdmFormElement parentElement, int style){
1727
        FeatureTreeDetailElement element = new FeatureTreeDetailElement(this, parentElement);
1728
        addAndAdaptElement(parentElement, element);
1729
        return element;
1730
    }
1731

    
1732
    public FeatureNodeDetailElement createFeatureNodeDetailElement(ICdmFormElement parentElement, int style){
1733
        FeatureNodeDetailElement element = new FeatureNodeDetailElement(this, parentElement);
1734
        addAndAdaptElement(parentElement, element);
1735
        return element;
1736
    }
1737

    
1738

    
1739
    //--------DetailSections---------
1740
    public NameDetailSection createNameDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1741
        NameDetailSection section = new NameDetailSection(this, conversation, parentElement, selectionProvider, style);
1742
        addAndAdaptSection(parentElement, section);
1743
        return section;
1744
    }
1745

    
1746
    public FeatureNodeDetailSection createFeatureNodeDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1747
        FeatureNodeDetailSection section = new FeatureNodeDetailSection(this, conversation, parentElement, selectionProvider, style);
1748
        addAndAdaptSection(parentElement, section);
1749
        return section;
1750
    }
1751

    
1752
    public FeatureTreeDetailSection createFeatureTreeDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1753
        FeatureTreeDetailSection section = new FeatureTreeDetailSection(this, conversation, parentElement, selectionProvider, style);
1754
        addAndAdaptSection(parentElement, section);
1755
        return section;
1756
    }
1757

    
1758
    public ReferenceDetailSection createReferenceDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1759
        ReferenceDetailSection section = new ReferenceDetailSection(this, conversation, parentElement, selectionProvider, style);
1760
        addAndAdaptSection(parentElement, section);
1761
        return section;
1762
    }
1763

    
1764
    public NomenclaturalReferenceDetailSection createNomenclaturalReferenceDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1765
        NomenclaturalReferenceDetailSection section = new NomenclaturalReferenceDetailSection(this, conversation, parentElement, selectionProvider, style);
1766
        addAndAdaptSection(parentElement, section);
1767
        return section;
1768
    }
1769

    
1770
    public TaxonBaseDetailSection createTaxonBaseDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1771
        TaxonBaseDetailSection section = new TaxonBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
1772
        addAndAdaptSection(parentElement, section);
1773
        return section;
1774
    }
1775

    
1776
    public AuthorshipDetailSection createAuthorshipDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1777
        AuthorshipDetailSection section = new AuthorshipDetailSection(this, conversation, parentElement, selectionProvider, style);
1778
        addAndAdaptSection(parentElement, section);
1779
        return section;
1780
    }
1781

    
1782
    public TeamOrPersonBaseDetailSection createTeamOrPersonBaseDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1783
        TeamOrPersonBaseDetailSection section = new TeamOrPersonBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
1784
        addAndAdaptSection(parentElement, section);
1785
        return section;
1786
    }
1787

    
1788
    public TeamDetailSection createTeamDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
1789
        TeamDetailSection section = new TeamDetailSection(this, conversation, parentElement, null, style);
1790
        addAndAdaptSection(parentElement, section);
1791
        return section;
1792
    }
1793

    
1794
    public PersonDetailSection createPersonDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
1795
        PersonDetailSection section = new PersonDetailSection(this, conversation, parentElement, null, style);
1796
        addAndAdaptSection(parentElement, section);
1797
        return section;
1798
    }
1799

    
1800
    public DescriptionDetailSection createDescriptionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1801
        DescriptionDetailSection section = new DescriptionDetailSection(this, conversation, parentElement, selectionProvider, style);
1802
        addAndAdaptSection(parentElement, section);
1803
        return section;
1804
    }
1805

    
1806
    public DescriptionElementDetailSection createDescriptionElementDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1807
        DescriptionElementDetailSection section = new DescriptionElementDetailSection(this, conversation, parentElement, selectionProvider, style);
1808
        addAndAdaptSection(parentElement, section);
1809
        return section;
1810
    }
1811

    
1812
    public ParsingMessagesSection createParsingMessagesSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1813
        ParsingMessagesSection section = new ParsingMessagesSection(this, conversation, parentElement, selectionProvider, style);
1814
        addAndAdaptSection(parentElement, section);
1815
        return section;
1816
    }
1817

    
1818

    
1819

    
1820
    public NonViralNameDetailSection createNonViralNameDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, boolean nameChoosable, int style){
1821
        NonViralNameDetailSection section = new NonViralNameDetailSection(this, conversation, parentElement, selectionProvider, nameChoosable, style);
1822
        addAndAdaptSection(parentElement, section);
1823
        return section;
1824
    }
1825

    
1826
    public MediaDetailsSection createMediaDetailsSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1827
        MediaDetailsSection section = new MediaDetailsSection(this, conversation, parentElement, selectionProvider, style);
1828
        addAndAdaptSection(parentElement, section);
1829
        return section;
1830
    }
1831

    
1832
    public FieldUnitDetailSection createFieldUnitDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1833
        FieldUnitDetailSection section = new FieldUnitDetailSection(this, conversation, parentElement, selectionProvider, style);
1834
        addAndAdaptSection(parentElement, section);
1835
        return section;
1836
    }
1837

    
1838
    public GatheringEventDetailSection createGatheringEventDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1839
        GatheringEventDetailSection section = new GatheringEventDetailSection(this, conversation, parentElement, selectionProvider, style);
1840
        addAndAdaptSection(parentElement, section);
1841
        return section;
1842
    }
1843

    
1844
    public DerivedUnitBaseDetailSection createDerivedUnitBaseDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1845
        DerivedUnitBaseDetailSection section = new DerivedUnitBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
1846
        addAndAdaptSection(parentElement, section);
1847
        return section;
1848
    }
1849

    
1850
    public DerivedUnitTypeDesignationSection createDerivedUnitTypeDesignationSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1851
        DerivedUnitTypeDesignationSection section = new DerivedUnitTypeDesignationSection(this, conversation, parentElement, style);
1852
        addAndAdaptSection(parentElement, section);
1853
        return section;
1854
    }
1855

    
1856
    public TaxonAssociationDetailSection createTaxonAssociationDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1857
        TaxonAssociationDetailSection section = new TaxonAssociationDetailSection(this, conversation, parentElement, selectionProvider, style);
1858
        addAndAdaptSection(parentElement, section);
1859
        return section;
1860
    }
1861

    
1862
    public OriginalLabelDataSection createOriginalLabelDataSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1863
        OriginalLabelDataSection section = new OriginalLabelDataSection(this, conversation, parentElement, selectionProvider, style);
1864
        addAndAdaptSection(parentElement, section);
1865
        return section;
1866
    }
1867

    
1868
    public NaturalLanguageSection createNaturalLanguageSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1869
        NaturalLanguageSection section = new NaturalLanguageSection(this, conversation, parentElement, selectionProvider, style);
1870
        addAndAdaptSection(parentElement, section);
1871
        return section;
1872
    }
1873

    
1874
    public FeatureDistributionDetailSection createFeatureDistributionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1875
        FeatureDistributionDetailSection section = new FeatureDistributionDetailSection(this, conversation, parentElement, selectionProvider, style);
1876
        addAndAdaptSection(parentElement, section);
1877
        return section;
1878
    }
1879

    
1880
    public ClassificationDetailSection createClassificationDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1881
        ClassificationDetailSection section = new ClassificationDetailSection(this, conversation, parentElement, selectionProvider, style);
1882
        addAndAdaptSection(parentElement, section);
1883
        return section;
1884
    }
1885

    
1886
    public TaxonNodeDetailSection createTaxonNodeDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1887
        TaxonNodeDetailSection section = new TaxonNodeDetailSection(this, conversation, parentElement, selectionProvider, style);
1888
        addAndAdaptSection(parentElement, section);
1889
        return section;
1890
    }
1891

    
1892
    public PolytomousKeyDetailSection createPolytomousKeyDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1893
        PolytomousKeyDetailSection section = new PolytomousKeyDetailSection(this, conversation, parentElement, selectionProvider, style);
1894
        addAndAdaptSection(parentElement, section);
1895
        return section;
1896
    }
1897

    
1898
    public PolytomousKeyNodeDetailSection createPolytomousKeyNodeDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1899
        PolytomousKeyNodeDetailSection section = new PolytomousKeyNodeDetailSection(this, conversation, parentElement, selectionProvider, style);
1900
        addAndAdaptSection(parentElement, section);
1901
        return section;
1902
    }
1903

    
1904
    public InstitutionDetailSection createInstitutionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1905
        InstitutionDetailSection section = new InstitutionDetailSection(this, conversation, parentElement, selectionProvider, style);
1906
        addAndAdaptSection(parentElement, section);
1907
        return section;
1908
    }
1909

    
1910
    public FieldUnitGeneralDetailSection createFieldUnitGeneralDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1911
        FieldUnitGeneralDetailSection section = new FieldUnitGeneralDetailSection(this, conversation, parentElement, selectionProvider, style);
1912
        addAndAdaptSection(parentElement, section);
1913
        return section;
1914
    }
1915

    
1916
    public DerivedUnitGeneralDetailSection createDerivedUnitGeneralDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1917
        DerivedUnitGeneralDetailSection section = new DerivedUnitGeneralDetailSection(this, conversation, parentElement, selectionProvider, style);
1918
        addAndAdaptSection(parentElement, section);
1919
        return section;
1920
    }
1921

    
1922
    public PreservedSpecimenGeneralDetailSection createPreservedSpecimenGeneralDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1923
        PreservedSpecimenGeneralDetailSection section = new PreservedSpecimenGeneralDetailSection(this, conversation, parentElement, selectionProvider, style);
1924
        addAndAdaptSection(parentElement, section);
1925
        return section;
1926
    }
1927

    
1928
    public TissueSampleGeneralDetailSection createTissueSampleGeneralDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1929
        TissueSampleGeneralDetailSection section = new TissueSampleGeneralDetailSection(this, conversation, parentElement, selectionProvider, style);
1930
        addAndAdaptSection(parentElement, section);
1931
        return section;
1932
    }
1933

    
1934
    public DnaSampleGeneralDetailSection createDnaSampleGeneralDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1935
        DnaSampleGeneralDetailSection section = new DnaSampleGeneralDetailSection(this, conversation, parentElement, selectionProvider, style);
1936
        addAndAdaptSection(parentElement, section);
1937
        return section;
1938
    }
1939

    
1940
    public DnaSamplePreparationPreservationSection createDnaSamplePreparationPreservationSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1941
        DnaSamplePreparationPreservationSection section = new DnaSamplePreparationPreservationSection(this, conversation, parentElement, selectionProvider, style);
1942
        addAndAdaptSection(parentElement, section);
1943
        return section;
1944
    }
1945

    
1946
    public DnaQualityDetailSection createDnaQualityDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1947
        DnaQualityDetailSection section = new DnaQualityDetailSection(this, conversation, parentElement, selectionProvider, style);
1948
        addAndAdaptSection(parentElement, section);
1949
        return section;
1950
    }
1951

    
1952
    public SequenceGeneralDetailSection createSequenceGeneralDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1953
        SequenceGeneralDetailSection section = new SequenceGeneralDetailSection(this, conversation, parentElement, selectionProvider, style);
1954
        addAndAdaptSection(parentElement, section);
1955
        return section;
1956
    }
1957

    
1958
    public SequenceContigFileCollectionDetailSection createSequenceContigFileCollectionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
1959
        SequenceContigFileCollectionDetailSection section = new SequenceContigFileCollectionDetailSection(this, conversation, parentElement, style);
1960
        addAndAdaptSection(parentElement, section);
1961
        return section;
1962
    }
1963

    
1964
    public SingleReadPherogramCollectionDetailSection createSingleReadPherogramCollectionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
1965
        SingleReadPherogramCollectionDetailSection section = new SingleReadPherogramCollectionDetailSection(this, conversation, parentElement, style);
1966
        addAndAdaptSection(parentElement, section);
1967
        return section;
1968
    }
1969

    
1970
    public SequenceReferenceCollectionDetailSection createSequenceReferenceCollectionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
1971
        SequenceReferenceCollectionDetailSection section = new SequenceReferenceCollectionDetailSection(this, conversation, parentElement, style);
1972
        addAndAdaptSection(parentElement, section);
1973
        return section;
1974
    }
1975

    
1976
    public SingleReadGeneralDetailSection createSingleReadGeneralDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1977
        SingleReadGeneralDetailSection section = new SingleReadGeneralDetailSection(this, conversation, parentElement, selectionProvider, style);
1978
        addAndAdaptSection(parentElement, section);
1979
        return section;
1980
    }
1981

    
1982
    public AmplificationGeneralDetailSection createAmplificationGeneralDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1983
        AmplificationGeneralDetailSection section = new AmplificationGeneralDetailSection(this, conversation, parentElement, selectionProvider, style);
1984
        addAndAdaptSection(parentElement, section);
1985
        return section;
1986
    }
1987

    
1988
    public AmplificationPrimerDetailSection createAmplificationPrimerDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1989
        AmplificationPrimerDetailSection section = new AmplificationPrimerDetailSection(this, conversation, parentElement, selectionProvider, style);
1990
        addAndAdaptSection(parentElement, section);
1991
        return section;
1992
    }
1993

    
1994
    public AmplificationCloningDetailSection createAmplificationCloningDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1995
        AmplificationCloningDetailSection section = new AmplificationCloningDetailSection(this, conversation, parentElement, selectionProvider, style);
1996
        addAndAdaptSection(parentElement, section);
1997
        return section;
1998
    }
1999

    
2000
    public AmplificationGelPhotoCollectionDetailSection createAmplificationGelPhotoCollectionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2001
        AmplificationGelPhotoCollectionDetailSection section = new AmplificationGelPhotoCollectionDetailSection(this, conversation, parentElement, style);
2002
        addAndAdaptSection(parentElement, section);
2003
        return section;
2004
    }
2005

    
2006
    public MediaSpecimenGeneralDetailSection createMediaSpecimenGeneralDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2007
        MediaSpecimenGeneralDetailSection section = new MediaSpecimenGeneralDetailSection(this, conversation, parentElement, selectionProvider, style);
2008
        addAndAdaptSection(parentElement, section);
2009
        return section;
2010
    }
2011

    
2012
    public HybridDetailSection createHybridDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2013
        HybridDetailSection section = new HybridDetailSection(this, conversation, parentElement, selectionProvider, style);
2014
        addAndAdaptSection(parentElement, section);
2015
        return section;
2016
    }
2017

    
2018
    public UserDetailSection createUserDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2019
        UserDetailSection section = new UserDetailSection(this, conversation, parentElement, selectionProvider, style);
2020
        addAndAdaptSection(parentElement, section);
2021
        return section;
2022
    }
2023

    
2024
    public GroupDetailSection createGroupDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2025
        GroupDetailSection section = new GroupDetailSection(this, conversation, parentElement, selectionProvider, style);
2026
        addAndAdaptSection(parentElement, section);
2027
        return section;
2028
    }
2029

    
2030
    public DeterminationDetailSection createDeterminationDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2031
        DeterminationDetailSection section = new DeterminationDetailSection(this, conversation, parentElement, selectionProvider, style);
2032
        addAndAdaptSection(parentElement, section);
2033
        return section;
2034
    }
2035

    
2036
    public SampleDesignationDetailSection createSampleDesignationDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2037
        SampleDesignationDetailSection section = new SampleDesignationDetailSection(this, conversation, parentElement, selectionProvider, style);
2038
        addAndAdaptSection(parentElement, section);
2039
        return section;
2040
    }
2041

    
2042
    public TaxonRelationshipDetailSection createTaxonRelationshipDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2043
        TaxonRelationshipDetailSection section = new TaxonRelationshipDetailSection(this, conversation, parentElement, selectionProvider, style, true);
2044
        addAndAdaptSection(parentElement, section);
2045
        return section;
2046
    }
2047

    
2048
    public ReferencedEntityDetailSection createReferencedEntityDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2049
        ReferencedEntityDetailSection section = new ReferencedEntityDetailSection(this, conversation, parentElement, selectionProvider, style);
2050
        addAndAdaptSection(parentElement, section);
2051
        return section;
2052
    }
2053

    
2054
    public TermVocabularyDetailSection createTermVocabularyDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2055
        TermVocabularyDetailSection section = new TermVocabularyDetailSection(this, conversation, parentElement, selectionProvider, style);
2056
        addAndAdaptSection(parentElement, section);
2057
        return section;
2058
    }
2059

    
2060
    public GatheringEventDetailSection createGatheringSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2061
        GatheringEventDetailSection section = new GatheringEventDetailSection(this, conversation, parentElement, selectionProvider, style);
2062
        addAndAdaptSection(parentElement, section);
2063
        return section;
2064
    }
2065

    
2066
    public NamedAreaDetailSection createNamedAreaDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2067
        NamedAreaDetailSection section = new NamedAreaDetailSection(this, conversation, parentElement, selectionProvider, style);
2068
        addAndAdaptSection(parentElement, section);
2069
        return section;
2070
    }
2071

    
2072
    public UseRecordDetailSection createUseRecordDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2073
        UseRecordDetailSection section = new UseRecordDetailSection(this, conversation, parentElement, selectionProvider, style);
2074
        addAndAdaptSection(parentElement, section);
2075
        return section;
2076
    }
2077

    
2078
    private void addAndAdaptSection(ICdmFormElement parentElement, AbstractFormSection<?> section) {
2079
        parentElement.addElement(section);
2080
        adapt(section);
2081
    }
2082

    
2083
    //--------DetailElements------------
2084

    
2085
    public UseRecordDetailElement createUseRecordDetailElement(ICdmFormElement parentElement){
2086
        UseRecordDetailElement element = new UseRecordDetailElement(this, parentElement);
2087
        addAndAdaptElement(parentElement, element);
2088
        return element;
2089
    }
2090

    
2091
    public DefinedTermDetailElement<NamedAreaLevel> createNamedAreaLevelElement(ICdmFormElement parentElement){
2092
        DefinedTermDetailElement<NamedAreaLevel> element = new DefinedTermDetailElement<NamedAreaLevel>(this, parentElement);
2093
        addAndAdaptElement(parentElement, element);
2094
        return element;
2095
    }
2096

    
2097
    public eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement createNamedAreaDetailElement(ICdmFormElement parentElement){
2098
        eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
2099
        addAndAdaptElement(parentElement, element);
2100
        return element;
2101
    }
2102

    
2103
    public TermVocabularyDetailElement createTermVocabularyDetailElement(ICdmFormElement parentElement){
2104
        TermVocabularyDetailElement element = new TermVocabularyDetailElement(this, parentElement);
2105
        addAndAdaptElement(parentElement, element);
2106
        return element;
2107
    }
2108

    
2109
    public ReferenceEntityDetailElement createReferenceEntityDetailElement(ICdmFormElement parentElement){
2110
        ReferenceEntityDetailElement element = new ReferenceEntityDetailElement(this, parentElement);
2111
        addAndAdaptElement(parentElement, element);
2112
        return element;
2113
    }
2114

    
2115
    public TaxonRelationshipDetailElement createTaxonRelationshipDetailElement(ICdmFormElement parentElement){
2116
        TaxonRelationshipDetailElement element = new TaxonRelationshipDetailElement(this, parentElement);
2117
        addAndAdaptElement(parentElement, element);
2118
        return element;
2119
    }
2120

    
2121
    public GrantedAuthorityDetailElement createGrantedAuthorityDetailElement(ICdmFormElement parentElement){
2122
        GrantedAuthorityDetailElement element = new GrantedAuthorityDetailElement(this, parentElement);
2123
        addAndAdaptElement(parentElement, element);
2124
        return element;
2125
    }
2126

    
2127
    public GroupDetailElement createGroupDetailElement(ICdmFormElement parentElement){
2128
        GroupDetailElement element = new GroupDetailElement(this, parentElement);
2129
        addAndAdaptElement(parentElement, element);
2130
        return element;
2131
    }
2132

    
2133
    public UserDetailElement createUserDetailElement(ICdmFormElement parentElement){
2134
        UserDetailElement element = new UserDetailElement(this, parentElement);
2135
        addAndAdaptElement(parentElement, element);
2136
        return element;
2137
    }
2138

    
2139
    public HybridDetailElement createHybridDetailElement(ICdmFormElement parentElement){
2140
        HybridDetailElement element = new HybridDetailElement(this, parentElement);
2141
        addAndAdaptElement(parentElement, element);
2142
        return element;
2143
    }
2144

    
2145
    public InstitutionDetailElement createInstitutionDetailElement(ICdmFormElement parentElement){
2146
        InstitutionDetailElement element = new InstitutionDetailElement(this, parentElement);
2147
        addAndAdaptElement(parentElement, element);
2148
        return element;
2149
    }
2150

    
2151
    public PolytomousKeyNodeDetailElement createPolytomousKeyNodeDetailElement(ICdmFormElement parentElement){
2152
        PolytomousKeyNodeDetailElement element = new PolytomousKeyNodeDetailElement(this, parentElement);
2153
        addAndAdaptElement(parentElement, element);
2154
        return element;
2155
    }
2156

    
2157
    public PolytomousKeyDetailElement createPolytomousKeyDetailElement(ICdmFormElement parentElement){
2158
        PolytomousKeyDetailElement element = new PolytomousKeyDetailElement(this, parentElement);
2159
        addAndAdaptElement(parentElement, element);
2160
        return element;
2161
    }
2162

    
2163
    public CollectionDetailElement createCollectionDetailElement(ICdmFormElement parentElement){
2164
        CollectionDetailElement element = new CollectionDetailElement(this, parentElement);
2165
        addAndAdaptElement(parentElement, element);
2166
        return element;
2167
    }
2168

    
2169
    public TaxonNodeAgentRelationCollectionSection createTaxonNodeAgentRelationCollectionElement(ICdmFormElement parentElement, ConversationHolder conversation, int style){
2170
        TaxonNodeAgentRelationCollectionSection element = new TaxonNodeAgentRelationCollectionSection(this, conversation, parentElement, style);
2171
        adapt(element);
2172
        parentElement.addElement(element);
2173

    
2174
        return element;
2175
    }
2176

    
2177
    public TaxonNodeDetailElement createTaxonNodeDetailElement(ICdmFormElement parentElement, boolean createNew){
2178
        TaxonNodeDetailElement element = new TaxonNodeDetailElement(this, parentElement, createNew);
2179
        addAndAdaptElement(parentElement, element);
2180
        return element;
2181
    }
2182

    
2183
    public ClassificationDetailElement createClassificationDetailElement(ICdmFormElement parentElement){
2184
        ClassificationDetailElement element = new ClassificationDetailElement(this, parentElement);
2185
        addAndAdaptElement(parentElement, element);
2186
        return element;
2187
    }
2188

    
2189
    public CloneClassificationDetailElement createCloneClassificationDetailElement(ICdmFormElement parentElement){
2190
        CloneClassificationDetailElement element = new CloneClassificationDetailElement(this, parentElement);
2191
        addAndAdaptElement(parentElement, element);
2192
        return element;
2193
    }
2194

    
2195
    public FeatureDistributionDetailElement createFeatureDistributionDetailElement(ICdmFormElement parentElement){
2196
        FeatureDistributionDetailElement element = new FeatureDistributionDetailElement(this, parentElement);
2197
        addAndAdaptElement(parentElement, element);
2198
        return element;
2199
    }
2200

    
2201
    public NaturalLanguageDetailElement createNaturalLanguageDetailElement(ICdmFormElement parentElement){
2202
        NaturalLanguageDetailElement element = new NaturalLanguageDetailElement(this, parentElement);
2203
        addAndAdaptElement(parentElement, element);
2204
        return element;
2205
    }
2206

    
2207
    public NonViralNameDetailElement createNonViralNameDetailElement(ICdmFormElement parentElement){
2208
        NonViralNameDetailElement element = new NonViralNameDetailElement(this, parentElement);
2209
        addAndAdaptElement(parentElement, element);
2210
        return element;
2211
    }
2212

    
2213
    public DescriptionElementDetailElement createDescriptionElementDetailElement(ICdmFormElement parentElement, int style){
2214
        DescriptionElementDetailElement element = new DescriptionElementDetailElement(this, parentElement, style);
2215
        addAndAdaptElement(parentElement, element);
2216
        return element;
2217
    }
2218

    
2219
    public DescriptionDetailElement createDescriptionDetailElement(ICdmFormElement parentElement, int style){
2220
        DescriptionDetailElement element = new DescriptionDetailElement(this, parentElement, style);
2221
        addAndAdaptElement(parentElement, element);
2222
        return element;
2223
    }
2224

    
2225
    public PersonDetailElement createPersonDetailElement(ICdmFormElement parentElement, int style){
2226
        PersonDetailElement element = new PersonDetailElement(this, parentElement, style);
2227
        addAndAdaptElement(parentElement, element);
2228
        return element;
2229
    }
2230

    
2231
    public TeamDetailElement createTeamDetailElement(ICdmFormElement parentElement, int style, boolean isNomenclatural){
2232
        TeamDetailElement element = new TeamDetailElement(this, parentElement, style, isNomenclatural);
2233
        addAndAdaptElement(parentElement, element);
2234
        return element;
2235
    }
2236

    
2237
    public AuthorshipDetailElement createAuthorshipDetailElement(ICdmFormElement parentElement, int style){
2238
        AuthorshipDetailElement element = new AuthorshipDetailElement(this, parentElement, style);
2239
        addAndAdaptElement(parentElement, element);
2240
        return element;
2241
    }
2242

    
2243
    public TaxonBaseDetailElement createTaxonBaseDetailElement(ICdmFormElement parentElement, int style){
2244
        TaxonBaseDetailElement element = new TaxonBaseDetailElement(this, parentElement, style);
2245
        addAndAdaptElement(parentElement, element);
2246
        return element;
2247
    }
2248

    
2249
    public NameDetailElement createNameDetailElement(ICdmFormElement parentElement, int style){
2250
        NameDetailElement element = new NameDetailElement(this, parentElement, style);
2251
        addAndAdaptElement(parentElement, element);
2252
        return element;
2253
    }
2254

    
2255
    public ReferenceDetailElement createReferenceDetailElement(ICdmFormElement parentElement, int style, boolean isWizard){
2256
        ReferenceDetailElement element = new ReferenceDetailElement(this, parentElement, style, isWizard);
2257
        addAndAdaptElement(parentElement, element);
2258
        return element;
2259
    }
2260

    
2261
    public NomenclaturalReferenceDetailElement createNomenclaturalReferenceDetailElement(ICdmFormElement parentElement, int style){
2262
        NomenclaturalReferenceDetailElement element = new NomenclaturalReferenceDetailElement(this, parentElement, style);
2263
        addAndAdaptElement(parentElement, element);
2264
        return element;
2265
    }
2266

    
2267

    
2268
    public FieldUnitGeneralDetailElement createFieldUnitGeneralDetailElement(ICdmFormElement parentElement){
2269
        FieldUnitGeneralDetailElement element = new FieldUnitGeneralDetailElement(this, parentElement);
2270
        addAndAdaptElement(parentElement, element);
2271
        return element;
2272
    }
2273

    
2274
    public DerivedUnitGeneralDetailElement createDerivedUnitGeneralDetailElement(ICdmFormElement parentElement){
2275
        DerivedUnitGeneralDetailElement element = new DerivedUnitGeneralDetailElement(this, parentElement);
2276
        addAndAdaptElement(parentElement, element);
2277
        return element;
2278
    }
2279

    
2280
    public TaxonAssociationDetailElement createTaxonAssociationDetailElement(ICdmFormElement parentElement){
2281
        TaxonAssociationDetailElement element = new TaxonAssociationDetailElement(this, parentElement);
2282
        addAndAdaptElement(parentElement, element);
2283
        return element;
2284
    }
2285

    
2286
    public PreservedSpecimenGeneralDetailElement createPreservedSpecimenGeneralDetailElement(ICdmFormElement parentElement){
2287
        PreservedSpecimenGeneralDetailElement element = new PreservedSpecimenGeneralDetailElement(this, parentElement);
2288
        addAndAdaptElement(parentElement, element);
2289
        return element;
2290
    }
2291

    
2292
    public TissueSampleGeneralDetailElement createTissueSampleGeneralDetailElement(ICdmFormElement parentElement){
2293
        TissueSampleGeneralDetailElement element = new TissueSampleGeneralDetailElement(this, parentElement);
2294
        addAndAdaptElement(parentElement, element);
2295
        return element;
2296
    }
2297

    
2298
    public DnaSampleGeneralDetailElement createDnaSampleGeneralDetailElement(ICdmFormElement parentElement){
2299
        DnaSampleGeneralDetailElement element = new DnaSampleGeneralDetailElement(this, parentElement);
2300
        addAndAdaptElement(parentElement, element);
2301
        return element;
2302
    }
2303

    
2304
    public DnaSamplePreparationPreservationDetailElement createDnaSamplePreparationPreservationDetailElement(ICdmFormElement parentElement){
2305
        DnaSamplePreparationPreservationDetailElement element = new DnaSamplePreparationPreservationDetailElement(this, parentElement);
2306
        addAndAdaptElement(parentElement, element);
2307
        return element;
2308
    }
2309

    
2310
    public DnaQualityDetailElement createDnaQualityDetailElement(ICdmFormElement parentElement){
2311
        DnaQualityDetailElement element = new DnaQualityDetailElement(this, parentElement);
2312
        addAndAdaptElement(parentElement, element);
2313
        return element;
2314
    }
2315

    
2316
    public SequenceGeneralDetailElement createSequenceGeneralDetailElement(ICdmFormElement parentElement){
2317
        SequenceGeneralDetailElement element = new SequenceGeneralDetailElement(this, parentElement);
2318
        addAndAdaptElement(parentElement, element);
2319
        return element;
2320
    }
2321

    
2322
    public SingleReadGeneralDetailElement createSingleReadGeneralDetailElement(ICdmFormElement parentElement){
2323
        SingleReadGeneralDetailElement element = new SingleReadGeneralDetailElement(this, parentElement);
2324
        addAndAdaptElement(parentElement, element);
2325
        return element;
2326
    }
2327

    
2328
    public PrimerGeneralDetailElement createPrimerGeneralDetailElement(ICdmFormElement parentElement){
2329
        PrimerGeneralDetailElement element = new PrimerGeneralDetailElement(this, parentElement);
2330
        addAndAdaptElement(parentElement, element);
2331
        return element;
2332
    }
2333

    
2334
    public AmplificationGeneralDetailElement createAmplificationGeneralDetailElement(ICdmFormElement parentElement){
2335
        AmplificationGeneralDetailElement element = new AmplificationGeneralDetailElement(this, parentElement);
2336
        addAndAdaptElement(parentElement, element);
2337
        return element;
2338
    }
2339

    
2340
    public AmplificationPrimerDetailElement createAmplificationPrimerDetailElement(ICdmFormElement parentElement){
2341
        AmplificationPrimerDetailElement element = new AmplificationPrimerDetailElement(this, parentElement);
2342
        addAndAdaptElement(parentElement, element);
2343
        return element;
2344
    }
2345

    
2346
    public AmplificationCloningDetailElement createAmplificationCloningDetailElement(ICdmFormElement parentElement){
2347
        AmplificationCloningDetailElement element = new AmplificationCloningDetailElement(this, parentElement);
2348
        addAndAdaptElement(parentElement, element);
2349
        return element;
2350
    }
2351

    
2352
    public AmplificationGelPhotoDetailElement createAmplificationGelPhotoDetailElement(ICdmFormElement parentElement){
2353
        AmplificationGelPhotoDetailElement element = new AmplificationGelPhotoDetailElement(this, parentElement);
2354
        addAndAdaptElement(parentElement, element);
2355
        return element;
2356
    }
2357

    
2358
    public MediaSpecimenGeneralDetailElement createMediaSpecimenGeneralDetailElement(ICdmFormElement parentElement){
2359
        MediaSpecimenGeneralDetailElement element = new MediaSpecimenGeneralDetailElement(this, parentElement);
2360
        addAndAdaptElement(parentElement, element);
2361
        return element;
2362
    }
2363

    
2364
    public MediaDetailElement createMediaDetailElement(ICdmFormElement parentElement){
2365
        MediaDetailElement mediaDetailElement = new MediaDetailElement(this, parentElement);
2366
        addAndAdaptElement(parentElement, mediaDetailElement);
2367
        return mediaDetailElement;
2368
    }
2369

    
2370
    public GatheringEventDetailElement createGatheringEventDetailElement(ICdmFormElement parentElement) {
2371
        GatheringEventDetailElement element = new GatheringEventDetailElement(this, parentElement);
2372
        addAndAdaptElement(parentElement, element);
2373
        return element;
2374
    }
2375

    
2376
    public FieldUnitDetailElement createFieldUnitDetailElement(ICdmFormElement parentElement) {
2377
        FieldUnitDetailElement element = new FieldUnitDetailElement(this, parentElement);
2378
        addAndAdaptElement(parentElement, element);
2379
        return element;
2380
    }
2381

    
2382
    public DerivedUnitBaseDetailElement createDerivedUnitBaseDetailElement(ICdmFormElement parentElement) {
2383
        DerivedUnitBaseDetailElement element = new DerivedUnitBaseDetailElement(this, parentElement);
2384
        addAndAdaptElement(parentElement, element);
2385
        return element;
2386
    }
2387

    
2388
    public OriginalLabelDataElement createOriginalLabelDataElement(ICdmFormElement parentElement) {
2389
        OriginalLabelDataElement element = new OriginalLabelDataElement(this, parentElement);
2390
        addAndAdaptElement(parentElement, element);
2391
        return element;
2392
    }
2393

    
2394
    public PreservedSpecimenDetailElement createPreservedSpecimenDetailElement(ICdmFormElement parentElement) {
2395
        PreservedSpecimenDetailElement element = new PreservedSpecimenDetailElement(this, parentElement);
2396
        addAndAdaptElement(parentElement, element);
2397
        return element;
2398
    }
2399

    
2400
    public DeterminationDetailElement createDeterminationDetailElement(ICdmFormElement parentElement) {
2401
        DeterminationDetailElement element = new DeterminationDetailElement(this, parentElement);
2402
        addAndAdaptElement(parentElement, element);
2403
        return element;
2404
    }
2405

    
2406
    public SampleDesignationDetailElement createSampleDesignationDetailElement(ICdmFormElement parentElement) {
2407
        SampleDesignationDetailElement element = new SampleDesignationDetailElement(this, parentElement);
2408
        addAndAdaptElement(parentElement, element);
2409
        return element;
2410
    }
2411

    
2412
    /**
2413
     * @param parentElement
2414
     * @param element
2415
     */
2416
    private void addAndAdaptElement(ICdmFormElement parentElement, AbstractCdmDetailElement<?> element) {
2417
        adapt(element);
2418
        parentElement.addElement(element);
2419
    }
2420

    
2421
    //--------EntityCollectionSection----------
2422
    public TeamMemberSection createTeamMemberSection(ConversationHolder conversation, ICdmFormElement parentElement, int style, boolean isNomenclatural){
2423
        TeamMemberSection section = new TeamMemberSection(this, conversation, parentElement, style, isNomenclatural);
2424
        addAndAdaptSection(parentElement, section);
2425
        return section;
2426
    }
2427

    
2428
    public InapplicableIfEntityCollectionSection createInapplicableIfEntityCollectionSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2429
        InapplicableIfEntityCollectionSection section = new InapplicableIfEntityCollectionSection(this, conversation, parentElement, style);
2430
        addAndAdaptSection(parentElement, section);
2431
        return section;
2432
    }
2433

    
2434
    public OnlyApplicableIfEntityCollectionSection createOnlyApplicableIfEntityCollectionSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2435
        OnlyApplicableIfEntityCollectionSection section = new OnlyApplicableIfEntityCollectionSection(this, conversation, parentElement, style);
2436
        addAndAdaptSection(parentElement, section);
2437
        return section;
2438
    }
2439

    
2440
    public AnnotationSection createAnnotationSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2441
        AnnotationSection section = new AnnotationSection(this, conversation, parentElement, style);
2442
        addAndAdaptSection(parentElement, section);
2443
        return section;
2444
    }
2445

    
2446
    public CreditSection createCreditSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2447
        CreditSection section = new CreditSection(this, conversation, parentElement, style);
2448
        addAndAdaptSection(parentElement, section);
2449
        return section;
2450
    }
2451

    
2452
    public DescriptionElementSourceSection createDescriptionElementSourceSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2453
        DescriptionElementSourceSection section = new DescriptionElementSourceSection(this, conversation, parentElement, style);
2454
        addAndAdaptSection(parentElement, section);
2455
        return section;
2456
    }
2457

    
2458
    public ExtensionSection createExtensionSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2459
        ExtensionSection section = new ExtensionSection(this, conversation, parentElement, style);
2460
        addAndAdaptSection(parentElement, section);
2461
        return section;
2462
    }
2463

    
2464
    public MarkerSection createMarkerSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2465
        MarkerSection section = new MarkerSection(this, conversation, parentElement, style);
2466
        addAndAdaptSection(parentElement, section);
2467
        return section;
2468
    }
2469

    
2470
    public MediaSection createMediaSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2471
        MediaSection section = new MediaSection(this, conversation, parentElement, style);
2472
        addAndAdaptSection(parentElement, section);
2473
        return section;
2474
    }
2475

    
2476
    public DescriptionElementMediaSection createDescriptionElementMediaSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2477
        DescriptionElementMediaSection section = new DescriptionElementMediaSection(this, conversation, parentElement, style);
2478
        addAndAdaptSection(parentElement, section);
2479
        return section;
2480
    }
2481

    
2482
    public MediaRepresentationSection createMediaRepresentationSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2483
        MediaRepresentationSection section = new MediaRepresentationSection(this, conversation, parentElement, style);
2484
        addAndAdaptSection(parentElement, section);
2485
        return section;
2486
    }
2487

    
2488
    public MediaRepresentationPartSection createMediaRepresentationPartSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2489
        MediaRepresentationPartSection section = new MediaRepresentationPartSection(this, conversation, parentElement, style);
2490
        addAndAdaptSection(parentElement, section);
2491
        return section;
2492
    }
2493

    
2494
    public ModifierSection createModifierSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2495
        ModifierSection section = new ModifierSection(this, conversation, parentElement, style);
2496
        addAndAdaptSection(parentElement, section);
2497
        return section;
2498
    }
2499

    
2500
    public NomenclaturalStatusSection createNomenclaturalStatusSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2501
        NomenclaturalStatusSection section = new NomenclaturalStatusSection(this, conversation, parentElement, style);
2502
        addAndAdaptSection(parentElement, section);
2503
        return section;
2504
    }
2505

    
2506
    public NameRelationshipDetailSection createNameRelationshipDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2507
        NameRelationshipDetailSection section = new NameRelationshipDetailSection(this, conversation, parentElement, style);
2508
        addAndAdaptSection(parentElement, section);
2509
        return section;
2510
    }
2511

    
2512
    public ProtologueSection createProtologueSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2513
        ProtologueSection section = new ProtologueSection(this, conversation, parentElement, style);
2514
        addAndAdaptSection(parentElement, section);
2515
        return section;
2516
    }
2517
    public ExternalLinksSection createExternalLinksSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2518
        ExternalLinksSection section = new ExternalLinksSection(this, conversation, parentElement, style);
2519
        addAndAdaptSection(parentElement, section);
2520
        return section;
2521
    }
2522

    
2523
    public RightsSection createRightsSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2524
        RightsSection section = new RightsSection(this, conversation, parentElement, style);
2525
        addAndAdaptSection(parentElement, section);
2526
        return section;
2527
    }
2528

    
2529
    public SourceSection createSourceSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2530
        SourceSection section = new SourceSection(this, conversation, parentElement, style);
2531
        addAndAdaptSection(parentElement, section);
2532
        return section;
2533
    }
2534

    
2535
    public ScopeSection createScopeSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2536
        ScopeSection section = new ScopeSection(this, conversation, parentElement, style);
2537
        addAndAdaptSection(parentElement, section);
2538
        return section;
2539
    }
2540

    
2541
    public DescriptionSourceSection createDescriptionSourceSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2542
        DescriptionSourceSection section = new DescriptionSourceSection(this, conversation, parentElement, style);
2543
        addAndAdaptSection(parentElement, section);
2544
        return section;
2545
    }
2546

    
2547
    public TypeDesignationSection createTypeDesignationSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2548
        TypeDesignationSection section = new TypeDesignationSection(this, conversation, parentElement, style);
2549
        addAndAdaptSection(parentElement, section);
2550
        return section;
2551
    }
2552

    
2553
    public StateDataSection createStateDataSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2554
        StateDataSection section = new StateDataSection(this, conversation, parentElement, style);
2555
        addAndAdaptSection(parentElement, section);
2556
        return section;
2557
    }
2558

    
2559
    public StatisticalMeasurementValueSection createStatisticalMeasurementValueSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2560
        StatisticalMeasurementValueSection section = new StatisticalMeasurementValueSection(this, conversation, parentElement, style);
2561
        addAndAdaptSection(parentElement, section);
2562
        return section;
2563
    }
2564

    
2565
    public DescribedSpecimenSection createDescribedSpecimenSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2566
        DescribedSpecimenSection section = new DescribedSpecimenSection(this, conversation, parentElement, style);
2567
        addAndAdaptSection(parentElement, section);
2568
        return section;
2569
    }
2570

    
2571
    public StateVocabularyCollectionSection createStateVocabulariesSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2572
        StateVocabularyCollectionSection section = new StateVocabularyCollectionSection(this, conversation, parentElement, style);
2573
        addAndAdaptSection(parentElement, section);
2574
        return section;
2575
    }
2576

    
2577
    public RecommendedModifierVocabulariesCollectionSection createRecommendedModifierVocabulariesCollectionSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2578
        RecommendedModifierVocabulariesCollectionSection section = new RecommendedModifierVocabulariesCollectionSection(this, conversation, parentElement, style);
2579
        addAndAdaptSection(parentElement, section);
2580
        return section;
2581
    }
2582

    
2583
    public MeasurementUnitCollectionSection createMeasurementUnitCollectionSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2584
        MeasurementUnitCollectionSection section = new MeasurementUnitCollectionSection(this, conversation, parentElement, style);
2585
        addAndAdaptSection(parentElement, section);
2586
        return section;
2587
    }
2588

    
2589
    public StatisticalMeasureCollectionSection createStatisticalMeasureCollectionSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2590
        StatisticalMeasureCollectionSection section = new StatisticalMeasureCollectionSection(this, conversation, parentElement, style);
2591
        addAndAdaptSection(parentElement, section);
2592
        return section;
2593
    }
2594

    
2595
    public CollectingAreasDetailSection createCollectingAreasDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2596
        CollectingAreasDetailSection section = new CollectingAreasDetailSection(this, conversation, parentElement, style);
2597
        addAndAdaptSection(parentElement, section);
2598
        return section;
2599
    }
2600

    
2601
    public GeoScopeDetailSection createGeoScopeDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2602
        GeoScopeDetailSection section = new GeoScopeDetailSection(this, conversation, parentElement, style);
2603
        addAndAdaptSection(parentElement, section);
2604
        return section;
2605
    }
2606

    
2607
    public GeoScopePolyKeyDetailSection createGeoScopePolyKeyDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2608
        GeoScopePolyKeyDetailSection section = new GeoScopePolyKeyDetailSection(this, conversation, parentElement, style);
2609
        addAndAdaptSection(parentElement, section);
2610
        return section;
2611
    }
2612

    
2613
    public IdentifierSection createIdentifierDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2614
        IdentifierSection section = new IdentifierSection(this, conversation, parentElement, style);
2615
        addAndAdaptSection(parentElement, section);
2616
        return section;
2617
    }
2618

    
2619
    public DerivedUnitFacadeIdentifierSection createDerivedUnitFacadeIdentifierSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2620
    	DerivedUnitFacadeIdentifierSection section = new DerivedUnitFacadeIdentifierSection(this, conversation, parentElement, style);
2621
    	addAndAdaptSection(parentElement, section);
2622
    	return section;
2623
    }
2624

    
2625
    public CurrentSampleDesignationDetailSection createCurrentSampleDesignationDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2626
        CurrentSampleDesignationDetailSection section = new CurrentSampleDesignationDetailSection(this, conversation, parentElement, style);
2627
        addAndAdaptSection(parentElement, section);
2628
        return section;
2629
    }
2630

    
2631
    public CurrentDeterminationDetailSection createCurrentDeterminationDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2632
        CurrentDeterminationDetailSection section = new CurrentDeterminationDetailSection(this, conversation, parentElement, style);
2633
        addAndAdaptSection(parentElement, section);
2634
        return section;
2635
    }
2636

    
2637
    public PreservedSpecimenCurrentDeterminationDetailSection createPreservedSpecimenCurrentDeterminationDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2638
        PreservedSpecimenCurrentDeterminationDetailSection section = new PreservedSpecimenCurrentDeterminationDetailSection(this, conversation, parentElement, style);
2639
        addAndAdaptSection(parentElement, section);
2640
        return section;
2641
    }
2642

    
2643
    public SampleDesignationHistoryDetailSection createSampleDesignationHistoryDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2644
        SampleDesignationHistoryDetailSection section = new SampleDesignationHistoryDetailSection(this, conversation, parentElement, style);
2645
        addAndAdaptSection(parentElement, section);
2646
        return section;
2647
    }
2648

    
2649
    public DeterminationHistoryDetailSection createDeterminationHistoryDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2650
        DeterminationHistoryDetailSection section = new DeterminationHistoryDetailSection(this, conversation, parentElement, style);
2651
        addAndAdaptSection(parentElement, section);
2652
        return section;
2653
    }
2654

    
2655
    public SpecimenCollectionDetailSection createSpecimenCollectionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2656
        SpecimenCollectionDetailSection section = new SpecimenCollectionDetailSection(this, conversation, parentElement, style);
2657
        addAndAdaptSection(parentElement, section);
2658
        return section;
2659
    }
2660

    
2661
    public PreservedSpecimenSourceCollectionDetailSection createPreservedSpecimenSourceCollectionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2662
        PreservedSpecimenSourceCollectionDetailSection section = new PreservedSpecimenSourceCollectionDetailSection(this, conversation, parentElement, style);
2663
        addAndAdaptSection(parentElement, section);
2664
        return section;
2665
    }
2666

    
2667
    public SourceCollectionDetailSection createSourceCollectionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2668
        SourceCollectionDetailSection section = new SourceCollectionDetailSection(this, conversation, parentElement, style);
2669
        addAndAdaptSection(parentElement, section);
2670
        return section;
2671
    }
2672

    
2673
    public ScopeRestrictionSection createScopeRestrictionSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2674
        ScopeRestrictionSection section = new ScopeRestrictionSection(this, conversation, parentElement, style);
2675
        addAndAdaptSection(parentElement, section);
2676
        return section;
2677
    }
2678

    
2679
    public MemberDetailSection createMemberDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2680
        MemberDetailSection section = new MemberDetailSection(this, conversation, parentElement, style);
2681
        addAndAdaptSection(parentElement, section);
2682
        return section;
2683
    }
2684

    
2685
    public GrantedAuthorityDetailSection createGrantedAuthorityDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2686
        GrantedAuthorityDetailSection section = new GrantedAuthorityDetailSection(this, conversation, parentElement, style);
2687
        addAndAdaptSection(parentElement, section);
2688
        return section;
2689
    }
2690

    
2691
    public GroupsByUserDetailSection createGroupsByUserDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2692
        GroupsByUserDetailSection section = new GroupsByUserDetailSection(this, conversation, parentElement, style);
2693
        addAndAdaptSection(parentElement, section);
2694
        return section;
2695
    }
2696

    
2697
    public TaxonomicScopeSection createTaxonomicScopeSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2698
        TaxonomicScopeSection section = new TaxonomicScopeSection(this, conversation, parentElement, style);
2699
        addAndAdaptSection(parentElement, section);
2700
        return section;
2701
    }
2702

    
2703

    
2704
    public AbstractEntityCollectionElement createEntityCollectionElement(AbstractFormSection parentElement,
2705
            Object versionableEntity, SelectionListener removeListener, Color backgroundColor, int style) {
2706
        AbstractEntityCollectionElement<?> element = null;
2707

    
2708
        Object entity = HibernateProxyHelper.deproxy(versionableEntity);
2709

    
2710
        if (entity instanceof Annotation) {
2711
            element = new AnnotationElement(this, parentElement, (Annotation) entity, removeListener, style);
2712
        }else if (entity instanceof Person ) {
2713
            boolean isNomenclatural = false;
2714
            if (parentElement instanceof TeamMemberSection){
2715
                isNomenclatural = ((TeamMemberSection) parentElement).isNomenclaturalTeam();
2716
            }
2717
            element = new TeamMemberElement(this, parentElement, (Person) entity, removeListener, style, isNomenclatural);
2718
        } else if (entity instanceof Credit) {
2719
            element = new CreditElement(this, parentElement, (Credit) entity, removeListener, style);
2720
        } else if (entity instanceof Extension) {
2721
            element = new ExtensionElement(this, parentElement, (Extension) entity, removeListener, style);
2722
        } else if (entity instanceof ExternalLink) {
2723
            element = new ExternalLinksElement(this, parentElement, (ExternalLink) entity, removeListener, style);
2724
        } else if (entity instanceof Marker) {
2725
            element = new MarkerElement(this, parentElement, (Marker) entity, removeListener, style);
2726
        } else if (entity instanceof TaxonNodeAgentRelation) {
2727
            element = new TaxonNodeAgentRelationCollectionElement(this, parentElement, (TaxonNodeAgentRelation) entity, removeListener, backgroundColor, style);
2728
        }else if (entity instanceof Media) {
2729
            element = new MediaMetaElement(this, parentElement, (Media) entity, removeListener, style);
2730
        } else if (entity instanceof MediaRepresentation) {
2731
            element = new MediaRepresentationElement(this, parentElement, (MediaRepresentation) entity, removeListener,
2732
                    style);
2733
        } else if (entity instanceof ImageFile) {
2734
            element = new ImageFileElement(this, parentElement, (ImageFile) entity, removeListener, style);
2735
        } else if (entity instanceof MediaRepresentationPart) {
2736
            element = new MediaRepresentationPartElement<>(this, parentElement, (MediaRepresentationPart) entity,
2737
                    removeListener, style);
2738
        } else if (entity instanceof NomenclaturalStatus) {
2739
            element = new NomenclaturalStatusElement(this, parentElement, (NomenclaturalStatus) entity, removeListener,
2740
                    style);
2741
        } else if (entity instanceof Rights) {
2742
            element = new RightsElement(this, parentElement, (Rights) entity, removeListener, style);
2743
        } else if (entity instanceof DescriptionElementSource && parentElement.getEntity() instanceof CommonTaxonName) {
2744
            element = new CommonNameSourceElement(this, parentElement, (DescriptionElementSource) entity,
2745
                    removeListener, style);
2746
        } else if (entity instanceof DescriptionElementSource) {
2747
            element = new DescriptionElementSourceElement(this, parentElement, (DescriptionElementSource) entity,
2748
                    removeListener, style, false);
2749
        } else if (entity instanceof TaxonNodeAgentRelation) {
2750
            element = new TaxonNodeAgentRelationCollectionElement(this, parentElement, (TaxonNodeAgentRelation) entity,
2751
                    removeListener,backgroundColor, style);
2752
        }
2753
        else if (entity instanceof IdentifiableSource) {
2754
            element = new IdentifiableSourceElement(this, parentElement, (IdentifiableSource) entity, removeListener,
2755
                    style);
2756
        } else if (entity instanceof DefinedTerm) {
2757
            switch(((DefinedTerm)entity).getTermType()) {
2758
            case Scope:
2759
                element = new ScopeElement(this,
2760
                        parentElement,
2761
                        (DefinedTerm) entity,
2762
                        removeListener,
2763
                        style);
2764
                break;
2765
            case Modifier:
2766
                element = new ModifierElement(this,
2767
                        parentElement,
2768
                        (DefinedTerm) entity,
2769
                        removeListener,
2770
                        style);
2771
                break;
2772
            default:
2773
                break;
2774

    
2775
            }
2776
        } else if (entity instanceof Reference) {
2777
            if(parentElement instanceof SequenceReferenceCollectionDetailSection){
2778
                element = new SequenceReferenceCollectionDetailElement(this, parentElement, (Reference) entity, removeListener, style);
2779
            }
2780
            else{
2781
                element = new DescriptionSourceElement(this, parentElement, (Reference) entity, removeListener, style);
2782
            }
2783
        } else if (entity instanceof NameTypeDesignation) {
2784
            element = new NameTypeDesignationElement(this, parentElement, (NameTypeDesignation) entity, removeListener,
2785
                    style);
2786
        } else if (entity instanceof NameRelationship) {
2787
            element = new NameRelationshipDetailElement(this, parentElement, (NameRelationship) entity, removeListener,
2788
                    style);
2789
        } else if (entity instanceof SpecimenTypeDesignation) {
2790
            if(parentElement instanceof DerivedUnitTypeDesignationSection){
2791
                element = new DerivedUnitTypeDesignationElement(this, parentElement, (SpecimenTypeDesignation) entity,
2792
                        removeListener, style);
2793
            }
2794
            else{
2795
                element = new SpecimenTypeDesignationElement(this, parentElement, (SpecimenTypeDesignation) entity,
2796
                        removeListener, style);
2797
            }
2798
        } else if (entity instanceof StateData) {
2799
            element = new StateDataElement(this, parentElement, (StateData) entity, removeListener, style);
2800
        } else if (entity instanceof StatisticalMeasurementValue) {
2801
            element = new StatisticalMeasurementValueElement(this, parentElement, (StatisticalMeasurementValue) entity,
2802
                    removeListener, style);
2803
        } else if (entity instanceof DerivedUnit) {
2804
            switch(((DerivedUnit)entity).getRecordBasis()) {
2805
            case LivingSpecimen:
2806
            case PreservedSpecimen:
2807
            case OtherSpecimen:
2808
                element = new SpecimenCollectionDetailElement(this,
2809
                        parentElement,
2810
                        (DerivedUnit) entity,
2811
                        removeListener,
2812
                        style);
2813
                break;
2814
            default:
2815
                element = new DerivedUnitElement(this,
2816
                        parentElement,
2817
                        (DerivedUnit) entity,
2818
                        removeListener,
2819
                        style);
2820
            }
2821

    
2822
        } else if (entity instanceof NamedArea) {
2823
            element = new CollectingAreaDetailElement(this, parentElement, (NamedArea) entity, removeListener, style);
2824
        } else if (entity instanceof DeterminationEvent) {
2825
            element = new DeterminationEventDetailElement(this, parentElement, (DeterminationEvent) entity, removeListener, style);
2826
        } else if (entity instanceof User) {
2827
            element = new MemberDetailElement(this, parentElement, (User) entity, removeListener, style);
2828
        } else if (entity instanceof GrantedAuthority) {
2829
            element = new GrantedAuthorityCollectionElement(this, parentElement, (GrantedAuthorityImpl) entity, ((Group)parentElement.getEntity()),
2830
                    removeListener, style);
2831
        } else if (entity instanceof Group) {
2832
            element = new GroupsByUserDetailElement(this, parentElement, (Group) entity, removeListener, style);
2833
        } else if (entity instanceof Taxon) {
2834
            element = new TaxonDetailElement(this, parentElement, (Taxon) entity, removeListener, style);
2835
        } else if (entity instanceof DescriptionElementBase) {
2836
            // this is the special case for protologs, maybe we can do this
2837
            // differently when API improves
2838
            DescriptionElementBase descriptionElement = (DescriptionElementBase) entity;
2839
            if (descriptionElement.getFeature().equals(Feature.PROTOLOGUE())) {
2840
                element = new ProtologueElement(this, parentElement, descriptionElement, removeListener, style);
2841
            }
2842
        } else if (entity instanceof Identifier) {
2843
            if(parentElement instanceof AbstractSampleDesignationDetailSection){
2844
                element = new SampleDesignationTextDetailElement(this, parentElement, (Identifier<DnaSample>) entity, removeListener, backgroundColor, style);
2845
            }
2846
            else{
2847
                element = new IdentifierElement(this, parentElement, (Identifier) entity, removeListener, style);
2848
            }
2849
        } else if (entity instanceof TermVocabulary) {
2850
            TermVocabulary<?> termVocabulary = (TermVocabulary<?>)entity;
2851
            switch (termVocabulary.getTermType()) {
2852
            case State:
2853
                element = new StateVocabularyCollectionElement(this, parentElement, (TermVocabulary<State>) entity, removeListener, backgroundColor, style);
2854
                break;
2855
            case Modifier:
2856
                element = new RecommendedModifierVocabulariesElement(this, parentElement, (TermVocabulary<DefinedTerm>) entity, removeListener, backgroundColor, style);
2857
                break;
2858
            default:
2859
                break;
2860
            }
2861
        } else if (entity instanceof MeasurementUnit) {
2862
            element = new MeasurementUnitCollectionElement(this, parentElement, (MeasurementUnit) entity, removeListener, backgroundColor, style);
2863
        } else if (entity instanceof StatisticalMeasure) {
2864
            element = new StatisticalMeasureCollectionElement(this, parentElement, (StatisticalMeasure) entity, removeListener, backgroundColor, style);
2865
        } else if (entity instanceof State && parentElement instanceof InapplicableIfEntityCollectionSection) {
2866
            element = new InapplicableIfCollectionElement(this, parentElement, (State) entity, removeListener, backgroundColor, style);
2867
        } else if (entity instanceof State && parentElement instanceof OnlyApplicableIfEntityCollectionSection) {
2868
            element = new OnlyApplicableIfCollectionElement(this, parentElement, (State) entity, removeListener, backgroundColor, style);
2869
        }
2870

    
2871
        //check for parent section when entity is null
2872
        //this happens when AbstractUnboundEntityCollectionSection is used
2873
        if(element==null){
2874
            if(parentElement instanceof ScopeSection || parentElement instanceof ScopeRestrictionSection){
2875
                element = new ScopeElement(this,
2876
                        parentElement,
2877
                        (DefinedTerm) entity,
2878
                        removeListener,
2879
                        style);
2880
            }
2881
            else if(parentElement instanceof ModifierSection){
2882
                element = new ModifierElement(this,
2883
                        parentElement,
2884
                        (DefinedTerm) entity,
2885
                        removeListener,
2886
                        style);
2887
            }
2888
        }
2889

    
2890

    
2891
        if (element == null) {
2892
            MessagingUtils.messageDialog(
2893
                    String.format("Error when creating section %s",
2894
                            parentElement.getClass().getSimpleName()),
2895
                    this,
2896
                    String.format("Could not generate collection element for entity of class %s."
2897
                            + " Looks like the case is not yet handled. Check implementation.\n"
2898
                            + "Entity: %s", entity.getClass(), entity.toString()), null);
2899
        }
2900

    
2901
        else{
2902
            if (backgroundColor != null && !backgroundColor.isDisposed()) {
2903
                element.setPersistentBackground(backgroundColor);
2904
            }
2905
            adapt(element);
2906
            parentElement.addElement(element);
2907
        }
2908

    
2909
        return element;
2910
    }
2911

    
2912
    /**
2913
     * <p>
2914
     * Creates a selection element for the given type T.
2915
     * </p>
2916
     * <p>
2917
     * <strong>Selection elements not handled by this method:</strong>
2918
     * <ul>
2919
     * <li>{@link TaxonNodeSelectionElement} see
2920
     * {@link #createTaxonNodeSelectionElement(ConversationHolder, ICdmFormElement, String, TaxonNode, int, int)}
2921
     * </li>
2922
     * <li>{@link NomenclaturalAuthorTeamSelectionElement} see
2923
     * {@link #createNomenclaturalAuthorTeamSelectionElement(ConversationHolder, ICdmFormElement, String, Team, int, int)}
2924
     * </li>
2925
     * </ul>
2926
     * </p>
2927
     *
2928
     * @param clazz
2929
     *            a {@link Class} object of the type that you want the selection
2930
     *            element to handle
2931
     * @param parentElement
2932
     *            a {@link ICdmFormElement} object.
2933
     * @param labelString
2934
     *            a {@link String} object.
2935
     * @param selectionType
2936
     * @param selection
2937
     *            a {@link ICdmBase} object.
2938
     * @param style
2939
     *            a int.
2940
     * @param conversation
2941
     *            a {@link ConversationHolder} object.
2942
     * @return a {@link EntitySelectionElement} object.
2943
     */
2944
    public <T extends CdmBase> EntitySelectionElement<T> createSelectionElement(Class<T> clazz,
2945
            ConversationHolder conversation, ICdmFormElement parentElement, String labelString, T selection, int mode,
2946
            int style, boolean filterElement) {
2947
        EntitySelectionElement<T> element = new EntitySelectionElement<T>(this, //conversation,
2948
                parentElement, clazz,
2949
                labelString, selection, mode, style, filterElement);
2950
        adapt(element);
2951
        parentElement.addElement(element);
2952
        return element;
2953
    }
2954

    
2955
    public <T extends CdmBase> EntitySelectionElement<T> createSelectionElement(Class<T> clazz,
2956
//            ConversationHolder conversation,
2957
            ICdmFormElement parentElement, String labelString, T selection, int mode,
2958
            int style) {
2959
        EntitySelectionElement<T> element = new EntitySelectionElement<T>(this,
2960
                parentElement, clazz,
2961
                labelString, selection, mode, style);
2962
        adapt(element);
2963
        parentElement.addElement(element);
2964
        return element;
2965
    }
2966

    
2967
    public CommonNameReferenceSelectionElement createCommonNameReferenceSelectionElement(ICdmFormElement parentElement, String labelString, Reference selection, int mode,
2968
          int style) {
2969
        CommonNameReferenceSelectionElement element = new CommonNameReferenceSelectionElement(this,
2970
              parentElement, labelString, selection, mode, style);
2971
      adapt(element);
2972
      parentElement.addElement(element);
2973
      return element;
2974
  }
2975

    
2976
    /**
2977
     * <p>
2978
     * Creates a selection element for the given type T which shows only the <b>abbreviated</b> title as the label.
2979
     * </p>
2980
     * <p>
2981
     * <strong>Selection elements not handled by this method:</strong>
2982
     * <ul>
2983
     * <li>{@link TaxonNodeSelectionElement} see
2984
     * {@link #createTaxonNodeSelectionElement(ConversationHolder, ICdmFormElement, String, TaxonNode, int, int)}
2985
     * </li>
2986
     * <li>{@link NomenclaturalAuthorTeamSelectionElement} see
2987
     * {@link #createNomenclaturalAuthorTeamSelectionElement(ConversationHolder, ICdmFormElement, String, Team, int, int)}
2988
     * </li>
2989
     * </ul>
2990
     * </p>
2991
     *
2992
     * @param clazz
2993
     *            a {@link Class} object of the type that you want the selection
2994
     *            element to handle
2995
     * @param parentElement
2996
     *            a {@link ICdmFormElement} object.
2997
     * @param labelString
2998
     *            a {@link String} object.
2999
     * @param selectionType
3000
     * @param selection
3001
     *            a {@link ICdmBase} object.
3002
     * @param style
3003
     *            a int.
3004
     * @param conversation
3005
     *            a {@link ConversationHolder} object.
3006
     * @return a {@link EntitySelectionElement} object.
3007
     */
3008
    public <T extends CdmBase> EntitySelectionElementWithAbbreviatedTitle<T> createSelectionElementWithAbbreviatedTitle(
3009
            Class<T> clazz, ConversationHolder conversation, ICdmFormElement parentElement, String labelString,
3010
            T selection, int mode, int style) {
3011
        EntitySelectionElementWithAbbreviatedTitle<T> element = new EntitySelectionElementWithAbbreviatedTitle<T>(this, //conversation,
3012
                parentElement, clazz,
3013
                labelString, selection, mode, style);
3014
        adapt(element);
3015
        parentElement.addElement(element);
3016
        return element;
3017
    }
3018

    
3019
    public TaxonNodeSelectionElement createTaxonNodeSelectionElement(ConversationHolder conversation,
3020
            ICdmFormElement parentElement, String labelString, TaxonNode selection, int mode, int style) {
3021
        TaxonNodeSelectionElement element = new TaxonNodeSelectionElement(this, //conversation,
3022
                parentElement,
3023
                labelString, selection, mode, style);
3024
        adapt(element);
3025
        parentElement.addElement(element);
3026
        return element;
3027
    }
3028

    
3029

    
3030

    
3031
//    public NomenclaturalAuthorTeamSelectionElement createNomenclaturalAuthorTeamSelectionElement(
3032
//            ConversationHolder conversation, ICdmFormElement parentElement, String labelString, Team selection,
3033
//            int mode, int style) {
3034
//        NomenclaturalAuthorTeamSelectionElement element = new NomenclaturalAuthorTeamSelectionElement(this,
3035
//                conversation, parentElement, labelString, selection, mode, style);
3036
//        adapt(element);
3037
//        parentElement.addElement(element);
3038
//        return element;
3039
//    }
3040

    
3041
    /** {@inheritDoc} */
3042
    public LabelElement createLabel(ICdmFormElement parentElement, String text) {
3043
        LabelElement labelElement = new LabelElement(this, parentElement, text);
3044
        adapt(labelElement);
3045
        parentElement.addElement(labelElement);
3046
        return labelElement;
3047
    }
3048

    
3049

    
3050

    
3051
//    public DateElementFormElement createDateElementForm(ICdmFormElement formElement, String labelText, DateTime dateTime, int style){
3052
//        Label label = new Label(formElement.getLayoutComposite(), style);
3053
//        label.setText(labelText+" (yyyy-MM-dd)");
3054
//        DateElementFormElement dateElement = new DateElementFormElement(this, dateTime, style, formElement.getLayoutComposite());
3055
//        dateElement.initInternalController();
3056
//
3057
//        return dateElement;
3058
//    }
3059

    
3060
    public DateElement createDateElement(ICdmFormElement formElement, String labelText, DateTime dateTime, int style, boolean editableText){
3061
    	 Label label = new Label(formElement.getLayoutComposite(), style);
3062
         label.setText(labelText);
3063
         label.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE, 1, 1));
3064
         DateElement dateElement = new DateElement(formElement.getLayoutComposite(), dateTime, labelText, style, editableText);
3065
         dateElement.initController(this, formElement);
3066
         dateElement.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE, 1, 1));
3067
         return dateElement;
3068
    }
3069

    
3070
    /**
3071
     * <p>
3072
     * Getter for the field <code>selectionProvider</code>.
3073
     * </p>
3074
     *
3075
     * @return a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
3076
     */
3077
    public ISelectionProvider getSelectionProvider() {
3078
        return selectionProvider;
3079
    }
3080

    
3081
    /**
3082
     * <p>
3083
     * createDetailedDescriptionDetailElement
3084
     * </p>
3085
     *
3086
     * @param parentElement
3087
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
3088
     *            object.
3089
     * @param entity
3090
     *            a
3091
     *            {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase}
3092
     *            object.
3093
     * @param style
3094
     *            a int.
3095
     * @return a
3096
     *         {@link eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement}
3097
     *         object.
3098
     */
3099
    public AbstractDetailedDescriptionDetailElement createDetailedDescriptionDetailElement(
3100
            ICdmFormElement parentElement, DescriptionElementBase entity, int style, boolean enabled) {
3101
        AbstractDetailedDescriptionDetailElement detailedDescriptionElement = null;
3102

    
3103
        if (entity instanceof CategoricalData) {
3104
            detailedDescriptionElement = new CategoricalDataDetailElement(this, parentElement,
3105
                    (CategoricalData) entity, style);
3106
        } else if (entity instanceof CommonTaxonName) {
3107
            detailedDescriptionElement = new CommonNameDetailElement(this, parentElement, (CommonTaxonName) entity,
3108
                    style);
3109
        } else if (entity instanceof Distribution && !enabled) {
3110
            detailedDescriptionElement = new DistributionDetailElement(this, parentElement, (Distribution) entity,
3111
                    enabled, style);
3112
        } else if (entity instanceof Distribution) {
3113
            detailedDescriptionElement = new DistributionDetailElement(this, parentElement, (Distribution) entity,
3114
                    true, style);
3115
        }else if (entity instanceof IndividualsAssociation) {
3116
            detailedDescriptionElement = new IndividualsAssociationDetailElement(this, parentElement,
3117
                    (IndividualsAssociation) entity, style);
3118
        } else if (entity instanceof QuantitativeData) {
3119
            detailedDescriptionElement = new QuantitativeDataDetailElement(this, parentElement,
3120
                    (QuantitativeData) entity, style);
3121
        } else if (entity instanceof TaxonInteraction) {
3122
            detailedDescriptionElement = new TaxonInteractionDetailElement(this, parentElement,
3123
                    (TaxonInteraction) entity, style);
3124
        } else if (entity instanceof TextData) {
3125
            detailedDescriptionElement = new TextDataDetailElement(this, parentElement, (TextData) entity, style);
3126
        } else {
3127
            throw new IllegalStateException("There is no interface for the given description element");
3128
        }
3129
        adapt(detailedDescriptionElement);
3130
        parentElement.addElement(detailedDescriptionElement);
3131
        return detailedDescriptionElement;
3132

    
3133
    }
3134

    
3135
    /**
3136
     * Creates a styled text as a part of the form.
3137
     *
3138
     * @param parent
3139
     *            the text parent
3140
     * @param value
3141
     *            the text initial value
3142
     * @param style
3143
     *            the text style
3144
     * @return the text widget
3145
     */
3146
    public StyledText createStyledText(Composite parent, String value, int style) {
3147
        StyledText text = new StyledText(parent, getBorderStyle() | style | getOrientation());
3148
        if (value != null) {
3149
            text.setText(value);
3150
        }
3151
        text.setForeground(getColors().getForeground());
3152
        text.setBackground(getColors().getBackground());
3153
        // text.addFocusListener(visibilityHandler);
3154
        return text;
3155
    }
3156

    
3157
    public PreservedSpecimenDetailSection createPreservedSpecimenDetailsSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
3158
        PreservedSpecimenDetailSection section = new PreservedSpecimenDetailSection(this, conversation, parentElement, selectionProvider, style);
3159
        addAndAdaptSection(parentElement, section);
3160
        return section;
3161
    }
3162

    
3163
    /**
3164
     * @param formElement
3165
     * @param conversationHolder
3166
     * @param style
3167
     * @return
3168
     */
3169
    public TaxonNodeAgentRelationCollectionSection createTaxonNodeAgentRelationCollectionSection(
3170
            ICdmFormElement formElement, ConversationHolder conversationHolder, int style) {
3171
        TaxonNodeAgentRelationCollectionSection section = new TaxonNodeAgentRelationCollectionSection(this, conversationHolder, formElement, style);
3172
        addAndAdaptSection(formElement, section);
3173
        return section;
3174
    }
3175

    
3176

    
3177
	public TaxonOfRelationshipElement createTaxonOfRelationshipDetailElement(
3178
			ICdmFormElement parentElement, int style) {
3179
		TaxonOfRelationshipElement section = new TaxonOfRelationshipElement(this, parentElement, style);
3180
		addAndAdaptElement(parentElement, section);
3181
        return section;
3182
	}
3183

    
3184
	public TaxonDetailSection createTaxonDetailSection(ConversationHolder conversationHolder,
3185
			ICdmFormElement formElement, ISelectionProvider selectionProvider, int style) {
3186
			TaxonDetailSection section = new TaxonDetailSection(this, conversationHolder, formElement, selectionProvider, style);
3187
	        addAndAdaptSection(formElement, section);
3188
	        return section;
3189
	}
3190

    
3191

    
3192

    
3193

    
3194

    
3195
//	public RichTextWithLabelElement createRichTextLabelElement(ICdmFormElement parentElement, String labelString, String initialText, int textHeight, int style) {
3196
//		 RichTextWithLabelElement element = new RichTextWithLabelElement(this, parentElement, labelString,
3197
//				 initialText, textHeight, style);
3198
//	        adapt(element);
3199
//	        parentElement.addElement(element);
3200
//	        return element;
3201
//	}
3202

    
3203

    
3204

    
3205

    
3206

    
3207

    
3208

    
3209
}
(7-7/48)