Project

General

Profile

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

    
373
/**
374
 * <p>
375
 * CdmFormFactory class.
376
 * </p>
377
 *
378
 * @author n.hoffmann
379
 * @created Feb 24, 2010
380
 */
381
public class CdmFormFactory extends FormToolkit {
382

    
383
    private BoldFontHolder2 boldFontHolder2;
384
    private MouseListener selectionMouseHandler;
385
    private FocusListener selectionFocusHandler;
386

    
387
    @Inject
388
    private IEclipseContext context;
389

    
390
    private final Set<SelectionListener> selectionListenerList = new HashSet<SelectionListener>();
391

    
392
    private final List<IPropertyChangeListener> propertyChangeListeners = new ArrayList<IPropertyChangeListener>();
393

    
394
    private final int orientation = Window.getDefaultOrientation();
395
    private ISelectionProvider selectionProvider;
396

    
397
    /** Constant <code>EMPTY_SELECTION</code> */
398
    public static ISelection EMPTY_SELECTION = new ISelection() {
399
        @Override
400
        public boolean isEmpty() {
401
            return true;
402
        }
403
    };
404

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

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

    
431
    private void notifySelectionListeners(TypedEvent e) {
432
        Event event = new Event();
433
        event.widget = e.widget;
434
        SelectionEvent selectionEvent = new SelectionEvent(event);
435

    
436
        for (SelectionListener listener : selectionListenerList) {
437
            listener.widgetSelected(selectionEvent);
438
        }
439
    }
440

    
441
    public CdmFormFactory(Display display) {
442
        this(display, null);
443
    }
444

    
445
    public CdmFormFactory(Display display, ISelectionProvider selectionProvider) {
446
        super(display);
447
        this.selectionProvider = selectionProvider;
448
        init();
449
    }
450

    
451
    private void init() {
452
        boldFontHolder2 = new BoldFontHolder2();
453
        selectionMouseHandler = new SelectionMouseHandler();
454
        selectionFocusHandler = new SelectionFocusHandler();
455
    }
456

    
457
    public IEclipseContext getContext() {
458
        return context;
459
    }
460

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

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

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

    
519
    /** {@inheritDoc} */
520
    @Override
521
    public void adapt(Control control, boolean trackFocus, boolean trackKeyboard) {
522
        if (trackFocus) {
523
            control.addFocusListener(selectionFocusHandler);
524
        }
525
        super.adapt(control, trackFocus, trackKeyboard);
526
    }
527

    
528
    /** {@inheritDoc} */
529
    @Override
530
    public void adapt(Composite composite) {
531
        composite.addMouseListener(selectionMouseHandler);
532

    
533
        super.adapt(composite);
534
    }
535

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

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

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

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

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

    
673
    public KeyStatementElement createKeyStatementElement(ICdmFormElement parentElement, String labelString,
674
            KeyStatement keyStatement, int textHeight, int style) {
675
        KeyStatementElement element = new KeyStatementElement(this, parentElement, labelString, keyStatement,
676
                textHeight, style);
677
        adapt(element);
678
        parentElement.addElement(element);
679
        return element;
680
    }
681

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

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

    
742
        TextWithLabelElement element = new TextWithLabelElement(this, parentElement, labelString, initialText, null,
743
                textLimit, style);
744
        adapt(element);
745
        parentElement.addElement(element);
746
        return element;
747
    }
748

    
749
    public TextWithLabelElement createMultiLineTextWithLabel(ICdmFormElement parentElement, String labelString,
750
            int textHeight, int style) {
751
        TextWithLabelElement element = new TextWithLabelElement(this, parentElement, labelString, "", textHeight, true, style);
752
        adapt(element);
753
        parentElement.addElement(element);
754
        return element;
755
    }
756

    
757
    public LsidWithExceptionLabelElement createLsidWithExceptionLabelElement(ICdmFormElement parentElement, String labelString,
758
            LSID initialLsid, int style) {
759
        LsidWithExceptionLabelElement element = new LsidWithExceptionLabelElement(this, parentElement, labelString, initialLsid, null, style);
760
        adapt(element);
761
        parentElement.addElement(element);
762
        return element;
763
    }
764

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

    
780

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

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

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

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

    
857
    public LanguageStringWithLabelElement createLanguageStringWithLabelElement(ICdmFormElement parentElement,
858
            String labelString, LanguageString languageString, int style) {
859
        return createLanguageStringWithLabelElement(parentElement, labelString, languageString, null, false, style);
860
    }
861

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

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

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

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

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

    
936
	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
937
            List<T> terms,
938
            ICdmFormElement parentElement,
939
            String labelString,
940
            T selection,
941
            int style) {
942
        return  this.createDefinedTermComboElement(null, null, terms, parentElement, labelString, selection, true, style, false, null);
943
    }
944
    public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
945
			TermType termType,
946
			ICdmFormElement parentElement,
947
			String labelString,
948
			T selection,
949
			boolean addEmptyElement,
950
			int style,
951
			boolean useAbbrevLabel) {
952
		return createDefinedTermComboElement(termType, null, null, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
953
	}
954

    
955

    
956
    public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
957
            TermVocabulary<?> termVocabulary,
958
            ICdmFormElement parentElement,
959
            String labelString,
960
            T selection,
961
            int style) {
962
        return this.createDefinedTermComboElement(null, termVocabulary, null, parentElement, labelString, selection, true, style, false, null);
963
    }
964

    
965
	public <T extends DefinedTermBase> TermComboElement<T> createDefinedTermComboElement(
966
	        TermVocabulary<?> termVocabulary,
967
	        ICdmFormElement parentElement,
968
	        String labelString,
969
	        T selection,
970
	        boolean addEmptyElement,
971
	        int style,
972
	        boolean useAbbrevLabel) {
973
	    return createDefinedTermComboElement(null, termVocabulary, null, parentElement, labelString, selection, addEmptyElement, style, useAbbrevLabel, null);
974
	}
975

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

    
1003
	        TermComboElement<T> element = new TermComboElement<T>(this, parentElement, terms, labelString, selection, addEmptyElement, style, useAbbrevLabel);
1004
            if (comparator!= null){
1005
                element.setTermComparator(comparator);
1006
            }
1007
            adapt(element);
1008
            parentElement.addElement(element);
1009
            return element;
1010
	    }
1011
	    else {
1012
	        //this should never happen
1013
	        return null;
1014
	    }
1015
	}
1016

    
1017
	public NameRelationshipTypeCombo createNameRelationshipTypeCombo(ICdmFormElement parentElement,
1018
            String labelString,
1019
            int style,
1020
            boolean useAbbrevLabel,
1021
            Comparator<NameRelationshipType> comparator) {
1022

    
1023
        NameRelationshipTypeCombo<InverseTermWrapper> element = new NameRelationshipTypeCombo(this, parentElement, labelString, true, style, useAbbrevLabel, comparator);
1024
        adapt(element);
1025
        parentElement.addElement(element);
1026
        return element;
1027
    }
1028

    
1029
	public MisappliedRelationshipComboElement createMisappliedRelationshipComboElement(
1030
	        ICdmFormElement parentElement,
1031
            String labelString,
1032
            TaxonRelationshipType selection,
1033
            int style) {
1034
	    MisappliedRelationshipComboElement combo = new MisappliedRelationshipComboElement(this, parentElement, labelString, selection, false, style, false);
1035
	    adapt(combo);
1036
        parentElement.addElement(combo);
1037
        return combo;
1038
    }
1039

    
1040
	public <T extends IEnumTerm<T>> EnumComboElement<T> createEnumComboElement(
1041
	        Class<T> enumComboType, ICdmFormElement parentElement,
1042
	        int style) {
1043
	    return createEnumComboElement(enumComboType, parentElement, null, style);
1044
	}
1045

    
1046
	public <T extends IEnumTerm<T>> EnumComboElement<T> createEnumComboElement(
1047
			Class<T> enumComboType, ICdmFormElement parentElement, Comparator<T> comparator,
1048
			int style) {
1049
        EnumComboElement<T> element = new EnumComboElement<T>(this, parentElement, enumComboType, comparator, style);
1050
        adapt(element);
1051
        parentElement.addElement(element);
1052
        return element;
1053
    }
1054

    
1055
	public <TERM extends DefinedTermBase<TERM>, VOC extends TermVocabulary<TERM>> VocabularyComboElement<TERM, VOC> createVocabularyComboElement(
1056
	        TermType termType, String label, VOC selection, ICdmFormElement parentElement, int style) {
1057
	    VocabularyComboElement<TERM, VOC> element = new VocabularyComboElement<TERM, VOC>(this, parentElement, termType, label, selection, style);
1058
	    adapt(element);
1059
	    parentElement.addElement(element);
1060
	    return element;
1061
	}
1062

    
1063
    /**
1064
     * <p>
1065
     * createBrowserElement
1066
     * </p>
1067
     *
1068
     * @param imageUri
1069
     *            a {@link java.net.URI} object.
1070
     * @param style
1071
     *            a int.
1072
     * @param parentElement
1073
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1074
     *            object.
1075
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.BrowserElement}
1076
     *         object.
1077
     */
1078
    public BrowserElement createBrowserElement(ICdmFormElement parentElement, URI imageUri, int style) {
1079
        BrowserElement element = new BrowserElement(this, parentElement, imageUri, style);
1080
        adapt(element);
1081
        parentElement.addElement(element);
1082
        return element;
1083
    }
1084

    
1085
    /**
1086
     * <p>
1087
     * createImageElement
1088
     * </p>
1089
     *
1090
     * @param parentElement
1091
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1092
     *            object.
1093
     * @param imageUri
1094
     *            a {@link java.net.URI} object.
1095
     * @param style
1096
     *            a int.
1097
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.ImageElement} object.
1098
     */
1099
    public ImageElement createImageElement(ICdmFormElement parentElement, URI imageUri, int style) {
1100
        ImageElement element = new ImageElement(this, parentElement, imageUri, style);
1101
        adapt(element);
1102
        parentElement.addElement(element);
1103
        return element;
1104
    }
1105

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

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

    
1161
    /**
1162
     * Creates a section as a part of the form.
1163
     *
1164
     * @return the section widget
1165
     * @param section
1166
     *            a
1167
     *            {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1168
     *            object.
1169
     */
1170
    public Section adapt(AbstractFormSection section) {
1171
        section.setMenu(section.getLayoutComposite().getMenu());
1172
        adapt(section, true, true);
1173

    
1174
        // handle focus and property change events for cdm use
1175
        section.addFocusListener(selectionFocusHandler);
1176
        section.setPropertyChangeListeners(propertyChangeListeners);
1177

    
1178
        section.addExpansionListener(new ExpansionAdapter(){
1179
            @Override
1180
            public void expansionStateChanged(ExpansionEvent e) {
1181
                super.expansionStateChanged(e);
1182
                if(section.getEntity()!=null){
1183
                    PreferencesUtil.setStringValue(StoreUtil.getPrefKey(section.getClass(), section.getEntity().getClass().getCanonicalName()), e.getState()?CdmSectionPart.EXPANDED:CdmSectionPart.COLLAPSED);
1184
                }
1185
            }
1186
        });
1187

    
1188
        if (section.getToggle() != null) {
1189
            section.getToggle().setHoverDecorationColor(getColors().getColor(IFormColors.TB_TOGGLE_HOVER));
1190
            section.getToggle().setDecorationColor(getColors().getColor(IFormColors.TB_TOGGLE));
1191
        }
1192

    
1193
        section.setFont(boldFontHolder2.getBoldFont(section.getLayoutComposite().getFont()));
1194

    
1195
        if ((section.getStyle() & ExpandableComposite.TITLE_BAR) != 0
1196
                || (section.getStyle() & ExpandableComposite.SHORT_TITLE_BAR) != 0) {
1197
            getColors().initializeSectionToolBarColors();
1198
            section.setTitleBarBackground(getColors().getColor(IFormColors.TB_BG));
1199
            section.setTitleBarBorderColor(getColors().getColor(IFormColors.TB_BORDER));
1200
        }
1201
        // call setTitleBarForeground regardless as it also sets the label color
1202
        section.setTitleBarForeground(getColors().getColor(IFormColors.TB_TOGGLE));
1203
        return section;
1204
    }
1205

    
1206
    private class BoldFontHolder2 {
1207
        private Font normalFont;
1208

    
1209
        private Font boldFont;
1210

    
1211
        public BoldFontHolder2() {
1212
        }
1213

    
1214
        public Font getBoldFont(Font font) {
1215
            createBoldFont(font);
1216
            return boldFont;
1217
        }
1218

    
1219
        private void createBoldFont(Font font) {
1220
            if (normalFont == null || !normalFont.equals(font)) {
1221
                normalFont = font;
1222
                dispose();
1223
            }
1224
            if (boldFont == null) {
1225
                boldFont = FormFonts.getInstance().getBoldFont(getColors().getDisplay(), normalFont);
1226
            }
1227
        }
1228

    
1229
        public void dispose() {
1230
            if (boldFont != null) {
1231
                FormFonts.getInstance().markFinished(boldFont, getColors().getDisplay());
1232
                boldFont = null;
1233
            }
1234
        }
1235
    }
1236

    
1237
    /**
1238
     * <p>
1239
     * createToggleableTextField
1240
     * </p>
1241
     *
1242
     * @param parentElement
1243
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1244
     *            object.
1245
     * @param labelString
1246
     *            a {@link java.lang.String} object.
1247
     * @param initialText
1248
     *            a {@link java.lang.String} object.
1249
     * @param initialState
1250
     *            a boolean.
1251
     * @param style
1252
     *            a int.
1253
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement}
1254
     *         object.
1255
     */
1256
    public ToggleableTextElement createToggleableTextField(ICdmFormElement parentElement, String labelString,
1257
            String initialText, boolean initialState, int style) {
1258
        ToggleableTextElement element = new ToggleableTextElement(this, parentElement, labelString, initialText,
1259
                initialState, style | orientation);
1260

    
1261
        adapt(element);
1262
        parentElement.addElement(element);
1263
        return element;
1264
    }
1265

    
1266
    /**
1267
     * <p>
1268
     * createTimePeriodElement
1269
     * </p>
1270
     *
1271
     * @param parentElement
1272
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1273
     *            object.
1274
     * @param labelString
1275
     *            a {@link java.lang.String} object.
1276
     * @param timePeriod
1277
     *            a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
1278
     * @param style
1279
     *            a int.
1280
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.TimePeriodElement}
1281
     *         object.
1282
     */
1283
    public TimePeriodElement createTimePeriodElement(ICdmFormElement parentElement, String labelString,
1284
            TimePeriod timePeriod, int style) {
1285
        TimePeriodElement element = new TimePeriodElement(this, parentElement, labelString, timePeriod, style);
1286
        adapt(element);
1287
        parentElement.addElement(element);
1288
        return element;
1289
    }
1290

    
1291
    /**
1292
     * <p>
1293
     * createVerbatimTimePeriodElement
1294
     * </p>
1295
     *
1296
     * @param parentElement
1297
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1298
     *            object.
1299
     * @param labelString
1300
     *            a {@link java.lang.String} object.
1301
     * @param timePeriod
1302
     *            a {@link eu.etaxonomy.cdm.model.common.VerbatimTimePeriod} object.
1303
     * @param style
1304
     *            a int.
1305
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.VerbatimTimePeriodElement}
1306
     *         object.
1307
     */
1308
    public VerbatimTimePeriodElement createVerbatimTimePeriodElement(ICdmFormElement parentElement, String labelString,
1309
            VerbatimTimePeriod timePeriod, int style) {
1310
        VerbatimTimePeriodElement element = new VerbatimTimePeriodElement(this, parentElement, labelString, timePeriod, style);
1311
        adapt(element);
1312
        parentElement.addElement(element);
1313
        return element;
1314
    }
1315

    
1316

    
1317

    
1318
	/**
1319
	 * <p>
1320
	 * createGatheringEventUnitElement
1321
	 * </p>
1322
	 *
1323
	 * @param parentElement
1324
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1325
	 *            object.
1326
	 * @param labelString
1327
	 *            a {@link java.lang.String} object.
1328
	 * @param timePeriod
1329
	 *            a {@link eu.etaxonomy.cdm.model.common.GatheringEvent} object.
1330
	 * @param style
1331
	 *            a int.
1332
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.GatheringEventUnitElement}
1333
	 *         object.
1334
	 */
1335
	public GatheringEventUnitElement createGatheringEventUnitElement(
1336
			ICdmFormElement parentElement,
1337
			String labelString,
1338
			DerivedUnitFacade gatheringEvent,
1339
			MinMaxTextSection.UnitType unitType,
1340
			int style) {
1341
		GatheringEventUnitElement element = new GatheringEventUnitElement(this,
1342
				parentElement,
1343
				labelString,
1344
				gatheringEvent,
1345
				unitType,
1346
				style);
1347
		adapt(element);
1348
		parentElement.addElement(element);
1349
		return element;
1350
	}
1351

    
1352
    /**
1353
     * <p>
1354
     * createPointElement
1355
     * </p>
1356
     *
1357
     * @param style
1358
     *            a int.
1359
     * @param parentElement
1360
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1361
     *            object.
1362
     * @param point
1363
     *            a {@link eu.etaxonomy.cdm.model.location.Point} object.
1364
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.PointElement} object.
1365
     */
1366
    public PointElement createPointElement(ICdmFormElement parentElement, Point point, int style) {
1367
        PointElement element = new PointElement(this, parentElement, point, style);
1368
        adapt(element);
1369
        parentElement.addElement(element);
1370
        return element;
1371
    }
1372

    
1373
    /**
1374
     * Creates an empty section with the given message.<br>
1375
     * If message is <code>null</code> a default message will be displayed.
1376
     */
1377
    public EmptySection createEmptySection(String message, CdmFormFactory formFactory, ICdmFormElement parentElement, int style) {
1378
        EmptySection section = new EmptySection(message, formFactory, parentElement, style);
1379
        parentElement.addElement(section);
1380
        adapt(section);
1381
        return section;
1382
    }
1383

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

    
1404
    /**
1405
     * <p>
1406
     * createVerbatimDateDetailSection
1407
     * </p>
1408
     *
1409
     * @param parentElement
1410
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1411
     *            object.
1412
     * @param style
1413
     *            a int.
1414
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.VerbatimDateDetailSection}
1415
     *         object.
1416
     */
1417
    public DateDetailSection<VerbatimTimePeriod> createVerbatimDateDetailSection(ICdmFormElement parentElement, int style) {
1418
        DateDetailSection<VerbatimTimePeriod> section
1419
        	= new DateDetailSection<VerbatimTimePeriod>(this, parentElement, true, style);
1420
        parentElement.addElement(section);
1421
        adapt(section);
1422
        return section;
1423
    }
1424

    
1425
	/**
1426
	 * <p>
1427
	 * createDateDetailSection
1428
	 * </p>
1429
	 *
1430
	 * @param parentElement
1431
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1432
	 *            object.
1433
	 * @param style
1434
	 *            a int.
1435
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.MinMaxTextSection}
1436
	 *         object.
1437
	 */
1438
	public MinMaxTextSection createMinMaxTextSection(ICdmFormElement parentElement, UnitType unitType, int style) {
1439
		MinMaxTextSection section = new MinMaxTextSection(this, parentElement, unitType, style);
1440
		parentElement.addElement(section);
1441
		adapt(section);
1442
		return section;
1443
	}
1444

    
1445
    /**
1446
     * <p>
1447
     * createPartialElement
1448
     * </p>
1449
     *
1450
     * @param parentElement
1451
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1452
     *            object.
1453
     * @param labelString
1454
     *            a {@link java.lang.String} object.
1455
     * @param partial
1456
     *            a {@link org.joda.time.Partial} object.
1457
     * @param style
1458
     *            a int.
1459
     * @return a {@link eu.etaxonomy.taxeditor.ui.element.PartialElement}
1460
     *         object.
1461
     */
1462
    public PartialElement createPartialElement(ICdmFormElement parentElement, String labelString, Partial partial,
1463
            int style) {
1464
        PartialElement element = new PartialElement(this, parentElement, labelString, style);
1465
        adapt(element);
1466
        parentElement.addElement(element);
1467
        return element;
1468
    }
1469

    
1470
    /**
1471
     * <p>
1472
     * addSelectionListener
1473
     * </p>
1474
     *
1475
     * @param listener
1476
     *            a {@link org.eclipse.swt.events.SelectionListener} object.
1477
     */
1478
    public void addSelectionListener(SelectionListener listener) {
1479
        selectionListenerList.add(listener);
1480
    }
1481

    
1482
    /**
1483
     * <p>
1484
     * removeSelectionListener
1485
     * </p>
1486
     *
1487
     * @param listener
1488
     *            a {@link org.eclipse.swt.events.SelectionListener} object.
1489
     */
1490
    public void removeSelectionListener(SelectionListener listener) {
1491
        if (listener == null) {
1492
            MessagingUtils.error(this.getClass(),
1493
                    "Tried to remove a selection listener from this factories listeners but was null", null);
1494
        } else {
1495
            selectionListenerList.remove(listener);
1496
        }
1497
    }
1498

    
1499
    /**
1500
     * <p>
1501
     * addPropertyChangeListener
1502
     * </p>
1503
     *
1504
     * @param listener
1505
     *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1506
     *            object.
1507
     */
1508
    public void addPropertyChangeListener(IPropertyChangeListener listener) {
1509
        if (propertyChangeListeners.contains(listener)) {
1510
            return;
1511
        }
1512
        propertyChangeListeners.add(0, listener);
1513
    }
1514

    
1515
    /**
1516
     * <p>
1517
     * removePropertyChangeListener
1518
     * </p>
1519
     *
1520
     * @param listener
1521
     *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1522
     *            object.
1523
     */
1524
    public void removePropertyChangeListener(IPropertyChangeListener listener) {
1525
        propertyChangeListeners.remove(listener);
1526
    }
1527

    
1528
    /**
1529
     * @return the propertyChangeListeners
1530
     */
1531
    public List<IPropertyChangeListener> getPropertyChangeListeners() {
1532
        return propertyChangeListeners;
1533
    }
1534

    
1535
    /**
1536
     * <p>
1537
     * createHorizontalSeparator
1538
     * </p>
1539
     *
1540
     * @param parentElement
1541
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1542
     *            object.
1543
     * @param style
1544
     *            a int.
1545
     * @return a {@link org.eclipse.swt.widgets.Label} object.
1546
     */
1547
    public Label createHorizontalSeparator(ICdmFormElement parentElement, int style) {
1548
        Label separator = this.createSeparator(parentElement.getLayoutComposite(), SWT.HORIZONTAL | style);
1549
        separator.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
1550
        return separator;
1551
    }
1552

    
1553
    /**
1554
     * <p>
1555
     * createVersionElement
1556
     * </p>
1557
     *
1558
     * @param parentElement
1559
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1560
     *            object.
1561
     * @param entity
1562
     *            a {@link eu.etaxonomy.cdm.model.common.VersionableEntity}
1563
     *            object.
1564
     * @param style
1565
     *            a int.
1566
     * @return a
1567
     *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionElement}
1568
     *         object.
1569
     */
1570
    public VersionElement createVersionElement(ICdmFormElement parentElement, VersionableEntity entity, int style) {
1571
        VersionElement element = new VersionElement(this, parentElement, entity, style);
1572
        adapt(element);
1573
        parentElement.addElement(element);
1574
        return element;
1575
    }
1576

    
1577
    /**
1578
     * @param cdmBaseSection
1579
     * @param object
1580
     * @param style
1581
     * @return
1582
     */
1583
    public CdmBaseElement createCdmBaseElement(ICdmFormElement parentElement, CdmBase entity, int style) {
1584
        CdmBaseElement element = new CdmBaseElement(this, parentElement, entity, style);
1585
        adapt(element);
1586
        parentElement.addElement(element);
1587
        return element;
1588
    }
1589

    
1590
    /**
1591
     * <p>
1592
     * createVersionSection
1593
     * </p>
1594
     *
1595
     * @param parentElement
1596
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1597
     *            object.
1598
     * @param style
1599
     *            a int.
1600
     * @return a
1601
     *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection}
1602
     *         object.
1603
     */
1604
    public VersionSection createVersionSection(ICdmFormElement parentElement, int style) {
1605
        VersionSection section = new VersionSection(this, parentElement, style);
1606
        parentElement.addElement(section);
1607
        adapt(section);
1608
        return section;
1609
    }
1610

    
1611
    /**
1612
     * @param parent
1613
     * @param i
1614
     * @return
1615
     */
1616
    public CdmBaseSection createCdmBaseSection(ICdmFormElement parentElement, int style) {
1617
        CdmBaseSection section = new CdmBaseSection(this, parentElement, style);
1618
        parentElement.addElement(section);
1619
        adapt(section);
1620
        return section;
1621
    }
1622

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

    
1640
    /**
1641
     * <p>
1642
     * createHeadlineSection
1643
     * </p>
1644
     *
1645
     * @param parentElement
1646
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1647
     *            object.
1648
     * @return a
1649
     *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection}
1650
     *         object.
1651
     */
1652
    public HeadlineSection createHeadlineSection(ICdmFormElement parentElement) {
1653
        HeadlineSection section = new HeadlineSection(this, parentElement, SWT.NULL);
1654
        parentElement.addElement(section);
1655
        adapt(section);
1656
        return section;
1657
    }
1658

    
1659
    /**
1660
     * <p>
1661
     * createParsingMessageElement
1662
     * </p>
1663
     *
1664
     * @param parentElement
1665
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1666
     *            object.
1667
     * @param parserProblem
1668
     *            a {@link eu.etaxonomy.cdm.strategy.parser.ParserProblem}
1669
     *            object.
1670
     * @param style
1671
     *            a int.
1672
     * @return a
1673
     *         {@link eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessageElement}
1674
     *         object.
1675
     */
1676
    public ParsingMessageElement createParsingMessageElement(ICdmFormElement parentElement,
1677
            ParserProblem parserProblem, int style) {
1678
        ParsingMessageElement element = new ParsingMessageElement(this, parentElement, parserProblem, style);
1679
        adapt(element);
1680
        parentElement.addElement(element);
1681
        return element;
1682
    }
1683

    
1684
    public DefinedTermDetailSection createDefinedTermDetailSection(Class definedTermClass, ConversationHolder conversation,
1685
            ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
1686

    
1687
        DefinedTermDetailSection section = new DefinedTermDetailSection(this, definedTermClass, conversation, parentElement,
1688
                selectionProvider, style);
1689

    
1690
        parentElement.addElement(section);
1691
        adapt(section);
1692
        return section;
1693

    
1694
    }
1695

    
1696
    public TermMediaSection createTermMediaSection(ConversationHolder conversation,
1697
            ICdmFormElement parentElement, int style) {
1698
        TermMediaSection section = new TermMediaSection(this, conversation, parentElement, style);
1699
        parentElement.addElement(section);
1700
        adapt(section);
1701
        return section;
1702

    
1703
    }
1704

    
1705
    /**
1706
     * @param definedTermClass
1707
     * @param formElement
1708
     * @param style
1709
     * @return
1710
     */
1711
    public AbstractCdmDetailElement createDefinedTermDetailElement(Class definedTermClass,
1712
            AbstractCdmDetailSection parentElement, int style) {
1713
        AbstractCdmDetailElement element = null;
1714

    
1715
        if (NamedArea.class.isAssignableFrom(definedTermClass)) {
1716
            element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
1717
        } else if (definedTermClass.equals(Feature.class)) {
1718
            element = new FeatureDetailElement(this, parentElement);
1719
        } else if(definedTermClass.equals(PresenceAbsenceTerm.class)){
1720
            element = new PresenceAbsenceTermDetailElement(this, parentElement);
1721
        } else {
1722
            element = new DefinedTermDetailElement(this, parentElement);
1723
        }
1724

    
1725

    
1726
        adapt(element);
1727
        parentElement.addElement(element);
1728
        return element;
1729
    }
1730

    
1731
    public CharacterDetailSection createCharacterDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1732
        CharacterDetailSection section = new CharacterDetailSection(this, conversation, parentElement, selectionProvider, style);
1733
        addAndAdaptSection(parentElement, section);
1734
        return section;
1735
    }
1736

    
1737
    public CharacterDetailElement createCharacterDetailElement(ICdmFormElement parentElement, int style){
1738
        CharacterDetailElement element = new CharacterDetailElement(this, parentElement);
1739
        addAndAdaptElement(parentElement, element);
1740
        return element;
1741
    }
1742

    
1743
    public FeatureTreeDetailElement createFeatureTreeDetailElement(ICdmFormElement parentElement, int style){
1744
        FeatureTreeDetailElement element = new FeatureTreeDetailElement(this, parentElement);
1745
        addAndAdaptElement(parentElement, element);
1746
        return element;
1747
    }
1748

    
1749
    public FeatureNodeDetailElement createFeatureNodeDetailElement(ICdmFormElement parentElement, int style){
1750
        FeatureNodeDetailElement element = new FeatureNodeDetailElement(this, parentElement);
1751
        addAndAdaptElement(parentElement, element);
1752
        return element;
1753
    }
1754

    
1755

    
1756
    //--------DetailSections---------
1757
    public NameDetailSection createNameDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1758
        NameDetailSection section = new NameDetailSection(this, conversation, parentElement, selectionProvider, style);
1759
        addAndAdaptSection(parentElement, section);
1760
        return section;
1761
    }
1762

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

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

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

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

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

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

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

    
1805
    public TeamDetailSection createTeamDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
1806
        TeamDetailSection section = new TeamDetailSection(this, conversation, parentElement, null, style);
1807
        addAndAdaptSection(parentElement, section);
1808
        return section;
1809
    }
1810

    
1811
    public PersonDetailSection createPersonDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
1812
        PersonDetailSection section = new PersonDetailSection(this, conversation, parentElement, null, style);
1813
        addAndAdaptSection(parentElement, section);
1814
        return section;
1815
    }
1816

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

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

    
1829
    public ParsingMessagesSection createParsingMessagesSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1830
        ParsingMessagesSection section = new ParsingMessagesSection(this, conversation, parentElement, selectionProvider, style);
1831
        addAndAdaptSection(parentElement, section);
1832
        return section;
1833
    }
1834

    
1835

    
1836

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2059
    public TaxonRelationshipDetailSection createTaxonRelationshipDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2060
        TaxonRelationshipDetailSection section = new TaxonRelationshipDetailSection(this, conversation, parentElement, selectionProvider, style, true);
2061
        addAndAdaptSection(parentElement, section);
2062
        return section;
2063
    }
2064

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

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

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

    
2083
    public NamedAreaDetailSection createNamedAreaDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
2084
        NamedAreaDetailSection section = new NamedAreaDetailSection(this, conversation, parentElement, selectionProvider, style);
2085
        addAndAdaptSection(parentElement, section);
2086
        return section;
2087
    }
2088

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

    
2095
    private void addAndAdaptSection(ICdmFormElement parentElement, AbstractFormSection<?> section) {
2096
        parentElement.addElement(section);
2097
        adapt(section);
2098
    }
2099

    
2100
    //--------DetailElements------------
2101

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

    
2108
    public DefinedTermDetailElement<NamedAreaLevel> createNamedAreaLevelElement(ICdmFormElement parentElement){
2109
        DefinedTermDetailElement<NamedAreaLevel> element = new DefinedTermDetailElement<NamedAreaLevel>(this, parentElement);
2110
        addAndAdaptElement(parentElement, element);
2111
        return element;
2112
    }
2113

    
2114
    public eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement createNamedAreaDetailElement(ICdmFormElement parentElement){
2115
        eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
2116
        addAndAdaptElement(parentElement, element);
2117
        return element;
2118
    }
2119

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

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

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

    
2138
    public GrantedAuthorityDetailElement createGrantedAuthorityDetailElement(ICdmFormElement parentElement){
2139
        GrantedAuthorityDetailElement element = new GrantedAuthorityDetailElement(this, parentElement);
2140
        addAndAdaptElement(parentElement, element);
2141
        return element;
2142
    }
2143

    
2144
    public GroupDetailElement createGroupDetailElement(ICdmFormElement parentElement){
2145
        GroupDetailElement element = new GroupDetailElement(this, parentElement);
2146
        addAndAdaptElement(parentElement, element);
2147
        return element;
2148
    }
2149

    
2150
    public UserDetailElement createUserDetailElement(ICdmFormElement parentElement){
2151
        UserDetailElement element = new UserDetailElement(this, parentElement);
2152
        addAndAdaptElement(parentElement, element);
2153
        return element;
2154
    }
2155

    
2156
    public HybridDetailElement createHybridDetailElement(ICdmFormElement parentElement){
2157
        HybridDetailElement element = new HybridDetailElement(this, parentElement);
2158
        addAndAdaptElement(parentElement, element);
2159
        return element;
2160
    }
2161

    
2162
    public InstitutionDetailElement createInstitutionDetailElement(ICdmFormElement parentElement){
2163
        InstitutionDetailElement element = new InstitutionDetailElement(this, parentElement);
2164
        addAndAdaptElement(parentElement, element);
2165
        return element;
2166
    }
2167

    
2168
    public PolytomousKeyNodeDetailElement createPolytomousKeyNodeDetailElement(ICdmFormElement parentElement){
2169
        PolytomousKeyNodeDetailElement element = new PolytomousKeyNodeDetailElement(this, parentElement);
2170
        addAndAdaptElement(parentElement, element);
2171
        return element;
2172
    }
2173

    
2174
    public PolytomousKeyDetailElement createPolytomousKeyDetailElement(ICdmFormElement parentElement){
2175
        PolytomousKeyDetailElement element = new PolytomousKeyDetailElement(this, parentElement);
2176
        addAndAdaptElement(parentElement, element);
2177
        return element;
2178
    }
2179

    
2180
    public CollectionDetailElement createCollectionDetailElement(ICdmFormElement parentElement){
2181
        CollectionDetailElement element = new CollectionDetailElement(this, parentElement);
2182
        addAndAdaptElement(parentElement, element);
2183
        return element;
2184
    }
2185

    
2186
    public TaxonNodeAgentRelationCollectionSection createTaxonNodeAgentRelationCollectionElement(ICdmFormElement parentElement, ConversationHolder conversation, int style){
2187
        TaxonNodeAgentRelationCollectionSection element = new TaxonNodeAgentRelationCollectionSection(this, conversation, parentElement, style);
2188
        adapt(element);
2189
        parentElement.addElement(element);
2190

    
2191
        return element;
2192
    }
2193

    
2194
    public TaxonNodeDetailElement createTaxonNodeDetailElement(ICdmFormElement parentElement, boolean createNew){
2195
        TaxonNodeDetailElement element = new TaxonNodeDetailElement(this, parentElement, createNew);
2196
        addAndAdaptElement(parentElement, element);
2197
        return element;
2198
    }
2199

    
2200
    public ClassificationDetailElement createClassificationDetailElement(ICdmFormElement parentElement){
2201
        ClassificationDetailElement element = new ClassificationDetailElement(this, parentElement);
2202
        addAndAdaptElement(parentElement, element);
2203
        return element;
2204
    }
2205

    
2206
    public CloneClassificationDetailElement createCloneClassificationDetailElement(ICdmFormElement parentElement){
2207
        CloneClassificationDetailElement element = new CloneClassificationDetailElement(this, parentElement);
2208
        addAndAdaptElement(parentElement, element);
2209
        return element;
2210
    }
2211

    
2212
    public FeatureDistributionDetailElement createFeatureDistributionDetailElement(ICdmFormElement parentElement){
2213
        FeatureDistributionDetailElement element = new FeatureDistributionDetailElement(this, parentElement);
2214
        addAndAdaptElement(parentElement, element);
2215
        return element;
2216
    }
2217

    
2218
    public NaturalLanguageDetailElement createNaturalLanguageDetailElement(ICdmFormElement parentElement){
2219
        NaturalLanguageDetailElement element = new NaturalLanguageDetailElement(this, parentElement);
2220
        addAndAdaptElement(parentElement, element);
2221
        return element;
2222
    }
2223

    
2224
    public NonViralNameDetailElement createNonViralNameDetailElement(ICdmFormElement parentElement){
2225
        NonViralNameDetailElement element = new NonViralNameDetailElement(this, parentElement);
2226
        addAndAdaptElement(parentElement, element);
2227
        return element;
2228
    }
2229

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

    
2236
    public DescriptionDetailElement createDescriptionDetailElement(ICdmFormElement parentElement, int style){
2237
        DescriptionDetailElement element = new DescriptionDetailElement(this, parentElement, style);
2238
        addAndAdaptElement(parentElement, element);
2239
        return element;
2240
    }
2241

    
2242
    public PersonDetailElement createPersonDetailElement(ICdmFormElement parentElement, int style){
2243
        PersonDetailElement element = new PersonDetailElement(this, parentElement, style);
2244
        addAndAdaptElement(parentElement, element);
2245
        return element;
2246
    }
2247

    
2248
    public TeamDetailElement createTeamDetailElement(ICdmFormElement parentElement, int style, boolean isNomenclatural){
2249
        TeamDetailElement element = new TeamDetailElement(this, parentElement, style, isNomenclatural);
2250
        addAndAdaptElement(parentElement, element);
2251
        return element;
2252
    }
2253

    
2254
    public AuthorshipDetailElement createAuthorshipDetailElement(ICdmFormElement parentElement, int style){
2255
        AuthorshipDetailElement element = new AuthorshipDetailElement(this, parentElement, style);
2256
        addAndAdaptElement(parentElement, element);
2257
        return element;
2258
    }
2259

    
2260
    public TaxonBaseDetailElement createTaxonBaseDetailElement(ICdmFormElement parentElement, int style){
2261
        TaxonBaseDetailElement element = new TaxonBaseDetailElement(this, parentElement, style);
2262
        addAndAdaptElement(parentElement, element);
2263
        return element;
2264
    }
2265

    
2266
    public NameDetailElement createNameDetailElement(ICdmFormElement parentElement, int style){
2267
        NameDetailElement element = new NameDetailElement(this, parentElement, style);
2268
        addAndAdaptElement(parentElement, element);
2269
        return element;
2270
    }
2271

    
2272
    public ReferenceDetailElement createReferenceDetailElement(ICdmFormElement parentElement, int style, boolean isWizard){
2273
        ReferenceDetailElement element = new ReferenceDetailElement(this, parentElement, style, isWizard);
2274
        addAndAdaptElement(parentElement, element);
2275
        return element;
2276
    }
2277

    
2278
    public NomenclaturalReferenceDetailElement createNomenclaturalReferenceDetailElement(ICdmFormElement parentElement, int style){
2279
        NomenclaturalReferenceDetailElement element = new NomenclaturalReferenceDetailElement(this, parentElement, style);
2280
        addAndAdaptElement(parentElement, element);
2281
        return element;
2282
    }
2283

    
2284

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

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

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

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

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

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

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

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

    
2333
    public SequenceGeneralDetailElement createSequenceGeneralDetailElement(ICdmFormElement parentElement){
2334
        SequenceGeneralDetailElement element = new SequenceGeneralDetailElement(this, parentElement);
2335
        addAndAdaptElement(parentElement, element);
2336
        return element;
2337
    }
2338

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

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

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

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

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

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

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

    
2381
    public MediaDetailElement createMediaDetailElement(ICdmFormElement parentElement){
2382
        MediaDetailElement mediaDetailElement = new MediaDetailElement(this, parentElement);
2383
        addAndAdaptElement(parentElement, mediaDetailElement);
2384
        return mediaDetailElement;
2385
    }
2386

    
2387
    public GatheringEventDetailElement createGatheringEventDetailElement(ICdmFormElement parentElement) {
2388
        GatheringEventDetailElement element = new GatheringEventDetailElement(this, parentElement);
2389
        addAndAdaptElement(parentElement, element);
2390
        return element;
2391
    }
2392

    
2393
    public FieldUnitDetailElement createFieldUnitDetailElement(ICdmFormElement parentElement) {
2394
        FieldUnitDetailElement element = new FieldUnitDetailElement(this, parentElement);
2395
        addAndAdaptElement(parentElement, element);
2396
        return element;
2397
    }
2398

    
2399
    public DerivedUnitBaseDetailElement createDerivedUnitBaseDetailElement(ICdmFormElement parentElement) {
2400
        DerivedUnitBaseDetailElement element = new DerivedUnitBaseDetailElement(this, parentElement);
2401
        addAndAdaptElement(parentElement, element);
2402
        return element;
2403
    }
2404

    
2405
    public OriginalLabelDataElement createOriginalLabelDataElement(ICdmFormElement parentElement) {
2406
        OriginalLabelDataElement element = new OriginalLabelDataElement(this, parentElement);
2407
        addAndAdaptElement(parentElement, element);
2408
        return element;
2409
    }
2410

    
2411
    public PreservedSpecimenDetailElement createPreservedSpecimenDetailElement(ICdmFormElement parentElement) {
2412
        PreservedSpecimenDetailElement element = new PreservedSpecimenDetailElement(this, parentElement);
2413
        addAndAdaptElement(parentElement, element);
2414
        return element;
2415
    }
2416

    
2417
    public DeterminationDetailElement createDeterminationDetailElement(ICdmFormElement parentElement) {
2418
        DeterminationDetailElement element = new DeterminationDetailElement(this, parentElement);
2419
        addAndAdaptElement(parentElement, element);
2420
        return element;
2421
    }
2422

    
2423
    public SampleDesignationDetailElement createSampleDesignationDetailElement(ICdmFormElement parentElement) {
2424
        SampleDesignationDetailElement element = new SampleDesignationDetailElement(this, parentElement);
2425
        addAndAdaptElement(parentElement, element);
2426
        return element;
2427
    }
2428

    
2429
    /**
2430
     * @param parentElement
2431
     * @param element
2432
     */
2433
    private void addAndAdaptElement(ICdmFormElement parentElement, AbstractCdmDetailElement<?> element) {
2434
        adapt(element);
2435
        parentElement.addElement(element);
2436
    }
2437

    
2438
    //--------EntityCollectionSection----------
2439
    public TeamMemberSection createTeamMemberSection(ConversationHolder conversation, ICdmFormElement parentElement, int style, boolean isNomenclatural){
2440
        TeamMemberSection section = new TeamMemberSection(this, conversation, parentElement, style, isNomenclatural);
2441
        addAndAdaptSection(parentElement, section);
2442
        return section;
2443
    }
2444

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2529
    public ProtologueSection createProtologueSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2530
        ProtologueSection section = new ProtologueSection(this, conversation, parentElement, style);
2531
        addAndAdaptSection(parentElement, section);
2532
        return section;
2533
    }
2534
    public ExternalLinksSection createExternalLinksSection(ConversationHolder conversation, ICdmFormElement parentElement, int style){
2535
        ExternalLinksSection section = new ExternalLinksSection(this, conversation, parentElement, style);
2536
        addAndAdaptSection(parentElement, section);
2537
        return section;
2538
    }
2539

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
2720

    
2721
    public AbstractEntityCollectionElement createEntityCollectionElement(AbstractFormSection parentElement,
2722
            Object versionableEntity, SelectionListener removeListener, Color backgroundColor, int style) {
2723
        AbstractEntityCollectionElement<?> element = null;
2724

    
2725
        Object entity = HibernateProxyHelper.deproxy(versionableEntity);
2726

    
2727
        if (entity instanceof Annotation) {
2728
            element = new AnnotationElement(this, parentElement, (Annotation) entity, removeListener, style);
2729
        }else if (entity instanceof Person ) {
2730
            boolean isNomenclatural = false;
2731
            if (parentElement instanceof TeamMemberSection){
2732
                isNomenclatural = ((TeamMemberSection) parentElement).isNomenclaturalTeam();
2733
            }
2734
            element = new TeamMemberElement(this, parentElement, (Person) entity, removeListener, style, isNomenclatural);
2735
        } else if (entity instanceof Credit) {
2736
            element = new CreditElement(this, parentElement, (Credit) entity, removeListener, style);
2737
        } else if (entity instanceof Extension) {
2738
            element = new ExtensionElement(this, parentElement, (Extension) entity, removeListener, style);
2739
        } else if (entity instanceof ExternalLink) {
2740
            element = new ExternalLinksElement(this, parentElement, (ExternalLink) entity, removeListener, style);
2741
        } else if (entity instanceof Marker) {
2742
            element = new MarkerElement(this, parentElement, (Marker) entity, removeListener, style);
2743
        } else if (entity instanceof TaxonNodeAgentRelation) {
2744
            element = new TaxonNodeAgentRelationCollectionElement(this, parentElement, (TaxonNodeAgentRelation) entity, removeListener, backgroundColor, style);
2745
        }else if (entity instanceof Media) {
2746
            element = new MediaMetaElement(this, parentElement, (Media) entity, removeListener, style);
2747
        } else if (entity instanceof MediaRepresentation) {
2748
            element = new MediaRepresentationElement(this, parentElement, (MediaRepresentation) entity, removeListener,
2749
                    style);
2750
        } else if (entity instanceof ImageFile) {
2751
            element = new ImageFileElement(this, parentElement, (ImageFile) entity, removeListener, style);
2752
        } else if (entity instanceof MediaRepresentationPart) {
2753
            element = new MediaRepresentationPartElement<>(this, parentElement, (MediaRepresentationPart) entity,
2754
                    removeListener, style);
2755
        } else if (entity instanceof NomenclaturalStatus) {
2756
            element = new NomenclaturalStatusElement(this, parentElement, (NomenclaturalStatus) entity, removeListener,
2757
                    style);
2758
        } else if (entity instanceof Rights) {
2759
            element = new RightsElement(this, parentElement, (Rights) entity, removeListener, style);
2760
        } else if (entity instanceof DescriptionElementSource && parentElement.getEntity() instanceof CommonTaxonName) {
2761
            element = new CommonNameSourceElement(this, parentElement, (DescriptionElementSource) entity,
2762
                    removeListener, style);
2763
        } else if (entity instanceof DescriptionElementSource) {
2764
            element = new DescriptionElementSourceElement(this, parentElement, (DescriptionElementSource) entity,
2765
                    removeListener, style, false);
2766
        } else if (entity instanceof TaxonNodeAgentRelation) {
2767
            element = new TaxonNodeAgentRelationCollectionElement(this, parentElement, (TaxonNodeAgentRelation) entity,
2768
                    removeListener,backgroundColor, style);
2769
        }
2770
        else if (entity instanceof IdentifiableSource) {
2771
            element = new IdentifiableSourceElement(this, parentElement, (IdentifiableSource) entity, removeListener,
2772
                    style);
2773
        } else if (entity instanceof DefinedTerm) {
2774
            switch(((DefinedTerm)entity).getTermType()) {
2775
            case Scope:
2776
                element = new ScopeElement(this,
2777
                        parentElement,
2778
                        (DefinedTerm) entity,
2779
                        removeListener,
2780
                        style);
2781
                break;
2782
            case Modifier:
2783
                element = new ModifierElement(this,
2784
                        parentElement,
2785
                        (DefinedTerm) entity,
2786
                        removeListener,
2787
                        style);
2788
                break;
2789
            default:
2790
                break;
2791

    
2792
            }
2793
        } else if (entity instanceof Reference) {
2794
            if(parentElement instanceof SequenceReferenceCollectionDetailSection){
2795
                element = new SequenceReferenceCollectionDetailElement(this, parentElement, (Reference) entity, removeListener, style);
2796
            }
2797
            else{
2798
                element = new DescriptionSourceElement(this, parentElement, (Reference) entity, removeListener, style);
2799
            }
2800
        } else if (entity instanceof NameTypeDesignation) {
2801
            element = new NameTypeDesignationElement(this, parentElement, (NameTypeDesignation) entity, removeListener,
2802
                    style);
2803
        } else if (entity instanceof TextualTypeDesignation) {
2804
            element = new TextTypeDesignationElement(this, parentElement, (TextualTypeDesignation) entity, removeListener,
2805
                    style);
2806
        } else if (entity instanceof NameRelationship) {
2807
            element = new NameRelationshipDetailElement(this, parentElement, (NameRelationship) entity, removeListener,
2808
                    style);
2809
        } else if (entity instanceof SpecimenTypeDesignation) {
2810
            if(parentElement instanceof DerivedUnitTypeDesignationSection){
2811
                element = new DerivedUnitTypeDesignationElement(this, parentElement, (SpecimenTypeDesignation) entity,
2812
                        removeListener, style);
2813
            }
2814
            else{
2815
                element = new SpecimenTypeDesignationElement(this, parentElement, (SpecimenTypeDesignation) entity,
2816
                        removeListener, style);
2817
            }
2818
        } else if (entity instanceof StateData) {
2819
            element = new StateDataElement(this, parentElement, (StateData) entity, removeListener, style);
2820
        } else if (entity instanceof StatisticalMeasurementValue) {
2821
            element = new StatisticalMeasurementValueElement(this, parentElement, (StatisticalMeasurementValue) entity,
2822
                    removeListener, style);
2823
        } else if (entity instanceof DerivedUnit) {
2824
            switch(((DerivedUnit)entity).getRecordBasis()) {
2825
            case LivingSpecimen:
2826
            case PreservedSpecimen:
2827
            case OtherSpecimen:
2828
                element = new SpecimenCollectionDetailElement(this,
2829
                        parentElement,
2830
                        (DerivedUnit) entity,
2831
                        removeListener,
2832
                        style);
2833
                break;
2834
            default:
2835
                element = new DerivedUnitElement(this,
2836
                        parentElement,
2837
                        (DerivedUnit) entity,
2838
                        removeListener,
2839
                        style);
2840
            }
2841

    
2842
        } else if (entity instanceof NamedArea) {
2843
            element = new CollectingAreaDetailElement(this, parentElement, (NamedArea) entity, removeListener, style);
2844
        } else if (entity instanceof DeterminationEvent) {
2845
            element = new DeterminationEventDetailElement(this, parentElement, (DeterminationEvent) entity, removeListener, style);
2846
        } else if (entity instanceof User) {
2847
            element = new MemberDetailElement(this, parentElement, (User) entity, removeListener, style);
2848
        } else if (entity instanceof GrantedAuthority) {
2849
            element = new GrantedAuthorityCollectionElement(this, parentElement, (GrantedAuthorityImpl) entity, ((Group)parentElement.getEntity()),
2850
                    removeListener, style);
2851
        } else if (entity instanceof Group) {
2852
            element = new GroupsByUserDetailElement(this, parentElement, (Group) entity, removeListener, style);
2853
        } else if (entity instanceof Taxon) {
2854
            element = new TaxonDetailElement(this, parentElement, (Taxon) entity, removeListener, style);
2855
        } else if (entity instanceof DescriptionElementBase) {
2856
            // this is the special case for protologs, maybe we can do this
2857
            // differently when API improves
2858
            DescriptionElementBase descriptionElement = (DescriptionElementBase) entity;
2859
            if (descriptionElement.getFeature().equals(Feature.PROTOLOGUE())) {
2860
                element = new ProtologueElement(this, parentElement, descriptionElement, removeListener, style);
2861
            }
2862
        } else if (entity instanceof Identifier) {
2863
            if(parentElement instanceof AbstractSampleDesignationDetailSection){
2864
                element = new SampleDesignationTextDetailElement(this, parentElement, (Identifier<DnaSample>) entity, removeListener, backgroundColor, style);
2865
            }
2866
            else{
2867
                element = new IdentifierElement(this, parentElement, (Identifier) entity, removeListener, style);
2868
            }
2869
        } else if (entity instanceof TermVocabulary) {
2870
            TermVocabulary<?> termVocabulary = (TermVocabulary<?>)entity;
2871
            switch (termVocabulary.getTermType()) {
2872
            case State:
2873
                element = new StateVocabularyCollectionElement(this, parentElement, (TermVocabulary<State>) entity, removeListener, backgroundColor, style);
2874
                break;
2875
            case Modifier:
2876
                element = new RecommendedModifierVocabulariesElement(this, parentElement, (TermVocabulary<DefinedTerm>) entity, removeListener, backgroundColor, style);
2877
                break;
2878
            default:
2879
                break;
2880
            }
2881
        } else if (entity instanceof MeasurementUnit) {
2882
            element = new MeasurementUnitCollectionElement(this, parentElement, (MeasurementUnit) entity, removeListener, backgroundColor, style);
2883
        } else if (entity instanceof StatisticalMeasure) {
2884
            element = new StatisticalMeasureCollectionElement(this, parentElement, (StatisticalMeasure) entity, removeListener, backgroundColor, style);
2885
        } else if (entity instanceof State && parentElement instanceof InapplicableIfEntityCollectionSection) {
2886
            element = new InapplicableIfCollectionElement(this, parentElement, (State) entity, removeListener, backgroundColor, style);
2887
        } else if (entity instanceof State && parentElement instanceof OnlyApplicableIfEntityCollectionSection) {
2888
            element = new OnlyApplicableIfCollectionElement(this, parentElement, (State) entity, removeListener, backgroundColor, style);
2889
        }
2890

    
2891
        //check for parent section when entity is null
2892
        //this happens when AbstractUnboundEntityCollectionSection is used
2893
        if(element==null){
2894
            if(parentElement instanceof ScopeSection || parentElement instanceof ScopeRestrictionSection){
2895
                element = new ScopeElement(this,
2896
                        parentElement,
2897
                        (DefinedTerm) entity,
2898
                        removeListener,
2899
                        style);
2900
            }
2901
            else if(parentElement instanceof ModifierSection){
2902
                element = new ModifierElement(this,
2903
                        parentElement,
2904
                        (DefinedTerm) entity,
2905
                        removeListener,
2906
                        style);
2907
            }
2908
        }
2909

    
2910

    
2911
        if (element == null) {
2912
            MessagingUtils.messageDialog(
2913
                    String.format("Error when creating section %s",
2914
                            parentElement.getClass().getSimpleName()),
2915
                    this,
2916
                    String.format("Could not generate collection element for entity of class %s."
2917
                            + " Looks like the case is not yet handled. Check implementation.\n"
2918
                            + "Entity: %s", entity.getClass(), entity.toString()), null);
2919
        }
2920

    
2921
        else{
2922
            if (backgroundColor != null && !backgroundColor.isDisposed()) {
2923
                element.setPersistentBackground(backgroundColor);
2924
            }
2925
            adapt(element);
2926
            parentElement.addElement(element);
2927
        }
2928

    
2929
        return element;
2930
    }
2931

    
2932
    /**
2933
     * <p>
2934
     * Creates a selection element for the given type T.
2935
     * </p>
2936
     * <p>
2937
     * <strong>Selection elements not handled by this method:</strong>
2938
     * <ul>
2939
     * <li>{@link TaxonNodeSelectionElement} see
2940
     * {@link #createTaxonNodeSelectionElement(ConversationHolder, ICdmFormElement, String, TaxonNode, int, int)}
2941
     * </li>
2942
     * <li>{@link NomenclaturalAuthorTeamSelectionElement} see
2943
     * {@link #createNomenclaturalAuthorTeamSelectionElement(ConversationHolder, ICdmFormElement, String, Team, int, int)}
2944
     * </li>
2945
     * </ul>
2946
     * </p>
2947
     *
2948
     * @param clazz
2949
     *            a {@link Class} object of the type that you want the selection
2950
     *            element to handle
2951
     * @param parentElement
2952
     *            a {@link ICdmFormElement} object.
2953
     * @param labelString
2954
     *            a {@link String} object.
2955
     * @param selectionType
2956
     * @param selection
2957
     *            a {@link ICdmBase} object.
2958
     * @param style
2959
     *            a int.
2960
     * @param conversation
2961
     *            a {@link ConversationHolder} object.
2962
     * @return a {@link EntitySelectionElement} object.
2963
     */
2964
    public <T extends CdmBase> EntitySelectionElement<T> createSelectionElement(Class<T> clazz,
2965
            ConversationHolder conversation, ICdmFormElement parentElement, String labelString, T selection, int mode,
2966
            int style, boolean filterElement) {
2967
        EntitySelectionElement<T> element = new EntitySelectionElement<T>(this, //conversation,
2968
                parentElement, clazz,
2969
                labelString, selection, mode, style, filterElement);
2970
        adapt(element);
2971
        parentElement.addElement(element);
2972
        return element;
2973
    }
2974

    
2975
    public <T extends CdmBase> EntitySelectionElement<T> createSelectionElement(Class<T> clazz,
2976
//            ConversationHolder conversation,
2977
            ICdmFormElement parentElement, String labelString, T selection, int mode,
2978
            int style) {
2979
        EntitySelectionElement<T> element = new EntitySelectionElement<T>(this,
2980
                parentElement, clazz,
2981
                labelString, selection, mode, style);
2982
        adapt(element);
2983
        parentElement.addElement(element);
2984
        return element;
2985
    }
2986

    
2987
    public CommonNameReferenceSelectionElement createCommonNameReferenceSelectionElement(ICdmFormElement parentElement, String labelString, Reference selection, int mode,
2988
          int style) {
2989
        CommonNameReferenceSelectionElement element = new CommonNameReferenceSelectionElement(this,
2990
              parentElement, labelString, selection, mode, style);
2991
      adapt(element);
2992
      parentElement.addElement(element);
2993
      return element;
2994
  }
2995

    
2996
    /**
2997
     * <p>
2998
     * Creates a selection element for the given type T which shows only the <b>abbreviated</b> title as the label.
2999
     * </p>
3000
     * <p>
3001
     * <strong>Selection elements not handled by this method:</strong>
3002
     * <ul>
3003
     * <li>{@link TaxonNodeSelectionElement} see
3004
     * {@link #createTaxonNodeSelectionElement(ConversationHolder, ICdmFormElement, String, TaxonNode, int, int)}
3005
     * </li>
3006
     * <li>{@link NomenclaturalAuthorTeamSelectionElement} see
3007
     * {@link #createNomenclaturalAuthorTeamSelectionElement(ConversationHolder, ICdmFormElement, String, Team, int, int)}
3008
     * </li>
3009
     * </ul>
3010
     * </p>
3011
     *
3012
     * @param clazz
3013
     *            a {@link Class} object of the type that you want the selection
3014
     *            element to handle
3015
     * @param parentElement
3016
     *            a {@link ICdmFormElement} object.
3017
     * @param labelString
3018
     *            a {@link String} object.
3019
     * @param selectionType
3020
     * @param selection
3021
     *            a {@link ICdmBase} object.
3022
     * @param style
3023
     *            a int.
3024
     * @param conversation
3025
     *            a {@link ConversationHolder} object.
3026
     * @return a {@link EntitySelectionElement} object.
3027
     */
3028
    public <T extends CdmBase> EntitySelectionElementWithAbbreviatedTitle<T> createSelectionElementWithAbbreviatedTitle(
3029
            Class<T> clazz, ConversationHolder conversation, ICdmFormElement parentElement, String labelString,
3030
            T selection, int mode, int style) {
3031
        EntitySelectionElementWithAbbreviatedTitle<T> element = new EntitySelectionElementWithAbbreviatedTitle<T>(this, //conversation,
3032
                parentElement, clazz,
3033
                labelString, selection, mode, style);
3034
        adapt(element);
3035
        parentElement.addElement(element);
3036
        return element;
3037
    }
3038

    
3039
    public TaxonNodeSelectionElement createTaxonNodeSelectionElement(ConversationHolder conversation,
3040
            ICdmFormElement parentElement, String labelString, TaxonNode selection, int mode, int style) {
3041
        TaxonNodeSelectionElement element = new TaxonNodeSelectionElement(this, //conversation,
3042
                parentElement,
3043
                labelString, selection, mode, style);
3044
        adapt(element);
3045
        parentElement.addElement(element);
3046
        return element;
3047
    }
3048

    
3049

    
3050

    
3051
//    public NomenclaturalAuthorTeamSelectionElement createNomenclaturalAuthorTeamSelectionElement(
3052
//            ConversationHolder conversation, ICdmFormElement parentElement, String labelString, Team selection,
3053
//            int mode, int style) {
3054
//        NomenclaturalAuthorTeamSelectionElement element = new NomenclaturalAuthorTeamSelectionElement(this,
3055
//                conversation, parentElement, labelString, selection, mode, style);
3056
//        adapt(element);
3057
//        parentElement.addElement(element);
3058
//        return element;
3059
//    }
3060

    
3061
    /** {@inheritDoc} */
3062
    public LabelElement createLabel(ICdmFormElement parentElement, String text) {
3063
        LabelElement labelElement = new LabelElement(this, parentElement, text);
3064
        adapt(labelElement);
3065
        parentElement.addElement(labelElement);
3066
        return labelElement;
3067
    }
3068

    
3069

    
3070

    
3071
//    public DateElementFormElement createDateElementForm(ICdmFormElement formElement, String labelText, DateTime dateTime, int style){
3072
//        Label label = new Label(formElement.getLayoutComposite(), style);
3073
//        label.setText(labelText+" (yyyy-MM-dd)");
3074
//        DateElementFormElement dateElement = new DateElementFormElement(this, dateTime, style, formElement.getLayoutComposite());
3075
//        dateElement.initInternalController();
3076
//
3077
//        return dateElement;
3078
//    }
3079

    
3080
    public DateElement createDateElement(ICdmFormElement formElement, String labelText, DateTime dateTime, int style, boolean editableText){
3081
    	 Label label = new Label(formElement.getLayoutComposite(), style);
3082
         label.setText(labelText);
3083
         label.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE, 1, 1));
3084
         DateElement dateElement = new DateElement(formElement.getLayoutComposite(), dateTime, labelText, style, editableText);
3085
         dateElement.initController(this, formElement);
3086
         dateElement.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.MIDDLE, 1, 1));
3087
         return dateElement;
3088
    }
3089

    
3090
    /**
3091
     * <p>
3092
     * Getter for the field <code>selectionProvider</code>.
3093
     * </p>
3094
     *
3095
     * @return a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
3096
     */
3097
    public ISelectionProvider getSelectionProvider() {
3098
        return selectionProvider;
3099
    }
3100

    
3101
    /**
3102
     * <p>
3103
     * createDetailedDescriptionDetailElement
3104
     * </p>
3105
     *
3106
     * @param parentElement
3107
     *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
3108
     *            object.
3109
     * @param entity
3110
     *            a
3111
     *            {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase}
3112
     *            object.
3113
     * @param style
3114
     *            a int.
3115
     * @return a
3116
     *         {@link eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement}
3117
     *         object.
3118
     */
3119
    public AbstractDetailedDescriptionDetailElement createDetailedDescriptionDetailElement(
3120
            ICdmFormElement parentElement, DescriptionElementBase entity, int style, boolean enabled) {
3121
        AbstractDetailedDescriptionDetailElement detailedDescriptionElement = null;
3122

    
3123
        if (entity instanceof CategoricalData) {
3124
            detailedDescriptionElement = new CategoricalDataDetailElement(this, parentElement,
3125
                    (CategoricalData) entity, style);
3126
        } else if (entity instanceof CommonTaxonName) {
3127
            detailedDescriptionElement = new CommonNameDetailElement(this, parentElement, (CommonTaxonName) entity,
3128
                    style);
3129
        } else if (entity instanceof Distribution && !enabled) {
3130
            detailedDescriptionElement = new DistributionDetailElement(this, parentElement, (Distribution) entity,
3131
                    enabled, style);
3132
        } else if (entity instanceof Distribution) {
3133
            detailedDescriptionElement = new DistributionDetailElement(this, parentElement, (Distribution) entity,
3134
                    true, style);
3135
        }else if (entity instanceof IndividualsAssociation) {
3136
            detailedDescriptionElement = new IndividualsAssociationDetailElement(this, parentElement,
3137
                    (IndividualsAssociation) entity, style);
3138
        } else if (entity instanceof QuantitativeData) {
3139
            detailedDescriptionElement = new QuantitativeDataDetailElement(this, parentElement,
3140
                    (QuantitativeData) entity, style);
3141
        } else if (entity instanceof TaxonInteraction) {
3142
            detailedDescriptionElement = new TaxonInteractionDetailElement(this, parentElement,
3143
                    (TaxonInteraction) entity, style);
3144
        } else if (entity instanceof TextData) {
3145
            detailedDescriptionElement = new TextDataDetailElement(this, parentElement, (TextData) entity, style);
3146
        } else {
3147
            throw new IllegalStateException("There is no interface for the given description element");
3148
        }
3149
        adapt(detailedDescriptionElement);
3150
        parentElement.addElement(detailedDescriptionElement);
3151
        return detailedDescriptionElement;
3152

    
3153
    }
3154

    
3155
    /**
3156
     * Creates a styled text as a part of the form.
3157
     *
3158
     * @param parent
3159
     *            the text parent
3160
     * @param value
3161
     *            the text initial value
3162
     * @param style
3163
     *            the text style
3164
     * @return the text widget
3165
     */
3166
    public StyledText createStyledText(Composite parent, String value, int style) {
3167
        StyledText text = new StyledText(parent, getBorderStyle() | style | getOrientation());
3168
        if (value != null) {
3169
            text.setText(value);
3170
        }
3171
        text.setForeground(getColors().getForeground());
3172
        text.setBackground(getColors().getBackground());
3173
        // text.addFocusListener(visibilityHandler);
3174
        return text;
3175
    }
3176

    
3177
    public PreservedSpecimenDetailSection createPreservedSpecimenDetailsSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
3178
        PreservedSpecimenDetailSection section = new PreservedSpecimenDetailSection(this, conversation, parentElement, selectionProvider, style);
3179
        addAndAdaptSection(parentElement, section);
3180
        return section;
3181
    }
3182

    
3183
    /**
3184
     * @param formElement
3185
     * @param conversationHolder
3186
     * @param style
3187
     * @return
3188
     */
3189
    public TaxonNodeAgentRelationCollectionSection createTaxonNodeAgentRelationCollectionSection(
3190
            ICdmFormElement formElement, ConversationHolder conversationHolder, int style) {
3191
        TaxonNodeAgentRelationCollectionSection section = new TaxonNodeAgentRelationCollectionSection(this, conversationHolder, formElement, style);
3192
        addAndAdaptSection(formElement, section);
3193
        return section;
3194
    }
3195

    
3196

    
3197
	public TaxonOfRelationshipElement createTaxonOfRelationshipDetailElement(
3198
			ICdmFormElement parentElement, int style) {
3199
		TaxonOfRelationshipElement section = new TaxonOfRelationshipElement(this, parentElement, style);
3200
		addAndAdaptElement(parentElement, section);
3201
        return section;
3202
	}
3203

    
3204
	public TaxonDetailSection createTaxonDetailSection(ConversationHolder conversationHolder,
3205
			ICdmFormElement formElement, ISelectionProvider selectionProvider, int style) {
3206
			TaxonDetailSection section = new TaxonDetailSection(this, conversationHolder, formElement, selectionProvider, style);
3207
	        addAndAdaptSection(formElement, section);
3208
	        return section;
3209
	}
3210

    
3211

    
3212

    
3213

    
3214

    
3215
//	public RichTextWithLabelElement createRichTextLabelElement(ICdmFormElement parentElement, String labelString, String initialText, int textHeight, int style) {
3216
//		 RichTextWithLabelElement element = new RichTextWithLabelElement(this, parentElement, labelString,
3217
//				 initialText, textHeight, style);
3218
//	        adapt(element);
3219
//	        parentElement.addElement(element);
3220
//	        return element;
3221
//	}
3222

    
3223

    
3224

    
3225

    
3226

    
3227

    
3228

    
3229
}
(7-7/48)