Project

General

Profile

Download (150 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.DefinedTerm;
60
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
61
import eu.etaxonomy.cdm.model.common.Extension;
62
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
63
import eu.etaxonomy.cdm.model.common.Group;
64
import eu.etaxonomy.cdm.model.common.ICdmBase;
65
import eu.etaxonomy.cdm.model.common.IEnumTerm;
66
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
67
import eu.etaxonomy.cdm.model.common.Identifier;
68
import eu.etaxonomy.cdm.model.common.LSID;
69
import eu.etaxonomy.cdm.model.common.Language;
70
import eu.etaxonomy.cdm.model.common.LanguageString;
71
import eu.etaxonomy.cdm.model.common.Marker;
72
import eu.etaxonomy.cdm.model.common.Representation;
73
import eu.etaxonomy.cdm.model.common.TermBase;
74
import eu.etaxonomy.cdm.model.common.TermType;
75
import eu.etaxonomy.cdm.model.common.TermVocabulary;
76
import eu.etaxonomy.cdm.model.common.TimePeriod;
77
import eu.etaxonomy.cdm.model.common.User;
78
import eu.etaxonomy.cdm.model.common.VerbatimTimePeriod;
79
import eu.etaxonomy.cdm.model.common.VersionableEntity;
80
import eu.etaxonomy.cdm.model.description.CategoricalData;
81
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
82
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
83
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
84
import eu.etaxonomy.cdm.model.description.Distribution;
85
import eu.etaxonomy.cdm.model.description.Feature;
86
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
87
import eu.etaxonomy.cdm.model.description.KeyStatement;
88
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
89
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
90
import eu.etaxonomy.cdm.model.description.QuantitativeData;
91
import eu.etaxonomy.cdm.model.description.State;
92
import eu.etaxonomy.cdm.model.description.StateData;
93
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
94
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
95
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
96
import eu.etaxonomy.cdm.model.description.TextData;
97
import eu.etaxonomy.cdm.model.location.NamedArea;
98
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
99
import eu.etaxonomy.cdm.model.location.Point;
100
import eu.etaxonomy.cdm.model.media.ExternalLink;
101
import eu.etaxonomy.cdm.model.media.ImageFile;
102
import eu.etaxonomy.cdm.model.media.Media;
103
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
104
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
105
import eu.etaxonomy.cdm.model.media.Rights;
106
import eu.etaxonomy.cdm.model.molecular.DnaSample;
107
import eu.etaxonomy.cdm.model.name.NameRelationship;
108
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
109
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
110
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
111
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
112
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
113
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
114
import eu.etaxonomy.cdm.model.reference.Reference;
115
import eu.etaxonomy.cdm.model.taxon.Taxon;
116
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
117
import eu.etaxonomy.cdm.model.taxon.TaxonNodeAgentRelation;
118
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
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.TermVocabularyDetailElement;
358
import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermVocabularyDetailSection;
359
import eu.etaxonomy.taxeditor.ui.selection.CommonNameReferenceSelectionElement;
360
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
361
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElementWithAbbreviatedTitle;
362
import eu.etaxonomy.taxeditor.ui.selection.NomenclaturalAuthorTeamSelectionElement;
363
import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
364

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

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

    
379
    @Inject
380
    private IEclipseContext context;
381

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
525
        super.adapt(composite);
526
    }
527

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

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

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

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

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

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

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

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

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

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

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

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

    
772

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

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

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

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

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

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

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

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

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

    
919
	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
920
			TermType termType,
921
			ICdmFormElement parentElement,
922
			String labelString,
923
			T selection,
924
			int style) {
925
		return  this.createDefinedTermComboElement(termType, null, parentElement, labelString, selection, true, style, false, null);
926
	}
927
    public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
928
			TermType termType,
929
			ICdmFormElement parentElement,
930
			String labelString,
931
			T selection,
932
			boolean addEmptyElement,
933
			int style,
934
			boolean useAbbrevLabel) {
935
		return createDefinedTermComboElement(termType, null, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
936
	}
937

    
938

    
939
    public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
940
            TermVocabulary<?> termVocabulary,
941
            ICdmFormElement parentElement,
942
            String labelString,
943
            T selection,
944
            int style) {
945
        return this.createDefinedTermComboElement(null, termVocabulary, parentElement, labelString, selection, true, style, false, null);
946
    }
947

    
948
	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
949
	        TermVocabulary<?> termVocabulary,
950
	        ICdmFormElement parentElement,
951
	        String labelString,
952
	        T selection,
953
	        boolean addEmptyElement,
954
	        int style,
955
	        boolean useAbbrevLabel) {
956
	    return createDefinedTermComboElement(null, termVocabulary, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
957
	}
958

    
959
	private <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
960
	        TermType termType,
961
	        TermVocabulary<?> termVocabulary,
962
	        ICdmFormElement parentElement,
963
	        String labelString,
964
	        T selection,
965
	        boolean addEmptyElement,
966
	        int style,
967
	        boolean useAbbrevLabel,
968
	        Comparator<T> comparator) {
969
	    if(termType!=null){
970
	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termType, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
971
	        adapt(element);
972
	        parentElement.addElement(element);
973
	        return element;
974
	    }
975
	    else if(termVocabulary!=null){
976
	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termVocabulary, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
977
	        if (comparator!= null){
978
	        	element.setTermComparator(comparator);
979
	        }
980
	        adapt(element);
981
	        parentElement.addElement(element);
982
	        return element;
983
	    }
984
	    else {
985
	        //this should never happen
986
	        return null;
987
	    }
988
	}
989

    
990
	public NameRelationshipTypeCombo createNameRelationshipTypeCombo(ICdmFormElement parentElement,
991
            String labelString,
992
            int style,
993
            boolean useAbbrevLabel,
994
            Comparator<NameRelationshipType> comparator) {
995

    
996
        NameRelationshipTypeCombo<InverseTermWrapper> element = new NameRelationshipTypeCombo(this, parentElement, labelString, true, style, useAbbrevLabel, comparator);
997
        adapt(element);
998
        parentElement.addElement(element);
999
        return element;
1000
    }
1001

    
1002
	public MisappliedRelationshipComboElement createMisappliedRelationshipComboElement(
1003
	        ICdmFormElement parentElement,
1004
            String labelString,
1005
            TaxonRelationshipType selection,
1006
            int style) {
1007
	    MisappliedRelationshipComboElement combo = new MisappliedRelationshipComboElement(this, parentElement, labelString, selection, false, style, false);
1008
	    adapt(combo);
1009
        parentElement.addElement(combo);
1010
        return combo;
1011
    }
1012

    
1013
	public <T extends IEnumTerm<T>> EnumComboElement<T> createEnumComboElement(
1014
	        Class<T> enumComboType, ICdmFormElement parentElement,
1015
	        int style) {
1016
	    return createEnumComboElement(enumComboType, parentElement, null, style);
1017
	}
1018

    
1019
	public <T extends IEnumTerm<T>> EnumComboElement<T> createEnumComboElement(
1020
			Class<T> enumComboType, ICdmFormElement parentElement, Comparator<T> comparator,
1021
			int style) {
1022
        EnumComboElement<T> element = new EnumComboElement<T>(this, parentElement, enumComboType, comparator, style);
1023
        adapt(element);
1024
        parentElement.addElement(element);
1025
        return element;
1026
    }
1027

    
1028
	public <TERM extends DefinedTermBase<TERM>, VOC extends TermVocabulary<TERM>> VocabularyComboElement<TERM, VOC> createVocabularyComboElement(
1029
	        TermType termType, String label, VOC selection, ICdmFormElement parentElement, int style) {
1030
	    VocabularyComboElement<TERM, VOC> element = new VocabularyComboElement<TERM, VOC>(this, parentElement, termType, label, selection, style);
1031
	    adapt(element);
1032
	    parentElement.addElement(element);
1033
	    return element;
1034
	}
1035

    
1036
    /**
1037
     * <p>
1038
     * createBrowserElement
1039
     * </p>
1040
     *
1041
     * @param imageUri
1042
     *            a {@link java.net.URI} object.
1043
     * @param style
1044
     *            a int.
1045
     * @param parentElement
1046
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1047
     *            object.
1048
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.BrowserElement}
1049
     *         object.
1050
     */
1051
    public BrowserElement createBrowserElement(ICdmFormElement parentElement, URI imageUri, int style) {
1052
        BrowserElement element = new BrowserElement(this, parentElement, imageUri, style);
1053
        adapt(element);
1054
        parentElement.addElement(element);
1055
        return element;
1056
    }
1057

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

    
1079
    /**
1080
     * <p>
1081
     * createTextActionElement
1082
     * </p>
1083
     *
1084
     * @param labelString
1085
     *            a {@link java.lang.String} object.
1086
     * @param initialText
1087
     *            a {@link java.lang.String} object.
1088
     * @param style
1089
     *            a int.
1090
     * @param parentElement
1091
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1092
     *            object.
1093
     * @param buttonLabel
1094
     *            a {@link java.lang.String} object.
1095
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextActionElement}
1096
     *         object.
1097
     */
1098
    public TextActionElement createTextActionElement(ICdmFormElement parentElement, String labelString,
1099
            String buttonLabel, String initialText, int style) {
1100
        TextActionElement element = new TextActionElement(this, parentElement, labelString, buttonLabel, initialText,
1101
                style);
1102
        adapt(element);
1103
        parentElement.addElement(element);
1104
        return element;
1105
    }
1106

    
1107
    /**
1108
     * <p>
1109
     * createCheckbox
1110
     * </p>
1111
     *
1112
     * @param parentElement
1113
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1114
     *            object.
1115
     * @param label
1116
     *            a {@link java.lang.String} object.
1117
     * @param initialState
1118
     *            a boolean.
1119
     * @param style
1120
     *            a int.
1121
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.CheckboxElement}
1122
     *         object.
1123
     */
1124
    public CheckboxElement createCheckbox(ICdmFormElement parentElement, String label, Boolean initialState, int style) {
1125
        if(initialState==null){
1126
            initialState = Boolean.FALSE;
1127
        }
1128
        CheckboxElement element = new CheckboxElement(this, parentElement, label, initialState, style | orientation);
1129
        adapt(element);
1130
        parentElement.addElement(element);
1131
        return element;
1132
    }
1133

    
1134
    /**
1135
     * Creates a section as a part of the form.
1136
     *
1137
     * @return the section widget
1138
     * @param section
1139
     *            a
1140
     *            {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1141
     *            object.
1142
     */
1143
    public Section adapt(AbstractFormSection section) {
1144
        section.setMenu(section.getLayoutComposite().getMenu());
1145
        adapt(section, true, true);
1146

    
1147
        // handle focus and property change events for cdm use
1148
        section.addFocusListener(selectionFocusHandler);
1149
        section.setPropertyChangeListeners(propertyChangeListeners);
1150

    
1151
        if (section.getToggle() != null) {
1152
            section.getToggle().setHoverDecorationColor(getColors().getColor(IFormColors.TB_TOGGLE_HOVER));
1153
            section.getToggle().setDecorationColor(getColors().getColor(IFormColors.TB_TOGGLE));
1154
        }
1155

    
1156
        section.setFont(boldFontHolder2.getBoldFont(section.getLayoutComposite().getFont()));
1157

    
1158
        if ((section.getStyle() & ExpandableComposite.TITLE_BAR) != 0
1159
                || (section.getStyle() & ExpandableComposite.SHORT_TITLE_BAR) != 0) {
1160
            getColors().initializeSectionToolBarColors();
1161
            section.setTitleBarBackground(getColors().getColor(IFormColors.TB_BG));
1162
            section.setTitleBarBorderColor(getColors().getColor(IFormColors.TB_BORDER));
1163
        }
1164
        // call setTitleBarForeground regardless as it also sets the label color
1165
        section.setTitleBarForeground(getColors().getColor(IFormColors.TB_TOGGLE));
1166
        return section;
1167
    }
1168

    
1169
    private class BoldFontHolder2 {
1170
        private Font normalFont;
1171

    
1172
        private Font boldFont;
1173

    
1174
        public BoldFontHolder2() {
1175
        }
1176

    
1177
        public Font getBoldFont(Font font) {
1178
            createBoldFont(font);
1179
            return boldFont;
1180
        }
1181

    
1182
        private void createBoldFont(Font font) {
1183
            if (normalFont == null || !normalFont.equals(font)) {
1184
                normalFont = font;
1185
                dispose();
1186
            }
1187
            if (boldFont == null) {
1188
                boldFont = FormFonts.getInstance().getBoldFont(getColors().getDisplay(), normalFont);
1189
            }
1190
        }
1191

    
1192
        public void dispose() {
1193
            if (boldFont != null) {
1194
                FormFonts.getInstance().markFinished(boldFont, getColors().getDisplay());
1195
                boldFont = null;
1196
            }
1197
        }
1198
    }
1199

    
1200
    /**
1201
     * <p>
1202
     * createToggleableTextField
1203
     * </p>
1204
     *
1205
     * @param parentElement
1206
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1207
     *            object.
1208
     * @param labelString
1209
     *            a {@link java.lang.String} object.
1210
     * @param initialText
1211
     *            a {@link java.lang.String} object.
1212
     * @param initialState
1213
     *            a boolean.
1214
     * @param style
1215
     *            a int.
1216
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement}
1217
     *         object.
1218
     */
1219
    public ToggleableTextElement createToggleableTextField(ICdmFormElement parentElement, String labelString,
1220
            String initialText, boolean initialState, int style) {
1221
        ToggleableTextElement element = new ToggleableTextElement(this, parentElement, labelString, initialText,
1222
                initialState, style | orientation);
1223

    
1224
        adapt(element);
1225
        parentElement.addElement(element);
1226
        return element;
1227
    }
1228

    
1229
    /**
1230
     * <p>
1231
     * createTimePeriodElement
1232
     * </p>
1233
     *
1234
     * @param parentElement
1235
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1236
     *            object.
1237
     * @param labelString
1238
     *            a {@link java.lang.String} object.
1239
     * @param timePeriod
1240
     *            a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
1241
     * @param style
1242
     *            a int.
1243
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.TimePeriodElement}
1244
     *         object.
1245
     */
1246
    public TimePeriodElement createTimePeriodElement(ICdmFormElement parentElement, String labelString,
1247
            TimePeriod timePeriod, int style) {
1248
        TimePeriodElement element = new TimePeriodElement(this, parentElement, labelString, timePeriod, style);
1249
        adapt(element);
1250
        parentElement.addElement(element);
1251
        return element;
1252
    }
1253

    
1254
    /**
1255
     * <p>
1256
     * createVerbatimTimePeriodElement
1257
     * </p>
1258
     *
1259
     * @param parentElement
1260
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1261
     *            object.
1262
     * @param labelString
1263
     *            a {@link java.lang.String} object.
1264
     * @param timePeriod
1265
     *            a {@link eu.etaxonomy.cdm.model.common.VerbatimTimePeriod} object.
1266
     * @param style
1267
     *            a int.
1268
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.VerbatimTimePeriodElement}
1269
     *         object.
1270
     */
1271
    public VerbatimTimePeriodElement createVerbatimTimePeriodElement(ICdmFormElement parentElement, String labelString,
1272
            VerbatimTimePeriod timePeriod, int style) {
1273
        VerbatimTimePeriodElement element = new VerbatimTimePeriodElement(this, parentElement, labelString, timePeriod, style);
1274
        adapt(element);
1275
        parentElement.addElement(element);
1276
        return element;
1277
    }
1278

    
1279
	/**
1280
	 * <p>
1281
	 * createGatheringEventUnitElement
1282
	 * </p>
1283
	 *
1284
	 * @param parentElement
1285
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1286
	 *            object.
1287
	 * @param labelString
1288
	 *            a {@link java.lang.String} object.
1289
	 * @param timePeriod
1290
	 *            a {@link eu.etaxonomy.cdm.model.common.GatheringEvent} object.
1291
	 * @param style
1292
	 *            a int.
1293
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.GatheringEventUnitElement}
1294
	 *         object.
1295
	 */
1296
	public GatheringEventUnitElement createGatheringEventUnitElement(
1297
			ICdmFormElement parentElement,
1298
			String labelString,
1299
			DerivedUnitFacade gatheringEvent,
1300
			MinMaxTextSection.UnitType unitType,
1301
			int style) {
1302
		GatheringEventUnitElement element = new GatheringEventUnitElement(this,
1303
				parentElement,
1304
				labelString,
1305
				gatheringEvent,
1306
				unitType,
1307
				style);
1308
		adapt(element);
1309
		parentElement.addElement(element);
1310
		return element;
1311
	}
1312

    
1313
    /**
1314
     * <p>
1315
     * createPointElement
1316
     * </p>
1317
     *
1318
     * @param style
1319
     *            a int.
1320
     * @param parentElement
1321
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1322
     *            object.
1323
     * @param point
1324
     *            a {@link eu.etaxonomy.cdm.model.location.Point} object.
1325
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.PointElement} object.
1326
     */
1327
    public PointElement createPointElement(ICdmFormElement parentElement, Point point, int style) {
1328
        PointElement element = new PointElement(this, parentElement, point, style);
1329
        adapt(element);
1330
        parentElement.addElement(element);
1331
        return element;
1332
    }
1333

    
1334
    /**
1335
     * Creates an empty section with the given message.<br>
1336
     * If message is <code>null</code> a default message will be displayed.
1337
     */
1338
    public EmptySection createEmptySection(String message, CdmFormFactory formFactory, ICdmFormElement parentElement, int style) {
1339
        EmptySection section = new EmptySection(message, formFactory, parentElement, style);
1340
        parentElement.addElement(section);
1341
        adapt(section);
1342
        return section;
1343
    }
1344

    
1345
    /**
1346
     * <p>
1347
     * createDateDetailSection
1348
     * </p>
1349
     *
1350
     * @param parentElement
1351
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1352
     *            object.
1353
     * @param style
1354
     *            a int.
1355
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.DateDetailSection}
1356
     *         object.
1357
     */
1358
    public DateDetailSection<TimePeriod> createDateDetailSection(ICdmFormElement parentElement, int style) {
1359
        DateDetailSection<TimePeriod> section = new DateDetailSection<TimePeriod>(this, parentElement, false, style);
1360
        parentElement.addElement(section);
1361
        adapt(section);
1362
        return section;
1363
    }
1364

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

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

    
1406
    /**
1407
     * <p>
1408
     * createPartialElement
1409
     * </p>
1410
     *
1411
     * @param parentElement
1412
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1413
     *            object.
1414
     * @param labelString
1415
     *            a {@link java.lang.String} object.
1416
     * @param partial
1417
     *            a {@link org.joda.time.Partial} object.
1418
     * @param style
1419
     *            a int.
1420
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.PartialElement}
1421
     *         object.
1422
     */
1423
    public PartialElement createPartialElement(ICdmFormElement parentElement, String labelString, Partial partial,
1424
            int style) {
1425
        PartialElement element = new PartialElement(this, parentElement, labelString, style);
1426
        adapt(element);
1427
        parentElement.addElement(element);
1428
        return element;
1429
    }
1430

    
1431
    /**
1432
     * <p>
1433
     * addSelectionListener
1434
     * </p>
1435
     *
1436
     * @param listener
1437
     *            a {@link org.eclipse.swt.events.SelectionListener} object.
1438
     */
1439
    public void addSelectionListener(SelectionListener listener) {
1440
        selectionListenerList.add(listener);
1441
    }
1442

    
1443
    /**
1444
     * <p>
1445
     * removeSelectionListener
1446
     * </p>
1447
     *
1448
     * @param listener
1449
     *            a {@link org.eclipse.swt.events.SelectionListener} object.
1450
     */
1451
    public void removeSelectionListener(SelectionListener listener) {
1452
        if (listener == null) {
1453
            MessagingUtils.error(this.getClass(),
1454
                    "Tried to remove a selection listener from this factories listeners but was null", null);
1455
        } else {
1456
            selectionListenerList.remove(listener);
1457
        }
1458
    }
1459

    
1460
    /**
1461
     * <p>
1462
     * addPropertyChangeListener
1463
     * </p>
1464
     *
1465
     * @param listener
1466
     *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1467
     *            object.
1468
     */
1469
    public void addPropertyChangeListener(IPropertyChangeListener listener) {
1470
        if (propertyChangeListeners.contains(listener)) {
1471
            return;
1472
        }
1473
        propertyChangeListeners.add(0, listener);
1474
    }
1475

    
1476
    /**
1477
     * <p>
1478
     * removePropertyChangeListener
1479
     * </p>
1480
     *
1481
     * @param listener
1482
     *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1483
     *            object.
1484
     */
1485
    public void removePropertyChangeListener(IPropertyChangeListener listener) {
1486
        propertyChangeListeners.remove(listener);
1487
    }
1488

    
1489
    /**
1490
     * @return the propertyChangeListeners
1491
     */
1492
    public List<IPropertyChangeListener> getPropertyChangeListeners() {
1493
        return propertyChangeListeners;
1494
    }
1495

    
1496
    /**
1497
     * <p>
1498
     * createHorizontalSeparator
1499
     * </p>
1500
     *
1501
     * @param parentElement
1502
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1503
     *            object.
1504
     * @param style
1505
     *            a int.
1506
     * @return a {@link org.eclipse.swt.widgets.Label} object.
1507
     */
1508
    public Label createHorizontalSeparator(ICdmFormElement parentElement, int style) {
1509
        Label separator = this.createSeparator(parentElement.getLayoutComposite(), SWT.HORIZONTAL | style);
1510
        separator.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
1511
        return separator;
1512
    }
1513

    
1514
    /**
1515
     * <p>
1516
     * createVersionElement
1517
     * </p>
1518
     *
1519
     * @param parentElement
1520
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1521
     *            object.
1522
     * @param entity
1523
     *            a {@link eu.etaxonomy.cdm.model.common.VersionableEntity}
1524
     *            object.
1525
     * @param style
1526
     *            a int.
1527
     * @return a
1528
     *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionElement}
1529
     *         object.
1530
     */
1531
    public VersionElement createVersionElement(ICdmFormElement parentElement, VersionableEntity entity, int style) {
1532
        VersionElement element = new VersionElement(this, parentElement, entity, style);
1533
        adapt(element);
1534
        parentElement.addElement(element);
1535
        return element;
1536
    }
1537

    
1538
    /**
1539
     * @param cdmBaseSection
1540
     * @param object
1541
     * @param style
1542
     * @return
1543
     */
1544
    public CdmBaseElement createCdmBaseElement(ICdmFormElement parentElement, CdmBase entity, int style) {
1545
        CdmBaseElement element = new CdmBaseElement(this, parentElement, entity, style);
1546
        adapt(element);
1547
        parentElement.addElement(element);
1548
        return element;
1549
    }
1550

    
1551
    /**
1552
     * <p>
1553
     * createVersionSection
1554
     * </p>
1555
     *
1556
     * @param parentElement
1557
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1558
     *            object.
1559
     * @param style
1560
     *            a int.
1561
     * @return a
1562
     *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection}
1563
     *         object.
1564
     */
1565
    public VersionSection createVersionSection(ICdmFormElement parentElement, int style) {
1566
        VersionSection section = new VersionSection(this, parentElement, style);
1567
        parentElement.addElement(section);
1568
        adapt(section);
1569
        return section;
1570
    }
1571

    
1572
    /**
1573
     * @param parent
1574
     * @param i
1575
     * @return
1576
     */
1577
    public CdmBaseSection createCdmBaseSection(ICdmFormElement parentElement, int style) {
1578
        CdmBaseSection section = new CdmBaseSection(this, parentElement, style);
1579
        parentElement.addElement(section);
1580
        adapt(section);
1581
        return section;
1582
    }
1583

    
1584
    /**
1585
     * <p>
1586
     * createEmptyElement
1587
     * </p>
1588
     *
1589
     * @param parentElement
1590
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1591
     *            object.
1592
     * @return a {@link eu.etaxonomy.taxeditor.ui.section.EmptyElement} object.
1593
     */
1594
    public EmptyElement createEmptyElement(ICdmFormElement parentElement, String emptyText) {
1595
        EmptyElement element = new EmptyElement(this, parentElement, emptyText, SWT.NULL);
1596
        adapt(element);
1597
        parentElement.addElement(element);
1598
        return element;
1599
    }
1600

    
1601
    /**
1602
     * <p>
1603
     * createHeadlineSection
1604
     * </p>
1605
     *
1606
     * @param parentElement
1607
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1608
     *            object.
1609
     * @return a
1610
     *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection}
1611
     *         object.
1612
     */
1613
    public HeadlineSection createHeadlineSection(ICdmFormElement parentElement) {
1614
        HeadlineSection section = new HeadlineSection(this, parentElement, SWT.NULL);
1615
        parentElement.addElement(section);
1616
        adapt(section);
1617
        return section;
1618
    }
1619

    
1620
    /**
1621
     * <p>
1622
     * createParsingMessageElement
1623
     * </p>
1624
     *
1625
     * @param parentElement
1626
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1627
     *            object.
1628
     * @param parserProblem
1629
     *            a {@link eu.etaxonomy.cdm.strategy.parser.ParserProblem}
1630
     *            object.
1631
     * @param style
1632
     *            a int.
1633
     * @return a
1634
     *         {@link eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessageElement}
1635
     *         object.
1636
     */
1637
    public ParsingMessageElement createParsingMessageElement(ICdmFormElement parentElement,
1638
            ParserProblem parserProblem, int style) {
1639
        ParsingMessageElement element = new ParsingMessageElement(this, parentElement, parserProblem, style);
1640
        adapt(element);
1641
        parentElement.addElement(element);
1642
        return element;
1643
    }
1644

    
1645
    public DefinedTermDetailSection createDefinedTermDetailSection(Class definedTermClass, ConversationHolder conversation,
1646
            ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
1647

    
1648
        DefinedTermDetailSection section = new DefinedTermDetailSection(this, definedTermClass, conversation, parentElement,
1649
                selectionProvider, style);
1650

    
1651
        parentElement.addElement(section);
1652
        adapt(section);
1653
        return section;
1654

    
1655
    }
1656

    
1657
    /**
1658
     * @param definedTermClass
1659
     * @param formElement
1660
     * @param style
1661
     * @return
1662
     */
1663
    public AbstractCdmDetailElement createDefinedTermDetailElement(Class definedTermClass,
1664
            AbstractCdmDetailSection parentElement, int style) {
1665
        AbstractCdmDetailElement element = null;
1666

    
1667
        if (NamedArea.class.isAssignableFrom(definedTermClass)) {
1668
            element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
1669
        } else if (definedTermClass.equals(Feature.class)) {
1670
            element = new FeatureDetailElement(this, parentElement);
1671
        } else if(definedTermClass.equals(PresenceAbsenceTerm.class)){
1672
            element = new PresenceAbsenceTermDetailElement(this, parentElement);
1673
        } else {
1674
            element = new DefinedTermDetailElement(this, parentElement);
1675
        }
1676

    
1677

    
1678
        adapt(element);
1679
        parentElement.addElement(element);
1680
        return element;
1681
    }
1682

    
1683
    public CharacterDetailSection createCharacterDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1684
        CharacterDetailSection section = new CharacterDetailSection(this, conversation, parentElement, selectionProvider, style);
1685
        addAndAdaptSection(parentElement, section);
1686
        return section;
1687
    }
1688

    
1689
    public CharacterDetailElement createCharacterDetailElement(ICdmFormElement parentElement, int style){
1690
        CharacterDetailElement element = new CharacterDetailElement(this, parentElement);
1691
        addAndAdaptElement(parentElement, element);
1692
        return element;
1693
    }
1694

    
1695
    public FeatureTreeDetailElement createFeatureTreeDetailElement(ICdmFormElement parentElement, int style){
1696
        FeatureTreeDetailElement element = new FeatureTreeDetailElement(this, parentElement);
1697
        addAndAdaptElement(parentElement, element);
1698
        return element;
1699
    }
1700

    
1701
    public FeatureNodeDetailElement createFeatureNodeDetailElement(ICdmFormElement parentElement, int style){
1702
        FeatureNodeDetailElement element = new FeatureNodeDetailElement(this, parentElement);
1703
        addAndAdaptElement(parentElement, element);
1704
        return element;
1705
    }
1706

    
1707

    
1708
    //--------DetailSections---------
1709
    public NameDetailSection createNameDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1710
        NameDetailSection section = new NameDetailSection(this, conversation, parentElement, selectionProvider, style);
1711
        addAndAdaptSection(parentElement, section);
1712
        return section;
1713
    }
1714

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

    
1721
    public FeatureTreeDetailSection createFeatureTreeDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1722
        FeatureTreeDetailSection section = new FeatureTreeDetailSection(this, conversation, parentElement, selectionProvider, style);
1723
        addAndAdaptSection(parentElement, section);
1724
        return section;
1725
    }
1726

    
1727
    public ReferenceDetailSection createReferenceDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1728
        ReferenceDetailSection section = new ReferenceDetailSection(this, conversation, parentElement, selectionProvider, style);
1729
        addAndAdaptSection(parentElement, section);
1730
        return section;
1731
    }
1732

    
1733
    public NomenclaturalReferenceDetailSection createNomenclaturalReferenceDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1734
        NomenclaturalReferenceDetailSection section = new NomenclaturalReferenceDetailSection(this, conversation, parentElement, selectionProvider, style);
1735
        addAndAdaptSection(parentElement, section);
1736
        return section;
1737
    }
1738

    
1739
    public TaxonBaseDetailSection createTaxonBaseDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1740
        TaxonBaseDetailSection section = new TaxonBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
1741
        addAndAdaptSection(parentElement, section);
1742
        return section;
1743
    }
1744

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

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

    
1757
    public TeamDetailSection createTeamDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
1758
        TeamDetailSection section = new TeamDetailSection(this, conversation, parentElement, null, style);
1759
        addAndAdaptSection(parentElement, section);
1760
        return section;
1761
    }
1762

    
1763
    public PersonDetailSection createPersonDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
1764
        PersonDetailSection section = new PersonDetailSection(this, conversation, parentElement, null, style);
1765
        addAndAdaptSection(parentElement, section);
1766
        return section;
1767
    }
1768

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

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

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

    
1787

    
1788

    
1789
    public NonViralNameDetailSection createNonViralNameDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, boolean nameChoosable, int style){
1790
        NonViralNameDetailSection section = new NonViralNameDetailSection(this, conversation, parentElement, selectionProvider, nameChoosable, style);
1791
        addAndAdaptSection(parentElement, section);
1792
        return section;
1793
    }
1794

    
1795
    public MediaDetailsSection createMediaDetailsSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1796
        MediaDetailsSection section = new MediaDetailsSection(this, conversation, parentElement, selectionProvider, style);
1797
        addAndAdaptSection(parentElement, section);
1798
        return section;
1799
    }
1800

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

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

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

    
1819
    public DerivedUnitTypeDesignationSection createDerivedUnitTypeDesignationSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1820
        DerivedUnitTypeDesignationSection section = new DerivedUnitTypeDesignationSection(this, conversation, parentElement, style);
1821
        addAndAdaptSection(parentElement, section);
1822
        return section;
1823
    }
1824

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
1927
    public SequenceContigFileCollectionDetailSection createSequenceContigFileCollectionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
1928
        SequenceContigFileCollectionDetailSection section = new SequenceContigFileCollectionDetailSection(this, conversation, parentElement, style);
1929
        addAndAdaptSection(parentElement, section);
1930
        return section;
1931
    }
1932

    
1933
    public SingleReadPherogramCollectionDetailSection createSingleReadPherogramCollectionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
1934
        SingleReadPherogramCollectionDetailSection section = new SingleReadPherogramCollectionDetailSection(this, conversation, parentElement, style);
1935
        addAndAdaptSection(parentElement, section);
1936
        return section;
1937
    }
1938

    
1939
    public SequenceReferenceCollectionDetailSection createSequenceReferenceCollectionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
1940
        SequenceReferenceCollectionDetailSection section = new SequenceReferenceCollectionDetailSection(this, conversation, parentElement, style);
1941
        addAndAdaptSection(parentElement, section);
1942
        return section;
1943
    }
1944

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

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

    
1957
    public AmplificationPrimerDetailSection createAmplificationPrimerDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1958
        AmplificationPrimerDetailSection section = new AmplificationPrimerDetailSection(this, conversation, parentElement, selectionProvider, style);
1959
        addAndAdaptSection(parentElement, section);
1960
        return section;
1961
    }
1962

    
1963
    public AmplificationCloningDetailSection createAmplificationCloningDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1964
        AmplificationCloningDetailSection section = new AmplificationCloningDetailSection(this, conversation, parentElement, selectionProvider, style);
1965
        addAndAdaptSection(parentElement, section);
1966
        return section;
1967
    }
1968

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

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

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

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

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

    
1999
    public DeterminationDetailSection createDeterminationDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2000
        DeterminationDetailSection section = new DeterminationDetailSection(this, conversation, parentElement, selectionProvider, style);
2001
        addAndAdaptSection(parentElement, section);
2002
        return section;
2003
    }
2004

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

    
2011
    public TaxonRelationshipDetailSection createTaxonRelationshipDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2012
        TaxonRelationshipDetailSection section = new TaxonRelationshipDetailSection(this, conversation, parentElement, selectionProvider, style, true);
2013
        addAndAdaptSection(parentElement, section);
2014
        return section;
2015
    }
2016

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

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

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

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

    
2041
    public UseRecordDetailSection createUseRecordDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2042
        UseRecordDetailSection section = new UseRecordDetailSection(this, conversation, parentElement, selectionProvider, style);
2043
        addAndAdaptSection(parentElement, section);
2044
        return section;
2045
    }
2046

    
2047
    private void addAndAdaptSection(ICdmFormElement parentElement, AbstractFormSection<?> section) {
2048
        parentElement.addElement(section);
2049
        adapt(section);
2050
    }
2051

    
2052
    //--------DetailElements------------
2053

    
2054
    public UseRecordDetailElement createUseRecordDetailElement(ICdmFormElement parentElement){
2055
        UseRecordDetailElement element = new UseRecordDetailElement(this, parentElement);
2056
        addAndAdaptElement(parentElement, element);
2057
        return element;
2058
    }
2059

    
2060
    public DefinedTermDetailElement<NamedAreaLevel> createNamedAreaLevelElement(ICdmFormElement parentElement){
2061
        DefinedTermDetailElement<NamedAreaLevel> element = new DefinedTermDetailElement<NamedAreaLevel>(this, parentElement);
2062
        addAndAdaptElement(parentElement, element);
2063
        return element;
2064
    }
2065

    
2066
    public eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement createNamedAreaDetailElement(ICdmFormElement parentElement){
2067
        eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
2068
        addAndAdaptElement(parentElement, element);
2069
        return element;
2070
    }
2071

    
2072
    public TermVocabularyDetailElement createTermVocabularyDetailElement(ICdmFormElement parentElement){
2073
        TermVocabularyDetailElement element = new TermVocabularyDetailElement(this, parentElement);
2074
        addAndAdaptElement(parentElement, element);
2075
        return element;
2076
    }
2077

    
2078
    public ReferenceEntityDetailElement createReferenceEntityDetailElement(ICdmFormElement parentElement){
2079
        ReferenceEntityDetailElement element = new ReferenceEntityDetailElement(this, parentElement);
2080
        addAndAdaptElement(parentElement, element);
2081
        return element;
2082
    }
2083

    
2084
    public TaxonRelationshipDetailElement createTaxonRelationshipDetailElement(ICdmFormElement parentElement){
2085
        TaxonRelationshipDetailElement element = new TaxonRelationshipDetailElement(this, parentElement);
2086
        addAndAdaptElement(parentElement, element);
2087
        return element;
2088
    }
2089

    
2090
    public GrantedAuthorityDetailElement createGrantedAuthorityDetailElement(ICdmFormElement parentElement){
2091
        GrantedAuthorityDetailElement element = new GrantedAuthorityDetailElement(this, parentElement);
2092
        addAndAdaptElement(parentElement, element);
2093
        return element;
2094
    }
2095

    
2096
    public GroupDetailElement createGroupDetailElement(ICdmFormElement parentElement){
2097
        GroupDetailElement element = new GroupDetailElement(this, parentElement);
2098
        addAndAdaptElement(parentElement, element);
2099
        return element;
2100
    }
2101

    
2102
    public UserDetailElement createUserDetailElement(ICdmFormElement parentElement){
2103
        UserDetailElement element = new UserDetailElement(this, parentElement);
2104
        addAndAdaptElement(parentElement, element);
2105
        return element;
2106
    }
2107

    
2108
    public HybridDetailElement createHybridDetailElement(ICdmFormElement parentElement){
2109
        HybridDetailElement element = new HybridDetailElement(this, parentElement);
2110
        addAndAdaptElement(parentElement, element);
2111
        return element;
2112
    }
2113

    
2114
    public InstitutionDetailElement createInstitutionDetailElement(ICdmFormElement parentElement){
2115
        InstitutionDetailElement element = new InstitutionDetailElement(this, parentElement);
2116
        addAndAdaptElement(parentElement, element);
2117
        return element;
2118
    }
2119

    
2120
    public PolytomousKeyNodeDetailElement createPolytomousKeyNodeDetailElement(ICdmFormElement parentElement){
2121
        PolytomousKeyNodeDetailElement element = new PolytomousKeyNodeDetailElement(this, parentElement);
2122
        addAndAdaptElement(parentElement, element);
2123
        return element;
2124
    }
2125

    
2126
    public PolytomousKeyDetailElement createPolytomousKeyDetailElement(ICdmFormElement parentElement){
2127
        PolytomousKeyDetailElement element = new PolytomousKeyDetailElement(this, parentElement);
2128
        addAndAdaptElement(parentElement, element);
2129
        return element;
2130
    }
2131

    
2132
    public CollectionDetailElement createCollectionDetailElement(ICdmFormElement parentElement){
2133
        CollectionDetailElement element = new CollectionDetailElement(this, parentElement);
2134
        addAndAdaptElement(parentElement, element);
2135
        return element;
2136
    }
2137

    
2138
    public TaxonNodeAgentRelationCollectionSection createTaxonNodeAgentRelationCollectionElement(ICdmFormElement parentElement, ConversationHolder conversation, int style){
2139
        TaxonNodeAgentRelationCollectionSection element = new TaxonNodeAgentRelationCollectionSection(this, conversation, parentElement, style);
2140
        adapt(element);
2141
        parentElement.addElement(element);
2142

    
2143
        return element;
2144
    }
2145

    
2146
    public TaxonNodeDetailElement createTaxonNodeDetailElement(ICdmFormElement parentElement, boolean createNew){
2147
        TaxonNodeDetailElement element = new TaxonNodeDetailElement(this, parentElement, createNew);
2148
        addAndAdaptElement(parentElement, element);
2149
        return element;
2150
    }
2151

    
2152
    public ClassificationDetailElement createClassificationDetailElement(ICdmFormElement parentElement){
2153
        ClassificationDetailElement element = new ClassificationDetailElement(this, parentElement);
2154
        addAndAdaptElement(parentElement, element);
2155
        return element;
2156
    }
2157

    
2158
    public CloneClassificationDetailElement createCloneClassificationDetailElement(ICdmFormElement parentElement){
2159
        CloneClassificationDetailElement element = new CloneClassificationDetailElement(this, parentElement);
2160
        addAndAdaptElement(parentElement, element);
2161
        return element;
2162
    }
2163

    
2164
    public FeatureDistributionDetailElement createFeatureDistributionDetailElement(ICdmFormElement parentElement){
2165
        FeatureDistributionDetailElement element = new FeatureDistributionDetailElement(this, parentElement);
2166
        addAndAdaptElement(parentElement, element);
2167
        return element;
2168
    }
2169

    
2170
    public NaturalLanguageDetailElement createNaturalLanguageDetailElement(ICdmFormElement parentElement){
2171
        NaturalLanguageDetailElement element = new NaturalLanguageDetailElement(this, parentElement);
2172
        addAndAdaptElement(parentElement, element);
2173
        return element;
2174
    }
2175

    
2176
    public NonViralNameDetailElement createNonViralNameDetailElement(ICdmFormElement parentElement){
2177
        NonViralNameDetailElement element = new NonViralNameDetailElement(this, parentElement);
2178
        addAndAdaptElement(parentElement, element);
2179
        return element;
2180
    }
2181

    
2182
    public DescriptionElementDetailElement createDescriptionElementDetailElement(ICdmFormElement parentElement, int style){
2183
        DescriptionElementDetailElement element = new DescriptionElementDetailElement(this, parentElement, style);
2184
        addAndAdaptElement(parentElement, element);
2185
        return element;
2186
    }
2187

    
2188
    public DescriptionDetailElement createDescriptionDetailElement(ICdmFormElement parentElement, int style){
2189
        DescriptionDetailElement element = new DescriptionDetailElement(this, parentElement, style);
2190
        addAndAdaptElement(parentElement, element);
2191
        return element;
2192
    }
2193

    
2194
    public PersonDetailElement createPersonDetailElement(ICdmFormElement parentElement, int style){
2195
        PersonDetailElement element = new PersonDetailElement(this, parentElement, style);
2196
        addAndAdaptElement(parentElement, element);
2197
        return element;
2198
    }
2199

    
2200
    public TeamDetailElement createTeamDetailElement(ICdmFormElement parentElement, int style, boolean isNomenclatural){
2201
        TeamDetailElement element = new TeamDetailElement(this, parentElement, style, isNomenclatural);
2202
        addAndAdaptElement(parentElement, element);
2203
        return element;
2204
    }
2205

    
2206
    public AuthorshipDetailElement createAuthorshipDetailElement(ICdmFormElement parentElement, int style){
2207
        AuthorshipDetailElement element = new AuthorshipDetailElement(this, parentElement, style);
2208
        addAndAdaptElement(parentElement, element);
2209
        return element;
2210
    }
2211

    
2212
    public TaxonBaseDetailElement createTaxonBaseDetailElement(ICdmFormElement parentElement, int style){
2213
        TaxonBaseDetailElement element = new TaxonBaseDetailElement(this, parentElement, style);
2214
        addAndAdaptElement(parentElement, element);
2215
        return element;
2216
    }
2217

    
2218
    public NameDetailElement createNameDetailElement(ICdmFormElement parentElement, int style){
2219
        NameDetailElement element = new NameDetailElement(this, parentElement, style);
2220
        addAndAdaptElement(parentElement, element);
2221
        return element;
2222
    }
2223

    
2224
    public ReferenceDetailElement createReferenceDetailElement(ICdmFormElement parentElement, int style, boolean isWizard){
2225
        ReferenceDetailElement element = new ReferenceDetailElement(this, parentElement, style, isWizard);
2226
        addAndAdaptElement(parentElement, element);
2227
        return element;
2228
    }
2229

    
2230
    public NomenclaturalReferenceDetailElement createNomenclaturalReferenceDetailElement(ICdmFormElement parentElement, int style){
2231
        NomenclaturalReferenceDetailElement element = new NomenclaturalReferenceDetailElement(this, parentElement, style);
2232
        addAndAdaptElement(parentElement, element);
2233
        return element;
2234
    }
2235

    
2236

    
2237
    public FieldUnitGeneralDetailElement createFieldUnitGeneralDetailElement(ICdmFormElement parentElement){
2238
        FieldUnitGeneralDetailElement element = new FieldUnitGeneralDetailElement(this, parentElement);
2239
        addAndAdaptElement(parentElement, element);
2240
        return element;
2241
    }
2242

    
2243
    public DerivedUnitGeneralDetailElement createDerivedUnitGeneralDetailElement(ICdmFormElement parentElement){
2244
        DerivedUnitGeneralDetailElement element = new DerivedUnitGeneralDetailElement(this, parentElement);
2245
        addAndAdaptElement(parentElement, element);
2246
        return element;
2247
    }
2248

    
2249
    public TaxonAssociationDetailElement createTaxonAssociationDetailElement(ICdmFormElement parentElement){
2250
        TaxonAssociationDetailElement element = new TaxonAssociationDetailElement(this, parentElement);
2251
        addAndAdaptElement(parentElement, element);
2252
        return element;
2253
    }
2254

    
2255
    public PreservedSpecimenGeneralDetailElement createPreservedSpecimenGeneralDetailElement(ICdmFormElement parentElement){
2256
        PreservedSpecimenGeneralDetailElement element = new PreservedSpecimenGeneralDetailElement(this, parentElement);
2257
        addAndAdaptElement(parentElement, element);
2258
        return element;
2259
    }
2260

    
2261
    public TissueSampleGeneralDetailElement createTissueSampleGeneralDetailElement(ICdmFormElement parentElement){
2262
        TissueSampleGeneralDetailElement element = new TissueSampleGeneralDetailElement(this, parentElement);
2263
        addAndAdaptElement(parentElement, element);
2264
        return element;
2265
    }
2266

    
2267
    public DnaSampleGeneralDetailElement createDnaSampleGeneralDetailElement(ICdmFormElement parentElement){
2268
        DnaSampleGeneralDetailElement element = new DnaSampleGeneralDetailElement(this, parentElement);
2269
        addAndAdaptElement(parentElement, element);
2270
        return element;
2271
    }
2272

    
2273
    public DnaSamplePreparationPreservationDetailElement createDnaSamplePreparationPreservationDetailElement(ICdmFormElement parentElement){
2274
        DnaSamplePreparationPreservationDetailElement element = new DnaSamplePreparationPreservationDetailElement(this, parentElement);
2275
        addAndAdaptElement(parentElement, element);
2276
        return element;
2277
    }
2278

    
2279
    public DnaQualityDetailElement createDnaQualityDetailElement(ICdmFormElement parentElement){
2280
        DnaQualityDetailElement element = new DnaQualityDetailElement(this, parentElement);
2281
        addAndAdaptElement(parentElement, element);
2282
        return element;
2283
    }
2284

    
2285
    public SequenceGeneralDetailElement createSequenceGeneralDetailElement(ICdmFormElement parentElement){
2286
        SequenceGeneralDetailElement element = new SequenceGeneralDetailElement(this, parentElement);
2287
        addAndAdaptElement(parentElement, element);
2288
        return element;
2289
    }
2290

    
2291
    public SingleReadGeneralDetailElement createSingleReadGeneralDetailElement(ICdmFormElement parentElement){
2292
        SingleReadGeneralDetailElement element = new SingleReadGeneralDetailElement(this, parentElement);
2293
        addAndAdaptElement(parentElement, element);
2294
        return element;
2295
    }
2296

    
2297
    public PrimerGeneralDetailElement createPrimerGeneralDetailElement(ICdmFormElement parentElement){
2298
        PrimerGeneralDetailElement element = new PrimerGeneralDetailElement(this, parentElement);
2299
        addAndAdaptElement(parentElement, element);
2300
        return element;
2301
    }
2302

    
2303
    public AmplificationGeneralDetailElement createAmplificationGeneralDetailElement(ICdmFormElement parentElement){
2304
        AmplificationGeneralDetailElement element = new AmplificationGeneralDetailElement(this, parentElement);
2305
        addAndAdaptElement(parentElement, element);
2306
        return element;
2307
    }
2308

    
2309
    public AmplificationPrimerDetailElement createAmplificationPrimerDetailElement(ICdmFormElement parentElement){
2310
        AmplificationPrimerDetailElement element = new AmplificationPrimerDetailElement(this, parentElement);
2311
        addAndAdaptElement(parentElement, element);
2312
        return element;
2313
    }
2314

    
2315
    public AmplificationCloningDetailElement createAmplificationCloningDetailElement(ICdmFormElement parentElement){
2316
        AmplificationCloningDetailElement element = new AmplificationCloningDetailElement(this, parentElement);
2317
        addAndAdaptElement(parentElement, element);
2318
        return element;
2319
    }
2320

    
2321
    public AmplificationGelPhotoDetailElement createAmplificationGelPhotoDetailElement(ICdmFormElement parentElement){
2322
        AmplificationGelPhotoDetailElement element = new AmplificationGelPhotoDetailElement(this, parentElement);
2323
        addAndAdaptElement(parentElement, element);
2324
        return element;
2325
    }
2326

    
2327
    public MediaSpecimenGeneralDetailElement createMediaSpecimenGeneralDetailElement(ICdmFormElement parentElement){
2328
        MediaSpecimenGeneralDetailElement element = new MediaSpecimenGeneralDetailElement(this, parentElement);
2329
        addAndAdaptElement(parentElement, element);
2330
        return element;
2331
    }
2332

    
2333
    public MediaDetailElement createMediaDetailElement(ICdmFormElement parentElement){
2334
        MediaDetailElement mediaDetailElement = new MediaDetailElement(this, parentElement);
2335
        addAndAdaptElement(parentElement, mediaDetailElement);
2336
        return mediaDetailElement;
2337
    }
2338

    
2339
    public GatheringEventDetailElement createGatheringEventDetailElement(ICdmFormElement parentElement) {
2340
        GatheringEventDetailElement element = new GatheringEventDetailElement(this, parentElement);
2341
        addAndAdaptElement(parentElement, element);
2342
        return element;
2343
    }
2344

    
2345
    public FieldUnitDetailElement createFieldUnitDetailElement(ICdmFormElement parentElement) {
2346
        FieldUnitDetailElement element = new FieldUnitDetailElement(this, parentElement);
2347
        addAndAdaptElement(parentElement, element);
2348
        return element;
2349
    }
2350

    
2351
    public DerivedUnitBaseDetailElement createDerivedUnitBaseDetailElement(ICdmFormElement parentElement) {
2352
        DerivedUnitBaseDetailElement element = new DerivedUnitBaseDetailElement(this, parentElement);
2353
        addAndAdaptElement(parentElement, element);
2354
        return element;
2355
    }
2356

    
2357
    public OriginalLabelDataElement createOriginalLabelDataElement(ICdmFormElement parentElement) {
2358
        OriginalLabelDataElement element = new OriginalLabelDataElement(this, parentElement);
2359
        addAndAdaptElement(parentElement, element);
2360
        return element;
2361
    }
2362

    
2363
    public PreservedSpecimenDetailElement createPreservedSpecimenDetailElement(ICdmFormElement parentElement) {
2364
        PreservedSpecimenDetailElement element = new PreservedSpecimenDetailElement(this, parentElement);
2365
        addAndAdaptElement(parentElement, element);
2366
        return element;
2367
    }
2368

    
2369
    public DeterminationDetailElement createDeterminationDetailElement(ICdmFormElement parentElement) {
2370
        DeterminationDetailElement element = new DeterminationDetailElement(this, parentElement);
2371
        addAndAdaptElement(parentElement, element);
2372
        return element;
2373
    }
2374

    
2375
    public SampleDesignationDetailElement createSampleDesignationDetailElement(ICdmFormElement parentElement) {
2376
        SampleDesignationDetailElement element = new SampleDesignationDetailElement(this, parentElement);
2377
        addAndAdaptElement(parentElement, element);
2378
        return element;
2379
    }
2380

    
2381
    /**
2382
     * @param parentElement
2383
     * @param element
2384
     */
2385
    private void addAndAdaptElement(ICdmFormElement parentElement, AbstractCdmDetailElement<?> element) {
2386
        adapt(element);
2387
        parentElement.addElement(element);
2388
    }
2389

    
2390
    //--------EntityCollectionSection----------
2391
    public TeamMemberSection createTeamMemberSection(ConversationHolder conversation, ICdmFormElement parentElement, int style, boolean isNomenclatural){
2392
        TeamMemberSection section = new TeamMemberSection(this, conversation, parentElement, style, isNomenclatural);
2393
        addAndAdaptSection(parentElement, section);
2394
        return section;
2395
    }
2396

    
2397
    public InapplicableIfEntityCollectionSection createInapplicableIfEntityCollectionSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2398
        InapplicableIfEntityCollectionSection section = new InapplicableIfEntityCollectionSection(this, conversation, parentElement, style);
2399
        addAndAdaptSection(parentElement, section);
2400
        return section;
2401
    }
2402

    
2403
    public OnlyApplicableIfEntityCollectionSection createOnlyApplicableIfEntityCollectionSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2404
        OnlyApplicableIfEntityCollectionSection section = new OnlyApplicableIfEntityCollectionSection(this, conversation, parentElement, style);
2405
        addAndAdaptSection(parentElement, section);
2406
        return section;
2407
    }
2408

    
2409
    public AnnotationSection createAnnotationSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2410
        AnnotationSection section = new AnnotationSection(this, conversation, parentElement, style);
2411
        addAndAdaptSection(parentElement, section);
2412
        return section;
2413
    }
2414

    
2415
    public CreditSection createCreditSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2416
        CreditSection section = new CreditSection(this, conversation, parentElement, style);
2417
        addAndAdaptSection(parentElement, section);
2418
        return section;
2419
    }
2420

    
2421
    public DescriptionElementSourceSection createDescriptionElementSourceSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2422
        DescriptionElementSourceSection section = new DescriptionElementSourceSection(this, conversation, parentElement, style);
2423
        addAndAdaptSection(parentElement, section);
2424
        return section;
2425
    }
2426

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

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

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

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

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

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

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

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

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

    
2481
    public ProtologueSection createProtologueSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2482
        ProtologueSection section = new ProtologueSection(this, conversation, parentElement, style);
2483
        addAndAdaptSection(parentElement, section);
2484
        return section;
2485
    }
2486
    public ExternalLinksSection createExternalLinksSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2487
        ExternalLinksSection section = new ExternalLinksSection(this, conversation, parentElement, style);
2488
        addAndAdaptSection(parentElement, section);
2489
        return section;
2490
    }
2491

    
2492
    public RightsSection createRightsSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2493
        RightsSection section = new RightsSection(this, conversation, parentElement, style);
2494
        addAndAdaptSection(parentElement, section);
2495
        return section;
2496
    }
2497

    
2498
    public SourceSection createSourceSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2499
        SourceSection section = new SourceSection(this, conversation, parentElement, style);
2500
        addAndAdaptSection(parentElement, section);
2501
        return section;
2502
    }
2503

    
2504
    public ScopeSection createScopeSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2505
        ScopeSection section = new ScopeSection(this, conversation, parentElement, style);
2506
        addAndAdaptSection(parentElement, section);
2507
        return section;
2508
    }
2509

    
2510
    public DescriptionSourceSection createDescriptionSourceSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2511
        DescriptionSourceSection section = new DescriptionSourceSection(this, conversation, parentElement, style);
2512
        addAndAdaptSection(parentElement, section);
2513
        return section;
2514
    }
2515

    
2516
    public TypeDesignationSection createTypeDesignationSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2517
        TypeDesignationSection section = new TypeDesignationSection(this, conversation, parentElement, style);
2518
        addAndAdaptSection(parentElement, section);
2519
        return section;
2520
    }
2521

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2672

    
2673
    public AbstractEntityCollectionElement createEntityCollectionElement(AbstractFormSection parentElement,
2674
            Object versionableEntity, SelectionListener removeListener, Color backgroundColor, int style) {
2675
        AbstractEntityCollectionElement<?> element = null;
2676

    
2677
        Object entity = HibernateProxyHelper.deproxy(versionableEntity);
2678

    
2679
        if (entity instanceof Annotation) {
2680
            element = new AnnotationElement(this, parentElement, (Annotation) entity, removeListener, style);
2681
        }else if (entity instanceof Person ) {
2682
            boolean isNomenclatural = false;
2683
            if (parentElement instanceof TeamMemberSection){
2684
                isNomenclatural = ((TeamMemberSection) parentElement).isNomenclaturalTeam();
2685
            }
2686
            element = new TeamMemberElement(this, parentElement, (Person) entity, removeListener, style, isNomenclatural);
2687
        } else if (entity instanceof Credit) {
2688
            element = new CreditElement(this, parentElement, (Credit) entity, removeListener, style);
2689
        } else if (entity instanceof Extension) {
2690
            element = new ExtensionElement(this, parentElement, (Extension) entity, removeListener, style);
2691
        } else if (entity instanceof ExternalLink) {
2692
            element = new ExternalLinksElement(this, parentElement, (ExternalLink) entity, removeListener, style);
2693
        } else if (entity instanceof Marker) {
2694
            element = new MarkerElement(this, parentElement, (Marker) entity, removeListener, style);
2695
        } else if (entity instanceof TaxonNodeAgentRelation) {
2696
            element = new TaxonNodeAgentRelationCollectionElement(this, parentElement, (TaxonNodeAgentRelation) entity, removeListener, backgroundColor, style);
2697
        }else if (entity instanceof Media) {
2698
            element = new MediaMetaElement(this, parentElement, (Media) entity, removeListener, style);
2699
        } else if (entity instanceof MediaRepresentation) {
2700
            element = new MediaRepresentationElement(this, parentElement, (MediaRepresentation) entity, removeListener,
2701
                    style);
2702
        } else if (entity instanceof ImageFile) {
2703
            element = new ImageFileElement(this, parentElement, (ImageFile) entity, removeListener, style);
2704
        } else if (entity instanceof MediaRepresentationPart) {
2705
            element = new MediaRepresentationPartElement<>(this, parentElement, (MediaRepresentationPart) entity,
2706
                    removeListener, style);
2707
        } else if (entity instanceof NomenclaturalStatus) {
2708
            element = new NomenclaturalStatusElement(this, parentElement, (NomenclaturalStatus) entity, removeListener,
2709
                    style);
2710
        } else if (entity instanceof Rights) {
2711
            element = new RightsElement(this, parentElement, (Rights) entity, removeListener, style);
2712
        } else if (entity instanceof DescriptionElementSource && parentElement.getEntity() instanceof CommonTaxonName) {
2713
            element = new CommonNameSourceElement(this, parentElement, (DescriptionElementSource) entity,
2714
                    removeListener, style);
2715
        } else if (entity instanceof DescriptionElementSource) {
2716
            element = new DescriptionElementSourceElement(this, parentElement, (DescriptionElementSource) entity,
2717
                    removeListener, style, false);
2718
        } else if (entity instanceof TaxonNodeAgentRelation) {
2719
            element = new TaxonNodeAgentRelationCollectionElement(this, parentElement, (TaxonNodeAgentRelation) entity,
2720
                    removeListener,backgroundColor, style);
2721
        }
2722
        else if (entity instanceof IdentifiableSource) {
2723
            element = new IdentifiableSourceElement(this, parentElement, (IdentifiableSource) entity, removeListener,
2724
                    style);
2725
        } else if (entity instanceof DefinedTerm) {
2726
            switch(((DefinedTerm)entity).getTermType()) {
2727
            case Scope:
2728
                element = new ScopeElement(this,
2729
                        parentElement,
2730
                        (DefinedTerm) entity,
2731
                        removeListener,
2732
                        style);
2733
                break;
2734
            case Modifier:
2735
                element = new ModifierElement(this,
2736
                        parentElement,
2737
                        (DefinedTerm) entity,
2738
                        removeListener,
2739
                        style);
2740
                break;
2741
            default:
2742
                break;
2743

    
2744
            }
2745
        } else if (entity instanceof Reference) {
2746
            if(parentElement instanceof SequenceReferenceCollectionDetailSection){
2747
                element = new SequenceReferenceCollectionDetailElement(this, parentElement, (Reference) entity, removeListener, style);
2748
            }
2749
            else{
2750
                element = new DescriptionSourceElement(this, parentElement, (Reference) entity, removeListener, style);
2751
            }
2752
        } else if (entity instanceof NameTypeDesignation) {
2753
            element = new NameTypeDesignationElement(this, parentElement, (NameTypeDesignation) entity, removeListener,
2754
                    style);
2755
        } else if (entity instanceof NameRelationship) {
2756
            element = new NameRelationshipDetailElement(this, parentElement, (NameRelationship) entity, removeListener,
2757
                    style);
2758
        } else if (entity instanceof SpecimenTypeDesignation) {
2759
            if(parentElement instanceof DerivedUnitTypeDesignationSection){
2760
                element = new DerivedUnitTypeDesignationElement(this, parentElement, (SpecimenTypeDesignation) entity,
2761
                        removeListener, style);
2762
            }
2763
            else{
2764
                element = new SpecimenTypeDesignationElement(this, parentElement, (SpecimenTypeDesignation) entity,
2765
                        removeListener, style);
2766
            }
2767
        } else if (entity instanceof StateData) {
2768
            element = new StateDataElement(this, parentElement, (StateData) entity, removeListener, style);
2769
        } else if (entity instanceof StatisticalMeasurementValue) {
2770
            element = new StatisticalMeasurementValueElement(this, parentElement, (StatisticalMeasurementValue) entity,
2771
                    removeListener, style);
2772
        } else if (entity instanceof DerivedUnit) {
2773
            switch(((DerivedUnit)entity).getRecordBasis()) {
2774
            case LivingSpecimen:
2775
            case PreservedSpecimen:
2776
            case OtherSpecimen:
2777
                element = new SpecimenCollectionDetailElement(this,
2778
                        parentElement,
2779
                        (DerivedUnit) entity,
2780
                        removeListener,
2781
                        style);
2782
                break;
2783
            default:
2784
                element = new DerivedUnitElement(this,
2785
                        parentElement,
2786
                        (DerivedUnit) entity,
2787
                        removeListener,
2788
                        style);
2789
            }
2790

    
2791
        } else if (entity instanceof NamedArea) {
2792
            element = new CollectingAreaDetailElement(this, parentElement, (NamedArea) entity, removeListener, style);
2793
        } else if (entity instanceof DeterminationEvent) {
2794
            element = new DeterminationEventDetailElement(this, parentElement, (DeterminationEvent) entity, removeListener, style);
2795
        } else if (entity instanceof User) {
2796
            element = new MemberDetailElement(this, parentElement, (User) entity, removeListener, style);
2797
        } else if (entity instanceof GrantedAuthority) {
2798
            element = new GrantedAuthorityCollectionElement(this, parentElement, (GrantedAuthorityImpl) entity, ((Group)parentElement.getEntity()),
2799
                    removeListener, style);
2800
        } else if (entity instanceof Group) {
2801
            element = new GroupsByUserDetailElement(this, parentElement, (Group) entity, removeListener, style);
2802
        } else if (entity instanceof Taxon) {
2803
            element = new TaxonDetailElement(this, parentElement, (Taxon) entity, removeListener, style);
2804
        } else if (entity instanceof DescriptionElementBase) {
2805
            // this is the special case for protologs, maybe we can do this
2806
            // differently when API improves
2807
            DescriptionElementBase descriptionElement = (DescriptionElementBase) entity;
2808
            if (descriptionElement.getFeature().equals(Feature.PROTOLOGUE())) {
2809
                element = new ProtologueElement(this, parentElement, descriptionElement, removeListener, style);
2810
            }
2811
        } else if (entity instanceof Identifier) {
2812
            if(parentElement instanceof AbstractSampleDesignationDetailSection){
2813
                element = new SampleDesignationTextDetailElement(this, parentElement, (Identifier<DnaSample>) entity, removeListener, backgroundColor, style);
2814
            }
2815
            else{
2816
                element = new IdentifierElement(this, parentElement, (Identifier) entity, removeListener, style);
2817
            }
2818
        } else if (entity instanceof TermVocabulary) {
2819
            TermVocabulary<?> termVocabulary = (TermVocabulary<?>)entity;
2820
            switch (termVocabulary.getTermType()) {
2821
            case State:
2822
                element = new StateVocabularyCollectionElement(this, parentElement, (TermVocabulary<State>) entity, removeListener, backgroundColor, style);
2823
                break;
2824
            case Modifier:
2825
                element = new RecommendedModifierVocabulariesElement(this, parentElement, (TermVocabulary<DefinedTerm>) entity, removeListener, backgroundColor, style);
2826
                break;
2827
            default:
2828
                break;
2829
            }
2830
        } else if (entity instanceof MeasurementUnit) {
2831
            element = new MeasurementUnitCollectionElement(this, parentElement, (MeasurementUnit) entity, removeListener, backgroundColor, style);
2832
        } else if (entity instanceof StatisticalMeasure) {
2833
            element = new StatisticalMeasureCollectionElement(this, parentElement, (StatisticalMeasure) entity, removeListener, backgroundColor, style);
2834
        } else if (entity instanceof State && parentElement instanceof InapplicableIfEntityCollectionSection) {
2835
            element = new InapplicableIfCollectionElement(this, parentElement, (State) entity, removeListener, backgroundColor, style);
2836
        } else if (entity instanceof State && parentElement instanceof OnlyApplicableIfEntityCollectionSection) {
2837
            element = new OnlyApplicableIfCollectionElement(this, parentElement, (State) entity, removeListener, backgroundColor, style);
2838
        }
2839

    
2840
        //check for parent section when entity is null
2841
        //this happens when AbstractUnboundEntityCollectionSection is used
2842
        if(element==null){
2843
            if(parentElement instanceof ScopeSection || parentElement instanceof ScopeRestrictionSection){
2844
                element = new ScopeElement(this,
2845
                        parentElement,
2846
                        (DefinedTerm) entity,
2847
                        removeListener,
2848
                        style);
2849
            }
2850
            else if(parentElement instanceof ModifierSection){
2851
                element = new ModifierElement(this,
2852
                        parentElement,
2853
                        (DefinedTerm) entity,
2854
                        removeListener,
2855
                        style);
2856
            }
2857
        }
2858

    
2859

    
2860
        if (element == null) {
2861
            MessagingUtils.messageDialog(
2862
                    String.format("Error when creating section %s",
2863
                            parentElement.getClass().getSimpleName()),
2864
                    this,
2865
                    String.format("Could not generate collection element for entity of class %s."
2866
                            + " Looks like the case is not yet handled. Check implementation.\n"
2867
                            + "Entity: %s", entity.getClass(), entity.toString()), null);
2868
        }
2869

    
2870
        else{
2871
            if (backgroundColor != null && !backgroundColor.isDisposed()) {
2872
                element.setPersistentBackground(backgroundColor);
2873
            }
2874
            adapt(element);
2875
            parentElement.addElement(element);
2876
        }
2877

    
2878
        return element;
2879
    }
2880

    
2881
    /**
2882
     * <p>
2883
     * Creates a selection element for the given type T.
2884
     * </p>
2885
     * <p>
2886
     * <strong>Selection elements not handled by this method:</strong>
2887
     * <ul>
2888
     * <li>{@link TaxonNodeSelectionElement} see
2889
     * {@link #createTaxonNodeSelectionElement(ConversationHolder, ICdmFormElement, String, TaxonNode, int, int)}
2890
     * </li>
2891
     * <li>{@link NomenclaturalAuthorTeamSelectionElement} see
2892
     * {@link #createNomenclaturalAuthorTeamSelectionElement(ConversationHolder, ICdmFormElement, String, Team, int, int)}
2893
     * </li>
2894
     * </ul>
2895
     * </p>
2896
     *
2897
     * @param clazz
2898
     *            a {@link Class} object of the type that you want the selection
2899
     *            element to handle
2900
     * @param parentElement
2901
     *            a {@link ICdmFormElement} object.
2902
     * @param labelString
2903
     *            a {@link String} object.
2904
     * @param selectionType
2905
     * @param selection
2906
     *            a {@link ICdmBase} object.
2907
     * @param style
2908
     *            a int.
2909
     * @param conversation
2910
     *            a {@link ConversationHolder} object.
2911
     * @return a {@link EntitySelectionElement} object.
2912
     */
2913
    public <T extends CdmBase> EntitySelectionElement<T> createSelectionElement(Class<T> clazz,
2914
            ConversationHolder conversation, ICdmFormElement parentElement, String labelString, T selection, int mode,
2915
            int style, boolean filterElement) {
2916
        EntitySelectionElement<T> element = new EntitySelectionElement<T>(this, //conversation,
2917
                parentElement, clazz,
2918
                labelString, selection, mode, style, filterElement);
2919
        adapt(element);
2920
        parentElement.addElement(element);
2921
        return element;
2922
    }
2923

    
2924
    public <T extends CdmBase> EntitySelectionElement<T> createSelectionElement(Class<T> clazz,
2925
//            ConversationHolder conversation,
2926
            ICdmFormElement parentElement, String labelString, T selection, int mode,
2927
            int style) {
2928
        EntitySelectionElement<T> element = new EntitySelectionElement<T>(this,
2929
                parentElement, clazz,
2930
                labelString, selection, mode, style);
2931
        adapt(element);
2932
        parentElement.addElement(element);
2933
        return element;
2934
    }
2935

    
2936
    public CommonNameReferenceSelectionElement createCommonNameReferenceSelectionElement(ICdmFormElement parentElement, String labelString, Reference selection, int mode,
2937
          int style) {
2938
        CommonNameReferenceSelectionElement element = new CommonNameReferenceSelectionElement(this,
2939
              parentElement, labelString, selection, mode, style);
2940
      adapt(element);
2941
      parentElement.addElement(element);
2942
      return element;
2943
  }
2944

    
2945
    /**
2946
     * <p>
2947
     * Creates a selection element for the given type T which shows only the <b>abbreviated</b> title as the label.
2948
     * </p>
2949
     * <p>
2950
     * <strong>Selection elements not handled by this method:</strong>
2951
     * <ul>
2952
     * <li>{@link TaxonNodeSelectionElement} see
2953
     * {@link #createTaxonNodeSelectionElement(ConversationHolder, ICdmFormElement, String, TaxonNode, int, int)}
2954
     * </li>
2955
     * <li>{@link NomenclaturalAuthorTeamSelectionElement} see
2956
     * {@link #createNomenclaturalAuthorTeamSelectionElement(ConversationHolder, ICdmFormElement, String, Team, int, int)}
2957
     * </li>
2958
     * </ul>
2959
     * </p>
2960
     *
2961
     * @param clazz
2962
     *            a {@link Class} object of the type that you want the selection
2963
     *            element to handle
2964
     * @param parentElement
2965
     *            a {@link ICdmFormElement} object.
2966
     * @param labelString
2967
     *            a {@link String} object.
2968
     * @param selectionType
2969
     * @param selection
2970
     *            a {@link ICdmBase} object.
2971
     * @param style
2972
     *            a int.
2973
     * @param conversation
2974
     *            a {@link ConversationHolder} object.
2975
     * @return a {@link EntitySelectionElement} object.
2976
     */
2977
    public <T extends CdmBase> EntitySelectionElementWithAbbreviatedTitle<T> createSelectionElementWithAbbreviatedTitle(
2978
            Class<T> clazz, ConversationHolder conversation, ICdmFormElement parentElement, String labelString,
2979
            T selection, int mode, int style) {
2980
        EntitySelectionElementWithAbbreviatedTitle<T> element = new EntitySelectionElementWithAbbreviatedTitle<T>(this, //conversation,
2981
                parentElement, clazz,
2982
                labelString, selection, mode, style);
2983
        adapt(element);
2984
        parentElement.addElement(element);
2985
        return element;
2986
    }
2987

    
2988
    public TaxonNodeSelectionElement createTaxonNodeSelectionElement(ConversationHolder conversation,
2989
            ICdmFormElement parentElement, String labelString, TaxonNode selection, int mode, int style) {
2990
        TaxonNodeSelectionElement element = new TaxonNodeSelectionElement(this, //conversation,
2991
                parentElement,
2992
                labelString, selection, mode, style);
2993
        adapt(element);
2994
        parentElement.addElement(element);
2995
        return element;
2996
    }
2997

    
2998

    
2999

    
3000
//    public NomenclaturalAuthorTeamSelectionElement createNomenclaturalAuthorTeamSelectionElement(
3001
//            ConversationHolder conversation, ICdmFormElement parentElement, String labelString, Team selection,
3002
//            int mode, int style) {
3003
//        NomenclaturalAuthorTeamSelectionElement element = new NomenclaturalAuthorTeamSelectionElement(this,
3004
//                conversation, parentElement, labelString, selection, mode, style);
3005
//        adapt(element);
3006
//        parentElement.addElement(element);
3007
//        return element;
3008
//    }
3009

    
3010
    /** {@inheritDoc} */
3011
    public LabelElement createLabel(ICdmFormElement parentElement, String text) {
3012
        LabelElement labelElement = new LabelElement(this, parentElement, text);
3013
        adapt(labelElement);
3014
        parentElement.addElement(labelElement);
3015
        return labelElement;
3016
    }
3017

    
3018

    
3019

    
3020
//    public DateElementFormElement createDateElementForm(ICdmFormElement formElement, String labelText, DateTime dateTime, int style){
3021
//        Label label = new Label(formElement.getLayoutComposite(), style);
3022
//        label.setText(labelText+" (yyyy-MM-dd)");
3023
//        DateElementFormElement dateElement = new DateElementFormElement(this, dateTime, style, formElement.getLayoutComposite());
3024
//        dateElement.initInternalController();
3025
//
3026
//        return dateElement;
3027
//    }
3028

    
3029
    public DateElement createDateElement(ICdmFormElement formElement, String labelText, DateTime dateTime, int style, boolean editableText){
3030
    	 Label label = new Label(formElement.getLayoutComposite(), style);
3031
         label.setText(labelText);
3032
         label.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE, 1, 1));
3033
         DateElement dateElement = new DateElement(formElement.getLayoutComposite(), dateTime, labelText, style, editableText);
3034
         dateElement.initController(this, formElement);
3035
         dateElement.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE, 1, 1));
3036
         return dateElement;
3037
    }
3038

    
3039
    /**
3040
     * <p>
3041
     * Getter for the field <code>selectionProvider</code>.
3042
     * </p>
3043
     *
3044
     * @return a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
3045
     */
3046
    public ISelectionProvider getSelectionProvider() {
3047
        return selectionProvider;
3048
    }
3049

    
3050
    /**
3051
     * <p>
3052
     * createDetailedDescriptionDetailElement
3053
     * </p>
3054
     *
3055
     * @param parentElement
3056
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
3057
     *            object.
3058
     * @param entity
3059
     *            a
3060
     *            {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase}
3061
     *            object.
3062
     * @param style
3063
     *            a int.
3064
     * @return a
3065
     *         {@link eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement}
3066
     *         object.
3067
     */
3068
    public AbstractDetailedDescriptionDetailElement createDetailedDescriptionDetailElement(
3069
            ICdmFormElement parentElement, DescriptionElementBase entity, int style, boolean enabled) {
3070
        AbstractDetailedDescriptionDetailElement detailedDescriptionElement = null;
3071

    
3072
        if (entity instanceof CategoricalData) {
3073
            detailedDescriptionElement = new CategoricalDataDetailElement(this, parentElement,
3074
                    (CategoricalData) entity, style);
3075
        } else if (entity instanceof CommonTaxonName) {
3076
            detailedDescriptionElement = new CommonNameDetailElement(this, parentElement, (CommonTaxonName) entity,
3077
                    style);
3078
        } else if (entity instanceof Distribution && !enabled) {
3079
            detailedDescriptionElement = new DistributionDetailElement(this, parentElement, (Distribution) entity,
3080
                    enabled, style);
3081
        } else if (entity instanceof Distribution) {
3082
            detailedDescriptionElement = new DistributionDetailElement(this, parentElement, (Distribution) entity,
3083
                    true, style);
3084
        }else if (entity instanceof IndividualsAssociation) {
3085
            detailedDescriptionElement = new IndividualsAssociationDetailElement(this, parentElement,
3086
                    (IndividualsAssociation) entity, style);
3087
        } else if (entity instanceof QuantitativeData) {
3088
            detailedDescriptionElement = new QuantitativeDataDetailElement(this, parentElement,
3089
                    (QuantitativeData) entity, style);
3090
        } else if (entity instanceof TaxonInteraction) {
3091
            detailedDescriptionElement = new TaxonInteractionDetailElement(this, parentElement,
3092
                    (TaxonInteraction) entity, style);
3093
        } else if (entity instanceof TextData) {
3094
            detailedDescriptionElement = new TextDataDetailElement(this, parentElement, (TextData) entity, style);
3095
        } else {
3096
            throw new IllegalStateException("There is no interface for the given description element");
3097
        }
3098
        adapt(detailedDescriptionElement);
3099
        parentElement.addElement(detailedDescriptionElement);
3100
        return detailedDescriptionElement;
3101

    
3102
    }
3103

    
3104
    /**
3105
     * Creates a styled text as a part of the form.
3106
     *
3107
     * @param parent
3108
     *            the text parent
3109
     * @param value
3110
     *            the text initial value
3111
     * @param style
3112
     *            the text style
3113
     * @return the text widget
3114
     */
3115
    public StyledText createStyledText(Composite parent, String value, int style) {
3116
        StyledText text = new StyledText(parent, getBorderStyle() | style | getOrientation());
3117
        if (value != null) {
3118
            text.setText(value);
3119
        }
3120
        text.setForeground(getColors().getForeground());
3121
        text.setBackground(getColors().getBackground());
3122
        // text.addFocusListener(visibilityHandler);
3123
        return text;
3124
    }
3125

    
3126
    public PreservedSpecimenDetailSection createPreservedSpecimenDetailsSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
3127
        PreservedSpecimenDetailSection section = new PreservedSpecimenDetailSection(this, conversation, parentElement, selectionProvider, style);
3128
        addAndAdaptSection(parentElement, section);
3129
        return section;
3130
    }
3131

    
3132
    /**
3133
     * @param formElement
3134
     * @param conversationHolder
3135
     * @param style
3136
     * @return
3137
     */
3138
    public TaxonNodeAgentRelationCollectionSection createTaxonNodeAgentRelationCollectionSection(
3139
            ICdmFormElement formElement, ConversationHolder conversationHolder, int style) {
3140
        TaxonNodeAgentRelationCollectionSection section = new TaxonNodeAgentRelationCollectionSection(this, conversationHolder, formElement, style);
3141
        addAndAdaptSection(formElement, section);
3142
        return section;
3143
    }
3144

    
3145

    
3146
	public TaxonOfRelationshipElement createTaxonOfRelationshipDetailElement(
3147
			ICdmFormElement parentElement, int style) {
3148
		TaxonOfRelationshipElement section = new TaxonOfRelationshipElement(this, parentElement, style);
3149
		addAndAdaptElement(parentElement, section);
3150
        return section;
3151
	}
3152

    
3153
	public TaxonDetailSection createTaxonDetailSection(ConversationHolder conversationHolder,
3154
			ICdmFormElement formElement, ISelectionProvider selectionProvider, int style) {
3155
			TaxonDetailSection section = new TaxonDetailSection(this, conversationHolder, formElement, selectionProvider, style);
3156
	        addAndAdaptSection(formElement, section);
3157
	        return section;
3158
	}
3159

    
3160

    
3161

    
3162

    
3163

    
3164
//	public RichTextWithLabelElement createRichTextLabelElement(ICdmFormElement parentElement, String labelString, String initialText, int textHeight, int style) {
3165
//		 RichTextWithLabelElement element = new RichTextWithLabelElement(this, parentElement, labelString,
3166
//				 initialText, textHeight, style);
3167
//	        adapt(element);
3168
//	        parentElement.addElement(element);
3169
//	        return element;
3170
//	}
3171

    
3172

    
3173

    
3174

    
3175

    
3176

    
3177

    
3178
}
(7-7/48)