Project

General

Profile

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

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

    
13
import org.eclipse.jface.util.IPropertyChangeListener;
14
import org.eclipse.jface.viewers.ISelection;
15
import org.eclipse.jface.viewers.ISelectionProvider;
16
import org.eclipse.jface.window.Window;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.events.FocusAdapter;
19
import org.eclipse.swt.events.FocusEvent;
20
import org.eclipse.swt.events.FocusListener;
21
import org.eclipse.swt.events.MouseAdapter;
22
import org.eclipse.swt.events.MouseEvent;
23
import org.eclipse.swt.events.MouseListener;
24
import org.eclipse.swt.events.SelectionEvent;
25
import org.eclipse.swt.events.SelectionListener;
26
import org.eclipse.swt.events.TypedEvent;
27
import org.eclipse.swt.graphics.Color;
28
import org.eclipse.swt.graphics.Font;
29
import org.eclipse.swt.widgets.Composite;
30
import org.eclipse.swt.widgets.Control;
31
import org.eclipse.swt.widgets.Display;
32
import org.eclipse.swt.widgets.Event;
33
import org.eclipse.swt.widgets.Label;
34
import org.eclipse.ui.forms.IFormColors;
35
import org.eclipse.ui.forms.widgets.FormToolkit;
36
import org.eclipse.ui.forms.widgets.Section;
37
import org.eclipse.ui.forms.widgets.TableWrapData;
38
import org.eclipse.ui.forms.widgets.TableWrapLayout;
39
import org.eclipse.ui.internal.forms.widgets.FormFonts;
40
import org.joda.time.Partial;
41
import org.springframework.security.core.GrantedAuthority;
42

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

    
315
/**
316
 * <p>
317
 * CdmFormFactory class.
318
 * </p>
319
 * 
320
 * @author n.hoffmann
321
 * @created Feb 24, 2010
322
 * @version 1.0
323
 */
324
public class CdmFormFactory extends FormToolkit {
325

    
326
	private BoldFontHolder2 boldFontHolder2;
327
	private MouseListener selectionMouseHandler;
328
	private FocusListener selectionFocusHandler;
329

    
330
	private final Set selectionListenerList = new HashSet();
331

    
332
	private final List<IPropertyChangeListener> propertyChangeListeners = new ArrayList<IPropertyChangeListener>();
333

    
334
	private final int orientation = Window.getDefaultOrientation();
335
	private ISelectionProvider selectionProvider;
336

    
337
	/**
338
	 * <p>
339
	 * LAYOUT
340
	 * </p>
341
	 * 
342
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapLayout} object.
343
	 */
344
	public static final TableWrapLayout LAYOUT() {
345
		return LAYOUT(1, false);
346
	}
347

    
348
	/**
349
	 * <p>
350
	 * LAYOUT
351
	 * </p>
352
	 * 
353
	 * @param columns
354
	 *            a int.
355
	 * @param equalWidth
356
	 *            a boolean.
357
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapLayout} object.
358
	 */
359
	public static final TableWrapLayout LAYOUT(int columns, boolean equalWidth) {
360
		TableWrapLayout layout = new TableWrapLayout();
361
		layout.topMargin = 0;
362
		layout.rightMargin = 0;
363
		layout.bottomMargin = 0;
364
		layout.leftMargin = 0;
365
		layout.numColumns = columns;
366
		layout.makeColumnsEqualWidth = equalWidth;
367
		layout.verticalSpacing = 0;
368
		layout.horizontalSpacing = 0;
369
		return layout;
370
	}
371

    
372
	/**
373
	 * <p>
374
	 * FILL
375
	 * </p>
376
	 * 
377
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
378
	 */
379
	public static final TableWrapData FILL() {
380
		return FILL(1, 1);
381
	}
382

    
383
	/**
384
	 * <p>
385
	 * FILL
386
	 * </p>
387
	 * 
388
	 * @param horizontalSpan
389
	 *            a int.
390
	 * @param verticalSpan
391
	 *            a int.
392
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
393
	 */
394
	public static final TableWrapData FILL(int horizontalSpan, int verticalSpan) {
395
		TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB,
396
				TableWrapData.FILL_GRAB);
397
		layoutData.colspan = horizontalSpan;
398
		layoutData.rowspan = verticalSpan;
399
		return layoutData;
400
	}
401

    
402
	/**
403
	 * <p>
404
	 * LEFT
405
	 * </p>
406
	 * 
407
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
408
	 */
409
	public static final TableWrapData LEFT() {
410
		return new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP);
411
	}
412

    
413
	/**
414
	 * <p>
415
	 * RIGHT
416
	 * </p>
417
	 * 
418
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
419
	 */
420
	public static final TableWrapData RIGHT() {
421
		return new TableWrapData(TableWrapData.RIGHT, TableWrapData.TOP);
422
	}
423

    
424
	/**
425
	 * <p>
426
	 * FILL_HORIZONTALLY
427
	 * </p>
428
	 * 
429
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
430
	 */
431
	public static final TableWrapData FILL_HORIZONTALLY() {
432
		return FILL_HORIZONTALLY(1, 1);
433
	}
434

    
435
	/**
436
	 * <p>
437
	 * FILL_HORIZONTALLY
438
	 * </p>
439
	 * 
440
	 * @param horizontalSpan
441
	 *            a int.
442
	 * @param verticalSpan
443
	 *            a int.
444
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
445
	 */
446
	public static final TableWrapData FILL_HORIZONTALLY(int horizontalSpan,
447
			int verticalSpan) {
448
		TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB,
449
				TableWrapData.TOP);
450
		layoutData.colspan = horizontalSpan;
451
		layoutData.rowspan = verticalSpan;
452
		return layoutData;
453
	}
454

    
455
	/** Constant <code>EMPTY_SELECTION</code> */
456
	public static ISelection EMPTY_SELECTION = new ISelection() {
457
		@Override
458
		public boolean isEmpty() {
459
			return true;
460
		}
461
	};
462

    
463
	private class SelectionMouseHandler extends MouseAdapter {
464
		@Override
465
		public void mouseDown(MouseEvent e) {
466
			notifySelectionListeners(e);
467
		}
468
	}
469

    
470
	private class SelectionFocusHandler extends FocusAdapter {
471
		@Override
472
		public void focusGained(FocusEvent e) {
473
			notifySelectionListeners(e);
474
		}
475
	}
476

    
477
	private void notifySelectionListeners(TypedEvent e) {
478
		Event event = new Event();
479
		event.widget = e.widget;
480
		SelectionEvent selectionEvent = new SelectionEvent(event);
481

    
482
		for (Object listener : selectionListenerList) {
483
			((SelectionListener) listener).widgetSelected(selectionEvent);
484
		}
485
	}
486

    
487
	/**
488
	 * <p>
489
	 * Constructor for CdmFormFactory.
490
	 * </p>
491
	 * 
492
	 * @param display
493
	 *            a {@link org.eclipse.swt.widgets.Display} object.
494
	 * @param selectionProvider
495
	 *            a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
496
	 */
497
	public CdmFormFactory(Display display, ISelectionProvider selectionProvider) {
498
		super(display);
499
		this.selectionProvider = selectionProvider;
500
		init();
501
	}
502

    
503
	/**
504
	 * <p>
505
	 * Constructor for CdmFormFactory.
506
	 * </p>
507
	 * 
508
	 * @param display
509
	 *            a {@link org.eclipse.swt.widgets.Display} object.
510
	 */
511
	public CdmFormFactory(Display display) {
512
		super(display);
513
		init();
514
	}
515

    
516
	/**
517
	 * 
518
	 */
519
	private void init() {
520
		boldFontHolder2 = new BoldFontHolder2();
521
		selectionMouseHandler = new SelectionMouseHandler();
522
		selectionFocusHandler = new SelectionFocusHandler();
523
	}
524

    
525
	/**
526
	 * Creates an instance initialized with the correct selectionProvider
527
	 * 
528
	 * Make sure to remove the instance when the entityComposite disposes via
529
	 * destroySelectionArbitrator(..)
530
	 * 
531
	 * @param entityElement
532
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.IEntityElement}
533
	 *            object.
534
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.SelectionArbitrator}
535
	 *         object.
536
	 */
537
	public SelectionArbitrator createSelectionArbitrator(
538
			IEntityElement entityElement) {
539
		SelectionArbitrator selectionArbitrator = new SelectionArbitrator(
540
				entityElement);
541
		selectionArbitrator.addSelectionProvider(selectionProvider);
542
		selectionProvider.addSelectionChangedListener(selectionArbitrator);
543
		addSelectionListener(selectionArbitrator);
544
		return selectionArbitrator;
545
	}
546

    
547
	/**
548
	 * <p>
549
	 * destroySelectionArbitrator
550
	 * </p>
551
	 * 
552
	 * @param selectionArbitrator
553
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.SelectionArbitrator}
554
	 *            object.
555
	 */
556
	public void destroySelectionArbitrator(
557
			SelectionArbitrator selectionArbitrator) {
558
		removeSelectionListener(selectionArbitrator);
559
		if (selectionProvider != null) {
560
			selectionProvider
561
					.removeSelectionChangedListener(selectionArbitrator);
562
		} else {
563
			StoreUtil
564
					.error(this.getClass(),
565
							"Tried to destroy a selection listener from this factories listeners but was null",
566
							null);
567
		}
568
	}
569

    
570
	/** {@inheritDoc} */
571
	@Override
572
	public void adapt(Composite composite) {
573
		composite.addMouseListener(selectionMouseHandler);
574
		super.adapt(composite);
575
	}
576

    
577
	/**
578
	 * <p>
579
	 * adapt
580
	 * </p>
581
	 * 
582
	 * @param formElement
583
	 *            a
584
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.AbstractCdmFormElement}
585
	 *            object.
586
	 */
587
	public void adapt(AbstractCdmFormElement formElement) {
588
		formElement.setPropertyChangeListeners(propertyChangeListeners);
589
	}
590

    
591
	/** {@inheritDoc} */
592
	@Override
593
	public void adapt(Control control, boolean trackFocus, boolean trackKeyboard) {
594
		if (trackFocus) {
595
			control.addFocusListener(selectionFocusHandler);
596
		}
597
		super.adapt(control, trackFocus, trackKeyboard);
598
	}
599

    
600
	/**
601
	 * <p>
602
	 * destroyElement
603
	 * </p>
604
	 * 
605
	 * @param formElement
606
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
607
	 *            object.
608
	 */
609
	public void destroyElement(ICdmFormElement formElement) {
610
		// return if element was not initialized
611
		if (formElement == null) {
612
			return;
613
		}
614
		// destroy selection arbitrator, if any
615
		if (formElement instanceof ISelectableElement) {
616
			destroySelectionArbitrator(((ISelectableElement) formElement)
617
					.getSelectionArbitrator());
618
		}
619
		// remove this element form its parents list of elements
620
		// ICdmFormElement parentElement = formElement.getParentElement();
621
		// if(parentElement != null){
622
		// parentElement.removeElement(formElement);
623
		// }
624
		// call destroy on child elements recursively
625
		for (ICdmFormElement childElement : formElement.getElements()) {
626
			destroyElement(childElement);
627
		}
628
		// dispose of the controls
629
		for (Control control : formElement.getControls()) {
630
			// we added the layoutComposite of the parental element as the
631
			// layout composite to this formElement
632
			// but we do not want to destroy it.
633
			if (control.equals(formElement.getLayoutComposite())) {
634
				continue;
635
			} else {
636
				control.dispose();
637
				control = null;
638
			}
639
		}
640
	}
641

    
642
	/**
643
	 * <p>
644
	 * createEmptyCell
645
	 * </p>
646
	 * 
647
	 * @param parent
648
	 *            a {@link org.eclipse.swt.widgets.Composite} object.
649
	 * @return a {@link org.eclipse.swt.widgets.Label} object.
650
	 */
651
	public Label createEmptyCell(Composite parent) {
652
		return this.createLabel(parent, null);
653
	}
654

    
655
	/**
656
	 * <p>
657
	 * createMultilineTextWithLabel
658
	 * </p>
659
	 * 
660
	 * @param labelString
661
	 *            a {@link java.lang.String} object.
662
	 * @param textHeight
663
	 *            a int.
664
	 * @param style
665
	 *            a int.
666
	 * @param parentElement
667
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
668
	 *            object.
669
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElementFacade}
670
	 *         object.
671
	 */
672
	public TextWithLabelElementFacade createMultilineTextWithLabel(
673
			ICdmFormElement parentElement, String labelString, int textHeight,
674
			int style) {
675
		TextWithLabelElementFacade element = TextWithLabelElementFacade.getInstance(this,
676
				parentElement, labelString, "", textHeight, style);
677
		adapt(element);
678
		parentElement.addElement(element);
679
		return element;
680
	}
681

    
682
	/**
683
	 * <p>
684
	 * createMultiLanguageTextElement
685
	 * </p>
686
	 * 
687
	 * @param parentElement
688
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
689
	 *            object.
690
	 * @param labelString
691
	 *            a {@link java.lang.String} object.
692
	 * @param multilanguageText
693
	 *            a {@link java.util.Map} object.
694
	 * @param textHeight
695
	 *            a int.
696
	 * @param style
697
	 *            a int.
698
	 * @return a
699
	 *         {@link eu.etaxonomy.taxeditor.ui.forms.MultilanguageTextElement}
700
	 *         object.
701
	 */
702
	public MultilanguageTextElement createMultiLanguageTextElement(
703
			ICdmFormElement parentElement, String labelString,
704
			Map<Language, LanguageString> multilanguageText, int textHeight,
705
			int style) {
706
		MultilanguageTextElement element = new MultilanguageTextElement(this,
707
				parentElement, labelString, multilanguageText, textHeight,
708
				style);
709
		adapt(element);
710
		parentElement.addElement(element);
711
		return element;
712
	}
713

    
714
	public KeyStatementElement createKeyStatementElement(
715
			ICdmFormElement parentElement, String labelString,
716
			KeyStatement keyStatement, int textHeight, int style) {
717
		KeyStatementElement element = new KeyStatementElement(this,
718
				parentElement, labelString, keyStatement, textHeight, style);
719
		adapt(element);
720
		parentElement.addElement(element);
721
		return element;
722
	}
723

    
724
	/**
725
	 * <p>
726
	 * createTextWithLabelElement
727
	 * </p>
728
	 * 
729
	 * @param labelString
730
	 *            a {@link java.lang.String} object.
731
	 * @param initialText
732
	 *            a {@link java.lang.String} object.
733
	 * @param style
734
	 *            a int.
735
	 * @param parentElement
736
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
737
	 *            object.
738
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElementFacade}
739
	 *         object.
740
	 */
741
	public TextWithLabelElementFacade createTextWithLabelElement(
742
			ICdmFormElement parentElement, String labelString,
743
			String initialText, int style) {
744
		TextWithLabelElementFacade element = TextWithLabelElementFacade.getInstance(this,
745
				parentElement, labelString, initialText, null, style);
746
		adapt(element);
747
		parentElement.addElement(element);
748
		return element;
749
	}
750

    
751
	public UriWithLabelElementFacade createUriWithLabelElement(
752
			ICdmFormElement parentElement, String labelString, URI initialUri,
753
			int style) {
754
		UriWithLabelElementFacade element = UriWithLabelElementFacade.getInstance(this,
755
				parentElement, labelString, initialUri, null, style);
756
		
757
		adapt(element);
758
		parentElement.addElement(element);
759
		return element;
760
	}
761

    
762
	/**
763
	 * @param element
764
	 * @param string
765
	 * @param uri
766
	 * @param style
767
	 * @return
768
	 */
769
	public OpenUrlSelectorElement createOpenUrlSelectorElement(
770
			ICdmFormElement parentElement, String labelString,
771
			IOpenUrlEnabled openUrlEnabled, int style) {
772
		OpenUrlSelectorElement element = new OpenUrlSelectorElement(this,
773
				parentElement, labelString, openUrlEnabled, style);
774
		adapt(element);
775
		parentElement.addElement(element);
776
		return element;
777
	}
778

    
779
	/**
780
	 * 
781
	 * @param parentElement
782
	 * @param labelString
783
	 * @param conversationEnabled
784
	 * @param user
785
	 * @param style
786
	 * @return
787
	 */
788
	public EditPasswordElement createEditPasswordElement(
789
			ICdmFormElement parentElement, String labelString,
790
			ConversationHolder conversation, User user, int style) {
791
		EditPasswordElement element = new EditPasswordElement(this,
792
				parentElement, labelString, user, conversation);
793
		adapt(element);
794
		parentElement.addElement(element);
795
		return element;
796
	}
797

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

    
825
	/**
826
	 * <p>
827
	 * createFloatTextWithLabelElement
828
	 * </p>
829
	 * 
830
	 * @param parentElement
831
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
832
	 *            object.
833
	 * @param labelString
834
	 *            a {@link java.lang.String} object.
835
	 * @param initialFloat
836
	 *            a float.
837
	 * @param style
838
	 *            a int.
839
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElementFacade}
840
	 *         object.
841
	 */
842
	public NumberWithLabelElementFacade createFloatTextWithLabelElement(
843
			ICdmFormElement parentElement, String labelString,
844
			float initialFloat, int style) {
845
		NumberWithLabelElementFacade element = NumberWithLabelElementFacade.getInstance(this,
846
				parentElement, labelString, initialFloat, style);
847
		adapt(element);
848
		parentElement.addElement(element);
849
		return element;
850
	}
851

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

    
880
	/**
881
	 * <p>
882
	 * createLanguageStringWithLabelElement
883
	 * </p>
884
	 * 
885
	 * @param parentElement
886
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
887
	 *            object.
888
	 * @param labelString
889
	 *            a {@link java.lang.String} object.
890
	 * @param languageString
891
	 *            a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
892
	 * @param height
893
	 *            a int.
894
	 * @param style
895
	 *            a int.
896
	 * @return a
897
	 *         {@link eu.etaxonomy.taxeditor.ui.forms.LanguageStringWithLabelElementFacade}
898
	 *         object.
899
	 */
900
	public LanguageStringWithLabelElementFacade createLanguageStringWithLabelElement(
901
			ICdmFormElement parentElement, String labelString,
902
			LanguageString languageString, int height, int style) {
903
		LanguageStringWithLabelElementFacade element = LanguageStringWithLabelElementFacade.getInstance(
904
				this, parentElement, labelString, languageString, height, style);
905
		adapt(element);
906
		parentElement.addElement(element);
907
		return element;
908
	}
909

    
910
	/**
911
	 * <p>
912
	 * createTextElement
913
	 * </p>
914
	 * 
915
	 * @param parentElement
916
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
917
	 *            object.
918
	 * @param initialText
919
	 *            a {@link java.lang.String} object.
920
	 * @param style
921
	 *            a int.
922
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElementFacade}
923
	 *         object.
924
	 */
925
	public TextWithLabelElementFacade createTextElement(
926
			ICdmFormElement parentElement, String initialText, int style) {
927
		TextWithLabelElementFacade element = TextWithLabelElementFacade.getInstance(this,
928
				parentElement, null, initialText, null, style);
929
		adapt(element);
930
		parentElement.addElement(element);
931
		return element;
932
	}
933

    
934
	/**
935
	 * <p>
936
	 * createKeyValueViewerElement
937
	 * </p>
938
	 * 
939
	 * @param parentElement
940
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
941
	 *            object.
942
	 * @param keyHeading
943
	 *            a {@link java.lang.String} object.
944
	 * @param valueHeading
945
	 *            a {@link java.lang.String} object.
946
	 * @param map
947
	 *            a {@link java.util.Map} object.
948
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.KeyValueViewerElement}
949
	 *         object.
950
	 */
951
	public KeyValueViewerElement createKeyValueViewerElement(
952
			ICdmFormElement parentElement, String keyHeading,
953
			String valueHeading, Map<Object, Object> map) {
954
		KeyValueViewerElement element = new KeyValueViewerElement(this,
955
				parentElement, keyHeading, valueHeading, map);
956
		adapt(element);
957
		parentElement.addElement(element);
958
		return element;
959
	}
960

    
961
	public static enum TermComboType {
962
		EXTENSIONTYPE, LANGUAGE, MARKERTYPE, NOMENCLATURALSTATUSTYPE, RANK, RIGHTSTYPE, NAMERELATIONSHIP, NAMEDAREATYPE, PRESENCEABSENCESTATUS, ANNOTATIONTYPE, NAMETYPEDESIGNATIONSTATUS, SPECIMENTYPEDESIGNATIONSTATUS, SEX, STAGE, PRESERVATION_METHOD, MEASUREMENT_UNIT, STATE, MODIFIER, STATISTICAL_MEASURE, SCOPE, EMPTY, DETERMINATION_MODIFIER, REFERENCE_SYSTEM
963
	}
964

    
965
	/**
966
	 * <p>
967
	 * createTermComboElement
968
	 * </p>
969
	 * 
970
	 * @param termComboType
971
	 *            a
972
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.TermComboType}
973
	 *            object.
974
	 * @param parentElement
975
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
976
	 *            object.
977
	 * @param labelString
978
	 *            a {@link java.lang.String} object.
979
	 * @param selection
980
	 *            a {@link eu.etaxonomy.cdm.model.common.DefinedTermBase}
981
	 *            object.
982
	 * @param style
983
	 *            a int.
984
	 * @return a {@link eu.etaxonomy.taxeditor.ui.term.AbstractTermComboElement}
985
	 *         object.
986
	 */
987
	public AbstractTermComboElement createTermComboElement(
988
			TermComboType termComboType, ICdmFormElement parentElement,
989
			String labelString, DefinedTermBase selection, int style) {
990
		AbstractTermComboElement element = null;
991

    
992
		switch (termComboType) {
993
		case EMPTY:
994
			element = new EmptyComboElement<DefinedTermBase>(this,
995
					parentElement, labelString, style);
996
			break;
997
		case EXTENSIONTYPE:
998
			element = new ExtensionTypeComboElement(this, parentElement,
999
					labelString, (ExtensionType) selection, style);
1000
			break;
1001
		case LANGUAGE:
1002
			element = new LanguageComboElement(this, parentElement,
1003
					labelString, (Language) selection, style);
1004
			break;
1005
		case MARKERTYPE:
1006
			element = new MarkerTypeComboElement(this, parentElement,
1007
					labelString, (MarkerType) selection, style);
1008
			break;
1009
		case NOMENCLATURALSTATUSTYPE:
1010
			element = new NomenclaturalStatusTypeComboElement(this,
1011
					parentElement, labelString,
1012
					(NomenclaturalStatusType) selection, style);
1013
			break;
1014
		case RANK:
1015
			element = new RankComboElement(this, parentElement, labelString,
1016
					(Rank) selection, style);
1017
			break;
1018
		case RIGHTSTYPE:
1019
			element = new RightsTypeComboElement(this, parentElement,
1020
					labelString, (RightsTerm) selection, style);
1021
			break;
1022
		case NAMERELATIONSHIP:
1023
			element = new NameRelationshipTypeComboElement(this, parentElement,
1024
					labelString, (NameRelationshipType) selection, style);
1025
			break;
1026
		case NAMEDAREATYPE:
1027
			element = new NamedAreaTypeComboElement(this, parentElement,
1028
					labelString, (NamedAreaType) selection, style);
1029
			break;
1030
		case ANNOTATIONTYPE:
1031
			element = new AnnotationTypeComboElement(this, parentElement,
1032
					labelString, (AnnotationType) selection, style);
1033
			break;
1034
		case PRESENCEABSENCESTATUS:
1035
			element = new PresenceAbsenceTermComboElement(this, parentElement,
1036
					labelString, (PresenceAbsenceTermBase) selection, style);
1037
			break;
1038
		case NAMETYPEDESIGNATIONSTATUS:
1039
			element = new NameTypeDesignationStatusComboElement(this,
1040
					parentElement, labelString,
1041
					(NameTypeDesignationStatus) selection, style);
1042
			break;
1043
		case SPECIMENTYPEDESIGNATIONSTATUS:
1044
			element = new SpecimenTypeDesignationStatusComboElement(this,
1045
					parentElement, labelString,
1046
					(SpecimenTypeDesignationStatus) selection, style);
1047
			break;
1048
		case SEX:
1049
			element = new SexComboElement(this, parentElement, labelString,
1050
					(Sex) selection, style);
1051
			break;
1052
		case STAGE:
1053
			element = new StageComboElement(this, parentElement, labelString,
1054
					(Stage) selection, style);
1055
			break;
1056
		case PRESERVATION_METHOD:
1057
			element = new PreservationMethodComboElement(this, parentElement,
1058
					labelString, (PreservationMethod) selection, style);
1059
			break;
1060
		case MEASUREMENT_UNIT:
1061
			element = new MeasurementUnitComboElement(this, parentElement,
1062
					labelString, (MeasurementUnit) selection, style);
1063
			break;
1064
		case STATE:
1065
			element = new StateComboElement(this, parentElement, labelString,
1066
					(State) selection, style);
1067
			break;
1068
		case SCOPE:
1069
			element = new ScopeComboElement(this, parentElement, labelString,
1070
					(Scope) selection, style);
1071
			break;
1072
		case MODIFIER:
1073
			element = new ModifierComboElement(this, parentElement,
1074
					labelString, (Modifier) selection, style);
1075
			break;
1076
		case STATISTICAL_MEASURE:
1077
			element = new StatisticalMeasureComboElement(this, parentElement,
1078
					labelString, (StatisticalMeasure) selection, style);
1079
			break;
1080
		case DETERMINATION_MODIFIER:
1081
			element = new DeterminationModifierComboElement(this,
1082
					parentElement, labelString,
1083
					(DeterminationModifier) selection, style);
1084
			break;
1085
		case REFERENCE_SYSTEM:
1086
			element = new ReferenceSystemComboElement(this, parentElement,
1087
					labelString, (ReferenceSystem) selection, style);
1088
			break;
1089
		}
1090

    
1091
		adapt(element);
1092
		parentElement.addElement(element);
1093
		return element;
1094
	}
1095

    
1096
	public static enum EnumComboType {
1097
		REFERENCETYPE, NOMENCLATURALCODE
1098
	}
1099

    
1100
	/**
1101
	 * <p>
1102
	 * createEnumComboElement
1103
	 * </p>
1104
	 * 
1105
	 * @param enumComboType
1106
	 *            a
1107
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EnumComboType}
1108
	 *            object.
1109
	 * @param parentElement
1110
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1111
	 *            object.
1112
	 * @param style
1113
	 *            a int.
1114
	 * @return a {@link eu.etaxonomy.taxeditor.ui.term.AbstractEnumComboElement}
1115
	 *         object.
1116
	 */
1117
	public AbstractEnumComboElement createEnumComboElement(
1118
			EnumComboType enumComboType, ICdmFormElement parentElement,
1119
			int style) {
1120
		AbstractEnumComboElement element = null;
1121

    
1122
		switch (enumComboType) {
1123
		case REFERENCETYPE:
1124
			element = new ReferenceTypeComboElement(this, parentElement,
1125
					"Reference Type", null, style);
1126
			break;
1127
		case NOMENCLATURALCODE:
1128
			element = new NomenclaturalCodeComboElement(this, parentElement,
1129
					"Nomenclatural Code", null, style);
1130
			break;
1131
		}
1132
		adapt(element);
1133
		parentElement.addElement(element);
1134
		return element;
1135
	}
1136

    
1137
	/**
1138
	 * <p>
1139
	 * createBrowserElement
1140
	 * </p>
1141
	 * 
1142
	 * @param imageUri
1143
	 *            a {@link java.net.URI} object.
1144
	 * @param style
1145
	 *            a int.
1146
	 * @param parentElement
1147
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1148
	 *            object.
1149
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.BrowserElement} object.
1150
	 */
1151
	public BrowserElement createBrowserElement(ICdmFormElement parentElement,
1152
			URI imageUri, int style) {
1153
		BrowserElement element = new BrowserElement(this, parentElement,
1154
				imageUri, style);
1155
		adapt(element);
1156
		parentElement.addElement(element);
1157
		return element;
1158
	}
1159

    
1160
	/**
1161
	 * <p>
1162
	 * createImageElement
1163
	 * </p>
1164
	 * 
1165
	 * @param parentElement
1166
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1167
	 *            object.
1168
	 * @param imageUri
1169
	 *            a {@link java.net.URI} object.
1170
	 * @param style
1171
	 *            a int.
1172
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.ImageElement} object.
1173
	 */
1174
	public ImageElement createImageElement(ICdmFormElement parentElement,
1175
			URI imageUri, int style) {
1176
		ImageElement element = new ImageElement(this, parentElement, imageUri,
1177
				style);
1178
		adapt(element);
1179
		parentElement.addElement(element);
1180
		return element;
1181
	}
1182

    
1183
	/**
1184
	 * <p>
1185
	 * createTextActionElement
1186
	 * </p>
1187
	 * 
1188
	 * @param labelString
1189
	 *            a {@link java.lang.String} object.
1190
	 * @param initialText
1191
	 *            a {@link java.lang.String} object.
1192
	 * @param style
1193
	 *            a int.
1194
	 * @param parentElement
1195
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1196
	 *            object.
1197
	 * @param buttonLabel
1198
	 *            a {@link java.lang.String} object.
1199
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TextActionElement}
1200
	 *         object.
1201
	 */
1202
	public TextActionElement createTextActionElement(
1203
			ICdmFormElement parentElement, String labelString,
1204
			String buttonLabel, String initialText, int style) {
1205
		TextActionElement element = new TextActionElement(this, parentElement,
1206
				labelString, buttonLabel, initialText, style);
1207
		adapt(element);
1208
		parentElement.addElement(element);
1209
		return element;
1210
	}
1211

    
1212
	/**
1213
	 * 
1214
	 * @author n.hoffmann
1215
	 * @created Mar 5, 2010
1216
	 * @version 1.0
1217
	 */
1218
	public static enum SelectionType {
1219
		AGENT, INSTITUTION, NAME, REFERENCE, TAXON_BASE, TAXON, SYNONYM, TEAM, AUTHOR_TEAM, PERSON, DERIVED_UNIT, FIELD_OBSERVATION, FEATURE_TREE, CLASSIFICATION, TAXON_NODE, COLLECTION, FEATURE, POLYTOMOUS_KEY, POLYTOMOUS_KEY_NODE, USER, GROUP
1220
	}
1221

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

    
1247
	/**
1248
	 * Creates a section as a part of the form.
1249
	 * 
1250
	 * @return the section widget
1251
	 * @param section
1252
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
1253
	 *            object.
1254
	 */
1255
	public Section adapt(AbstractFormSection section) {
1256
		section.setMenu(section.getLayoutComposite().getMenu());
1257
		adapt(section, true, true);
1258

    
1259
		// handle focus and property change events for cdm use
1260
		section.addFocusListener(selectionFocusHandler);
1261
		section.setPropertyChangeListeners(propertyChangeListeners);
1262

    
1263
		if (section.getToggle() != null) {
1264
			section.getToggle().setHoverDecorationColor(
1265
					getColors().getColor(IFormColors.TB_TOGGLE_HOVER));
1266
			section.getToggle().setDecorationColor(
1267
					getColors().getColor(IFormColors.TB_TOGGLE));
1268
		}
1269

    
1270
		section.setFont(boldFontHolder2.getBoldFont(section
1271
				.getLayoutComposite().getFont()));
1272

    
1273
		if ((section.getStyle() & Section.TITLE_BAR) != 0
1274
				|| (section.getStyle() & Section.SHORT_TITLE_BAR) != 0) {
1275
			getColors().initializeSectionToolBarColors();
1276
			section.setTitleBarBackground(getColors().getColor(
1277
					IFormColors.TB_BG));
1278
			section.setTitleBarBorderColor(getColors().getColor(
1279
					IFormColors.TB_BORDER));
1280
		}
1281
		// call setTitleBarForeground regardless as it also sets the label color
1282
		section.setTitleBarForeground(getColors().getColor(
1283
				IFormColors.TB_TOGGLE));
1284
		return section;
1285
	}
1286

    
1287
	private class BoldFontHolder2 {
1288
		private Font normalFont;
1289

    
1290
		private Font boldFont;
1291

    
1292
		public BoldFontHolder2() {
1293
		}
1294

    
1295
		public Font getBoldFont(Font font) {
1296
			createBoldFont(font);
1297
			return boldFont;
1298
		}
1299

    
1300
		private void createBoldFont(Font font) {
1301
			if (normalFont == null || !normalFont.equals(font)) {
1302
				normalFont = font;
1303
				dispose();
1304
			}
1305
			if (boldFont == null) {
1306
				boldFont = FormFonts.getInstance().getBoldFont(
1307
						getColors().getDisplay(), normalFont);
1308
			}
1309
		}
1310

    
1311
		public void dispose() {
1312
			if (boldFont != null) {
1313
			/** RAPSS:Modify: Only one parameter required in Indigo				
1314
				FormFonts.getInstance().markFinished(boldFont,
1315
						getColors().getDisplay());
1316
			 */						
1317
			/** RAPSS:Modify: Two parameter required in Helios				
1318
				FormFonts.getInstance().markFinished(boldFont);
1319
			*/
1320
			FormFonts.getInstance().markFinished(boldFont);
1321
			boldFont = null;
1322
			}
1323
		}
1324
	}
1325

    
1326
	/**
1327
	 * <p>
1328
	 * createToggleableTextField
1329
	 * </p>
1330
	 * 
1331
	 * @param parentElement
1332
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1333
	 *            object.
1334
	 * @param labelString
1335
	 *            a {@link java.lang.String} object.
1336
	 * @param initialText
1337
	 *            a {@link java.lang.String} object.
1338
	 * @param initialState
1339
	 *            a boolean.
1340
	 * @param style
1341
	 *            a int.
1342
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.ToggleableTextElement}
1343
	 *         object.
1344
	 */
1345
	public ToggleableTextElement createToggleableTextField(
1346
			ICdmFormElement parentElement, String labelString,
1347
			String initialText, boolean initialState, int style) {
1348
		ToggleableTextElement element = new ToggleableTextElement(this,
1349
				parentElement, labelString, initialText, initialState, style
1350
						| orientation);
1351
		adapt(element);
1352
		parentElement.addElement(element);
1353
		return element;
1354
	}
1355

    
1356
	/**
1357
	 * <p>
1358
	 * createTimePeriodElement
1359
	 * </p>
1360
	 * 
1361
	 * @param parentElement
1362
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1363
	 *            object.
1364
	 * @param labelString
1365
	 *            a {@link java.lang.String} object.
1366
	 * @param timePeriod
1367
	 *            a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
1368
	 * @param style
1369
	 *            a int.
1370
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TimePeriodElement}
1371
	 *         object.
1372
	 */
1373
	public TimePeriodElement createTimePeriodElement(
1374
			ICdmFormElement parentElement, String labelString,
1375
			TimePeriod timePeriod, int style) {
1376
		TimePeriodElement element = new TimePeriodElement(this, parentElement,
1377
				labelString, timePeriod, style);
1378
		adapt(element);
1379
		parentElement.addElement(element);
1380
		return element;
1381
	}
1382

    
1383
	/**
1384
	 * <p>
1385
	 * createPointElement
1386
	 * </p>
1387
	 * 
1388
	 * @param style
1389
	 *            a int.
1390
	 * @param parentElement
1391
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1392
	 *            object.
1393
	 * @param point
1394
	 *            a {@link eu.etaxonomy.cdm.model.location.Point} object.
1395
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.PointElement} object.
1396
	 */
1397
	public PointElement createPointElement(ICdmFormElement parentElement,
1398
			Point point, int style) {
1399
		PointElement element = new PointElement(this, parentElement, point,
1400
				style);
1401
		adapt(element);
1402
		parentElement.addElement(element);
1403
		return element;
1404
	}
1405

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

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

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

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

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

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

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

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

    
1559
	/**
1560
	 * <p>
1561
	 * createVersionSection
1562
	 * </p>
1563
	 * 
1564
	 * @param parentElement
1565
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1566
	 *            object.
1567
	 * @param style
1568
	 *            a int.
1569
	 * @return a
1570
	 *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection}
1571
	 *         object.
1572
	 */
1573
	public VersionSection createVersionSection(ICdmFormElement parentElement,
1574
			int style) {
1575
		VersionSection section = new VersionSection(this, parentElement, style);
1576
		parentElement.addElement(section);
1577
		adapt(section);
1578
		return section;
1579
	}
1580

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

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

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

    
1646
	// SIMPLIFY
1647

    
1648
	/**
1649
	 * 
1650
	 */
1651
	public static enum DetailType {
1652
		NONVIRALNAME, 
1653
		SCIENTIFICNAME, 
1654
		REFERENCEBASE, 
1655
		NOMENCLATURALREFERENCE, 
1656
		TAXONBASE, 
1657
		AUTHORSHIP, 
1658
		TEAM, 
1659
		PERSON, 
1660
		DESCRIPTION, 
1661
		DESCRIPTIONELEMENT, 
1662
		PARSINGMESSAGE, 
1663
		NAMERELATIONSHIP, 
1664
		TEAMORPERSONBASE, 
1665
		MEDIA, 
1666
		FIELD_OBSERVATION, 
1667
		DERIVED_UNIT_FACADE, 
1668
		GATHERING_EVENT, 
1669
		DERIVED_UNIT, 
1670
		NATURAL_LANGUAGE, 
1671
		FEATURE_DISTRIBUTION, 
1672
		CLASSIFICATION, 
1673
		TAXON_NODE, 
1674
		COLLECTION, 
1675
		POLYTOMOUS_KEY, 
1676
		POLYTOMOUS_KEY_NODE, 
1677
		INSTITUTION, 
1678
		DERIVED_UNIT_GENERAL, 
1679
		HYBRID, 
1680
		USER, 
1681
		GROUP, 
1682
		DETERMINATION
1683
	}
1684

    
1685
	/**
1686
	 * <p>
1687
	 * createCdmDetailSection
1688
	 * </p>
1689
	 * 
1690
	 * @param detailType
1691
	 *            a
1692
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType}
1693
	 *            object.
1694
	 * @param parentElement
1695
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1696
	 *            object.
1697
	 * @param selectionProvider
1698
	 *            a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
1699
	 * @param style
1700
	 *            a int.
1701
	 * @param conversation
1702
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1703
	 *            object.
1704
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
1705
	 *         object.
1706
	 */
1707
	public AbstractFormSection createCdmDetailSection(DetailType detailType,
1708
			ConversationHolder conversation, ICdmFormElement parentElement,
1709
			ISelectionProvider selectionProvider, int style) {
1710
		AbstractFormSection section = null;
1711

    
1712
		switch (detailType) {
1713
		case SCIENTIFICNAME:
1714
			section = new NameDetailSection(this, conversation, parentElement,
1715
					selectionProvider, style);
1716
			break;
1717
		case REFERENCEBASE:
1718
			section = new ReferenceDetailSection(this, conversation,
1719
					parentElement, selectionProvider, style);
1720
			break;
1721
		case NOMENCLATURALREFERENCE:
1722
			section = new NomenclaturalReferenceDetailSection(this,
1723
					conversation, parentElement, selectionProvider, style);
1724
			break;
1725
		case TAXONBASE:
1726
			section = new TaxonBaseDetailSection(this, conversation,
1727
					parentElement, selectionProvider, style);
1728
			break;
1729
		case AUTHORSHIP:
1730
			section = new AuthorshipDetailSection(this, conversation,
1731
					parentElement, selectionProvider, style);
1732
			break;
1733
		case TEAMORPERSONBASE:
1734
			section = new TeamOrPersonBaseDetailSection(this, conversation,
1735
					parentElement, selectionProvider, style);
1736
			break;
1737
		case TEAM:
1738
			section = new TeamDetailSection(this, conversation, parentElement,
1739
					null, style);
1740
			break;
1741
		case PERSON:
1742
			section = new PersonDetailSection(this, conversation,
1743
					parentElement, null, style);
1744
			break;
1745
		case DESCRIPTION:
1746
			section = new DescriptionDetailSection(this, conversation,
1747
					parentElement, selectionProvider, style);
1748
			break;
1749
		case DESCRIPTIONELEMENT:
1750
			section = new DescriptionElementDetailSection(this, conversation,
1751
					parentElement, selectionProvider, style);
1752
			break;
1753
		case PARSINGMESSAGE:
1754
			section = new ParsingMessagesSection(this, conversation,
1755
					parentElement, selectionProvider, style);
1756
			break;
1757
		case NONVIRALNAME:
1758
			section = new NonViralNameDetailSection(this, conversation,
1759
					parentElement, selectionProvider, style);
1760
			break;
1761
		case MEDIA:
1762
			section = new eu.etaxonomy.taxeditor.ui.section.description.MediaDetailsSection(
1763
					this, conversation, parentElement, selectionProvider, style);
1764
			break;
1765
		case DERIVED_UNIT_FACADE:
1766
			section = new DerivedUnitFacadeDetailSection(this, conversation,
1767
					parentElement, selectionProvider, style);
1768
			break;
1769
		case FIELD_OBSERVATION:
1770
			section = new FieldObservationDetailSection(this, conversation,
1771
					parentElement, selectionProvider, style);
1772
			break;
1773
		case GATHERING_EVENT:
1774
			section = new GatheringEventDetailSection(this, conversation,
1775
					parentElement, selectionProvider, style);
1776
			break;
1777
		case DERIVED_UNIT:
1778
			section = new DerivedUnitBaseDetailSection(this, conversation,
1779
					parentElement, selectionProvider, style);
1780
			break;
1781
		case NATURAL_LANGUAGE:
1782
			section = new NaturalLanguageSection(this, conversation,
1783
					parentElement, selectionProvider, style);
1784
			break;
1785
		case FEATURE_DISTRIBUTION:
1786
			section = new FeatureDistributionDetailSection(this, conversation,
1787
					parentElement, selectionProvider, style);
1788
			break;
1789
		case CLASSIFICATION:
1790
			section = new ClassificationDetailSection(this, conversation,
1791
					parentElement, selectionProvider, style);
1792
			break;
1793
		case TAXON_NODE:
1794
			section = new TaxonNodeDetailSection(this, conversation,
1795
					parentElement, selectionProvider, style);
1796
			break;
1797
		case POLYTOMOUS_KEY:
1798
			section = new PolytomousKeyDetailSection(this, conversation,
1799
					parentElement, selectionProvider, style);
1800
			break;
1801
		case POLYTOMOUS_KEY_NODE:
1802
			section = new PolytomousKeyNodeDetailSection(this, conversation,
1803
					parentElement, selectionProvider, style);
1804
			break;
1805
		case INSTITUTION:
1806
			section = new InstitutionDetailSection(this, conversation,
1807
					parentElement, selectionProvider, style);
1808
			break;
1809
		case DERIVED_UNIT_GENERAL:
1810
			section = new GeneralDetailSection(this, conversation,
1811
					parentElement, selectionProvider, style);
1812
			break;
1813
		case HYBRID:
1814
			section = new HybridDetailSection(this, conversation,
1815
					parentElement, selectionProvider, style);
1816
			break;
1817
		case USER:
1818
			section = new UserDetailSection(this, conversation, parentElement,
1819
					selectionProvider, style);
1820
			break;
1821
		case GROUP:
1822
			section = new GroupDetailSection(this, conversation, parentElement,
1823
					selectionProvider, style);
1824
			break;
1825
		case DETERMINATION:
1826
			section = new DeterminationDetailSection(this, conversation, parentElement,
1827
					selectionProvider, style);
1828
		}
1829

    
1830
		if (section == null) {
1831
			throw new RuntimeException(
1832
					"You tried to create a cdm detail section that is not implemented yet.");
1833
		}
1834

    
1835
		parentElement.addElement(section);
1836
		adapt(section);
1837
		return section;
1838
	}
1839

    
1840
	/**
1841
	 * <p>
1842
	 * createCdmDetailElement
1843
	 * </p>
1844
	 * 
1845
	 * @param detailType
1846
	 *            a
1847
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType}
1848
	 *            object.
1849
	 * @param style
1850
	 *            a int.
1851
	 * @param parentElement
1852
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1853
	 *            object.
1854
	 * @return a
1855
	 *         {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
1856
	 *         object.
1857
	 */
1858
	public AbstractCdmDetailElement createCdmDetailElement(
1859
			DetailType detailType, ICdmFormElement parentElement, int style) {
1860
		AbstractCdmDetailElement element = null;
1861

    
1862
		switch (detailType) {
1863
		case SCIENTIFICNAME:
1864
			element = new NameDetailElement(this, parentElement, style);
1865
			break;
1866
		case REFERENCEBASE:
1867
			element = new ReferenceDetailElement(this, parentElement, style);
1868
			break;
1869
		case NOMENCLATURALREFERENCE:
1870
			element = new NomenclaturalReferenceDetailElement(this,
1871
					parentElement, style);
1872
			break;
1873
		case TAXONBASE:
1874
			element = new TaxonBaseDetailElement(this, parentElement, style);
1875
			break;
1876
		case AUTHORSHIP:
1877
			element = new AuthorshipDetailElement(this, parentElement, style);
1878
			break;
1879
		case TEAM:
1880
			element = new TeamDetailElement(this, parentElement, style);
1881
			break;
1882
		case PERSON:
1883
			element = new PersonDetailElement(this, parentElement, style);
1884
			break;
1885
		case DESCRIPTION:
1886
			element = new DescriptionDetailElement(this, parentElement, style);
1887
			break;
1888
		case DESCRIPTIONELEMENT:
1889
			element = new DescriptionElementDetailElement(this, parentElement,
1890
					style);
1891
			break;
1892
		case NONVIRALNAME:
1893
			element = new NonViralNameDetailElement(this, parentElement);
1894
			break;
1895
		case DERIVED_UNIT_FACADE:
1896
			element = new DerivedUnitFacadeDetailElement(this, parentElement);
1897
			break;
1898
		case FIELD_OBSERVATION:
1899
			element = new FieldObservationDetailElement(this, parentElement);
1900
			break;
1901
		case GATHERING_EVENT:
1902
			element = new GatheringEventDetailElement(this, parentElement);
1903
			break;
1904
		case DERIVED_UNIT:
1905
			element = new DerivedUnitBaseDetailElement(this, parentElement);
1906
			break;
1907
		case NATURAL_LANGUAGE:
1908
			element = new NaturalLanguageDetailElement(this, parentElement);
1909
			break;
1910
		case FEATURE_DISTRIBUTION:
1911
			element = new FeatureDistributionDetailElement(this, parentElement);
1912
			break;
1913
		case CLASSIFICATION:
1914
			element = new ClassificationDetailElement(this, parentElement);
1915
			break;
1916
		case TAXON_NODE:
1917
			element = new TaxonNodeDetailElement(this, parentElement);
1918
			break;
1919
		case COLLECTION:
1920
			element = new CollectionDetailElement(this, parentElement);
1921
			break;
1922
		case POLYTOMOUS_KEY:
1923
			element = new PolytomousKeyDetailElement(this, parentElement);
1924
			break;
1925
		case POLYTOMOUS_KEY_NODE:
1926
			element = new PolytomousKeyNodeDetailElement(this, parentElement);
1927
			break;
1928
		case INSTITUTION:
1929
			element = new InstitutionDetailElement(this, parentElement);
1930
			break;
1931
		case DERIVED_UNIT_GENERAL:
1932
			element = new GeneralDetailElement(this, parentElement);
1933
			break;
1934
		case HYBRID:
1935
			element = new HybridDetailElement(this, parentElement);
1936
			break;
1937
		case USER:
1938
			element = new UserDetailElement(this, parentElement);
1939
			break;
1940
		case GROUP:
1941
			element = new GroupDetailElement(this, parentElement);
1942
			break;
1943
		case DETERMINATION:
1944
			element = new DeterminationDetailElement(this, parentElement);
1945
			break;
1946
		}
1947

    
1948
		if (element == null) {
1949
			StoreUtil
1950
					.error(this.getClass(),
1951
							"Detail element was not created. Seems like the case was not implemented for the requested detail type: "
1952
									+ detailType, null);
1953
		}
1954

    
1955
		adapt(element);
1956
		parentElement.addElement(element);
1957
		return element;
1958
	}
1959

    
1960
	/**
1961
	 * 
1962
	 * @author n.hoffmann
1963
	 * @created Mar 5, 2010
1964
	 * @version 1.0
1965
	 */
1966
	public static enum EntityDetailType {
1967
		TEAM, TEAMMEMBER, ANNOTATION, CREDIT, DESCRIPTIONELEMENTSOURCE, EXTENSION, MARKER, MEDIA, DESCRIPTIONELEMENTMEDIA, MEDIAREPRESENTATION, MEDIAREPRESENTATIONPART, MODIFIER, NOMENCLATURALSTATUS, NAME_RELATIONSHIP, PROTOLOG, RIGHTS, SOURCE, SCOPE, DESCRIPTIONSOURCE, TYPEDESIGNATION, STATE_DATA, STATISTICAL_MEASUREMENT_VALUE, DESCRIBED_SPECIMEN, COLLECTING_AREA, DETERMINATION_EVENT, SPECIMEN_COLLECTION, IDENTIFIABLE_SOURCE_COLLECTION, GEOGRAPHICAL_SCOPE, SCOPE_RESTRICTION, MEMBER, GRANTED_AUTHORITY, GROUPS_BY_USER, TAXONOMIC_SCOPE, DETERMINATION_CURRENT, DETERMINATION_HISTORY
1968
	}
1969

    
1970
	/**
1971
	 * <p>
1972
	 * createEntityDetailSection
1973
	 * </p>
1974
	 * 
1975
	 * @param entityDetailType
1976
	 *            a
1977
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EntityDetailType}
1978
	 *            object.
1979
	 * @param style
1980
	 *            a int.
1981
	 * @param conversation
1982
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1983
	 *            object.
1984
	 * @param parentElement
1985
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1986
	 *            object.
1987
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
1988
	 *         object.
1989
	 */
1990
	public AbstractFormSection createEntityDetailSection(
1991
			EntityDetailType entityDetailType, ConversationHolder conversation,
1992
			ICdmFormElement parentElement, int style) {
1993
		AbstractFormSection section = null;
1994

    
1995
		switch (entityDetailType) {
1996
		case TEAM:
1997
			section = new TeamDetailSection(this, conversation, parentElement,
1998
					null, style);
1999
			break;
2000
		case TEAMMEMBER:
2001
			section = new TeamMemberSection(this, conversation, parentElement,
2002
					style);
2003
			break;
2004
		case ANNOTATION:
2005
			section = new AnnotationSection(this, conversation, parentElement,
2006
					style);
2007
			break;
2008
		case CREDIT:
2009
			section = new CreditSection(this, conversation, parentElement,
2010
					style);
2011
			break;
2012
		case DESCRIPTIONELEMENTSOURCE:
2013
			section = new DescriptionElementSourceSection(this, conversation,
2014
					parentElement, style);
2015
			break;
2016
		case EXTENSION:
2017
			section = new ExtensionSection(this, conversation, parentElement,
2018
					style);
2019
			break;
2020
		case MARKER:
2021
			section = new MarkerSection(this, conversation, parentElement,
2022
					style);
2023
			break;
2024
		case MEDIA:
2025
			section = new MediaSection(this, conversation, parentElement, style);
2026
			break;
2027
		case DESCRIPTIONELEMENTMEDIA:
2028
			section = new DescriptionElementMediaSection(this, conversation,
2029
					parentElement, style);
2030
			break;
2031
		case MEDIAREPRESENTATION:
2032
			section = new MediaRepresentationSection(this, conversation,
2033
					parentElement, style);
2034
			break;
2035
		case MEDIAREPRESENTATIONPART:
2036
			section = new MediaRepresentationPartSection(this, conversation,
2037
					parentElement, style);
2038
			break;
2039
		case MODIFIER:
2040
			section = new ModifierSection(this, conversation, parentElement,
2041
					style);
2042
			break;
2043
		case NOMENCLATURALSTATUS:
2044
			section = new NomenclaturalStatusSection(this, conversation,
2045
					parentElement, style);
2046
			break;
2047
		case NAME_RELATIONSHIP:
2048
			section = new NameRelationshipDetailSection(this, conversation,
2049
					parentElement, style);
2050
			break;
2051
		case PROTOLOG:
2052
			section = new ProtologueSection(this, conversation, parentElement,
2053
					style);
2054
			break;
2055
		case RIGHTS:
2056
			section = new RightsSection(this, conversation, parentElement,
2057
					style);
2058
			break;
2059
		case SOURCE:
2060
			section = new SourceSection(this, conversation, parentElement,
2061
					style);
2062
			break;
2063
		case SCOPE:
2064
			section = new ScopeSection(this, conversation, parentElement, style);
2065
			break;
2066
		case DESCRIPTIONSOURCE:
2067
			section = new DescriptionSourceSection(this, conversation,
2068
					parentElement, style);
2069
			break;
2070
		case TYPEDESIGNATION:
2071
			section = new TypeDesignationSection(this, conversation,
2072
					parentElement, style);
2073
			break;
2074
		case STATE_DATA:
2075
			section = new StateDataSection(this, conversation, parentElement,
2076
					style);
2077
			break;
2078
		case STATISTICAL_MEASUREMENT_VALUE:
2079
			section = new StatisticalMeasurementValueSection(this,
2080
					conversation, parentElement, style);
2081
			break;
2082
		case DESCRIBED_SPECIMEN:
2083
			section = new DescribedSpecimenSection(this, conversation,
2084
					parentElement, style);
2085
			break;
2086
		case COLLECTING_AREA:
2087
			section = new CollectingAreasDetailSection(this, conversation,
2088
					parentElement, style);
2089
			break;
2090
		case DETERMINATION_CURRENT:
2091
			section = new CurrentDeterminationDetailSection(this, conversation,
2092
					parentElement, style);
2093
			break;
2094
		case DETERMINATION_HISTORY:
2095
			section = new DeterminationHistoryDetailSection(this, conversation,
2096
					parentElement, style);
2097
			break;
2098
		case SPECIMEN_COLLECTION:
2099
			section = new SpecimenCollectionDetailSection(this, conversation,
2100
					parentElement, style);
2101
			break;
2102
		case IDENTIFIABLE_SOURCE_COLLECTION:
2103
			section = new SourceCollectionDetailSection(this, conversation,
2104
					parentElement, style);
2105
			break;
2106
		case GEOGRAPHICAL_SCOPE:
2107
			section = new GeographicalScopeDetailSection(this, conversation,
2108
					parentElement, style);
2109
			break;
2110
		case SCOPE_RESTRICTION:
2111
			section = new ScopeRestrictionSection(this, conversation,
2112
					parentElement, style);
2113
			break;
2114
		case MEMBER:
2115
			section = new MemberDetailSection(this, conversation,
2116
					parentElement, style);
2117
			break;
2118
		case GRANTED_AUTHORITY:
2119
			section = new GrantedAuthorityDetailSection(this, conversation,
2120
					parentElement, style);
2121
			break;
2122
		case GROUPS_BY_USER:
2123
			section = new GroupsByUserDetailSection(this, conversation,
2124
					parentElement, style);
2125
			break;
2126
		case TAXONOMIC_SCOPE:
2127
			section = new TaxonomicScopeSection(this, conversation,
2128
					parentElement, style);
2129
			break;
2130
		}
2131
		parentElement.addElement(section);
2132
		adapt(section);
2133
		return section;
2134
	}
2135

    
2136
	/**
2137
	 * <p>
2138
	 * createEntityCollectionElement
2139
	 * </p>
2140
	 * 
2141
	 * @param removeListener
2142
	 *            a {@link org.eclipse.swt.events.SelectionListener} object.
2143
	 * @param style
2144
	 *            a int.
2145
	 * @param parentElement
2146
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
2147
	 *            object.
2148
	 * @param versionableEntity
2149
	 *            a {@link eu.etaxonomy.cdm.model.common.IVersionableEntity}
2150
	 *            object.
2151
	 * @param backgroundColor
2152
	 *            a {@link org.eclipse.swt.graphics.Color} object.
2153
	 * @return a
2154
	 *         {@link eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement}
2155
	 *         object.
2156
	 */
2157
	public AbstractEntityCollectionElement createEntityCollectionElement(
2158
			AbstractFormSection parentElement, Object versionableEntity,
2159
			SelectionListener removeListener, Color backgroundColor, int style) {
2160
		AbstractEntityCollectionElement element = null;
2161

    
2162
		Object entity = HibernateProxyHelper.deproxy(versionableEntity);
2163

    
2164
		if (entity instanceof Annotation) {
2165
			element = new AnnotationElement(this, parentElement,
2166
					(Annotation) entity, removeListener, style);
2167
		} else if (entity instanceof Person) {
2168
			element = new TeamMemberElement(this, parentElement,
2169
					(Person) entity, removeListener, style);
2170
		} else if (entity instanceof Credit) {
2171
			element = new CreditElement(this, parentElement, (Credit) entity,
2172
					removeListener, style);
2173
		} else if (entity instanceof Extension) {
2174
			element = new ExtensionElement(this, parentElement,
2175
					(Extension) entity, removeListener, style);
2176
		} else if (entity instanceof Marker) {
2177
			element = new MarkerElement(this, parentElement, (Marker) entity,
2178
					removeListener, style);
2179
		} else if (entity instanceof Media) {
2180
			element = new MediaElement(this, parentElement, (Media) entity,
2181
					removeListener, style);
2182
		} else if (entity instanceof MediaRepresentation) {
2183
			element = new MediaRepresentationElement(this, parentElement,
2184
					(MediaRepresentation) entity, removeListener, style);
2185
		} else if (entity instanceof ImageFile) {
2186
			element = new ImageFileElement(this, parentElement,
2187
					(ImageFile) entity, removeListener, style);
2188
		} else if (entity instanceof NomenclaturalStatus) {
2189
			element = new NomenclaturalStatusElement(this, parentElement,
2190
					(NomenclaturalStatus) entity, removeListener, style);
2191
		} else if (entity instanceof Rights) {
2192
			element = new RightsElement(this, parentElement, (Rights) entity,
2193
					removeListener, style);
2194
		} else if (entity instanceof DescriptionElementSource) {
2195
			element = new DescriptionElementSourceElement(this, parentElement,
2196
					(DescriptionElementSource) entity, removeListener, style);
2197
		} else if (entity instanceof IdentifiableSource) {
2198
			element = new IdentifiableSourceElement(this, parentElement,
2199
					(IdentifiableSource) entity, removeListener, style);
2200
		} else if (entity instanceof Scope) {
2201
			element = new ScopeElement(this, parentElement, (Scope) entity,
2202
					removeListener, style);
2203
		} else if (entity instanceof Modifier) {
2204
			element = new ModifierElement(this, parentElement,
2205
					(Modifier) entity, removeListener, style);
2206
		} else if (entity instanceof Reference) {
2207
			element = new DescriptionSourceElement(this, parentElement,
2208
					(Reference) entity, removeListener, style);
2209
		} else if (entity instanceof NameTypeDesignation) {
2210
			element = new NameTypeDesignationElement(this, parentElement,
2211
					(NameTypeDesignation) entity, removeListener, style);
2212
		} else if (entity instanceof NameRelationship) {
2213
			element = new NameRelationshipDetailElement(this, parentElement,
2214
					(NameRelationship) entity, removeListener, style);
2215
		} else if (entity instanceof SpecimenTypeDesignation) {
2216
			element = new SpecimenTypeDesignationElement(this, parentElement,
2217
					(SpecimenTypeDesignation) entity, removeListener, style);
2218
		} else if (entity instanceof StateData) {
2219
			element = new StateDataElement(this, parentElement,
2220
					(StateData) entity, removeListener, style);
2221
		} else if (entity instanceof StatisticalMeasurementValue) {
2222
			element = new StatisticalMeasurementValueElement(this,
2223
					parentElement, (StatisticalMeasurementValue) entity,
2224
					removeListener, style);
2225
		} else if (entity instanceof DerivedUnit) {
2226
			element = new DerivedUnitElement(this, parentElement,
2227
					(DerivedUnit) entity, removeListener, style);
2228
		} else if (entity instanceof NamedArea) {
2229
			element = new NamedAreaDetailElement(this, parentElement,
2230
					(NamedArea) entity, removeListener, style);
2231
		} else if (entity instanceof DeterminationEvent) {
2232
			element = new DeterminationEventDetailElement(this, parentElement,
2233
					(DeterminationEvent) entity, removeListener, style);
2234
		} else if (entity instanceof Specimen) {
2235
			element = new SpecimenCollectionDetailElement(this, parentElement,
2236
					(Specimen) entity, removeListener, style);
2237
		} else if (entity instanceof User) {
2238
			element = new MemberDetailElement(this, parentElement,
2239
					(User) entity, removeListener, style);
2240
		} else if (entity instanceof GrantedAuthority) {
2241
			element = new GrantedAuthorityDetailElement(this, parentElement,
2242
					(GrantedAuthority) entity, removeListener, style);
2243
		} else if (entity instanceof Group) {
2244
			element = new GroupsByUserDetailElement(this, parentElement,
2245
					(Group) entity, removeListener, style);
2246
		} else if (entity instanceof Taxon) {
2247
			element = new TaxonDetailElement(this, parentElement,
2248
					(Taxon) entity, removeListener, style);
2249
		} else if (entity instanceof DescriptionElementBase) {
2250
			// this is the special case for protologs, maybe we can do this
2251
			// differently when API improves
2252
			DescriptionElementBase descriptionElement = (DescriptionElementBase) entity;
2253
			if (descriptionElement.getFeature().equals(Feature.PROTOLOGUE())) {
2254
				element = new ProtologueElement(this, parentElement,
2255
						descriptionElement, removeListener, style);
2256
			}
2257
		}
2258

    
2259
		if (element == null) {
2260
			StoreUtil
2261
					.errorDialog(
2262
							"No element for entity",
2263
							this,
2264
							"Could not generate element for entity. "
2265
									+ "Looks like the case is not handled already. Check implementation. Entity: "
2266
									+ entity, null);
2267
		}
2268

    
2269
		if (backgroundColor != null && !backgroundColor.isDisposed()) {
2270
			element.setBackgroundColor(backgroundColor);
2271
		}
2272

    
2273
		adapt(element);
2274
		parentElement.addElement(element);
2275
		return element;
2276
	}
2277

    
2278
	/**
2279
	 * <p>
2280
	 * createSelectionElement
2281
	 * </p>
2282
	 * 
2283
	 * @param selectionType
2284
	 *            a
2285
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.SelectionType}
2286
	 *            object.
2287
	 * @param parentElement
2288
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
2289
	 *            object.
2290
	 * @param labelString
2291
	 *            a {@link java.lang.String} object.
2292
	 * @param selectionType
2293
	 * @param selection
2294
	 *            a {@link eu.etaxonomy.cdm.model.common.IAnnotatableEntity}
2295
	 *            object.
2296
	 * @param style
2297
	 *            a int.
2298
	 * @param conversation
2299
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
2300
	 *            object.
2301
	 * @return a
2302
	 *         {@link eu.etaxonomy.taxeditor.ui.selection.AbstractSelectionElement}
2303
	 *         object.
2304
	 */
2305
	public AbstractSelectionElement createSelectionElement(
2306
			SelectionType selectionType, ConversationHolder conversation,
2307
			ICdmFormElement parentElement, String labelString,
2308
			ICdmBase selection, int mode, int style) {
2309
		AbstractSelectionElement element = null;
2310

    
2311
		IAnnotatableEntity entity = (IAnnotatableEntity) HibernateProxyHelper
2312
				.deproxy(selection);
2313

    
2314
		switch (selectionType) {
2315
		case AGENT:
2316
			element = new AgentSelectionElement(this, conversation,
2317
					parentElement, labelString, (TeamOrPersonBase) entity,
2318
					mode, style);
2319
			break;
2320
		case PERSON:
2321
			element = new PersonSelectionElement(this, conversation,
2322
					parentElement, labelString, (Person) entity, mode, style);
2323
			break;
2324
		case TEAM:
2325
			element = new TeamSelectionElement(this, conversation,
2326
					parentElement, labelString, (Team) entity, mode, style);
2327
			break;
2328
		case AUTHOR_TEAM:
2329
			element = new NomenclaturalAuthorTeamSelectionElement(this,
2330
					conversation, parentElement, labelString, (Team) entity,
2331
					mode, style);
2332
			break;
2333
		case INSTITUTION:
2334
			element = new InstitutionSelectionElement(this, conversation,
2335
					parentElement, labelString, (Institution) entity, mode,
2336
					style);
2337
			break;
2338
		case NAME:
2339
			element = new NameSelectionElement(this, conversation,
2340
					parentElement, labelString, (TaxonNameBase) entity, mode,
2341
					style);
2342
			break;
2343
		case REFERENCE:
2344
			element = new ReferenceSelectionElement(this, conversation,
2345
					parentElement, labelString, (Reference) entity, mode, style);
2346
			break;
2347
		case TAXON_BASE:
2348
			element = new TaxonBaseSelectionElement(this, conversation,
2349
					parentElement, labelString, (TaxonBase) entity, mode, style);
2350
			break;
2351
		case TAXON:
2352
			element = new TaxonSelectionElement(this, conversation,
2353
					parentElement, labelString, (Taxon) entity, mode, style);
2354
			break;
2355
		case SYNONYM:
2356
			element = new SynonymSelectionElement(this, conversation,
2357
					parentElement, labelString, (Synonym) entity, mode, style);
2358
			break;
2359
		case DERIVED_UNIT:
2360
			element = new DerivedUnitBaseSelectionElement(this, conversation,
2361
					parentElement, labelString, (DerivedUnitBase) entity, mode,
2362
					style);
2363
			break;
2364
		case FIELD_OBSERVATION:
2365
			element = new FieldObservationSelectionElement(this, conversation,
2366
					parentElement, labelString, (FieldObservation) entity,
2367
					mode, style);
2368
			break;
2369
		case FEATURE_TREE:
2370
			element = new FeatureTreeSelectionElement(this, conversation,
2371
					parentElement, labelString, (FeatureTree) entity, mode,
2372
					style);
2373
			break;
2374
		case CLASSIFICATION:
2375
			element = new ClassificationSelectionElement(this, conversation,
2376
					parentElement, labelString, (Classification) entity, mode,
2377
					style);
2378
			break;
2379
		case TAXON_NODE:
2380
			element = new TaxonNodeSelectionElement(this, conversation,
2381
					parentElement, labelString, (TaxonNode) entity, mode, style);
2382
			break;
2383
		case COLLECTION:
2384
			element = new CollectionSelectionElement(this, conversation,
2385
					parentElement, labelString, (Collection) entity, mode,
2386
					style);
2387
			break;
2388
		case FEATURE:
2389
			element = new FeatureSelectionElement(this, conversation,
2390
					parentElement, labelString, (Feature) entity, mode, style);
2391
			break;
2392
		case POLYTOMOUS_KEY:
2393
			element = new PolytomousKeySelectionElement(this, conversation,
2394
					parentElement, labelString, (PolytomousKey) entity, mode,
2395
					style);
2396
			break;
2397
		case POLYTOMOUS_KEY_NODE:
2398
			element = new PolytomousKeyNodeSelectionElement(this, conversation,
2399
					parentElement, labelString, (PolytomousKeyNode) entity,
2400
					mode, style);
2401
			break;
2402
		case USER:
2403
			element = new UserSelectionElement(this, conversation,
2404
					parentElement, labelString, (User) entity, mode, style);
2405
			break;
2406
		case GROUP:
2407
			element = new GroupSelectionElement(this, conversation,
2408
					parentElement, labelString, (Group) entity, mode, style);
2409
			break;
2410
		default:
2411
			new RuntimeException(
2412
					"There is no selection composite for the desired selection type.");
2413
			break;
2414
		}
2415

    
2416
		adapt(element);
2417
		parentElement.addElement(element);
2418
		return element;
2419
	}
2420

    
2421
	/**
2422
	 * <p>
2423
	 * createNamedAreaSelectionElement
2424
	 * </p>
2425
	 * 
2426
	 * @param parentElement
2427
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
2428
	 *            object.
2429
	 * @param conversation
2430
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
2431
	 *            object.
2432
	 * @param labelString
2433
	 *            a {@link java.lang.String} object.
2434
	 * @param selection
2435
	 *            a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
2436
	 * @param style
2437
	 *            a int.
2438
	 * @return a
2439
	 *         {@link eu.etaxonomy.taxeditor.ui.selection.NamedAreaSelectionElement}
2440
	 *         object.
2441
	 */
2442
	public NamedAreaSelectionElement createNamedAreaSelectionElement(
2443
			ICdmFormElement parentElement, ConversationHolder conversation,
2444
			String labelString, NamedArea selection, int style) {
2445
		NamedAreaSelectionElement element = new NamedAreaSelectionElement(this,
2446
				conversation, parentElement, labelString, selection,
2447
				AbstractSelectionElement.NOTHING, style);
2448
		adapt(element);
2449
		parentElement.addElement(element);
2450
		return element;
2451
	}
2452

    
2453
	/** {@inheritDoc} */
2454
	public LabelElement createLabel(ICdmFormElement parentElement, String text) {
2455
		LabelElement labelElement = new LabelElement(this, parentElement, text);
2456
		adapt(labelElement);
2457
		parentElement.addElement(labelElement);
2458
		return labelElement;
2459
	}
2460

    
2461
	/**
2462
	 * <p>
2463
	 * Getter for the field <code>selectionProvider</code>.
2464
	 * </p>
2465
	 * 
2466
	 * @return a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
2467
	 */
2468
	public ISelectionProvider getSelectionProvider() {
2469
		return selectionProvider;
2470
	}
2471

    
2472
	/**
2473
	 * <p>
2474
	 * createDetailedDescriptionDetailElement
2475
	 * </p>
2476
	 * 
2477
	 * @param parentElement
2478
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
2479
	 *            object.
2480
	 * @param entity
2481
	 *            a
2482
	 *            {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase}
2483
	 *            object.
2484
	 * @param style
2485
	 *            a int.
2486
	 * @return a
2487
	 *         {@link eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement}
2488
	 *         object.
2489
	 */
2490
	public AbstractDetailedDescriptionDetailElement createDetailedDescriptionDetailElement(
2491
			ICdmFormElement parentElement, DescriptionElementBase entity,
2492
			int style) {
2493
		AbstractDetailedDescriptionDetailElement detailedDescriptionElement = null;
2494

    
2495
		if (entity instanceof CategoricalData) {
2496
			detailedDescriptionElement = new CategoricalDataDetailElement(this,
2497
					parentElement, (CategoricalData) entity, style);
2498
		} else if (entity instanceof CommonTaxonName) {
2499
			detailedDescriptionElement = new CommonNameDetailElement(this,
2500
					parentElement, (CommonTaxonName) entity, style);
2501
		} else if (entity instanceof Distribution) {
2502
			detailedDescriptionElement = new DistributionDetailElement(this,
2503
					parentElement, (Distribution) entity, style);
2504
		} else if (entity instanceof IndividualsAssociation) {
2505
			detailedDescriptionElement = new IndividualsAssociationDetailElement(
2506
					this, parentElement, (IndividualsAssociation) entity, style);
2507
		} else if (entity instanceof QuantitativeData) {
2508
			detailedDescriptionElement = new QuantitativeDataDetailElement(
2509
					this, parentElement, (QuantitativeData) entity, style);
2510
		} else if (entity instanceof TaxonInteraction) {
2511
			detailedDescriptionElement = new TaxonInteractionDetailElement(
2512
					this, parentElement, (TaxonInteraction) entity, style);
2513
		} else if (entity instanceof TextData) {
2514
			detailedDescriptionElement = new TextDataDetailElement(this,
2515
					parentElement, (TextData) entity, style);
2516
		} else {
2517
			throw new IllegalStateException(
2518
					"There is no interface for the given description element");
2519
		}
2520
		adapt(detailedDescriptionElement);
2521
		parentElement.addElement(detailedDescriptionElement);
2522
		return detailedDescriptionElement;
2523

    
2524
	}
2525

    
2526
	/**
2527
	 * Creates a styled text as a part of the form.
2528
	 * 
2529
	 * @param parent
2530
	 *            the text parent
2531
	 * @param value
2532
	 *            the text initial value
2533
	 * @param style
2534
	 *            the text style
2535
	 * @return the text widget
2536
	 */
2537
	
2538
/** RAPSS:Remove  This is never used anywhere */	
2539
//	public StyledText createStyledText(Composite parent, String value, int style) {
2540
//		StyledText text = new StyledText(parent, getBorderStyle() | style
2541
//				| getOrientation());
2542
//		if (value != null)
2543
//			text.setText(value);
2544
//		text.setForeground(getColors().getForeground());
2545
//		text.setBackground(getColors().getBackground());
2546
//		// text.addFocusListener(visibilityHandler);
2547
//		return text;
2548
//	}
2549
}
(6-6/31)