Project

General

Profile

Download (157 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.events.ExpansionAdapter;
42
import org.eclipse.ui.forms.events.ExpansionEvent;
43
import org.eclipse.ui.forms.widgets.ExpandableComposite;
44
import org.eclipse.ui.forms.widgets.FormToolkit;
45
import org.eclipse.ui.forms.widgets.Section;
46
import org.eclipse.ui.forms.widgets.TableWrapData;
47
import org.eclipse.ui.internal.forms.widgets.FormFonts;
48
import org.joda.time.DateTime;
49
import org.joda.time.Partial;
50
import org.springframework.security.core.GrantedAuthority;
51

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

    
377
/**
378
 * <p>
379
 * CdmFormFactory class.
380
 * </p>
381
 *
382
 * @author n.hoffmann
383
 * @created Feb 24, 2010
384
 */
385
public class CdmFormFactory extends FormToolkit {
386

    
387
    private BoldFontHolder2 boldFontHolder2;
388
    private MouseListener selectionMouseHandler;
389
    private FocusListener selectionFocusHandler;
390

    
391
    @Inject
392
    private IEclipseContext context;
393

    
394
    private final Set<SelectionListener> selectionListenerList = new HashSet<SelectionListener>();
395

    
396
    private final List<IPropertyChangeListener> propertyChangeListeners = new ArrayList<IPropertyChangeListener>();
397

    
398
    private final int orientation = Window.getDefaultOrientation();
399
    private ISelectionProvider selectionProvider;
400

    
401
    /** Constant <code>EMPTY_SELECTION</code> */
402
    public static ISelection EMPTY_SELECTION = new ISelection() {
403
        @Override
404
        public boolean isEmpty() {
405
            return true;
406
        }
407
    };
408

    
409
    /**
410
     *
411
     * @author n.hoffmann
412
     * @date Jan 25, 2010
413
     *
414
     */
415
    private class SelectionMouseHandler extends MouseAdapter {
416
        @Override
417
        public void mouseDown(MouseEvent e) {
418
            notifySelectionListeners(e);
419
        }
420
    }
421

    
422
    /**
423
     *
424
     * @author n.hoffmann
425
     * @date Jan 25, 2010
426
     *
427
     */
428
    private class SelectionFocusHandler extends FocusAdapter {
429
        @Override
430
        public void focusGained(FocusEvent e) {
431
            notifySelectionListeners(e);
432
        }
433
    }
434

    
435
    private void notifySelectionListeners(TypedEvent e) {
436
        Event event = new Event();
437
        event.widget = e.widget;
438
        SelectionEvent selectionEvent = new SelectionEvent(event);
439

    
440
        for (SelectionListener listener : selectionListenerList) {
441
            listener.widgetSelected(selectionEvent);
442
        }
443
    }
444

    
445
    public CdmFormFactory(Display display) {
446
        this(display, null);
447
    }
448

    
449
    public CdmFormFactory(Display display, ISelectionProvider selectionProvider) {
450
        super(display);
451
        this.selectionProvider = selectionProvider;
452
        init();
453
    }
454

    
455
    private void init() {
456
        boldFontHolder2 = new BoldFontHolder2();
457
        selectionMouseHandler = new SelectionMouseHandler();
458
        selectionFocusHandler = new SelectionFocusHandler();
459
    }
460

    
461
    public IEclipseContext getContext() {
462
        return context;
463
    }
464

    
465
    /**
466
     * Creates an instance initialized with the correct selectionProvider
467
     *
468
     * Make sure to remove the instance when the entityComposite disposes via
469
     * destroySelectionArbitrator(..)
470
     *
471
     * @param entityElement
472
     *            a {@link eu.etaxonomy.taxeditor.ui.element.IEntityElement}
473
     *            object.
474
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator}
475
     *         object.
476
     */
477
    public SelectionArbitrator createSelectionArbitrator(IEntityElement entityElement) {
478
        SelectionArbitrator selectionArbitrator = new SelectionArbitrator(entityElement);
479
        selectionArbitrator.addSelectionProvider(selectionProvider);
480
        selectionProvider.addSelectionChangedListener(selectionArbitrator);
481
        addSelectionListener(selectionArbitrator);
482
        return selectionArbitrator;
483
    }
484

    
485
    /**
486
     * <p>
487
     * destroySelectionArbitrator
488
     * </p>
489
     *
490
     * @param selectionArbitrator
491
     *            a
492
     *            {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator}
493
     *            object.
494
     */
495
    public void destroySelectionArbitrator(SelectionArbitrator selectionArbitrator) {
496
        if(selectionArbitrator==null){
497
            return;
498
        }
499
        removeSelectionListener(selectionArbitrator);
500
        if (selectionProvider != null) {
501
            selectionProvider.removeSelectionChangedListener(selectionArbitrator);
502
        } else {
503
            MessagingUtils.error(this.getClass(),
504
                    "Tried to destroy a selection listener from this factories listeners but was null", null);
505
        }
506
    }
507

    
508
    /**
509
     * <p>
510
     * Adapts the {@link AbstractCdmFormElement}:<br>
511
     * - sets the {@link IPropertyChangeListener}s handled by this class
512
     * </p>
513
     *
514
     * @param formElement
515
     *            a
516
     *            {@link eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement}
517
     *            object.
518
     */
519
    public void adapt(ICdmFormElement formElement) {
520
        formElement.setPropertyChangeListeners(propertyChangeListeners);
521
    }
522

    
523
    /** {@inheritDoc} */
524
    @Override
525
    public void adapt(Control control, boolean trackFocus, boolean trackKeyboard) {
526
        if (trackFocus) {
527
            control.addFocusListener(selectionFocusHandler);
528
        }
529
        super.adapt(control, trackFocus, trackKeyboard);
530
    }
531

    
532
    /** {@inheritDoc} */
533
    @Override
534
    public void adapt(Composite composite) {
535
        composite.addMouseListener(selectionMouseHandler);
536

    
537
        super.adapt(composite);
538
    }
539

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

    
583
    /**
584
     * <p>
585
     * createEmptyCell
586
     * </p>
587
     *
588
     * @param parent
589
     *            a {@link org.eclipse.swt.widgets.Composite} object.
590
     * @return a {@link org.eclipse.swt.widgets.Label} object.
591
     */
592
    public Label createEmptyCell(Composite parent) {
593
        return this.createLabel(parent, null);
594
    }
595

    
596
    /**
597
     * <p>
598
     * createMultiLanguageTextElement
599
     * </p>
600
     *
601
     * @param parentElement
602
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
603
     *            object.
604
     * @param labelString
605
     *            a {@link java.lang.String} object.
606
     * @param multilanguageText
607
     *            a {@link java.util.Map} object.
608
     * @param textHeight
609
     *            a int.
610
     * @param style
611
     *            a int.
612
     * @return a
613
     *         {@link eu.etaxonomy.taxeditor.ui.element.MultilanguageTextElement}
614
     *         object.
615
     */
616
    public MultilanguageTextElement createMultiLanguageTextElement(ICdmFormElement parentElement, String labelString,
617
            Map<Language, LanguageString> multilanguageText, int textHeight, int style) {
618
        MultilanguageTextElement element = new MultilanguageTextElement(this, parentElement, labelString,
619
                multilanguageText, textHeight, style);
620
        adapt(element);
621
        parentElement.addElement(element);
622
        return element;
623
    }
624

    
625
    /**
626
     * <p>
627
     * createMultiLanguageTextElement
628
     * </p>
629
     *
630
     * @param parentElement
631
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
632
     *            object.
633
     *
634
     * @param Representation
635
     *            a {@link eu.etaxonomy.cdm.model.term.Representation} object.
636
     * @param textHeight
637
     *            a int.
638
     * @param style
639
     *            a int.
640
     * @return a
641
     *         {@link eu.etaxonomy.taxeditor.ui.element.RepresentationElement}
642
     *         object.
643
     */
644
    public RepresentationElement createRepresentationElement(ICdmFormElement parentElement, Representation representation, TermBase term,int textHeight, int style, boolean fillDetails) {
645
        RepresentationElement element = new RepresentationElement(this, parentElement, representation, term, textHeight, style, fillDetails);
646
        adapt(element);
647
        parentElement.addElement(element);
648
        return element;
649
    }
650

    
651
    /**
652
     * <p>
653
     * createMultiLanguageTextElement
654
     * </p>
655
     *
656
     * @param parentElement
657
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
658
     *            object.
659
     *
660
     * @param Representation
661
     *            a {@link eu.etaxonomy.cdm.model.term.Representation} object.
662
     * @param textHeight
663
     *            a int.
664
     * @param style
665
     *            a int.
666
     * @return a
667
     *         {@link eu.etaxonomy.taxeditor.ui.element.RepresentationElement}
668
     *         object.
669
     */
670
    public TranslatableRepresentationElement createTranslatableRepresentationElement(ICdmFormElement parentElement, Representation representation, TermBase term,int textHeight, int style, boolean fillDetails) {
671
        TranslatableRepresentationElement element = new TranslatableRepresentationElement(this, parentElement, representation, term, textHeight, style, fillDetails);
672
        adapt(element);
673
        parentElement.addElement(element);
674
        return element;
675
    }
676

    
677
    public KeyStatementElement createKeyStatementElement(ICdmFormElement parentElement, String labelString,
678
            KeyStatement keyStatement, int textHeight, int style) {
679
        KeyStatementElement element = new KeyStatementElement(this, parentElement, labelString, keyStatement,
680
                textHeight, style);
681
        adapt(element);
682
        parentElement.addElement(element);
683
        return element;
684
    }
685

    
686
    /**
687
     * Creates a text field with a label. The initial content will be the return value of the initalObject's {@link #toString()}
688
     * method.<br>
689
     * <b>Note</b>: if initialObject is <code>null</code> then an empty string is used.
690
     * @param parentElement the parent container
691
     * @param labelString the label name
692
     * @param initialObject the object from which the <code>toString()</code> method is called
693
     * @param style {@link SWT} style constant
694
     * @return the created textfield with label
695
     */
696
    public TextWithLabelElement createTextWithLabelElement(ICdmFormElement parentElement, String labelString,
697
            Object initialObject, int style) {
698
        return createTextWithLabelElement(parentElement, labelString, initialObject==null?"":initialObject.toString(), style);
699
    }
700

    
701
    /**
702
     * <p>
703
     * createTextWithLabelElement
704
     * </p>
705
     *
706
     * @param parentElement
707
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
708
     *            object.
709
     * @param labelString
710
     *            a {@link java.lang.String} object.
711
     * @param initialText
712
     *            a {@link java.lang.String} object.
713
     * @param style
714
     *            a int.
715
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
716
     *         object.
717
     */
718
    public TextWithLabelElement createTextWithLabelElement(ICdmFormElement parentElement, String labelString,
719
            String initialText, int style) {
720
        return createTextWithLabelElement(parentElement, labelString, initialText, null, style);
721
    }
722
    /**
723
     * <p>
724
     * createTextWithLabelElement
725
     * </p>
726
     *
727
     * @param parentElement
728
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
729
     *            object.
730
     * @param labelString
731
     *            a {@link java.lang.String} object.
732
     * @param initialText
733
     *            a {@link java.lang.String} object.
734
     * @param textLimit maximal number of characters allowed
735
     * @param style
736
     *            a int.
737
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
738
     *         object.
739
     */
740
    public TextWithLabelElement createTextWithLabelElement(ICdmFormElement parentElement, String labelString,
741
            String initialText, Integer textLimit, int style) {
742
        if(initialText==null){
743
            initialText = "";
744
        }
745

    
746
        TextWithLabelElement element = new TextWithLabelElement(this, parentElement, labelString, initialText, null,
747
                textLimit, style);
748
        adapt(element);
749
        parentElement.addElement(element);
750
        return element;
751
    }
752

    
753
    public TextWithLabelElement createMultiLineTextWithLabel(ICdmFormElement parentElement, String labelString,
754
            int textHeight, int style) {
755
        TextWithLabelElement element = new TextWithLabelElement(this, parentElement, labelString, "", textHeight, true, style);
756
        adapt(element);
757
        parentElement.addElement(element);
758
        return element;
759
    }
760

    
761
    public LsidWithExceptionLabelElement createLsidWithExceptionLabelElement(ICdmFormElement parentElement, String labelString,
762
            LSID initialLsid, int style) {
763
        LsidWithExceptionLabelElement element = new LsidWithExceptionLabelElement(this, parentElement, labelString, initialLsid, null, style);
764
        adapt(element);
765
        parentElement.addElement(element);
766
        return element;
767
    }
768

    
769
    public UriWithLabelElement createUriWithLabelElement(ICdmFormElement parentElement, String labelString,
770
            URI initialUri, int style) {
771
        UriWithLabelElement element = new UriWithLabelElement(this, parentElement, labelString, initialUri, null, style);
772
        adapt(element);
773
        parentElement.addElement(element);
774
        return element;
775
    }
776
    public UriWithLabelElement createUriWithLabelElement(ICdmFormElement parentElement, String labelString,
777
            URI initialUri,Integer textHeight, int style) {
778
        UriWithLabelElement element = new UriWithLabelElement(this, parentElement, labelString, initialUri, textHeight, style);
779
        adapt(element);
780
        parentElement.addElement(element);
781
        return element;
782
    }
783

    
784

    
785
    public DoiWithLabelElement createDoiWithLabelElement(ICdmFormElement parentElement, String labelString,
786
            DOI initialDoi, int style) {
787
        DoiWithLabelElement element = new DoiWithLabelElement(this, parentElement, labelString, initialDoi, null, style);
788
        adapt(element);
789
        parentElement.addElement(element);
790
        return element;
791
    }
792
    public DoiWithLabelElement createDoiWithLabelElement(ICdmFormElement parentElement, String labelString,
793
            DOI initialDoi,Integer textHeight, int style) {
794
        DoiWithLabelElement element = new DoiWithLabelElement(this, parentElement, labelString, initialDoi, textHeight, style);
795
        adapt(element);
796
        parentElement.addElement(element);
797
        return element;
798
    }
799

    
800
    /**
801
     * @param element
802
     * @param string
803
     * @param uri
804
     * @param style
805
     * @return
806
     */
807
    public OpenUrlSelectorElement createOpenUrlSelectorElement(ICdmFormElement parentElement, String labelString,
808
            IOpenUrlEnabled openUrlEnabled, int style) {
809
        OpenUrlSelectorElement element = new OpenUrlSelectorElement(this, parentElement, labelString, openUrlEnabled,
810
                style);
811
        adapt(element);
812
        parentElement.addElement(element);
813
        return element;
814
    }
815

    
816
    /**
817
     *
818
     * @param parentElement
819
     * @param labelString
820
     * @param conversationEnabled
821
     * @param user
822
     * @param style
823
     * @return
824
     */
825
    public EditPasswordElement createEditPasswordElement(ICdmFormElement parentElement, String labelString,
826
            ConversationHolder conversation, User user, int style) {
827
        EditPasswordElement element = new EditPasswordElement(this, parentElement, labelString, user, conversation);
828
        adapt(element);
829
        parentElement.addElement(element);
830
        return element;
831
    }
832

    
833
    /**
834
     * <p>
835
     * createIntegerTextWithLabelElement
836
     * </p>
837
     *
838
     * @param parentElement
839
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
840
     *            object.
841
     * @param labelString
842
     *            a {@link java.lang.String} object.
843
     * @param initialInteger
844
     *            a {@link java.lang.Integer} object.
845
     * @param style
846
     *            a int.
847
     * @return a
848
     *         {@link eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement}
849
     *         object.
850
     */
851
	public NumberWithLabelElement createNumberTextWithLabelElement(
852
			ICdmFormElement parentElement, String labelString,
853
			Number initialNumber, int style) {
854
		NumberWithLabelElement element = new NumberWithLabelElement(this,
855
				parentElement, labelString, initialNumber, style);
856
		adapt(element);
857
		parentElement.addElement(element);
858
		return element;
859
	}
860

    
861
    public LanguageStringWithLabelElement createLanguageStringWithLabelElement(ICdmFormElement parentElement,
862
            String labelString, LanguageString languageString, int style) {
863
        return createLanguageStringWithLabelElement(parentElement, labelString, languageString, null, false, style);
864
    }
865

    
866
    public LanguageStringWithLabelElement createLanguageStringWithLabelElement(ICdmFormElement parentElement,
867
            String labelString, LanguageString languageString, Integer height, boolean isMultiLine, int style) {
868
        LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(this, parentElement, labelString,
869
                languageString, height, isMultiLine, style);
870
        adapt(element);
871
        parentElement.addElement(element);
872
        return element;
873
    }
874

    
875
    /**
876
     * <p>
877
     * createKeyValueViewerElement
878
     * </p>
879
     *
880
     * @param parentElement
881
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
882
     *            object.
883
     * @param keyHeading
884
     *            a {@link java.lang.String} object.
885
     * @param valueHeading
886
     *            a {@link java.lang.String} object.
887
     * @param map
888
     *            a {@link java.util.Map} object.
889
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.KeyValueViewerElement}
890
     *         object.
891
     */
892
    public KeyValueViewerElement createKeyValueViewerElement(ICdmFormElement parentElement, String keyHeading,
893
            String valueHeading, Map<Object, Object> map) {
894
        KeyValueViewerElement element = new KeyValueViewerElement(this, parentElement, keyHeading, valueHeading, map);
895
        adapt(element);
896
        parentElement.addElement(element);
897
        return element;
898
    }
899
    /**
900
     * @deprecated Use {@link #createDefinedTermComboElement(TermType, ICdmFormElement, String, DefinedTermBase, int)} instead
901
     */
902
    @Deprecated
903
    public <T extends DefinedTermBase> TermComboElement<T> createTermComboElement(Class<T> termComboType,
904
            ICdmFormElement parentElement, String labelString, T selection, int style) {
905
        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termComboType, labelString, selection, true, style);
906
        adapt(element);
907
        parentElement.addElement(element);
908
        return element;
909
    }
910

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

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

    
931
	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
932
			TermType termType,
933
			ICdmFormElement parentElement,
934
			String labelString,
935
			T selection,
936
			int style) {
937
		return  this.createDefinedTermComboElement(termType, null, null, parentElement, labelString, selection, true, style, false, null);
938
	}
939

    
940
	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
941
            List<T> terms,
942
            ICdmFormElement parentElement,
943
            String labelString,
944
            T selection,
945
            int style) {
946
        return  this.createDefinedTermComboElement(null, null, terms, parentElement, labelString, selection, true, style, false, null);
947
    }
948
	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
949
	        List<T> terms,
950
	        ICdmFormElement parentElement,
951
	        String labelString,
952
	        T selection,
953
	        boolean addEmptyElement,
954
	        int style) {
955
	    return  this.createDefinedTermComboElement(null, null, terms, parentElement, labelString, selection, addEmptyElement, style, false, null);
956
	}
957
    public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
958
			TermType termType,
959
			ICdmFormElement parentElement,
960
			String labelString,
961
			T selection,
962
			boolean addEmptyElement,
963
			int style,
964
			boolean useAbbrevLabel) {
965
		return createDefinedTermComboElement(termType, null, null, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
966
	}
967

    
968

    
969
    public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
970
            TermVocabulary<?> termVocabulary,
971
            ICdmFormElement parentElement,
972
            String labelString,
973
            T selection,
974
            int style) {
975
        return this.createDefinedTermComboElement(null, termVocabulary, null, parentElement, labelString, selection, true, style, false, null);
976
    }
977

    
978
	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
979
	        TermVocabulary<?> termVocabulary,
980
	        ICdmFormElement parentElement,
981
	        String labelString,
982
	        T selection,
983
	        boolean addEmptyElement,
984
	        int style,
985
	        boolean useAbbrevLabel) {
986
	    return createDefinedTermComboElement(null, termVocabulary, null, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
987
	}
988

    
989
	private <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
990
	        TermType termType,
991
	        TermVocabulary<?> termVocabulary,
992
	        List<T> terms,
993
	        ICdmFormElement parentElement,
994
	        String labelString,
995
	        T selection,
996
	        boolean addEmptyElement,
997
	        int style,
998
	        boolean useAbbrevLabel,
999
	        Comparator<T> comparator) {
1000
	    if(termType!=null){
1001
	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termType, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
1002
	        adapt(element);
1003
	        parentElement.addElement(element);
1004
	        return element;
1005
	    }
1006
	    else if(termVocabulary!=null){
1007
	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termVocabulary, labelString, selection, addEmptyElement, style, useAbbrevLabel, comparator);
1008
	        if (comparator!= null){
1009
	        	element.setTermComparator(comparator);
1010
	        }
1011
	        adapt(element);
1012
	        parentElement.addElement(element);
1013
	        return element;
1014
	    }else if (terms != null){
1015

    
1016
	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, terms, labelString, selection, addEmptyElement, style, useAbbrevLabel);
1017
            if (comparator!= null){
1018
                element.setTermComparator(comparator);
1019
            }
1020
            adapt(element);
1021
            parentElement.addElement(element);
1022
            return element;
1023
	    }
1024
	    else {
1025
	        //this should never happen
1026
	        return null;
1027
	    }
1028
	}
1029

    
1030
	public NameRelationshipTypeCombo createNameRelationshipTypeCombo(ICdmFormElement parentElement,
1031
            String labelString,
1032
            int style,
1033
            boolean useAbbrevLabel,
1034
            Comparator<NameRelationshipType> comparator) {
1035

    
1036
        NameRelationshipTypeCombo<InverseTermWrapper> element = new NameRelationshipTypeCombo(this, parentElement, labelString, true, style, useAbbrevLabel, comparator);
1037
        adapt(element);
1038
        parentElement.addElement(element);
1039
        return element;
1040
    }
1041

    
1042
	public MisappliedRelationshipComboElement createMisappliedRelationshipComboElement(
1043
	        ICdmFormElement parentElement,
1044
            String labelString,
1045
            TaxonRelationshipType selection,
1046
            int style) {
1047
	    MisappliedRelationshipComboElement combo = new MisappliedRelationshipComboElement(this, parentElement, labelString, selection, false, style, false);
1048
	    adapt(combo);
1049
        parentElement.addElement(combo);
1050
        return combo;
1051
    }
1052

    
1053
	public <T extends IEnumTerm<T>> EnumComboElement<T> createEnumComboElement(
1054
	        Class<T> enumComboType, ICdmFormElement parentElement,
1055
	        int style) {
1056
	    return createEnumComboElement(enumComboType, parentElement, null, style);
1057
	}
1058

    
1059
	public <T extends IEnumTerm<T>> EnumComboElement<T> createEnumComboElement(
1060
			Class<T> enumComboType, ICdmFormElement parentElement, Comparator<T> comparator,
1061
			int style) {
1062
        EnumComboElement<T> element = new EnumComboElement<T>(this, parentElement, enumComboType, comparator, style);
1063
        adapt(element);
1064
        parentElement.addElement(element);
1065
        return element;
1066
    }
1067

    
1068
	public <TERM extends DefinedTermBase<TERM>, VOC extends TermVocabulary<TERM>> VocabularyComboElement<TERM, VOC> createVocabularyComboElement(
1069
	        TermType termType, String label, VOC selection, ICdmFormElement parentElement, int style) {
1070
	    VocabularyComboElement<TERM, VOC> element = new VocabularyComboElement<TERM, VOC>(this, parentElement, termType, label, selection, style);
1071
	    adapt(element);
1072
	    parentElement.addElement(element);
1073
	    return element;
1074
	}
1075

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

    
1098
    /**
1099
     * <p>
1100
     * createImageElement
1101
     * </p>
1102
     *
1103
     * @param parentElement
1104
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1105
     *            object.
1106
     * @param imageUri
1107
     *            a {@link java.net.URI} object.
1108
     * @param style
1109
     *            a int.
1110
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.ImageElement} object.
1111
     */
1112
    public ImageElement createImageElement(ICdmFormElement parentElement, URI imageUri, int style) {
1113
        ImageElement element = new ImageElement(this, parentElement, imageUri, style);
1114
        adapt(element);
1115
        parentElement.addElement(element);
1116
        return element;
1117
    }
1118

    
1119
    /**
1120
     * <p>
1121
     * createTextActionElement
1122
     * </p>
1123
     *
1124
     * @param labelString
1125
     *            a {@link java.lang.String} object.
1126
     * @param initialText
1127
     *            a {@link java.lang.String} object.
1128
     * @param style
1129
     *            a int.
1130
     * @param parentElement
1131
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1132
     *            object.
1133
     * @param buttonLabel
1134
     *            a {@link java.lang.String} object.
1135
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextActionElement}
1136
     *         object.
1137
     */
1138
    public TextActionElement createTextActionElement(ICdmFormElement parentElement, String labelString,
1139
            String buttonLabel, String initialText, int style) {
1140
        TextActionElement element = new TextActionElement(this, parentElement, labelString, buttonLabel, initialText,
1141
                style);
1142
        adapt(element);
1143
        parentElement.addElement(element);
1144
        return element;
1145
    }
1146

    
1147
    /**
1148
     * <p>
1149
     * createCheckbox
1150
     * </p>
1151
     *
1152
     * @param parentElement
1153
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1154
     *            object.
1155
     * @param label
1156
     *            a {@link java.lang.String} object.
1157
     * @param initialState
1158
     *            a boolean.
1159
     * @param style
1160
     *            a int.
1161
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.CheckboxElement}
1162
     *         object.
1163
     */
1164
    public CheckboxElement createCheckbox(ICdmFormElement parentElement, String label, Boolean initialState, int style) {
1165
        if(initialState==null){
1166
            initialState = Boolean.FALSE;
1167
        }
1168
        CheckboxElement element = new CheckboxElement(this, parentElement, label, initialState, style | orientation);
1169
        adapt(element);
1170
        parentElement.addElement(element);
1171
        return element;
1172
    }
1173

    
1174
    /**
1175
     * Creates a section as a part of the form.
1176
     *
1177
     * @return the section widget
1178
     * @param section
1179
     *            a
1180
     *            {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1181
     *            object.
1182
     */
1183
    public Section adapt(AbstractFormSection section) {
1184
        section.setMenu(section.getLayoutComposite().getMenu());
1185
        adapt(section, true, true);
1186

    
1187
        // handle focus and property change events for cdm use
1188
        section.addFocusListener(selectionFocusHandler);
1189
        section.setPropertyChangeListeners(propertyChangeListeners);
1190

    
1191
        section.addExpansionListener(new ExpansionAdapter(){
1192
            @Override
1193
            public void expansionStateChanged(ExpansionEvent e) {
1194
                super.expansionStateChanged(e);
1195
                if(section.getEntity()!=null){
1196
                    PreferencesUtil.setStringValue(StoreUtil.getPrefKey(section.getClass(), section.getEntity().getClass().getCanonicalName()), e.getState()?CdmSectionPart.EXPANDED:CdmSectionPart.COLLAPSED);
1197
                }
1198
            }
1199
        });
1200

    
1201
        if (section.getToggle() != null) {
1202
            section.getToggle().setHoverDecorationColor(getColors().getColor(IFormColors.TB_TOGGLE_HOVER));
1203
            section.getToggle().setDecorationColor(getColors().getColor(IFormColors.TB_TOGGLE));
1204
        }
1205

    
1206
        section.setFont(boldFontHolder2.getBoldFont(section.getLayoutComposite().getFont()));
1207

    
1208
        if ((section.getStyle() & ExpandableComposite.TITLE_BAR) != 0
1209
                || (section.getStyle() & ExpandableComposite.SHORT_TITLE_BAR) != 0) {
1210
            getColors().initializeSectionToolBarColors();
1211
            section.setTitleBarBackground(getColors().getColor(IFormColors.TB_BG));
1212
            section.setTitleBarBorderColor(getColors().getColor(IFormColors.TB_BORDER));
1213
        }
1214
        // call setTitleBarForeground regardless as it also sets the label color
1215
        section.setTitleBarForeground(getColors().getColor(IFormColors.TB_TOGGLE));
1216
        return section;
1217
    }
1218

    
1219
    private class BoldFontHolder2 {
1220
        private Font normalFont;
1221

    
1222
        private Font boldFont;
1223

    
1224
        public BoldFontHolder2() {
1225
        }
1226

    
1227
        public Font getBoldFont(Font font) {
1228
            createBoldFont(font);
1229
            return boldFont;
1230
        }
1231

    
1232
        private void createBoldFont(Font font) {
1233
            if (normalFont == null || !normalFont.equals(font)) {
1234
                normalFont = font;
1235
                dispose();
1236
            }
1237
            if (boldFont == null) {
1238
                boldFont = FormFonts.getInstance().getBoldFont(getColors().getDisplay(), normalFont);
1239
            }
1240
        }
1241

    
1242
        public void dispose() {
1243
            if (boldFont != null) {
1244
                FormFonts.getInstance().markFinished(boldFont, getColors().getDisplay());
1245
                boldFont = null;
1246
            }
1247
        }
1248
    }
1249

    
1250
    /**
1251
     * <p>
1252
     * createToggleableTextField
1253
     * </p>
1254
     *
1255
     * @param parentElement
1256
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1257
     *            object.
1258
     * @param labelString
1259
     *            a {@link java.lang.String} object.
1260
     * @param initialText
1261
     *            a {@link java.lang.String} object.
1262
     * @param initialState
1263
     *            a boolean.
1264
     * @param style
1265
     *            a int.
1266
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement}
1267
     *         object.
1268
     */
1269
    public ToggleableTextElement createToggleableTextField(ICdmFormElement parentElement, String labelString,
1270
            String initialText, boolean initialState, int style) {
1271
        ToggleableTextElement element = new ToggleableTextElement(this, parentElement, labelString, initialText,
1272
                initialState, style | orientation);
1273

    
1274
        adapt(element);
1275
        parentElement.addElement(element);
1276
        return element;
1277
    }
1278

    
1279
    /**
1280
     * <p>
1281
     * createTimePeriodElement
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.TimePeriod} object.
1291
     * @param style
1292
     *            a int.
1293
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.TimePeriodElement}
1294
     *         object.
1295
     */
1296
    public TimePeriodElement createTimePeriodElement(ICdmFormElement parentElement, String labelString,
1297
            TimePeriod timePeriod, int style) {
1298
        TimePeriodElement element = new TimePeriodElement(this, parentElement, labelString, timePeriod, style);
1299
        adapt(element);
1300
        parentElement.addElement(element);
1301
        return element;
1302
    }
1303

    
1304
    /**
1305
     * <p>
1306
     * createVerbatimTimePeriodElement
1307
     * </p>
1308
     *
1309
     * @param parentElement
1310
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1311
     *            object.
1312
     * @param labelString
1313
     *            a {@link java.lang.String} object.
1314
     * @param timePeriod
1315
     *            a {@link eu.etaxonomy.cdm.model.common.VerbatimTimePeriod} object.
1316
     * @param style
1317
     *            a int.
1318
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.VerbatimTimePeriodElement}
1319
     *         object.
1320
     */
1321
    public VerbatimTimePeriodElement createVerbatimTimePeriodElement(ICdmFormElement parentElement, String labelString,
1322
            VerbatimTimePeriod timePeriod, int style) {
1323
        VerbatimTimePeriodElement element = new VerbatimTimePeriodElement(this, parentElement, labelString, timePeriod, style);
1324
        adapt(element);
1325
        parentElement.addElement(element);
1326
        return element;
1327
    }
1328

    
1329

    
1330

    
1331
	/**
1332
	 * <p>
1333
	 * createGatheringEventUnitElement
1334
	 * </p>
1335
	 *
1336
	 * @param parentElement
1337
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1338
	 *            object.
1339
	 * @param labelString
1340
	 *            a {@link java.lang.String} object.
1341
	 * @param timePeriod
1342
	 *            a {@link eu.etaxonomy.cdm.model.common.GatheringEvent} object.
1343
	 * @param style
1344
	 *            a int.
1345
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.GatheringEventUnitElement}
1346
	 *         object.
1347
	 */
1348
	public GatheringEventUnitElement createGatheringEventUnitElement(
1349
			ICdmFormElement parentElement,
1350
			String labelString,
1351
			DerivedUnitFacade gatheringEvent,
1352
			MinMaxTextSection.UnitType unitType,
1353
			int style) {
1354
		GatheringEventUnitElement element = new GatheringEventUnitElement(this,
1355
				parentElement,
1356
				labelString,
1357
				gatheringEvent,
1358
				unitType,
1359
				style);
1360
		adapt(element);
1361
		parentElement.addElement(element);
1362
		return element;
1363
	}
1364

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

    
1386
    /**
1387
     * Creates an empty section with the given message.<br>
1388
     * If message is <code>null</code> a default message will be displayed.
1389
     */
1390
    public EmptySection createEmptySection(String message, CdmFormFactory formFactory, ICdmFormElement parentElement, int style) {
1391
        EmptySection section = new EmptySection(message, formFactory, parentElement, style);
1392
        parentElement.addElement(section);
1393
        adapt(section);
1394
        return section;
1395
    }
1396

    
1397
    /**
1398
     * <p>
1399
     * createDateDetailSection
1400
     * </p>
1401
     *
1402
     * @param parentElement
1403
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1404
     *            object.
1405
     * @param style
1406
     *            a int.
1407
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.DateDetailSection}
1408
     *         object.
1409
     */
1410
    public DateDetailSection<TimePeriod> createDateDetailSection(ICdmFormElement parentElement, int style) {
1411
        DateDetailSection<TimePeriod> section = new DateDetailSection<TimePeriod>(this, parentElement, false, style);
1412
        parentElement.addElement(section);
1413
        adapt(section);
1414
        return section;
1415
    }
1416

    
1417
    /**
1418
     * <p>
1419
     * createVerbatimDateDetailSection
1420
     * </p>
1421
     *
1422
     * @param parentElement
1423
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1424
     *            object.
1425
     * @param style
1426
     *            a int.
1427
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.VerbatimDateDetailSection}
1428
     *         object.
1429
     */
1430
    public DateDetailSection<VerbatimTimePeriod> createVerbatimDateDetailSection(ICdmFormElement parentElement, int style) {
1431
        DateDetailSection<VerbatimTimePeriod> section
1432
        	= new DateDetailSection<VerbatimTimePeriod>(this, parentElement, true, style);
1433
        parentElement.addElement(section);
1434
        adapt(section);
1435
        return section;
1436
    }
1437

    
1438
	/**
1439
	 * <p>
1440
	 * createDateDetailSection
1441
	 * </p>
1442
	 *
1443
	 * @param parentElement
1444
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1445
	 *            object.
1446
	 * @param style
1447
	 *            a int.
1448
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection}
1449
	 *         object.
1450
	 */
1451
	public MinMaxTextSection createMinMaxTextSection(ICdmFormElement parentElement, UnitType unitType, int style) {
1452
		MinMaxTextSection section = new MinMaxTextSection(this, parentElement, unitType, style);
1453
		parentElement.addElement(section);
1454
		adapt(section);
1455
		return section;
1456
	}
1457

    
1458
    /**
1459
     * <p>
1460
     * createPartialElement
1461
     * </p>
1462
     *
1463
     * @param parentElement
1464
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1465
     *            object.
1466
     * @param labelString
1467
     *            a {@link java.lang.String} object.
1468
     * @param partial
1469
     *            a {@link org.joda.time.Partial} object.
1470
     * @param style
1471
     *            a int.
1472
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.PartialElement}
1473
     *         object.
1474
     */
1475
    public PartialElement createPartialElement(ICdmFormElement parentElement, String labelString, Partial partial,
1476
            int style) {
1477
        PartialElement element = new PartialElement(this, parentElement, labelString, style);
1478
        adapt(element);
1479
        parentElement.addElement(element);
1480
        return element;
1481
    }
1482

    
1483
    /**
1484
     * <p>
1485
     * addSelectionListener
1486
     * </p>
1487
     *
1488
     * @param listener
1489
     *            a {@link org.eclipse.swt.events.SelectionListener} object.
1490
     */
1491
    public void addSelectionListener(SelectionListener listener) {
1492
        selectionListenerList.add(listener);
1493
    }
1494

    
1495
    /**
1496
     * <p>
1497
     * removeSelectionListener
1498
     * </p>
1499
     *
1500
     * @param listener
1501
     *            a {@link org.eclipse.swt.events.SelectionListener} object.
1502
     */
1503
    public void removeSelectionListener(SelectionListener listener) {
1504
        if (listener == null) {
1505
            MessagingUtils.error(this.getClass(),
1506
                    "Tried to remove a selection listener from this factories listeners but was null", null);
1507
        } else {
1508
            selectionListenerList.remove(listener);
1509
        }
1510
    }
1511

    
1512
    /**
1513
     * <p>
1514
     * addPropertyChangeListener
1515
     * </p>
1516
     *
1517
     * @param listener
1518
     *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1519
     *            object.
1520
     */
1521
    public void addPropertyChangeListener(IPropertyChangeListener listener) {
1522
        if (propertyChangeListeners.contains(listener)) {
1523
            return;
1524
        }
1525
        propertyChangeListeners.add(0, listener);
1526
    }
1527

    
1528
    /**
1529
     * <p>
1530
     * removePropertyChangeListener
1531
     * </p>
1532
     *
1533
     * @param listener
1534
     *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1535
     *            object.
1536
     */
1537
    public void removePropertyChangeListener(IPropertyChangeListener listener) {
1538
        propertyChangeListeners.remove(listener);
1539
    }
1540

    
1541
    /**
1542
     * @return the propertyChangeListeners
1543
     */
1544
    public List<IPropertyChangeListener> getPropertyChangeListeners() {
1545
        return propertyChangeListeners;
1546
    }
1547

    
1548
    /**
1549
     * <p>
1550
     * createHorizontalSeparator
1551
     * </p>
1552
     *
1553
     * @param parentElement
1554
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1555
     *            object.
1556
     * @param style
1557
     *            a int.
1558
     * @return a {@link org.eclipse.swt.widgets.Label} object.
1559
     */
1560
    public Label createHorizontalSeparator(ICdmFormElement parentElement, int style) {
1561
        Label separator = this.createSeparator(parentElement.getLayoutComposite(), SWT.HORIZONTAL | style);
1562
        separator.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
1563
        return separator;
1564
    }
1565

    
1566
    /**
1567
     * <p>
1568
     * createVersionElement
1569
     * </p>
1570
     *
1571
     * @param parentElement
1572
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1573
     *            object.
1574
     * @param entity
1575
     *            a {@link eu.etaxonomy.cdm.model.common.VersionableEntity}
1576
     *            object.
1577
     * @param style
1578
     *            a int.
1579
     * @return a
1580
     *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionElement}
1581
     *         object.
1582
     */
1583
    public VersionElement createVersionElement(ICdmFormElement parentElement, VersionableEntity entity, int style) {
1584
        VersionElement element = new VersionElement(this, parentElement, entity, style);
1585
        adapt(element);
1586
        parentElement.addElement(element);
1587
        return element;
1588
    }
1589

    
1590
    /**
1591
     * @param cdmBaseSection
1592
     * @param object
1593
     * @param style
1594
     * @return
1595
     */
1596
    public CdmBaseElement createCdmBaseElement(ICdmFormElement parentElement, CdmBase entity, int style) {
1597
        CdmBaseElement element = new CdmBaseElement(this, parentElement, entity, style);
1598
        adapt(element);
1599
        parentElement.addElement(element);
1600
        return element;
1601
    }
1602

    
1603
    /**
1604
     * <p>
1605
     * createVersionSection
1606
     * </p>
1607
     *
1608
     * @param parentElement
1609
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1610
     *            object.
1611
     * @param style
1612
     *            a int.
1613
     * @return a
1614
     *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection}
1615
     *         object.
1616
     */
1617
    public VersionSection createVersionSection(ICdmFormElement parentElement, int style) {
1618
        VersionSection section = new VersionSection(this, parentElement, style);
1619
        parentElement.addElement(section);
1620
        adapt(section);
1621
        return section;
1622
    }
1623

    
1624
    /**
1625
     * @param parent
1626
     * @param i
1627
     * @return
1628
     */
1629
    public CdmBaseSection createCdmBaseSection(ICdmFormElement parentElement, int style) {
1630
        CdmBaseSection section = new CdmBaseSection(this, parentElement, style);
1631
        parentElement.addElement(section);
1632
        adapt(section);
1633
        return section;
1634
    }
1635

    
1636
    /**
1637
     * <p>
1638
     * createEmptyElement
1639
     * </p>
1640
     *
1641
     * @param parentElement
1642
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1643
     *            object.
1644
     * @return a {@link eu.etaxonomy.taxeditor.ui.section.EmptyElement} object.
1645
     */
1646
    public EmptyElement createEmptyElement(ICdmFormElement parentElement, String emptyText) {
1647
        EmptyElement element = new EmptyElement(this, parentElement, emptyText, SWT.NULL);
1648
        adapt(element);
1649
        parentElement.addElement(element);
1650
        return element;
1651
    }
1652

    
1653
    /**
1654
     * <p>
1655
     * createHeadlineSection
1656
     * </p>
1657
     *
1658
     * @param parentElement
1659
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1660
     *            object.
1661
     * @return a
1662
     *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection}
1663
     *         object.
1664
     */
1665
    public HeadlineSection createHeadlineSection(ICdmFormElement parentElement) {
1666
        HeadlineSection section = new HeadlineSection(this, parentElement, SWT.NULL);
1667
        parentElement.addElement(section);
1668
        adapt(section);
1669
        return section;
1670
    }
1671

    
1672
    /**
1673
     * <p>
1674
     * createParsingMessageElement
1675
     * </p>
1676
     *
1677
     * @param parentElement
1678
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1679
     *            object.
1680
     * @param parserProblem
1681
     *            a {@link eu.etaxonomy.cdm.strategy.parser.ParserProblem}
1682
     *            object.
1683
     * @param style
1684
     *            a int.
1685
     * @return a
1686
     *         {@link eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessageElement}
1687
     *         object.
1688
     */
1689
    public ParsingMessageElement createParsingMessageElement(ICdmFormElement parentElement,
1690
            ParserProblem parserProblem, int style) {
1691
        ParsingMessageElement element = new ParsingMessageElement(this, parentElement, parserProblem, style);
1692
        adapt(element);
1693
        parentElement.addElement(element);
1694
        return element;
1695
    }
1696

    
1697
    public DefinedTermDetailSection createDefinedTermDetailSection(Class definedTermClass, ConversationHolder conversation,
1698
            ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
1699

    
1700
        DefinedTermDetailSection section = new DefinedTermDetailSection(this, definedTermClass, conversation, parentElement,
1701
                selectionProvider, style);
1702

    
1703
        parentElement.addElement(section);
1704
        adapt(section);
1705
        return section;
1706

    
1707
    }
1708

    
1709
    public TermMediaSection createTermMediaSection(ConversationHolder conversation,
1710
            ICdmFormElement parentElement, int style) {
1711
        TermMediaSection section = new TermMediaSection(this, conversation, parentElement, style);
1712
        parentElement.addElement(section);
1713
        adapt(section);
1714
        return section;
1715

    
1716
    }
1717

    
1718
    /**
1719
     * @param definedTermClass
1720
     * @param formElement
1721
     * @param style
1722
     * @return
1723
     */
1724
    public AbstractCdmDetailElement createDefinedTermDetailElement(Class definedTermClass,
1725
            AbstractCdmDetailSection parentElement, int style) {
1726
        AbstractCdmDetailElement element = null;
1727

    
1728
        if (NamedArea.class.isAssignableFrom(definedTermClass)) {
1729
            element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
1730
        } else if (definedTermClass.equals(Feature.class)) {
1731
            element = new FeatureDetailElement(this, parentElement);
1732
        } else if(definedTermClass.equals(PresenceAbsenceTerm.class)){
1733
            element = new PresenceAbsenceTermDetailElement(this, parentElement);
1734
        } else {
1735
            element = new DefinedTermDetailElement(this, parentElement);
1736
        }
1737

    
1738

    
1739
        adapt(element);
1740
        parentElement.addElement(element);
1741
        return element;
1742
    }
1743

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

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

    
1756
    public CharacterNodeDetailElement createCharacterNodeDetailElement(ICdmFormElement parentElement, int style){
1757
        CharacterNodeDetailElement element = new CharacterNodeDetailElement(this, parentElement);
1758
        addAndAdaptElement(parentElement, element);
1759
        return element;
1760
    }
1761

    
1762
    public CharacterDetailElement createCharacterDetailElement(ICdmFormElement parentElement, int style){
1763
        CharacterDetailElement element = new CharacterDetailElement(this, parentElement);
1764
        addAndAdaptElement(parentElement, element);
1765
        return element;
1766
    }
1767

    
1768
    public FeatureTreeDetailElement createFeatureTreeDetailElement(ICdmFormElement parentElement, int style){
1769
        FeatureTreeDetailElement element = new FeatureTreeDetailElement(this, parentElement);
1770
        addAndAdaptElement(parentElement, element);
1771
        return element;
1772
    }
1773

    
1774
    public FeatureNodeDetailElement createFeatureNodeDetailElement(ICdmFormElement parentElement, int style){
1775
        FeatureNodeDetailElement element = new FeatureNodeDetailElement(this, parentElement);
1776
        addAndAdaptElement(parentElement, element);
1777
        return element;
1778
    }
1779

    
1780

    
1781
    //--------DetailSections---------
1782
    public NameDetailSection createNameDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1783
        NameDetailSection section = new NameDetailSection(this, conversation, parentElement, selectionProvider, style);
1784
        addAndAdaptSection(parentElement, section);
1785
        return section;
1786
    }
1787

    
1788
    public FeatureNodeDetailSection createFeatureNodeDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1789
        FeatureNodeDetailSection section = new FeatureNodeDetailSection(this, conversation, parentElement, selectionProvider, style);
1790
        addAndAdaptSection(parentElement, section);
1791
        return section;
1792
    }
1793

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

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

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

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

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

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

    
1830
    public TeamDetailSection createTeamDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
1831
        TeamDetailSection section = new TeamDetailSection(this, conversation, parentElement, null, style);
1832
        addAndAdaptSection(parentElement, section);
1833
        return section;
1834
    }
1835

    
1836
    public PersonDetailSection createPersonDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
1837
        PersonDetailSection section = new PersonDetailSection(this, conversation, parentElement, null, style);
1838
        addAndAdaptSection(parentElement, section);
1839
        return section;
1840
    }
1841

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

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

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

    
1860

    
1861

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2042
    public AmplificationGelPhotoCollectionDetailSection createAmplificationGelPhotoCollectionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2043
        AmplificationGelPhotoCollectionDetailSection section = new AmplificationGelPhotoCollectionDetailSection(this, conversation, parentElement, style);
2044
        addAndAdaptSection(parentElement, section);
2045
        return section;
2046
    }
2047

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

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

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

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

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

    
2078
    public SampleDesignationDetailSection createSampleDesignationDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2079
        SampleDesignationDetailSection section = new SampleDesignationDetailSection(this, conversation, parentElement, selectionProvider, style);
2080
        addAndAdaptSection(parentElement, section);
2081
        return section;
2082
    }
2083

    
2084
    public TaxonRelationshipDetailSection createTaxonRelationshipDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2085
        TaxonRelationshipDetailSection section = new TaxonRelationshipDetailSection(this, conversation, parentElement, selectionProvider, style, true);
2086
        addAndAdaptSection(parentElement, section);
2087
        return section;
2088
    }
2089

    
2090
    public ReferencedEntityDetailSection createReferencedEntityDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2091
        ReferencedEntityDetailSection section = new ReferencedEntityDetailSection(this, conversation, parentElement, selectionProvider, style);
2092
        addAndAdaptSection(parentElement, section);
2093
        return section;
2094
    }
2095

    
2096
    public TermVocabularyDetailSection createTermVocabularyDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2097
        TermVocabularyDetailSection section = new TermVocabularyDetailSection(this, conversation, parentElement, selectionProvider, style);
2098
        addAndAdaptSection(parentElement, section);
2099
        return section;
2100
    }
2101

    
2102
    public GatheringEventDetailSection createGatheringSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2103
        GatheringEventDetailSection section = new GatheringEventDetailSection(this, conversation, parentElement, selectionProvider, style);
2104
        addAndAdaptSection(parentElement, section);
2105
        return section;
2106
    }
2107

    
2108
    public NamedAreaDetailSection createNamedAreaDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2109
        NamedAreaDetailSection section = new NamedAreaDetailSection(this, conversation, parentElement, selectionProvider, style);
2110
        addAndAdaptSection(parentElement, section);
2111
        return section;
2112
    }
2113

    
2114
    public UseRecordDetailSection createUseRecordDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2115
        UseRecordDetailSection section = new UseRecordDetailSection(this, conversation, parentElement, selectionProvider, style);
2116
        addAndAdaptSection(parentElement, section);
2117
        return section;
2118
    }
2119

    
2120
    private void addAndAdaptSection(ICdmFormElement parentElement, AbstractFormSection<?> section) {
2121
        parentElement.addElement(section);
2122
        adapt(section);
2123
    }
2124

    
2125
    //--------DetailElements------------
2126

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

    
2133
    public DefinedTermDetailElement<NamedAreaLevel> createNamedAreaLevelElement(ICdmFormElement parentElement){
2134
        DefinedTermDetailElement<NamedAreaLevel> element = new DefinedTermDetailElement<NamedAreaLevel>(this, parentElement);
2135
        addAndAdaptElement(parentElement, element);
2136
        return element;
2137
    }
2138

    
2139
    public eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement createNamedAreaDetailElement(ICdmFormElement parentElement){
2140
        eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
2141
        addAndAdaptElement(parentElement, element);
2142
        return element;
2143
    }
2144

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

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

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

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

    
2169
    public GroupDetailElement createGroupDetailElement(ICdmFormElement parentElement){
2170
        GroupDetailElement element = new GroupDetailElement(this, parentElement);
2171
        addAndAdaptElement(parentElement, element);
2172
        return element;
2173
    }
2174

    
2175
    public UserDetailElement createUserDetailElement(ICdmFormElement parentElement){
2176
        UserDetailElement element = new UserDetailElement(this, parentElement);
2177
        addAndAdaptElement(parentElement, element);
2178
        return element;
2179
    }
2180

    
2181
    public HybridDetailElement createHybridDetailElement(ICdmFormElement parentElement){
2182
        HybridDetailElement element = new HybridDetailElement(this, parentElement);
2183
        addAndAdaptElement(parentElement, element);
2184
        return element;
2185
    }
2186

    
2187
    public InstitutionDetailElement createInstitutionDetailElement(ICdmFormElement parentElement){
2188
        InstitutionDetailElement element = new InstitutionDetailElement(this, parentElement);
2189
        addAndAdaptElement(parentElement, element);
2190
        return element;
2191
    }
2192

    
2193
    public PolytomousKeyNodeDetailElement createPolytomousKeyNodeDetailElement(ICdmFormElement parentElement){
2194
        PolytomousKeyNodeDetailElement element = new PolytomousKeyNodeDetailElement(this, parentElement);
2195
        addAndAdaptElement(parentElement, element);
2196
        return element;
2197
    }
2198

    
2199
    public PolytomousKeyDetailElement createPolytomousKeyDetailElement(ICdmFormElement parentElement){
2200
        PolytomousKeyDetailElement element = new PolytomousKeyDetailElement(this, parentElement);
2201
        addAndAdaptElement(parentElement, element);
2202
        return element;
2203
    }
2204

    
2205
    public CollectionDetailElement createCollectionDetailElement(ICdmFormElement parentElement){
2206
        CollectionDetailElement element = new CollectionDetailElement(this, parentElement);
2207
        addAndAdaptElement(parentElement, element);
2208
        return element;
2209
    }
2210

    
2211
    public TaxonNodeAgentRelationCollectionSection createTaxonNodeAgentRelationCollectionElement(ICdmFormElement parentElement, ConversationHolder conversation, int style){
2212
        TaxonNodeAgentRelationCollectionSection element = new TaxonNodeAgentRelationCollectionSection(this, conversation, parentElement, style);
2213
        adapt(element);
2214
        parentElement.addElement(element);
2215

    
2216
        return element;
2217
    }
2218

    
2219
    public TaxonNodeDetailElement createTaxonNodeDetailElement(ICdmFormElement parentElement, boolean createNew){
2220
        TaxonNodeDetailElement element = new TaxonNodeDetailElement(this, parentElement, createNew);
2221
        addAndAdaptElement(parentElement, element);
2222
        return element;
2223
    }
2224

    
2225
    public ClassificationDetailElement createClassificationDetailElement(ICdmFormElement parentElement){
2226
        ClassificationDetailElement element = new ClassificationDetailElement(this, parentElement);
2227
        addAndAdaptElement(parentElement, element);
2228
        return element;
2229
    }
2230

    
2231
    public CloneClassificationDetailElement createCloneClassificationDetailElement(ICdmFormElement parentElement){
2232
        CloneClassificationDetailElement element = new CloneClassificationDetailElement(this, parentElement);
2233
        addAndAdaptElement(parentElement, element);
2234
        return element;
2235
    }
2236

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

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

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

    
2255
    public DescriptionElementDetailElement createDescriptionElementDetailElement(ICdmFormElement parentElement, int style){
2256
        DescriptionElementDetailElement element = new DescriptionElementDetailElement(this, parentElement, style);
2257
        addAndAdaptElement(parentElement, element);
2258
        return element;
2259
    }
2260

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

    
2267
    public PersonDetailElement createPersonDetailElement(ICdmFormElement parentElement, int style){
2268
        PersonDetailElement element = new PersonDetailElement(this, parentElement, style);
2269
        addAndAdaptElement(parentElement, element);
2270
        return element;
2271
    }
2272

    
2273
    public TeamDetailElement createTeamDetailElement(ICdmFormElement parentElement, int style, boolean isNomenclatural){
2274
        TeamDetailElement element = new TeamDetailElement(this, parentElement, style, isNomenclatural);
2275
        addAndAdaptElement(parentElement, element);
2276
        return element;
2277
    }
2278

    
2279
    public AuthorshipDetailElement createAuthorshipDetailElement(ICdmFormElement parentElement, int style){
2280
        AuthorshipDetailElement element = new AuthorshipDetailElement(this, parentElement, style);
2281
        addAndAdaptElement(parentElement, element);
2282
        return element;
2283
    }
2284

    
2285
    public TaxonBaseDetailElement createTaxonBaseDetailElement(ICdmFormElement parentElement, int style){
2286
        TaxonBaseDetailElement element = new TaxonBaseDetailElement(this, parentElement, style);
2287
        addAndAdaptElement(parentElement, element);
2288
        return element;
2289
    }
2290

    
2291
    public NameDetailElement createNameDetailElement(ICdmFormElement parentElement, int style){
2292
        NameDetailElement element = new NameDetailElement(this, parentElement, style);
2293
        addAndAdaptElement(parentElement, element);
2294
        return element;
2295
    }
2296

    
2297
    public ReferenceDetailElement createReferenceDetailElement(ICdmFormElement parentElement, int style, boolean isWizard){
2298
        ReferenceDetailElement element = new ReferenceDetailElement(this, parentElement, style, isWizard);
2299
        addAndAdaptElement(parentElement, element);
2300
        return element;
2301
    }
2302

    
2303
    public NomenclaturalReferenceDetailElement createNomenclaturalReferenceDetailElement(ICdmFormElement parentElement, int style){
2304
        NomenclaturalReferenceDetailElement element = new NomenclaturalReferenceDetailElement(this, parentElement, style);
2305
        addAndAdaptElement(parentElement, element);
2306
        return element;
2307
    }
2308

    
2309

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

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

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

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

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

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

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

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

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

    
2364
    public SingleReadGeneralDetailElement createSingleReadGeneralDetailElement(ICdmFormElement parentElement){
2365
        SingleReadGeneralDetailElement element = new SingleReadGeneralDetailElement(this, parentElement);
2366
        addAndAdaptElement(parentElement, element);
2367
        return element;
2368
    }
2369

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

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

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

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

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

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

    
2406
    public MediaDetailElement createMediaDetailElement(ICdmFormElement parentElement){
2407
        MediaDetailElement mediaDetailElement = new MediaDetailElement(this, parentElement);
2408
        addAndAdaptElement(parentElement, mediaDetailElement);
2409
        return mediaDetailElement;
2410
    }
2411

    
2412
    public GatheringEventDetailElement createGatheringEventDetailElement(ICdmFormElement parentElement) {
2413
        GatheringEventDetailElement element = new GatheringEventDetailElement(this, parentElement);
2414
        addAndAdaptElement(parentElement, element);
2415
        return element;
2416
    }
2417

    
2418
    public FieldUnitDetailElement createFieldUnitDetailElement(ICdmFormElement parentElement) {
2419
        FieldUnitDetailElement element = new FieldUnitDetailElement(this, parentElement);
2420
        addAndAdaptElement(parentElement, element);
2421
        return element;
2422
    }
2423

    
2424
    public DerivedUnitBaseDetailElement createDerivedUnitBaseDetailElement(ICdmFormElement parentElement) {
2425
        DerivedUnitBaseDetailElement element = new DerivedUnitBaseDetailElement(this, parentElement);
2426
        addAndAdaptElement(parentElement, element);
2427
        return element;
2428
    }
2429

    
2430
    public OriginalLabelDataElement createOriginalLabelDataElement(ICdmFormElement parentElement) {
2431
        OriginalLabelDataElement element = new OriginalLabelDataElement(this, parentElement);
2432
        addAndAdaptElement(parentElement, element);
2433
        return element;
2434
    }
2435

    
2436
    public PreservedSpecimenDetailElement createPreservedSpecimenDetailElement(ICdmFormElement parentElement) {
2437
        PreservedSpecimenDetailElement element = new PreservedSpecimenDetailElement(this, parentElement);
2438
        addAndAdaptElement(parentElement, element);
2439
        return element;
2440
    }
2441

    
2442
    public DeterminationDetailElement createDeterminationDetailElement(ICdmFormElement parentElement) {
2443
        DeterminationDetailElement element = new DeterminationDetailElement(this, parentElement);
2444
        addAndAdaptElement(parentElement, element);
2445
        return element;
2446
    }
2447

    
2448
    public SampleDesignationDetailElement createSampleDesignationDetailElement(ICdmFormElement parentElement) {
2449
        SampleDesignationDetailElement element = new SampleDesignationDetailElement(this, parentElement);
2450
        addAndAdaptElement(parentElement, element);
2451
        return element;
2452
    }
2453

    
2454
    /**
2455
     * @param parentElement
2456
     * @param element
2457
     */
2458
    private void addAndAdaptElement(ICdmFormElement parentElement, AbstractCdmDetailElement<?> element) {
2459
        adapt(element);
2460
        parentElement.addElement(element);
2461
    }
2462

    
2463
    //--------EntityCollectionSection----------
2464
    public TeamMemberSection createTeamMemberSection(ConversationHolder conversation, ICdmFormElement parentElement, int style, boolean isNomenclatural){
2465
        TeamMemberSection section = new TeamMemberSection(this, conversation, parentElement, style, isNomenclatural);
2466
        addAndAdaptSection(parentElement, section);
2467
        return section;
2468
    }
2469

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

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

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

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

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

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

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

    
2512
    public MediaSection createMediaSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2513
        MediaSection section = new MediaSection(this, conversation, parentElement, style);
2514
        addAndAdaptSection(parentElement, section);
2515
        return section;
2516
    }
2517

    
2518
    public DescriptionElementMediaSection createDescriptionElementMediaSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2519
        DescriptionElementMediaSection section = new DescriptionElementMediaSection(this, conversation, parentElement, style);
2520
        addAndAdaptSection(parentElement, section);
2521
        return section;
2522
    }
2523

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

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

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

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

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

    
2554
    public ProtologueSection createProtologueSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2555
        ProtologueSection section = new ProtologueSection(this, conversation, parentElement, style);
2556
        addAndAdaptSection(parentElement, section);
2557
        return section;
2558
    }
2559
    public ExternalLinksSection createExternalLinksSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2560
        ExternalLinksSection section = new ExternalLinksSection(this, conversation, parentElement, style);
2561
        addAndAdaptSection(parentElement, section);
2562
        return section;
2563
    }
2564

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2703
    public PreservedSpecimenSourceCollectionDetailSection createPreservedSpecimenSourceCollectionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2704
        PreservedSpecimenSourceCollectionDetailSection section = new PreservedSpecimenSourceCollectionDetailSection(this, conversation, parentElement, style);
2705
        addAndAdaptSection(parentElement, section);
2706
        return section;
2707
    }
2708

    
2709
    public SourceCollectionDetailSection createSourceCollectionDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2710
        SourceCollectionDetailSection section = new SourceCollectionDetailSection(this, conversation, parentElement, style);
2711
        addAndAdaptSection(parentElement, section);
2712
        return section;
2713
    }
2714

    
2715
    public ScopeRestrictionSection createScopeRestrictionSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2716
        ScopeRestrictionSection section = new ScopeRestrictionSection(this, conversation, parentElement, style);
2717
        addAndAdaptSection(parentElement, section);
2718
        return section;
2719
    }
2720

    
2721
    public MemberDetailSection createMemberDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2722
        MemberDetailSection section = new MemberDetailSection(this, conversation, parentElement, style);
2723
        addAndAdaptSection(parentElement, section);
2724
        return section;
2725
    }
2726

    
2727
    public GrantedAuthorityDetailSection createGrantedAuthorityDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2728
        GrantedAuthorityDetailSection section = new GrantedAuthorityDetailSection(this, conversation, parentElement, style);
2729
        addAndAdaptSection(parentElement, section);
2730
        return section;
2731
    }
2732

    
2733
    public GroupsByUserDetailSection createGroupsByUserDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2734
        GroupsByUserDetailSection section = new GroupsByUserDetailSection(this, conversation, parentElement, style);
2735
        addAndAdaptSection(parentElement, section);
2736
        return section;
2737
    }
2738

    
2739
    public TaxonomicScopeSection createTaxonomicScopeSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2740
        TaxonomicScopeSection section = new TaxonomicScopeSection(this, conversation, parentElement, style);
2741
        addAndAdaptSection(parentElement, section);
2742
        return section;
2743
    }
2744

    
2745

    
2746
    public AbstractEntityCollectionElement createEntityCollectionElement(AbstractFormSection parentElement,
2747
            Object versionableEntity, SelectionListener removeListener, Color backgroundColor, int style) {
2748
        AbstractEntityCollectionElement<?> element = null;
2749

    
2750
        Object entity = HibernateProxyHelper.deproxy(versionableEntity);
2751

    
2752
        if (entity instanceof Annotation) {
2753
            element = new AnnotationElement(this, parentElement, (Annotation) entity, removeListener, style);
2754
        }else if (entity instanceof Person ) {
2755
            boolean isNomenclatural = false;
2756
            if (parentElement instanceof TeamMemberSection){
2757
                isNomenclatural = ((TeamMemberSection) parentElement).isNomenclaturalTeam();
2758
            }
2759
            element = new TeamMemberElement(this, parentElement, (Person) entity, removeListener, style, isNomenclatural);
2760
        } else if (entity instanceof Credit) {
2761
            element = new CreditElement(this, parentElement, (Credit) entity, removeListener, style);
2762
        } else if (entity instanceof Extension) {
2763
            element = new ExtensionElement(this, parentElement, (Extension) entity, removeListener, style);
2764
        } else if (entity instanceof ExternalLink) {
2765
            element = new ExternalLinksElement(this, parentElement, (ExternalLink) entity, removeListener, style);
2766
        } else if (entity instanceof Marker) {
2767
            element = new MarkerElement(this, parentElement, (Marker) entity, removeListener, style);
2768
        } else if (entity instanceof TaxonNodeAgentRelation) {
2769
            element = new TaxonNodeAgentRelationCollectionElement(this, parentElement, (TaxonNodeAgentRelation) entity, removeListener, backgroundColor, style);
2770
        }else if (entity instanceof Media) {
2771
            element = new MediaMetaElement(this, parentElement, (Media) entity, removeListener, style);
2772
        } else if (entity instanceof MediaRepresentation) {
2773
            element = new MediaRepresentationElement(this, parentElement, (MediaRepresentation) entity, removeListener,
2774
                    style);
2775
        } else if (entity instanceof ImageFile) {
2776
            element = new ImageFileElement(this, parentElement, (ImageFile) entity, removeListener, style);
2777
        } else if (entity instanceof MediaRepresentationPart) {
2778
            element = new MediaRepresentationPartElement<>(this, parentElement, (MediaRepresentationPart) entity,
2779
                    removeListener, style);
2780
        } else if (entity instanceof NomenclaturalStatus) {
2781
            element = new NomenclaturalStatusElement(this, parentElement, (NomenclaturalStatus) entity, removeListener,
2782
                    style);
2783
        } else if (entity instanceof Rights) {
2784
            element = new RightsElement(this, parentElement, (Rights) entity, removeListener, style);
2785
        } else if (entity instanceof DescriptionElementSource && parentElement.getEntity() instanceof CommonTaxonName) {
2786
            element = new CommonNameSourceElement(this, parentElement, (DescriptionElementSource) entity,
2787
                    removeListener, style);
2788
        } else if (entity instanceof DescriptionElementSource) {
2789
            element = new DescriptionElementSourceElement(this, parentElement, (DescriptionElementSource) entity,
2790
                    removeListener, style, false);
2791
        } else if (entity instanceof TaxonNodeAgentRelation) {
2792
            element = new TaxonNodeAgentRelationCollectionElement(this, parentElement, (TaxonNodeAgentRelation) entity,
2793
                    removeListener,backgroundColor, style);
2794
        }
2795
        else if (entity instanceof IdentifiableSource) {
2796
            element = new IdentifiableSourceElement(this, parentElement, (IdentifiableSource) entity, removeListener,
2797
                    style);
2798
        } else if (entity instanceof DefinedTerm) {
2799
            switch(((DefinedTerm)entity).getTermType()) {
2800
            case Scope:
2801
                element = new ScopeElement(this,
2802
                        parentElement,
2803
                        (DefinedTerm) entity,
2804
                        removeListener,
2805
                        style);
2806
                break;
2807
            case Modifier:
2808
                element = new ModifierElement(this,
2809
                        parentElement,
2810
                        (DefinedTerm) entity,
2811
                        removeListener,
2812
                        style);
2813
                break;
2814
            default:
2815
                break;
2816

    
2817
            }
2818
        } else if (entity instanceof Reference) {
2819
            if(parentElement instanceof SequenceReferenceCollectionDetailSection){
2820
                element = new SequenceReferenceCollectionDetailElement(this, parentElement, (Reference) entity, removeListener, style);
2821
            }
2822
            else{
2823
                element = new DescriptionSourceElement(this, parentElement, (Reference) entity, removeListener, style);
2824
            }
2825
        } else if (entity instanceof NameTypeDesignation) {
2826
            element = new NameTypeDesignationElement(this, parentElement, (NameTypeDesignation) entity, removeListener,
2827
                    style);
2828
        } else if (entity instanceof TextualTypeDesignation) {
2829
            element = new TextTypeDesignationElement(this, parentElement, (TextualTypeDesignation) entity, removeListener,
2830
                    style);
2831
        } else if (entity instanceof NameRelationship) {
2832
            element = new NameRelationshipDetailElement(this, parentElement, (NameRelationship) entity, removeListener,
2833
                    style);
2834
        } else if (entity instanceof SpecimenTypeDesignation) {
2835
            if(parentElement instanceof DerivedUnitTypeDesignationSection){
2836
                element = new DerivedUnitTypeDesignationElement(this, parentElement, (SpecimenTypeDesignation) entity,
2837
                        removeListener, style);
2838
            }
2839
            else{
2840
                element = new SpecimenTypeDesignationElement(this, parentElement, (SpecimenTypeDesignation) entity,
2841
                        removeListener, style);
2842
            }
2843
        } else if (entity instanceof StateData) {
2844
            element = new StateDataElement(this, parentElement, (StateData) entity, removeListener, style);
2845
        } else if (entity instanceof StatisticalMeasurementValue) {
2846
            element = new StatisticalMeasurementValueElement(this, parentElement, (StatisticalMeasurementValue) entity,
2847
                    removeListener, style);
2848
        } else if (entity instanceof DerivedUnit) {
2849
            switch(((DerivedUnit)entity).getRecordBasis()) {
2850
            case LivingSpecimen:
2851
            case PreservedSpecimen:
2852
            case OtherSpecimen:
2853
                element = new SpecimenCollectionDetailElement(this,
2854
                        parentElement,
2855
                        (DerivedUnit) entity,
2856
                        removeListener,
2857
                        style);
2858
                break;
2859
            default:
2860
                element = new DerivedUnitElement(this,
2861
                        parentElement,
2862
                        (DerivedUnit) entity,
2863
                        removeListener,
2864
                        style);
2865
            }
2866

    
2867
        } else if (entity instanceof NamedArea) {
2868
            element = new CollectingAreaDetailElement(this, parentElement, (NamedArea) entity, removeListener, style);
2869
        } else if (entity instanceof DeterminationEvent) {
2870
            element = new DeterminationEventDetailElement(this, parentElement, (DeterminationEvent) entity, removeListener, style);
2871
        } else if (entity instanceof User) {
2872
            element = new MemberDetailElement(this, parentElement, (User) entity, removeListener, style);
2873
        } else if (entity instanceof GrantedAuthority) {
2874
            element = new GrantedAuthorityCollectionElement(this, parentElement, (GrantedAuthorityImpl) entity, ((Group)parentElement.getEntity()),
2875
                    removeListener, style);
2876
        } else if (entity instanceof Group) {
2877
            element = new GroupsByUserDetailElement(this, parentElement, (Group) entity, removeListener, style);
2878
        } else if (entity instanceof Taxon) {
2879
            element = new TaxonDetailElement(this, parentElement, (Taxon) entity, removeListener, style);
2880
        } else if (entity instanceof DescriptionElementBase) {
2881
            // this is the special case for protologs, maybe we can do this
2882
            // differently when API improves
2883
            DescriptionElementBase descriptionElement = (DescriptionElementBase) entity;
2884
            if (descriptionElement.getFeature().equals(Feature.PROTOLOGUE())) {
2885
                element = new ProtologueElement(this, parentElement, descriptionElement, removeListener, style);
2886
            }
2887
        } else if (entity instanceof Identifier) {
2888
            if(parentElement instanceof AbstractSampleDesignationDetailSection){
2889
                element = new SampleDesignationTextDetailElement(this, parentElement, (Identifier<DnaSample>) entity, removeListener, backgroundColor, style);
2890
            }
2891
            else{
2892
                element = new IdentifierElement(this, parentElement, (Identifier) entity, removeListener, style);
2893
            }
2894
        } else if (entity instanceof TermVocabulary) {
2895
            TermVocabulary<?> termVocabulary = (TermVocabulary<?>)entity;
2896
            switch (termVocabulary.getTermType()) {
2897
            case State:
2898
                element = new StateVocabularyCollectionElement(this, parentElement, (TermVocabulary<State>) entity, removeListener, backgroundColor, style);
2899
                break;
2900
            case Modifier:
2901
                element = new RecommendedModifierVocabulariesElement(this, parentElement, (TermVocabulary<DefinedTerm>) entity, removeListener, backgroundColor, style);
2902
                break;
2903
            default:
2904
                break;
2905
            }
2906
        } else if (entity instanceof MeasurementUnit) {
2907
            element = new MeasurementUnitCollectionElement(this, parentElement, (MeasurementUnit) entity, removeListener, backgroundColor, style);
2908
        } else if (entity instanceof StatisticalMeasure) {
2909
            element = new StatisticalMeasureCollectionElement(this, parentElement, (StatisticalMeasure) entity, removeListener, backgroundColor, style);
2910
        } else if (entity instanceof FeatureState && parentElement instanceof InapplicableIfEntityCollectionSection) {
2911
            element = new InapplicableIfCollectionElement(this, parentElement, (FeatureState) entity, removeListener, backgroundColor, style);
2912
        } else if (entity instanceof FeatureState && parentElement instanceof OnlyApplicableIfEntityCollectionSection) {
2913
            element = new OnlyApplicableIfCollectionElement(this, parentElement, (FeatureState) entity, removeListener, backgroundColor, style);
2914
        }
2915

    
2916
        //check for parent section when entity is null
2917
        //this happens when AbstractUnboundEntityCollectionSection is used
2918
        if(element==null){
2919
            if(parentElement instanceof ScopeSection || parentElement instanceof ScopeRestrictionSection){
2920
                element = new ScopeElement(this,
2921
                        parentElement,
2922
                        (DefinedTerm) entity,
2923
                        removeListener,
2924
                        style);
2925
            }
2926
            else if(parentElement instanceof ModifierSection){
2927
                element = new ModifierElement(this,
2928
                        parentElement,
2929
                        (DefinedTerm) entity,
2930
                        removeListener,
2931
                        style);
2932
            }
2933
        }
2934

    
2935

    
2936
        if (element == null) {
2937
            MessagingUtils.messageDialog(
2938
                    String.format("Error when creating section %s",
2939
                            parentElement.getClass().getSimpleName()),
2940
                    this,
2941
                    String.format("Could not generate collection element for entity of class %s."
2942
                            + " Looks like the case is not yet handled. Check implementation.\n"
2943
                            + "Entity: %s", entity.getClass(), entity.toString()), null);
2944
        }
2945

    
2946
        else{
2947
            if (backgroundColor != null && !backgroundColor.isDisposed()) {
2948
                element.setPersistentBackground(backgroundColor);
2949
            }
2950
            adapt(element);
2951
            parentElement.addElement(element);
2952
        }
2953

    
2954
        return element;
2955
    }
2956

    
2957
    /**
2958
     * <p>
2959
     * Creates a selection element for the given type T.
2960
     * </p>
2961
     * <p>
2962
     * <strong>Selection elements not handled by this method:</strong>
2963
     * <ul>
2964
     * <li>{@link TaxonNodeSelectionElement} see
2965
     * {@link #createTaxonNodeSelectionElement(ConversationHolder, ICdmFormElement, String, TaxonNode, int, int)}
2966
     * </li>
2967
     * <li>{@link NomenclaturalAuthorTeamSelectionElement} see
2968
     * {@link #createNomenclaturalAuthorTeamSelectionElement(ConversationHolder, ICdmFormElement, String, Team, int, int)}
2969
     * </li>
2970
     * </ul>
2971
     * </p>
2972
     *
2973
     * @param clazz
2974
     *            a {@link Class} object of the type that you want the selection
2975
     *            element to handle
2976
     * @param parentElement
2977
     *            a {@link ICdmFormElement} object.
2978
     * @param labelString
2979
     *            a {@link String} object.
2980
     * @param selectionType
2981
     * @param selection
2982
     *            a {@link ICdmBase} object.
2983
     * @param style
2984
     *            a int.
2985
     * @param conversation
2986
     *            a {@link ConversationHolder} object.
2987
     * @return a {@link EntitySelectionElement} object.
2988
     */
2989
    public <T extends CdmBase> EntitySelectionElement<T> createSelectionElement(Class<T> clazz,
2990
            ICdmFormElement parentElement, String labelString, T selection, int mode,
2991
            int style, boolean filterElement) {
2992
        EntitySelectionElement<T> element = new EntitySelectionElement<T>(this, //conversation,
2993
                parentElement, clazz,
2994
                labelString, selection, mode, style, filterElement);
2995
        adapt(element);
2996
        parentElement.addElement(element);
2997
        return element;
2998
    }
2999

    
3000
    public <T extends CdmBase> EntitySelectionElement<T> createSelectionElement(Class<T> clazz,
3001
//            ConversationHolder conversation,
3002
            ICdmFormElement parentElement, String labelString, T selection, int mode,
3003
            int style) {
3004
        EntitySelectionElement<T> element = new EntitySelectionElement<T>(this,
3005
                parentElement, clazz,
3006
                labelString, selection, mode, style);
3007
        adapt(element);
3008
        parentElement.addElement(element);
3009
        return element;
3010
    }
3011

    
3012
    public CommonNameReferenceSelectionElement createCommonNameReferenceSelectionElement(ICdmFormElement parentElement, String labelString, Reference selection, int mode,
3013
          int style) {
3014
        CommonNameReferenceSelectionElement element = new CommonNameReferenceSelectionElement(this,
3015
              parentElement, labelString, selection, mode, style);
3016
      adapt(element);
3017
      parentElement.addElement(element);
3018
      return element;
3019
  }
3020

    
3021
    /**
3022
     * <p>
3023
     * Creates a selection element for the given type T which shows only the <b>abbreviated</b> title as the label.
3024
     * </p>
3025
     * <p>
3026
     * <strong>Selection elements not handled by this method:</strong>
3027
     * <ul>
3028
     * <li>{@link TaxonNodeSelectionElement} see
3029
     * {@link #createTaxonNodeSelectionElement(ConversationHolder, ICdmFormElement, String, TaxonNode, int, int)}
3030
     * </li>
3031
     * <li>{@link NomenclaturalAuthorTeamSelectionElement} see
3032
     * {@link #createNomenclaturalAuthorTeamSelectionElement(ConversationHolder, ICdmFormElement, String, Team, int, int)}
3033
     * </li>
3034
     * </ul>
3035
     * </p>
3036
     *
3037
     * @param clazz
3038
     *            a {@link Class} object of the type that you want the selection
3039
     *            element to handle
3040
     * @param parentElement
3041
     *            a {@link ICdmFormElement} object.
3042
     * @param labelString
3043
     *            a {@link String} object.
3044
     * @param selectionType
3045
     * @param selection
3046
     *            a {@link ICdmBase} object.
3047
     * @param style
3048
     *            a int.
3049
     * @param conversation
3050
     *            a {@link ConversationHolder} object.
3051
     * @return a {@link EntitySelectionElement} object.
3052
     */
3053
    public <T extends CdmBase> EntitySelectionElementWithAbbreviatedTitle<T> createSelectionElementWithAbbreviatedTitle(
3054
            Class<T> clazz, ConversationHolder conversation, ICdmFormElement parentElement, String labelString,
3055
            T selection, int mode, int style) {
3056
        EntitySelectionElementWithAbbreviatedTitle<T> element = new EntitySelectionElementWithAbbreviatedTitle<T>(this, //conversation,
3057
                parentElement, clazz,
3058
                labelString, selection, mode, style);
3059
        adapt(element);
3060
        parentElement.addElement(element);
3061
        return element;
3062
    }
3063

    
3064
    public TaxonNodeSelectionElement createTaxonNodeSelectionElement(ConversationHolder conversation,
3065
            ICdmFormElement parentElement, String labelString, TaxonNode selection, int mode, int style) {
3066
        TaxonNodeSelectionElement element = new TaxonNodeSelectionElement(this, //conversation,
3067
                parentElement,
3068
                labelString, selection, mode, style);
3069
        adapt(element);
3070
        parentElement.addElement(element);
3071
        return element;
3072
    }
3073

    
3074

    
3075

    
3076
//    public NomenclaturalAuthorTeamSelectionElement createNomenclaturalAuthorTeamSelectionElement(
3077
//            ConversationHolder conversation, ICdmFormElement parentElement, String labelString, Team selection,
3078
//            int mode, int style) {
3079
//        NomenclaturalAuthorTeamSelectionElement element = new NomenclaturalAuthorTeamSelectionElement(this,
3080
//                conversation, parentElement, labelString, selection, mode, style);
3081
//        adapt(element);
3082
//        parentElement.addElement(element);
3083
//        return element;
3084
//    }
3085

    
3086
    /** {@inheritDoc} */
3087
    public LabelElement createLabel(ICdmFormElement parentElement, String text) {
3088
        LabelElement labelElement = new LabelElement(this, parentElement, text);
3089
        adapt(labelElement);
3090
        parentElement.addElement(labelElement);
3091
        return labelElement;
3092
    }
3093

    
3094

    
3095

    
3096
//    public DateElementFormElement createDateElementForm(ICdmFormElement formElement, String labelText, DateTime dateTime, int style){
3097
//        Label label = new Label(formElement.getLayoutComposite(), style);
3098
//        label.setText(labelText+" (yyyy-MM-dd)");
3099
//        DateElementFormElement dateElement = new DateElementFormElement(this, dateTime, style, formElement.getLayoutComposite());
3100
//        dateElement.initInternalController();
3101
//
3102
//        return dateElement;
3103
//    }
3104

    
3105
    public DateElement createDateElement(ICdmFormElement formElement, String labelText, DateTime dateTime, int style, boolean editableText){
3106
    	 Label label = new Label(formElement.getLayoutComposite(), style);
3107
         label.setText(labelText);
3108
         label.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE, 1, 1));
3109
         DateElement dateElement = new DateElement(formElement.getLayoutComposite(), dateTime, labelText, style, editableText);
3110
         dateElement.initController(this, formElement);
3111
         dateElement.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE, 1, 1));
3112
         return dateElement;
3113
    }
3114

    
3115
    /**
3116
     * <p>
3117
     * Getter for the field <code>selectionProvider</code>.
3118
     * </p>
3119
     *
3120
     * @return a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
3121
     */
3122
    public ISelectionProvider getSelectionProvider() {
3123
        return selectionProvider;
3124
    }
3125

    
3126
    /**
3127
     * <p>
3128
     * createDetailedDescriptionDetailElement
3129
     * </p>
3130
     *
3131
     * @param parentElement
3132
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
3133
     *            object.
3134
     * @param entity
3135
     *            a
3136
     *            {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase}
3137
     *            object.
3138
     * @param style
3139
     *            a int.
3140
     * @return a
3141
     *         {@link eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement}
3142
     *         object.
3143
     */
3144
    public AbstractDetailedDescriptionDetailElement createDetailedDescriptionDetailElement(
3145
            ICdmFormElement parentElement, DescriptionElementBase entity, int style, boolean enabled) {
3146
        AbstractDetailedDescriptionDetailElement detailedDescriptionElement = null;
3147

    
3148
        if (entity instanceof CategoricalData) {
3149
            detailedDescriptionElement = new CategoricalDataDetailElement(this, parentElement,
3150
                    (CategoricalData) entity, style);
3151
        } else if (entity instanceof CommonTaxonName) {
3152
            detailedDescriptionElement = new CommonNameDetailElement(this, parentElement, (CommonTaxonName) entity,
3153
                    style);
3154
        } else if (entity instanceof Distribution && !enabled) {
3155
            detailedDescriptionElement = new DistributionDetailElement(this, parentElement, (Distribution) entity,
3156
                    enabled, style);
3157
        } else if (entity instanceof Distribution) {
3158
            detailedDescriptionElement = new DistributionDetailElement(this, parentElement, (Distribution) entity,
3159
                    true, style);
3160
        }else if (entity instanceof IndividualsAssociation) {
3161
            detailedDescriptionElement = new IndividualsAssociationDetailElement(this, parentElement,
3162
                    (IndividualsAssociation) entity, style);
3163
        } else if (entity instanceof QuantitativeData) {
3164
            detailedDescriptionElement = new QuantitativeDataDetailElement(this, parentElement,
3165
                    (QuantitativeData) entity, style);
3166
        } else if (entity instanceof TaxonInteraction) {
3167
            detailedDescriptionElement = new TaxonInteractionDetailElement(this, parentElement,
3168
                    (TaxonInteraction) entity, style);
3169
        } else if (entity instanceof TextData) {
3170
            detailedDescriptionElement = new TextDataDetailElement(this, parentElement, (TextData) entity, style);
3171
        } else {
3172
            throw new IllegalStateException("There is no interface for the given description element");
3173
        }
3174
        adapt(detailedDescriptionElement);
3175
        parentElement.addElement(detailedDescriptionElement);
3176
        return detailedDescriptionElement;
3177

    
3178
    }
3179

    
3180
    /**
3181
     * Creates a styled text as a part of the form.
3182
     *
3183
     * @param parent
3184
     *            the text parent
3185
     * @param value
3186
     *            the text initial value
3187
     * @param style
3188
     *            the text style
3189
     * @return the text widget
3190
     */
3191
    public StyledText createStyledText(Composite parent, String value, int style) {
3192
        StyledText text = new StyledText(parent, getBorderStyle() | style | getOrientation());
3193
        if (value != null) {
3194
            text.setText(value);
3195
        }
3196
        text.setForeground(getColors().getForeground());
3197
        text.setBackground(getColors().getBackground());
3198
        // text.addFocusListener(visibilityHandler);
3199
        return text;
3200
    }
3201

    
3202
    public PreservedSpecimenDetailSection createPreservedSpecimenDetailsSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
3203
        PreservedSpecimenDetailSection section = new PreservedSpecimenDetailSection(this, conversation, parentElement, selectionProvider, style);
3204
        addAndAdaptSection(parentElement, section);
3205
        return section;
3206
    }
3207

    
3208
    /**
3209
     * @param formElement
3210
     * @param conversationHolder
3211
     * @param style
3212
     * @return
3213
     */
3214
    public TaxonNodeAgentRelationCollectionSection createTaxonNodeAgentRelationCollectionSection(
3215
            ICdmFormElement formElement, ConversationHolder conversationHolder, int style) {
3216
        TaxonNodeAgentRelationCollectionSection section = new TaxonNodeAgentRelationCollectionSection(this, conversationHolder, formElement, style);
3217
        addAndAdaptSection(formElement, section);
3218
        return section;
3219
    }
3220

    
3221

    
3222
	public TaxonOfRelationshipElement createTaxonOfRelationshipDetailElement(
3223
			ICdmFormElement parentElement, int style) {
3224
		TaxonOfRelationshipElement section = new TaxonOfRelationshipElement(this, parentElement, style);
3225
		addAndAdaptElement(parentElement, section);
3226
        return section;
3227
	}
3228

    
3229
	public TaxonDetailSection createTaxonDetailSection(ConversationHolder conversationHolder,
3230
			ICdmFormElement formElement, ISelectionProvider selectionProvider, int style) {
3231
			TaxonDetailSection section = new TaxonDetailSection(this, conversationHolder, formElement, selectionProvider, style);
3232
	        addAndAdaptSection(formElement, section);
3233
	        return section;
3234
	}
3235

    
3236
	  /**
3237
     * <p>
3238
     * createTextWithLabelElement
3239
     * </p>
3240
     *
3241
     * @param parentElement
3242
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
3243
     *            object.
3244
     * @param labelString
3245
     *            a {@link java.lang.String} object.
3246
     * @param initialText
3247
     *            a {@link java.lang.String} object.
3248
     * @param textLimit maximal number of characters allowed
3249
     * @param style
3250
     *            a int.
3251
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
3252
     *         object.
3253
     */
3254
    public RuleConsideredElement createRuleConsideredElement(ICdmFormElement parentElement, String labelString,
3255
            NameRelationship relation, int style) {
3256

    
3257

    
3258
        RuleConsideredElement element = new RuleConsideredElement(this, parentElement, labelString, relation, style);
3259
        adapt(element);
3260
        parentElement.addElement(element);
3261
        return element;
3262
    }
3263

    
3264
    /**
3265
     * <p>
3266
     * createTextWithLabelElement
3267
     * </p>
3268
     *
3269
     * @param parentElement
3270
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
3271
     *            object.
3272
     * @param labelString
3273
     *            a {@link java.lang.String} object.
3274
     * @param initialText
3275
     *            a {@link java.lang.String} object.
3276
     * @param textLimit maximal number of characters allowed
3277
     * @param style
3278
     *            a int.
3279
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
3280
     *         object.
3281
     */
3282
    public RuleConsideredElement createRuleConsideredElement(ICdmFormElement parentElement, String labelString,
3283
            NomenclaturalStatus status, int style) {
3284

    
3285

    
3286
        RuleConsideredElement element = new RuleConsideredElement(this, parentElement, labelString, status, style);
3287
        adapt(element);
3288
        parentElement.addElement(element);
3289
        return element;
3290
    }
3291
    /**
3292
     * <p>
3293
     * createTextWithLabelElement
3294
     * </p>
3295
     *
3296
     * @param parentElement
3297
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
3298
     *            object.
3299
     * @param labelString
3300
     *            a {@link java.lang.String} object.
3301
     * @param initialText
3302
     *            a {@link java.lang.String} object.
3303
     * @param textLimit maximal number of characters allowed
3304
     * @param style
3305
     *            a int.
3306
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
3307
     *         object.
3308
     */
3309
    public RuleConsideredElement createRuleConsideredElement(ICdmFormElement parentElement, String labelString,
3310
            int style) {
3311

    
3312

    
3313
        RuleConsideredElement element = new RuleConsideredElement(this, parentElement, labelString, style);
3314
        adapt(element);
3315
        parentElement.addElement(element);
3316
        return element;
3317
    }
3318

    
3319

    
3320
//	public RichTextWithLabelElement createRichTextLabelElement(ICdmFormElement parentElement, String labelString, String initialText, int textHeight, int style) {
3321
//		 RichTextWithLabelElement element = new RichTextWithLabelElement(this, parentElement, labelString,
3322
//				 initialText, textHeight, style);
3323
//	        adapt(element);
3324
//	        parentElement.addElement(element);
3325
//	        return element;
3326
//	}
3327

    
3328

    
3329

    
3330

    
3331

    
3332

    
3333

    
3334
}
(7-7/48)