Project

General

Profile

Download (84.6 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.custom.StyledText;
19
import org.eclipse.swt.events.FocusAdapter;
20
import org.eclipse.swt.events.FocusEvent;
21
import org.eclipse.swt.events.FocusListener;
22
import org.eclipse.swt.events.MouseAdapter;
23
import org.eclipse.swt.events.MouseEvent;
24
import org.eclipse.swt.events.MouseListener;
25
import org.eclipse.swt.events.SelectionEvent;
26
import org.eclipse.swt.events.SelectionListener;
27
import org.eclipse.swt.events.TypedEvent;
28
import org.eclipse.swt.graphics.Color;
29
import org.eclipse.swt.graphics.Font;
30
import org.eclipse.swt.widgets.Composite;
31
import org.eclipse.swt.widgets.Control;
32
import org.eclipse.swt.widgets.Display;
33
import org.eclipse.swt.widgets.Event;
34
import org.eclipse.swt.widgets.Label;
35
import org.eclipse.ui.forms.IFormColors;
36
import org.eclipse.ui.forms.widgets.FormToolkit;
37
import org.eclipse.ui.forms.widgets.Section;
38
import org.eclipse.ui.forms.widgets.TableWrapData;
39
import org.eclipse.ui.forms.widgets.TableWrapLayout;
40
import org.eclipse.ui.internal.forms.widgets.FormFonts;
41
import org.joda.time.Partial;
42
import org.springframework.security.core.GrantedAuthority;
43

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

    
293
/**
294
 * <p>
295
 * CdmFormFactory class.
296
 * </p>
297
 * 
298
 * @author n.hoffmann
299
 * @created Feb 24, 2010
300
 * @version 1.0
301
 */
302
public class CdmFormFactory extends FormToolkit {
303

    
304
	private BoldFontHolder2 boldFontHolder2;
305
	private MouseListener selectionMouseHandler;
306
	private FocusListener selectionFocusHandler;
307

    
308
	private final Set selectionListenerList = new HashSet();
309

    
310
	private final List<IPropertyChangeListener> propertyChangeListeners = new ArrayList<IPropertyChangeListener>();
311

    
312
	private final int orientation = Window.getDefaultOrientation();
313
	private ISelectionProvider selectionProvider;
314

    
315
	/**
316
	 * <p>
317
	 * LAYOUT
318
	 * </p>
319
	 * 
320
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapLayout} object.
321
	 */
322
	public static final TableWrapLayout LAYOUT() {
323
		return LAYOUT(1, false);
324
	}
325

    
326
	/**
327
	 * <p>
328
	 * LAYOUT
329
	 * </p>
330
	 * 
331
	 * @param columns
332
	 *            a int.
333
	 * @param equalWidth
334
	 *            a boolean.
335
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapLayout} object.
336
	 */
337
	public static final TableWrapLayout LAYOUT(int columns, boolean equalWidth) {
338
		TableWrapLayout layout = new TableWrapLayout();
339
		layout.topMargin = 0;
340
		layout.rightMargin = 0;
341
		layout.bottomMargin = 0;
342
		layout.leftMargin = 0;
343
		layout.numColumns = columns;
344
		layout.makeColumnsEqualWidth = equalWidth;
345
		layout.verticalSpacing = 0;
346
		layout.horizontalSpacing = 0;
347
		return layout;
348
	}
349

    
350
	/**
351
	 * <p>
352
	 * FILL
353
	 * </p>
354
	 * 
355
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
356
	 */
357
	public static final TableWrapData FILL() {
358
		return FILL(1, 1);
359
	}
360

    
361
	/**
362
	 * <p>
363
	 * FILL
364
	 * </p>
365
	 * 
366
	 * @param horizontalSpan
367
	 *            a int.
368
	 * @param verticalSpan
369
	 *            a int.
370
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
371
	 */
372
	public static final TableWrapData FILL(int horizontalSpan, int verticalSpan) {
373
		TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB,
374
				TableWrapData.FILL_GRAB);
375
		layoutData.colspan = horizontalSpan;
376
		layoutData.rowspan = verticalSpan;
377
		return layoutData;
378
	}
379

    
380
	/**
381
	 * <p>
382
	 * LEFT
383
	 * </p>
384
	 * 
385
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
386
	 */
387
	public static final TableWrapData LEFT() {
388
		return new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP);
389
	}
390

    
391
	/**
392
	 * <p>
393
	 * RIGHT
394
	 * </p>
395
	 * 
396
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
397
	 */
398
	public static final TableWrapData RIGHT() {
399
		return new TableWrapData(TableWrapData.RIGHT, TableWrapData.TOP);
400
	}
401

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

    
413
	/**
414
	 * <p>
415
	 * FILL_HORIZONTALLY
416
	 * </p>
417
	 * 
418
	 * @param horizontalSpan
419
	 *            a int.
420
	 * @param verticalSpan
421
	 *            a int.
422
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
423
	 */
424
	public static final TableWrapData FILL_HORIZONTALLY(int horizontalSpan,
425
			int verticalSpan) {
426
		TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB,
427
				TableWrapData.TOP);
428
		layoutData.colspan = horizontalSpan;
429
		layoutData.rowspan = verticalSpan;
430
		return layoutData;
431
	}
432

    
433
	/** Constant <code>EMPTY_SELECTION</code> */
434
	public static ISelection EMPTY_SELECTION = new ISelection() {
435
		@Override
436
		public boolean isEmpty() {
437
			return true;
438
		}
439
	};
440

    
441
	private class SelectionMouseHandler extends MouseAdapter {
442
		@Override
443
		public void mouseDown(MouseEvent e) {
444
			notifySelectionListeners(e);
445
		}
446
	}
447

    
448
	private class SelectionFocusHandler extends FocusAdapter {
449
		@Override
450
		public void focusGained(FocusEvent e) {
451
			notifySelectionListeners(e);
452
		}
453
	}
454

    
455
	private void notifySelectionListeners(TypedEvent e) {
456
		Event event = new Event();
457
		event.widget = e.widget;
458
		SelectionEvent selectionEvent = new SelectionEvent(event);
459

    
460
		for (Object listener : selectionListenerList) {
461
			((SelectionListener) listener).widgetSelected(selectionEvent);
462
		}
463
	}
464

    
465
	/**
466
	 * <p>
467
	 * Constructor for CdmFormFactory.
468
	 * </p>
469
	 * 
470
	 * @param display
471
	 *            a {@link org.eclipse.swt.widgets.Display} object.
472
	 * @param selectionProvider
473
	 *            a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
474
	 */
475
	public CdmFormFactory(Display display, ISelectionProvider selectionProvider) {
476
		super(display);
477
		this.selectionProvider = selectionProvider;
478
		init();
479
	}
480

    
481
	/**
482
	 * <p>
483
	 * Constructor for CdmFormFactory.
484
	 * </p>
485
	 * 
486
	 * @param display
487
	 *            a {@link org.eclipse.swt.widgets.Display} object.
488
	 */
489
	public CdmFormFactory(Display display) {
490
		super(display);
491
		init();
492
	}
493

    
494
	/**
495
	 * 
496
	 */
497
	private void init() {
498
		boldFontHolder2 = new BoldFontHolder2();
499
		selectionMouseHandler = new SelectionMouseHandler();
500
		selectionFocusHandler = new SelectionFocusHandler();
501
	}
502

    
503
	/**
504
	 * Creates an instance initialized with the correct selectionProvider
505
	 * 
506
	 * Make sure to remove the instance when the entityComposite disposes via
507
	 * destroySelectionArbitrator(..)
508
	 * 
509
	 * @param entityElement
510
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.IEntityElement}
511
	 *            object.
512
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.SelectionArbitrator}
513
	 *         object.
514
	 */
515
	public SelectionArbitrator createSelectionArbitrator(
516
			IEntityElement entityElement) {
517
		SelectionArbitrator selectionArbitrator = new SelectionArbitrator(
518
				entityElement);
519
		selectionArbitrator.addSelectionProvider(selectionProvider);
520
		selectionProvider.addSelectionChangedListener(selectionArbitrator);
521
		addSelectionListener(selectionArbitrator);
522
		return selectionArbitrator;
523
	}
524

    
525
	/**
526
	 * <p>
527
	 * destroySelectionArbitrator
528
	 * </p>
529
	 * 
530
	 * @param selectionArbitrator
531
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.SelectionArbitrator}
532
	 *            object.
533
	 */
534
	public void destroySelectionArbitrator(
535
			SelectionArbitrator selectionArbitrator) {
536
		removeSelectionListener(selectionArbitrator);
537
		if (selectionProvider != null) {
538
			selectionProvider
539
					.removeSelectionChangedListener(selectionArbitrator);
540
		} else {
541
			StoreUtil
542
					.error(this.getClass(),
543
							"Tried to destroy a selection listener from this factories listeners but was null",
544
							null);
545
		}
546
	}
547

    
548
	/** {@inheritDoc} */
549
	@Override
550
	public void adapt(Composite composite) {
551
		composite.addMouseListener(selectionMouseHandler);
552
		super.adapt(composite);
553
	}
554

    
555
	/**
556
	 * <p>
557
	 * adapt
558
	 * </p>
559
	 * 
560
	 * @param formElement
561
	 *            a
562
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.AbstractCdmFormElement}
563
	 *            object.
564
	 */
565
	public void adapt(AbstractCdmFormElement formElement) {
566
		formElement.setPropertyChangeListeners(propertyChangeListeners);
567
	}
568

    
569
	/** {@inheritDoc} */
570
	@Override
571
	public void adapt(Control control, boolean trackFocus, boolean trackKeyboard) {
572
		if (trackFocus) {
573
			control.addFocusListener(selectionFocusHandler);
574
		}
575
		super.adapt(control, trackFocus, trackKeyboard);
576
	}
577

    
578
	/**
579
	 * <p>
580
	 * destroyElement
581
	 * </p>
582
	 * 
583
	 * @param formElement
584
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
585
	 *            object.
586
	 */
587
	public void destroyElement(ICdmFormElement formElement) {
588
		// return if element was not initialized
589
		if (formElement == null) {
590
			return;
591
		}
592
		// destroy selection arbitrator, if any
593
		if (formElement instanceof ISelectableElement) {
594
			destroySelectionArbitrator(((ISelectableElement) formElement)
595
					.getSelectionArbitrator());
596
		}
597
		// remove this element form its parents list of elements
598
		// ICdmFormElement parentElement = formElement.getParentElement();
599
		// if(parentElement != null){
600
		// parentElement.removeElement(formElement);
601
		// }
602
		// call destroy on child elements recursively
603
		for (ICdmFormElement childElement : formElement.getElements()) {
604
			destroyElement(childElement);
605
		}
606
		// dispose of the controls
607
		for (Control control : formElement.getControls()) {
608
			// we added the layoutComposite of the parental element as the
609
			// layout composite to this formElement
610
			// but we do not want to destroy it.
611
			if (control.equals(formElement.getLayoutComposite())) {
612
				continue;
613
			} else {
614
				control.dispose();
615
				control = null;
616
			}
617
		}
618
	}
619

    
620
	/**
621
	 * <p>
622
	 * createEmptyCell
623
	 * </p>
624
	 * 
625
	 * @param parent
626
	 *            a {@link org.eclipse.swt.widgets.Composite} object.
627
	 * @return a {@link org.eclipse.swt.widgets.Label} object.
628
	 */
629
	public Label createEmptyCell(Composite parent) {
630
		return this.createLabel(parent, null);
631
	}
632

    
633
	/**
634
	 * <p>
635
	 * createMultilineTextWithLabel
636
	 * </p>
637
	 * 
638
	 * @param labelString
639
	 *            a {@link java.lang.String} object.
640
	 * @param textHeight
641
	 *            a int.
642
	 * @param style
643
	 *            a int.
644
	 * @param parentElement
645
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
646
	 *            object.
647
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement}
648
	 *         object.
649
	 */
650
	public TextWithLabelElement createMultilineTextWithLabel(
651
			ICdmFormElement parentElement, String labelString, int textHeight,
652
			int style) {
653
		TextWithLabelElement element = new TextWithLabelElement(this,
654
				parentElement, labelString, "", textHeight, style);
655
		adapt(element);
656
		parentElement.addElement(element);
657
		return element;
658
	}
659

    
660
	/**
661
	 * <p>
662
	 * createMultiLanguageTextElement
663
	 * </p>
664
	 * 
665
	 * @param parentElement
666
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
667
	 *            object.
668
	 * @param labelString
669
	 *            a {@link java.lang.String} object.
670
	 * @param multilanguageText
671
	 *            a {@link java.util.Map} object.
672
	 * @param textHeight
673
	 *            a int.
674
	 * @param style
675
	 *            a int.
676
	 * @return a
677
	 *         {@link eu.etaxonomy.taxeditor.ui.forms.MultilanguageTextElement}
678
	 *         object.
679
	 */
680
	public MultilanguageTextElement createMultiLanguageTextElement(
681
			ICdmFormElement parentElement, String labelString,
682
			Map<Language, LanguageString> multilanguageText, int textHeight,
683
			int style) {
684
		MultilanguageTextElement element = new MultilanguageTextElement(this,
685
				parentElement, labelString, multilanguageText, textHeight,
686
				style);
687
		adapt(element);
688
		parentElement.addElement(element);
689
		return element;
690
	}
691

    
692
	public KeyStatementElement createKeyStatementElement(
693
			ICdmFormElement parentElement, String labelString,
694
			KeyStatement keyStatement, int textHeight, int style) {
695
		KeyStatementElement element = new KeyStatementElement(this,
696
				parentElement, labelString, keyStatement, textHeight, style);
697
		adapt(element);
698
		parentElement.addElement(element);
699
		return element;
700
	}
701

    
702
	/**
703
	 * <p>
704
	 * createTextWithLabelElement
705
	 * </p>
706
	 * 
707
	 * @param labelString
708
	 *            a {@link java.lang.String} object.
709
	 * @param initialText
710
	 *            a {@link java.lang.String} object.
711
	 * @param style
712
	 *            a int.
713
	 * @param parentElement
714
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
715
	 *            object.
716
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement}
717
	 *         object.
718
	 */
719
	public TextWithLabelElement createTextWithLabelElement(
720
			ICdmFormElement parentElement, String labelString,
721
			String initialText, int style) {
722
		TextWithLabelElement element = new TextWithLabelElement(this,
723
				parentElement, labelString, initialText, null, style);
724
		adapt(element);
725
		parentElement.addElement(element);
726
		return element;
727
	}
728

    
729
	public UriWithLabelElement createUriWithLabelElement(
730
			ICdmFormElement parentElement, String labelString, URI initialUri,
731
			int style) {
732
		UriWithLabelElement element = new UriWithLabelElement(this,
733
				parentElement, labelString, initialUri, null, style);
734
		adapt(element);
735
		parentElement.addElement(element);
736
		return element;
737
	}
738

    
739
	/**
740
	 * @param element
741
	 * @param string
742
	 * @param uri
743
	 * @param style
744
	 * @return
745
	 */
746
	public OpenUrlSelectorElement createOpenUrlSelectorElement(
747
			ICdmFormElement parentElement, String labelString,
748
			IOpenUrlEnabled openUrlEnabled, int style) {
749
		OpenUrlSelectorElement element = new OpenUrlSelectorElement(this,
750
				parentElement, labelString, openUrlEnabled, style);
751
		adapt(element);
752
		parentElement.addElement(element);
753
		return element;
754
	}
755

    
756
	/**
757
	 * 
758
	 * @param parentElement
759
	 * @param labelString
760
	 * @param conversationEnabled
761
	 * @param user
762
	 * @param style
763
	 * @return
764
	 */
765
	public EditPasswordElement createEditPasswordElement(
766
			ICdmFormElement parentElement, String labelString,
767
			ConversationHolder conversation, User user, int style) {
768
		EditPasswordElement element = new EditPasswordElement(this,
769
				parentElement, labelString, user, conversation);
770
		adapt(element);
771
		parentElement.addElement(element);
772
		return element;
773
	}
774

    
775
	/**
776
	 * <p>
777
	 * createIntegerTextWithLabelElement
778
	 * </p>
779
	 * 
780
	 * @param parentElement
781
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
782
	 *            object.
783
	 * @param labelString
784
	 *            a {@link java.lang.String} object.
785
	 * @param initialInteger
786
	 *            a {@link java.lang.Integer} object.
787
	 * @param style
788
	 *            a int.
789
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElement}
790
	 *         object.
791
	 */
792
	public NumberWithLabelElement createIntegerTextWithLabelElement(
793
			ICdmFormElement parentElement, String labelString,
794
			Integer initialInteger, int style) {
795
		NumberWithLabelElement element = new NumberWithLabelElement(this,
796
				parentElement, labelString, initialInteger, style);
797
		adapt(element);
798
		parentElement.addElement(element);
799
		return element;
800
	}
801

    
802
	/**
803
	 * <p>
804
	 * createFloatTextWithLabelElement
805
	 * </p>
806
	 * 
807
	 * @param parentElement
808
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
809
	 *            object.
810
	 * @param labelString
811
	 *            a {@link java.lang.String} object.
812
	 * @param initialFloat
813
	 *            a float.
814
	 * @param style
815
	 *            a int.
816
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElement}
817
	 *         object.
818
	 */
819
	public NumberWithLabelElement createFloatTextWithLabelElement(
820
			ICdmFormElement parentElement, String labelString,
821
			float initialFloat, int style) {
822
		NumberWithLabelElement element = new NumberWithLabelElement(this,
823
				parentElement, labelString, initialFloat, style);
824
		adapt(element);
825
		parentElement.addElement(element);
826
		return element;
827
	}
828

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

    
857
	/**
858
	 * <p>
859
	 * createLanguageStringWithLabelElement
860
	 * </p>
861
	 * 
862
	 * @param parentElement
863
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
864
	 *            object.
865
	 * @param labelString
866
	 *            a {@link java.lang.String} object.
867
	 * @param languageString
868
	 *            a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
869
	 * @param height
870
	 *            a int.
871
	 * @param style
872
	 *            a int.
873
	 * @return a
874
	 *         {@link eu.etaxonomy.taxeditor.ui.forms.LanguageStringWithLabelElement}
875
	 *         object.
876
	 */
877
	public LanguageStringWithLabelElement createLanguageStringWithLabelElement(
878
			ICdmFormElement parentElement, String labelString,
879
			LanguageString languageString, int height, int style) {
880
		LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(
881
				this, parentElement, labelString, languageString, height, style);
882
		adapt(element);
883
		parentElement.addElement(element);
884
		return element;
885
	}
886

    
887
	/**
888
	 * <p>
889
	 * createTextElement
890
	 * </p>
891
	 * 
892
	 * @param parentElement
893
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
894
	 *            object.
895
	 * @param initialText
896
	 *            a {@link java.lang.String} object.
897
	 * @param style
898
	 *            a int.
899
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement}
900
	 *         object.
901
	 */
902
	public TextWithLabelElement createTextElement(
903
			ICdmFormElement parentElement, String initialText, int style) {
904
		TextWithLabelElement element = new TextWithLabelElement(this,
905
				parentElement, null, initialText, null, style);
906
		adapt(element);
907
		parentElement.addElement(element);
908
		return element;
909
	}
910

    
911
	/**
912
	 * <p>
913
	 * createKeyValueViewerElement
914
	 * </p>
915
	 * 
916
	 * @param parentElement
917
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
918
	 *            object.
919
	 * @param keyHeading
920
	 *            a {@link java.lang.String} object.
921
	 * @param valueHeading
922
	 *            a {@link java.lang.String} object.
923
	 * @param map
924
	 *            a {@link java.util.Map} object.
925
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.KeyValueViewerElement}
926
	 *         object.
927
	 */
928
	public KeyValueViewerElement createKeyValueViewerElement(
929
			ICdmFormElement parentElement, String keyHeading,
930
			String valueHeading, Map<Object, Object> map) {
931
		KeyValueViewerElement element = new KeyValueViewerElement(this,
932
				parentElement, keyHeading, valueHeading, map);
933
		adapt(element);
934
		parentElement.addElement(element);
935
		return element;
936
	}
937

    
938
	/**
939
	 * <p>
940
	 * createTermComboElement
941
	 * </p>
942
	 * 
943
	 * @param termComboType
944
	 *            a
945
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.TermComboType}
946
	 *            object.
947
	 * @param parentElement
948
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
949
	 *            object.
950
	 * @param labelString
951
	 *            a {@link java.lang.String} object.
952
	 * @param selection
953
	 *            a {@link eu.etaxonomy.cdm.model.common.DefinedTermBase}
954
	 *            object.
955
	 * @param style
956
	 *            a int.
957
	 * @return a {@link eu.etaxonomy.taxeditor.ui.combo.TermComboElement}
958
	 *         object.
959
	 */
960

    
961
	public <T extends DefinedTermBase> TermComboElement createTermComboElement(
962
			Class<T> termComboType, ICdmFormElement parentElement,
963
			String labelString, T selection, int style) {
964
		TermComboElement element = new TermComboElement<T>(this, parentElement,
965
				termComboType, labelString, selection, style);
966
		adapt(element);
967
		parentElement.addElement(element);
968
		return element;
969
	}
970

    
971
	/**
972
	 * <p>
973
	 * createEnumComboElement
974
	 * </p>
975
	 * 
976
	 * @param enumComboType
977
	 *            a
978
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EnumComboType}
979
	 *            object.
980
	 * @param parentElement
981
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
982
	 *            object.
983
	 * @param style
984
	 *            a int.
985
	 * @return a {@link eu.etaxonomy.taxeditor.ui.term.AbstractEnumComboElement}
986
	 *         object.
987
	 */
988
	public <T extends IDefinedTerm> EnumComboElement<T> createEnumComboElement(
989
			Class<T> enumComboType, ICdmFormElement parentElement, int style) {
990
		EnumComboElement<T> element = new EnumComboElement<T>(this,
991
				parentElement, enumComboType, style);
992
		adapt(element);
993
		parentElement.addElement(element);
994
		return element;
995
	}
996

    
997
	/**
998
	 * <p>
999
	 * createBrowserElement
1000
	 * </p>
1001
	 * 
1002
	 * @param imageUri
1003
	 *            a {@link java.net.URI} object.
1004
	 * @param style
1005
	 *            a int.
1006
	 * @param parentElement
1007
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1008
	 *            object.
1009
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.BrowserElement} object.
1010
	 */
1011
	public BrowserElement createBrowserElement(ICdmFormElement parentElement,
1012
			URI imageUri, int style) {
1013
		BrowserElement element = new BrowserElement(this, parentElement,
1014
				imageUri, style);
1015
		adapt(element);
1016
		parentElement.addElement(element);
1017
		return element;
1018
	}
1019

    
1020
	/**
1021
	 * <p>
1022
	 * createImageElement
1023
	 * </p>
1024
	 * 
1025
	 * @param parentElement
1026
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1027
	 *            object.
1028
	 * @param imageUri
1029
	 *            a {@link java.net.URI} object.
1030
	 * @param style
1031
	 *            a int.
1032
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.ImageElement} object.
1033
	 */
1034
	public ImageElement createImageElement(ICdmFormElement parentElement,
1035
			URI imageUri, int style) {
1036
		ImageElement element = new ImageElement(this, parentElement, imageUri,
1037
				style);
1038
		adapt(element);
1039
		parentElement.addElement(element);
1040
		return element;
1041
	}
1042

    
1043
	/**
1044
	 * <p>
1045
	 * createTextActionElement
1046
	 * </p>
1047
	 * 
1048
	 * @param labelString
1049
	 *            a {@link java.lang.String} object.
1050
	 * @param initialText
1051
	 *            a {@link java.lang.String} object.
1052
	 * @param style
1053
	 *            a int.
1054
	 * @param parentElement
1055
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1056
	 *            object.
1057
	 * @param buttonLabel
1058
	 *            a {@link java.lang.String} object.
1059
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TextActionElement}
1060
	 *         object.
1061
	 */
1062
	public TextActionElement createTextActionElement(
1063
			ICdmFormElement parentElement, String labelString,
1064
			String buttonLabel, String initialText, int style) {
1065
		TextActionElement element = new TextActionElement(this, parentElement,
1066
				labelString, buttonLabel, initialText, style);
1067
		adapt(element);
1068
		parentElement.addElement(element);
1069
		return element;
1070
	}
1071

    
1072
	/**
1073
	 * 
1074
	 * @author n.hoffmann
1075
	 * @created Mar 5, 2010
1076
	 * @version 1.0
1077
	 */
1078
	public static enum SelectionType {
1079
		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
1080
	}
1081

    
1082
	/**
1083
	 * <p>
1084
	 * createCheckbox
1085
	 * </p>
1086
	 * 
1087
	 * @param parentElement
1088
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1089
	 *            object.
1090
	 * @param label
1091
	 *            a {@link java.lang.String} object.
1092
	 * @param initialState
1093
	 *            a boolean.
1094
	 * @param style
1095
	 *            a int.
1096
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.CheckboxElement} object.
1097
	 */
1098
	public CheckboxElement createCheckbox(ICdmFormElement parentElement,
1099
			String label, boolean initialState, int style) {
1100
		CheckboxElement element = new CheckboxElement(this, parentElement,
1101
				label, initialState, style | orientation);
1102
		adapt(element);
1103
		parentElement.addElement(element);
1104
		return element;
1105
	}
1106

    
1107
	/**
1108
	 * Creates a section as a part of the form.
1109
	 * 
1110
	 * @return the section widget
1111
	 * @param section
1112
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
1113
	 *            object.
1114
	 */
1115
	public Section adapt(AbstractFormSection section) {
1116
		section.setMenu(section.getLayoutComposite().getMenu());
1117
		adapt(section, true, true);
1118

    
1119
		// handle focus and property change events for cdm use
1120
		section.addFocusListener(selectionFocusHandler);
1121
		section.setPropertyChangeListeners(propertyChangeListeners);
1122

    
1123
		if (section.getToggle() != null) {
1124
			section.getToggle().setHoverDecorationColor(
1125
					getColors().getColor(IFormColors.TB_TOGGLE_HOVER));
1126
			section.getToggle().setDecorationColor(
1127
					getColors().getColor(IFormColors.TB_TOGGLE));
1128
		}
1129

    
1130
		section.setFont(boldFontHolder2.getBoldFont(section
1131
				.getLayoutComposite().getFont()));
1132

    
1133
		if ((section.getStyle() & Section.TITLE_BAR) != 0
1134
				|| (section.getStyle() & Section.SHORT_TITLE_BAR) != 0) {
1135
			getColors().initializeSectionToolBarColors();
1136
			section.setTitleBarBackground(getColors().getColor(
1137
					IFormColors.TB_BG));
1138
			section.setTitleBarBorderColor(getColors().getColor(
1139
					IFormColors.TB_BORDER));
1140
		}
1141
		// call setTitleBarForeground regardless as it also sets the label color
1142
		section.setTitleBarForeground(getColors().getColor(
1143
				IFormColors.TB_TOGGLE));
1144
		return section;
1145
	}
1146

    
1147
	private class BoldFontHolder2 {
1148
		private Font normalFont;
1149

    
1150
		private Font boldFont;
1151

    
1152
		public BoldFontHolder2() {
1153
		}
1154

    
1155
		public Font getBoldFont(Font font) {
1156
			createBoldFont(font);
1157
			return boldFont;
1158
		}
1159

    
1160
		private void createBoldFont(Font font) {
1161
			if (normalFont == null || !normalFont.equals(font)) {
1162
				normalFont = font;
1163
				dispose();
1164
			}
1165
			if (boldFont == null) {
1166
				boldFont = FormFonts.getInstance().getBoldFont(
1167
						getColors().getDisplay(), normalFont);
1168
			}
1169
		}
1170

    
1171
		public void dispose() {
1172
			if (boldFont != null) {
1173
				FormFonts.getInstance().markFinished(boldFont,
1174
						getColors().getDisplay());
1175
				boldFont = null;
1176
			}
1177
		}
1178
	}
1179

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

    
1210
	/**
1211
	 * <p>
1212
	 * createTimePeriodElement
1213
	 * </p>
1214
	 * 
1215
	 * @param parentElement
1216
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1217
	 *            object.
1218
	 * @param labelString
1219
	 *            a {@link java.lang.String} object.
1220
	 * @param timePeriod
1221
	 *            a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
1222
	 * @param style
1223
	 *            a int.
1224
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TimePeriodElement}
1225
	 *         object.
1226
	 */
1227
	public TimePeriodElement createTimePeriodElement(
1228
			ICdmFormElement parentElement, String labelString,
1229
			TimePeriod timePeriod, int style) {
1230
		TimePeriodElement element = new TimePeriodElement(this, parentElement,
1231
				labelString, timePeriod, style);
1232
		adapt(element);
1233
		parentElement.addElement(element);
1234
		return element;
1235
	}
1236

    
1237
	/**
1238
	 * <p>
1239
	 * createPointElement
1240
	 * </p>
1241
	 * 
1242
	 * @param style
1243
	 *            a int.
1244
	 * @param parentElement
1245
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1246
	 *            object.
1247
	 * @param point
1248
	 *            a {@link eu.etaxonomy.cdm.model.location.Point} object.
1249
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.PointElement} object.
1250
	 */
1251
	public PointElement createPointElement(ICdmFormElement parentElement,
1252
			Point point, int style) {
1253
		PointElement element = new PointElement(this, parentElement, point,
1254
				style);
1255
		adapt(element);
1256
		parentElement.addElement(element);
1257
		return element;
1258
	}
1259

    
1260
	/**
1261
	 * <p>
1262
	 * createDateDetailSection
1263
	 * </p>
1264
	 * 
1265
	 * @param parentElement
1266
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1267
	 *            object.
1268
	 * @param style
1269
	 *            a int.
1270
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.DateDetailSection}
1271
	 *         object.
1272
	 */
1273
	public DateDetailSection createDateDetailSection(
1274
			ICdmFormElement parentElement, int style) {
1275
		DateDetailSection section = new DateDetailSection(this, parentElement,
1276
				style);
1277
		parentElement.addElement(section);
1278
		adapt(section);
1279
		return section;
1280
	}
1281

    
1282
	/**
1283
	 * <p>
1284
	 * createPartialElement
1285
	 * </p>
1286
	 * 
1287
	 * @param parentElement
1288
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1289
	 *            object.
1290
	 * @param labelString
1291
	 *            a {@link java.lang.String} object.
1292
	 * @param partial
1293
	 *            a {@link org.joda.time.Partial} object.
1294
	 * @param style
1295
	 *            a int.
1296
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.PartialElement} object.
1297
	 */
1298
	public PartialElement createPartialElement(ICdmFormElement parentElement,
1299
			String labelString, Partial partial, int style) {
1300
		PartialElement element = new PartialElement(this, parentElement,
1301
				labelString, style);
1302
		adapt(element);
1303
		parentElement.addElement(element);
1304
		return element;
1305
	}
1306

    
1307
	/**
1308
	 * <p>
1309
	 * addSelectionListener
1310
	 * </p>
1311
	 * 
1312
	 * @param listener
1313
	 *            a {@link org.eclipse.swt.events.SelectionListener} object.
1314
	 */
1315
	public void addSelectionListener(SelectionListener listener) {
1316
		selectionListenerList.add(listener);
1317
	}
1318

    
1319
	/**
1320
	 * <p>
1321
	 * removeSelectionListener
1322
	 * </p>
1323
	 * 
1324
	 * @param listener
1325
	 *            a {@link org.eclipse.swt.events.SelectionListener} object.
1326
	 */
1327
	public void removeSelectionListener(SelectionListener listener) {
1328
		if (listener == null) {
1329
			StoreUtil
1330
					.error(this.getClass(),
1331
							"Tried to remove a selection listener from this factories listeners but was null",
1332
							null);
1333
		} else {
1334
			selectionListenerList.remove(listener);
1335
		}
1336
	}
1337

    
1338
	/**
1339
	 * <p>
1340
	 * addPropertyChangeListener
1341
	 * </p>
1342
	 * 
1343
	 * @param listener
1344
	 *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1345
	 *            object.
1346
	 */
1347
	public void addPropertyChangeListener(IPropertyChangeListener listener) {
1348
		if (propertyChangeListeners.contains(listener)) {
1349
			return;
1350
		}
1351
		propertyChangeListeners.add(0, listener);
1352
	}
1353

    
1354
	/**
1355
	 * <p>
1356
	 * removePropertyChangeListener
1357
	 * </p>
1358
	 * 
1359
	 * @param listener
1360
	 *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1361
	 *            object.
1362
	 */
1363
	public void removePropertyChangeListener(IPropertyChangeListener listener) {
1364
		propertyChangeListeners.remove(listener);
1365
	}
1366

    
1367
	/**
1368
	 * <p>
1369
	 * createHorizontalSeparator
1370
	 * </p>
1371
	 * 
1372
	 * @param parentElement
1373
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1374
	 *            object.
1375
	 * @param style
1376
	 *            a int.
1377
	 * @return a {@link org.eclipse.swt.widgets.Label} object.
1378
	 */
1379
	public Label createHorizontalSeparator(ICdmFormElement parentElement,
1380
			int style) {
1381
		Label separator = this.createSeparator(
1382
				parentElement.getLayoutComposite(), SWT.HORIZONTAL | style);
1383
		separator.setLayoutData(FILL_HORIZONTALLY());
1384
		return separator;
1385
	}
1386

    
1387
	/**
1388
	 * <p>
1389
	 * createVersionElement
1390
	 * </p>
1391
	 * 
1392
	 * @param parentElement
1393
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1394
	 *            object.
1395
	 * @param entity
1396
	 *            a {@link eu.etaxonomy.cdm.model.common.VersionableEntity}
1397
	 *            object.
1398
	 * @param style
1399
	 *            a int.
1400
	 * @return a
1401
	 *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionElement}
1402
	 *         object.
1403
	 */
1404
	public VersionElement createVersionElement(ICdmFormElement parentElement,
1405
			VersionableEntity entity, int style) {
1406
		VersionElement element = new VersionElement(this, parentElement,
1407
				entity, style);
1408
		adapt(element);
1409
		parentElement.addElement(element);
1410
		return element;
1411
	}
1412

    
1413
	/**
1414
	 * <p>
1415
	 * createVersionSection
1416
	 * </p>
1417
	 * 
1418
	 * @param parentElement
1419
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1420
	 *            object.
1421
	 * @param style
1422
	 *            a int.
1423
	 * @return a
1424
	 *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection}
1425
	 *         object.
1426
	 */
1427
	public VersionSection createVersionSection(ICdmFormElement parentElement,
1428
			int style) {
1429
		VersionSection section = new VersionSection(this, parentElement, style);
1430
		parentElement.addElement(section);
1431
		adapt(section);
1432
		return section;
1433
	}
1434

    
1435
	/**
1436
	 * <p>
1437
	 * createEmptyElement
1438
	 * </p>
1439
	 * 
1440
	 * @param parentElement
1441
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1442
	 *            object.
1443
	 * @return a {@link eu.etaxonomy.taxeditor.ui.section.EmptyElement} object.
1444
	 */
1445
	public EmptyElement createEmptyElement(ICdmFormElement parentElement) {
1446
		EmptyElement element = new EmptyElement(this, parentElement, null,
1447
				SWT.NULL);
1448
		adapt(element);
1449
		parentElement.addElement(element);
1450
		return element;
1451
	}
1452

    
1453
	/**
1454
	 * <p>
1455
	 * createHeadlineSection
1456
	 * </p>
1457
	 * 
1458
	 * @param parentElement
1459
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1460
	 *            object.
1461
	 * @return a
1462
	 *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection}
1463
	 *         object.
1464
	 */
1465
	public HeadlineSection createHeadlineSection(ICdmFormElement parentElement) {
1466
		HeadlineSection section = new HeadlineSection(this, parentElement,
1467
				SWT.NULL);
1468
		parentElement.addElement(section);
1469
		adapt(section);
1470
		return section;
1471
	}
1472

    
1473
	/**
1474
	 * <p>
1475
	 * createParsingMessageElement
1476
	 * </p>
1477
	 * 
1478
	 * @param parentElement
1479
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1480
	 *            object.
1481
	 * @param parserProblem
1482
	 *            a {@link eu.etaxonomy.cdm.strategy.parser.ParserProblem}
1483
	 *            object.
1484
	 * @param style
1485
	 *            a int.
1486
	 * @return a
1487
	 *         {@link eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessageElement}
1488
	 *         object.
1489
	 */
1490
	public ParsingMessageElement createParsingMessageElement(
1491
			ICdmFormElement parentElement, ParserProblem parserProblem,
1492
			int style) {
1493
		ParsingMessageElement element = new ParsingMessageElement(this,
1494
				parentElement, parserProblem, style);
1495
		adapt(element);
1496
		parentElement.addElement(element);
1497
		return element;
1498
	}
1499

    
1500
	// SIMPLIFY
1501

    
1502
	/**
1503
	 * 
1504
	 */
1505
	public static enum DetailType {
1506
		NONVIRALNAME, SCIENTIFICNAME, REFERENCEBASE, NOMENCLATURALREFERENCE, TAXONBASE, AUTHORSHIP, TEAM, PERSON, DESCRIPTION, DESCRIPTIONELEMENT, PARSINGMESSAGE, NAMERELATIONSHIP, TEAMORPERSONBASE, MEDIA, FIELD_OBSERVATION, DERIVED_UNIT_FACADE, GATHERING_EVENT, DERIVED_UNIT, NATURAL_LANGUAGE, FEATURE_DISTRIBUTION, CLASSIFICATION, TAXON_NODE, COLLECTION, POLYTOMOUS_KEY, POLYTOMOUS_KEY_NODE, INSTITUTION, DERIVED_UNIT_GENERAL, HYBRID, USER, GROUP, DETERMINATION, TAXON_RELATIONSHIP, REFERENCED_ENTITY, TERM_VOCABULARY, NAMED_AREA, NAMED_AREA_LEVEL, USE_RECORD
1507
	}
1508

    
1509
	public AbstractFormSection createDefinedTermDetailSection(
1510
			Class definedTermClass, ConversationHolder conversation,
1511
			ICdmFormElement parentElement,
1512
			ISelectionProvider selectionProvider, int style) {
1513

    
1514
		AbstractFormSection section = new DefinedTermDetailSection(this,
1515
				definedTermClass, conversation, parentElement,
1516
				selectionProvider, style);
1517

    
1518
		parentElement.addElement(section);
1519
		adapt(section);
1520
		return section;
1521

    
1522
	}
1523

    
1524
	/**
1525
	 * @param definedTermClass
1526
	 * @param formElement
1527
	 * @param style
1528
	 * @return
1529
	 */
1530
	public AbstractCdmDetailElement createDefinedTermDetailElement(
1531
			Class definedTermClass, AbstractCdmDetailSection parentElement,
1532
			int style) {
1533
		AbstractCdmDetailElement element = null;
1534

    
1535
		if (NamedArea.class.isAssignableFrom(definedTermClass)) {
1536
			element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(
1537
					this, parentElement);
1538
		} else {
1539
			element = new DefinedTermDetailElement(this, parentElement);
1540
		}
1541

    
1542
		adapt(element);
1543
		parentElement.addElement(element);
1544
		return element;
1545
	}
1546

    
1547
	/**
1548
	 * <p>
1549
	 * createCdmDetailSection
1550
	 * </p>
1551
	 * 
1552
	 * @param detailType
1553
	 *            a
1554
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType}
1555
	 *            object.
1556
	 * @param parentElement
1557
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1558
	 *            object.
1559
	 * @param selectionProvider
1560
	 *            a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
1561
	 * @param style
1562
	 *            a int.
1563
	 * @param conversation
1564
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1565
	 *            object.
1566
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
1567
	 *         object.
1568
	 */
1569
	public AbstractFormSection createCdmDetailSection(DetailType detailType,
1570
			ConversationHolder conversation, ICdmFormElement parentElement,
1571
			ISelectionProvider selectionProvider, int style) {
1572
		AbstractFormSection section = null;
1573

    
1574
		switch (detailType) {
1575
		case SCIENTIFICNAME:
1576
			section = new NameDetailSection(this, conversation, parentElement,
1577
					selectionProvider, style);
1578
			break;
1579
		case REFERENCEBASE:
1580
			section = new ReferenceDetailSection(this, conversation,
1581
					parentElement, selectionProvider, style);
1582
			break;
1583
		case NOMENCLATURALREFERENCE:
1584
			section = new NomenclaturalReferenceDetailSection(this,
1585
					conversation, parentElement, selectionProvider, style);
1586
			break;
1587
		case TAXONBASE:
1588
			section = new TaxonBaseDetailSection(this, conversation,
1589
					parentElement, selectionProvider, style);
1590
			break;
1591
		case AUTHORSHIP:
1592
			section = new AuthorshipDetailSection(this, conversation,
1593
					parentElement, selectionProvider, style);
1594
			break;
1595
		case TEAMORPERSONBASE:
1596
			section = new TeamOrPersonBaseDetailSection(this, conversation,
1597
					parentElement, selectionProvider, style);
1598
			break;
1599
		case TEAM:
1600
			section = new TeamDetailSection(this, conversation, parentElement,
1601
					null, style);
1602
			break;
1603
		case PERSON:
1604
			section = new PersonDetailSection(this, conversation,
1605
					parentElement, null, style);
1606
			break;
1607
		case DESCRIPTION:
1608
			section = new DescriptionDetailSection(this, conversation,
1609
					parentElement, selectionProvider, style);
1610
			break;
1611
		case DESCRIPTIONELEMENT:
1612
			section = new DescriptionElementDetailSection(this, conversation,
1613
					parentElement, selectionProvider, style);
1614
			break;
1615
		case PARSINGMESSAGE:
1616
			section = new ParsingMessagesSection(this, conversation,
1617
					parentElement, selectionProvider, style);
1618
			break;
1619
		case NONVIRALNAME:
1620
			section = new NonViralNameDetailSection(this, conversation,
1621
					parentElement, selectionProvider, style);
1622
			break;
1623
		case MEDIA:
1624
			section = new eu.etaxonomy.taxeditor.ui.section.description.MediaDetailsSection(
1625
					this, conversation, parentElement, selectionProvider, style);
1626
			break;
1627
		case DERIVED_UNIT_FACADE:
1628
			section = new DerivedUnitFacadeDetailSection(this, conversation,
1629
					parentElement, selectionProvider, style);
1630
			break;
1631
		case FIELD_OBSERVATION:
1632
			section = new FieldObservationDetailSection(this, conversation,
1633
					parentElement, selectionProvider, style);
1634
			break;
1635
		case GATHERING_EVENT:
1636
			section = new GatheringEventDetailSection(this, conversation,
1637
					parentElement, selectionProvider, style);
1638
			break;
1639
		case DERIVED_UNIT:
1640
			section = new DerivedUnitBaseDetailSection(this, conversation,
1641
					parentElement, selectionProvider, style);
1642
			break;
1643
		case NATURAL_LANGUAGE:
1644
			section = new NaturalLanguageSection(this, conversation,
1645
					parentElement, selectionProvider, style);
1646
			break;
1647
		case FEATURE_DISTRIBUTION:
1648
			section = new FeatureDistributionDetailSection(this, conversation,
1649
					parentElement, selectionProvider, style);
1650
			break;
1651
		case CLASSIFICATION:
1652
			section = new ClassificationDetailSection(this, conversation,
1653
					parentElement, selectionProvider, style);
1654
			break;
1655
		case TAXON_NODE:
1656
			section = new TaxonNodeDetailSection(this, conversation,
1657
					parentElement, selectionProvider, style);
1658
			break;
1659
		case POLYTOMOUS_KEY:
1660
			section = new PolytomousKeyDetailSection(this, conversation,
1661
					parentElement, selectionProvider, style);
1662
			break;
1663
		case POLYTOMOUS_KEY_NODE:
1664
			section = new PolytomousKeyNodeDetailSection(this, conversation,
1665
					parentElement, selectionProvider, style);
1666
			break;
1667
		case INSTITUTION:
1668
			section = new InstitutionDetailSection(this, conversation,
1669
					parentElement, selectionProvider, style);
1670
			break;
1671
		case DERIVED_UNIT_GENERAL:
1672
			section = new GeneralDetailSection(this, conversation,
1673
					parentElement, selectionProvider, style);
1674
			break;
1675
		case HYBRID:
1676
			section = new HybridDetailSection(this, conversation,
1677
					parentElement, selectionProvider, style);
1678
			break;
1679
		case USER:
1680
			section = new UserDetailSection(this, conversation, parentElement,
1681
					selectionProvider, style);
1682
			break;
1683
		case GROUP:
1684
			section = new GroupDetailSection(this, conversation, parentElement,
1685
					selectionProvider, style);
1686
			break;
1687
		case DETERMINATION:
1688
			section = new DeterminationDetailSection(this, conversation,
1689
					parentElement, selectionProvider, style);
1690
			break;
1691
		case TAXON_RELATIONSHIP:
1692
			section = new TaxonRelationshipDetailSection(this, conversation,
1693
					parentElement, selectionProvider, style);
1694
			break;
1695
		case REFERENCED_ENTITY:
1696
			section = new ReferencedEntityDetailSection(this, conversation,
1697
					parentElement, selectionProvider, style);
1698
			break;
1699
		case TERM_VOCABULARY:
1700
			section = new TermVocabularyDetailSection(this, conversation,
1701
					parentElement, selectionProvider, style);
1702
			break;
1703
		case NAMED_AREA:
1704
			section = new NamedAreaDetailSection(this, conversation,
1705
					parentElement, selectionProvider, style);
1706
			break;
1707
		case USE_RECORD:
1708
			section = new UseRecordDetailSection(this, conversation,
1709
					parentElement, selectionProvider, style);
1710
			break;
1711
		}
1712

    
1713
		if (section == null) {
1714
			throw new RuntimeException(
1715
					"You tried to create a cdm detail section that is not implemented yet.");
1716
		}
1717

    
1718
		parentElement.addElement(section);
1719
		adapt(section);
1720
		return section;
1721
	}
1722

    
1723
	/**
1724
	 * <p>
1725
	 * createCdmDetailElement
1726
	 * </p>
1727
	 * 
1728
	 * @param detailType
1729
	 *            a
1730
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType}
1731
	 *            object.
1732
	 * @param style
1733
	 *            a int.
1734
	 * @param parentElement
1735
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1736
	 *            object.
1737
	 * @return a
1738
	 *         {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
1739
	 *         object.
1740
	 */
1741
	public AbstractCdmDetailElement createCdmDetailElement(
1742
			DetailType detailType, ICdmFormElement parentElement, int style) {
1743
		AbstractCdmDetailElement element = null;
1744

    
1745
		switch (detailType) {
1746
		case SCIENTIFICNAME:
1747
			element = new NameDetailElement(this, parentElement, style);
1748
			break;
1749
		case REFERENCEBASE:
1750
			element = new ReferenceDetailElement(this, parentElement, style);
1751
			break;
1752
		case NOMENCLATURALREFERENCE:
1753
			element = new NomenclaturalReferenceDetailElement(this,
1754
					parentElement, style);
1755
			break;
1756
		case TAXONBASE:
1757
			element = new TaxonBaseDetailElement(this, parentElement, style);
1758
			break;
1759
		case AUTHORSHIP:
1760
			element = new AuthorshipDetailElement(this, parentElement, style);
1761
			break;
1762
		case TEAM:
1763
			element = new TeamDetailElement(this, parentElement, style);
1764
			break;
1765
		case PERSON:
1766
			element = new PersonDetailElement(this, parentElement, style);
1767
			break;
1768
		case DESCRIPTION:
1769
			element = new DescriptionDetailElement(this, parentElement, style);
1770
			break;
1771
		case DESCRIPTIONELEMENT:
1772
			element = new DescriptionElementDetailElement(this, parentElement,
1773
					style);
1774
			break;
1775
		case NONVIRALNAME:
1776
			element = new NonViralNameDetailElement(this, parentElement);
1777
			break;
1778
		case DERIVED_UNIT_FACADE:
1779
			element = new DerivedUnitFacadeDetailElement(this, parentElement);
1780
			break;
1781
		case FIELD_OBSERVATION:
1782
			element = new FieldObservationDetailElement(this, parentElement);
1783
			break;
1784
		case GATHERING_EVENT:
1785
			element = new GatheringEventDetailElement(this, parentElement);
1786
			break;
1787
		case DERIVED_UNIT:
1788
			element = new DerivedUnitBaseDetailElement(this, parentElement);
1789
			break;
1790
		case NATURAL_LANGUAGE:
1791
			element = new NaturalLanguageDetailElement(this, parentElement);
1792
			break;
1793
		case FEATURE_DISTRIBUTION:
1794
			element = new FeatureDistributionDetailElement(this, parentElement);
1795
			break;
1796
		case CLASSIFICATION:
1797
			element = new ClassificationDetailElement(this, parentElement);
1798
			break;
1799
		case TAXON_NODE:
1800
			element = new TaxonNodeDetailElement(this, parentElement);
1801
			break;
1802
		case COLLECTION:
1803
			element = new CollectionDetailElement(this, parentElement);
1804
			break;
1805
		case POLYTOMOUS_KEY:
1806
			element = new PolytomousKeyDetailElement(this, parentElement);
1807
			break;
1808
		case POLYTOMOUS_KEY_NODE:
1809
			element = new PolytomousKeyNodeDetailElement(this, parentElement);
1810
			break;
1811
		case INSTITUTION:
1812
			element = new InstitutionDetailElement(this, parentElement);
1813
			break;
1814
		case DERIVED_UNIT_GENERAL:
1815
			element = new GeneralDetailElement(this, parentElement);
1816
			break;
1817
		case HYBRID:
1818
			element = new HybridDetailElement(this, parentElement);
1819
			break;
1820
		case USER:
1821
			element = new UserDetailElement(this, parentElement);
1822
			break;
1823
		case GROUP:
1824
			element = new GroupDetailElement(this, parentElement);
1825
			break;
1826
		case DETERMINATION:
1827
			element = new DeterminationDetailElement(this, parentElement);
1828
			break;
1829
		case TAXON_RELATIONSHIP:
1830
			element = new TaxonRelationshipDetailElement(this, parentElement);
1831
			break;
1832
		case REFERENCED_ENTITY:
1833
			element = new RefereneEntityDetailElement(this, parentElement);
1834
			break;
1835
		case TERM_VOCABULARY:
1836
			element = new TermVocabularyDetailElement(this, parentElement);
1837
			break;
1838
		case NAMED_AREA:
1839
			element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(
1840
					this, parentElement);
1841
			break;
1842
		case NAMED_AREA_LEVEL:
1843
			element = new DefinedTermDetailElement<NamedAreaLevel>(this,
1844
					parentElement);
1845
			break;
1846
		case USE_RECORD:
1847
			//element = new UseRecordDetailElement(this, parentElement, style);
1848
			element = new UseRecordDetailElement(this, parentElement);
1849
			break;
1850
		}
1851

    
1852
		if (element == null) {
1853
			StoreUtil
1854
					.error(this.getClass(),
1855
							"Detail element was not created. Seems like the case was not implemented for the requested detail type: "
1856
									+ detailType, null);
1857
		}
1858

    
1859
		adapt(element);
1860
		parentElement.addElement(element);
1861
		return element;
1862
	}
1863

    
1864
	/**
1865
	 * 
1866
	 * @author n.hoffmann
1867
	 * @created Mar 5, 2010
1868
	 * @version 1.0
1869
	 */
1870
	public static enum EntityDetailType {
1871
		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, USE_CAT, USE_SUBCAT
1872
	}
1873

    
1874
	/**
1875
	 * <p>
1876
	 * createEntityDetailSection
1877
	 * </p>
1878
	 * 
1879
	 * @param entityDetailType
1880
	 *            a
1881
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EntityDetailType}
1882
	 *            object.
1883
	 * @param style
1884
	 *            a int.
1885
	 * @param conversation
1886
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1887
	 *            object.
1888
	 * @param parentElement
1889
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1890
	 *            object.
1891
	 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
1892
	 *         object.
1893
	 */
1894
	public AbstractFormSection createEntityDetailSection(
1895
			EntityDetailType entityDetailType, ConversationHolder conversation,
1896
			ICdmFormElement parentElement, int style) {
1897
		AbstractFormSection section = null;
1898

    
1899
		switch (entityDetailType) {
1900
		case TEAM:
1901
			section = new TeamDetailSection(this, conversation, parentElement,
1902
					null, style);
1903
			break;
1904
		case TEAMMEMBER:
1905
			section = new TeamMemberSection(this, conversation, parentElement,
1906
					style);
1907
			break;
1908
		case ANNOTATION:
1909
			section = new AnnotationSection(this, conversation, parentElement,
1910
					style);
1911
			break;
1912
		case CREDIT:
1913
			section = new CreditSection(this, conversation, parentElement,
1914
					style);
1915
			break;
1916
		case DESCRIPTIONELEMENTSOURCE:
1917
			section = new DescriptionElementSourceSection(this, conversation,
1918
					parentElement, style);
1919
			break;
1920
		case EXTENSION:
1921
			section = new ExtensionSection(this, conversation, parentElement,
1922
					style);
1923
			break;
1924
		case MARKER:
1925
			section = new MarkerSection(this, conversation, parentElement,
1926
					style);
1927
			break;
1928
		case MEDIA:
1929
			section = new MediaSection(this, conversation, parentElement, style);
1930
			break;
1931
		case DESCRIPTIONELEMENTMEDIA:
1932
			section = new DescriptionElementMediaSection(this, conversation,
1933
					parentElement, style);
1934
			break;
1935
		case MEDIAREPRESENTATION:
1936
			section = new MediaRepresentationSection(this, conversation,
1937
					parentElement, style);
1938
			break;
1939
		case MEDIAREPRESENTATIONPART:
1940
			section = new MediaRepresentationPartSection(this, conversation,
1941
					parentElement, style);
1942
			break;
1943
		case MODIFIER:
1944
			section = new ModifierSection(this, conversation, parentElement,
1945
					style);
1946
			break;
1947
		case NOMENCLATURALSTATUS:
1948
			section = new NomenclaturalStatusSection(this, conversation,
1949
					parentElement, style);
1950
			break;
1951
		case NAME_RELATIONSHIP:
1952
			section = new NameRelationshipDetailSection(this, conversation,
1953
					parentElement, style);
1954
			break;
1955
		case PROTOLOG:
1956
			section = new ProtologueSection(this, conversation, parentElement,
1957
					style);
1958
			break;
1959
		case RIGHTS:
1960
			section = new RightsSection(this, conversation, parentElement,
1961
					style);
1962
			break;
1963
		case SOURCE:
1964
			section = new SourceSection(this, conversation, parentElement,
1965
					style);
1966
			break;
1967
		case SCOPE:
1968
			section = new ScopeSection(this, conversation, parentElement, style);
1969
			break;
1970
		case DESCRIPTIONSOURCE:
1971
			section = new DescriptionSourceSection(this, conversation,
1972
					parentElement, style);
1973
			break;
1974
		case TYPEDESIGNATION:
1975
			section = new TypeDesignationSection(this, conversation,
1976
					parentElement, style);
1977
			break;
1978
		case STATE_DATA:
1979
			section = new StateDataSection(this, conversation, parentElement,
1980
					style);
1981
			break;
1982
		case STATISTICAL_MEASUREMENT_VALUE:
1983
			section = new StatisticalMeasurementValueSection(this,
1984
					conversation, parentElement, style);
1985
			break;
1986
		case DESCRIBED_SPECIMEN:
1987
			section = new DescribedSpecimenSection(this, conversation,
1988
					parentElement, style);
1989
			break;
1990
		case COLLECTING_AREA:
1991
			section = new CollectingAreasDetailSection(this, conversation,
1992
					parentElement, style);
1993
			break;
1994
		case DETERMINATION_CURRENT:
1995
			section = new CurrentDeterminationDetailSection(this, conversation,
1996
					parentElement, style);
1997
			break;
1998
		case DETERMINATION_HISTORY:
1999
			section = new DeterminationHistoryDetailSection(this, conversation,
2000
					parentElement, style);
2001
			break;
2002
		case SPECIMEN_COLLECTION:
2003
			section = new SpecimenCollectionDetailSection(this, conversation,
2004
					parentElement, style);
2005
			break;
2006
		case IDENTIFIABLE_SOURCE_COLLECTION:
2007
			section = new SourceCollectionDetailSection(this, conversation,
2008
					parentElement, style);
2009
			break;
2010
		case GEOGRAPHICAL_SCOPE:
2011
			section = new GeographicalScopeDetailSection(this, conversation,
2012
					parentElement, style);
2013
			break;
2014
		case SCOPE_RESTRICTION:
2015
			section = new ScopeRestrictionSection(this, conversation,
2016
					parentElement, style);
2017
			break;
2018
		case MEMBER:
2019
			section = new MemberDetailSection(this, conversation,
2020
					parentElement, style);
2021
			break;
2022
		case GRANTED_AUTHORITY:
2023
			section = new GrantedAuthorityDetailSection(this, conversation,
2024
					parentElement, style);
2025
			break;
2026
		case GROUPS_BY_USER:
2027
			section = new GroupsByUserDetailSection(this, conversation,
2028
					parentElement, style);
2029
			break;
2030
		case TAXONOMIC_SCOPE:
2031
			section = new TaxonomicScopeSection(this, conversation,
2032
					parentElement, style);
2033
			break;
2034
		case USE_CAT:
2035
			section = new UseCategorySection(this, conversation, parentElement,
2036
					style);
2037
			break;
2038
		case USE_SUBCAT:
2039
			section = new UseSubCategorySection(this, conversation, parentElement,
2040
					style);
2041
			break;
2042
		}
2043
		parentElement.addElement(section);
2044
		adapt(section);
2045
		return section;
2046
	}
2047

    
2048
	/**
2049
	 * <p>
2050
	 * createEntityCollectionElement
2051
	 * </p>
2052
	 * 
2053
	 * @param removeListener
2054
	 *            a {@link org.eclipse.swt.events.SelectionListener} object.
2055
	 * @param style
2056
	 *            a int.
2057
	 * @param parentElement
2058
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
2059
	 *            object.
2060
	 * @param versionableEntity
2061
	 *            a {@link eu.etaxonomy.cdm.model.common.IVersionableEntity}
2062
	 *            object.
2063
	 * @param backgroundColor
2064
	 *            a {@link org.eclipse.swt.graphics.Color} object.
2065
	 * @return a
2066
	 *         {@link eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement}
2067
	 *         object.
2068
	 */
2069
	public AbstractEntityCollectionElement createEntityCollectionElement(
2070
			AbstractFormSection parentElement, Object versionableEntity,
2071
			SelectionListener removeListener, Color backgroundColor, int style) {
2072
		AbstractEntityCollectionElement element = null;
2073

    
2074
		Object entity = HibernateProxyHelper.deproxy(versionableEntity);
2075

    
2076
		if (entity instanceof Annotation) {
2077
			element = new AnnotationElement(this, parentElement,
2078
					(Annotation) entity, removeListener, style);
2079
		} else if (entity instanceof Person) {
2080
			element = new TeamMemberElement(this, parentElement,
2081
					(Person) entity, removeListener, style);
2082
		} else if (entity instanceof Credit) {
2083
			element = new CreditElement(this, parentElement, (Credit) entity,
2084
					removeListener, style);
2085
		} else if (entity instanceof Extension) {
2086
			element = new ExtensionElement(this, parentElement,
2087
					(Extension) entity, removeListener, style);
2088
		} else if (entity instanceof Marker) {
2089
			element = new MarkerElement(this, parentElement, (Marker) entity,
2090
					removeListener, style);
2091
		} else if (entity instanceof Media) {
2092
			element = new MediaElement(this, parentElement, (Media) entity,
2093
					removeListener, style);
2094
		} else if (entity instanceof MediaRepresentation) {
2095
			element = new MediaRepresentationElement(this, parentElement,
2096
					(MediaRepresentation) entity, removeListener, style);
2097
		} else if (entity instanceof ImageFile) {
2098
			element = new ImageFileElement(this, parentElement,
2099
					(ImageFile) entity, removeListener, style);
2100
		} else if (entity instanceof MediaRepresentationPart) {
2101
			element = new MediaRepresentationPartElement(this, parentElement,
2102
					(MediaRepresentationPart) entity, removeListener, style);
2103
		} else if (entity instanceof NomenclaturalStatus) {
2104
			element = new NomenclaturalStatusElement(this, parentElement,
2105
					(NomenclaturalStatus) entity, removeListener, style);
2106
		} else if (entity instanceof Rights) {
2107
			element = new RightsElement(this, parentElement, (Rights) entity,
2108
					removeListener, style);
2109
		} else if (entity instanceof DescriptionElementSource) {
2110
			element = new DescriptionElementSourceElement(this, parentElement,
2111
					(DescriptionElementSource) entity, removeListener, style);
2112
		} else if (entity instanceof IdentifiableSource) {
2113
			element = new IdentifiableSourceElement(this, parentElement,
2114
					(IdentifiableSource) entity, removeListener, style);
2115
		} else if (entity instanceof Scope) {
2116
			element = new ScopeElement(this, parentElement, (Scope) entity,
2117
					removeListener, style);
2118
		} else if (entity instanceof Modifier) {
2119
			element = new ModifierElement(this, parentElement,
2120
					(Modifier) entity, removeListener, style);
2121
		} else if (entity instanceof Reference) {
2122
			element = new DescriptionSourceElement(this, parentElement,
2123
					(Reference) entity, removeListener, style);
2124
		} else if (entity instanceof NameTypeDesignation) {
2125
			element = new NameTypeDesignationElement(this, parentElement,
2126
					(NameTypeDesignation) entity, removeListener, style);
2127
		} else if (entity instanceof NameRelationship) {
2128
			element = new NameRelationshipDetailElement(this, parentElement,
2129
					(NameRelationship) entity, removeListener, style);
2130
		} else if (entity instanceof SpecimenTypeDesignation) {
2131
			element = new SpecimenTypeDesignationElement(this, parentElement,
2132
					(SpecimenTypeDesignation) entity, removeListener, style);
2133
		} else if (entity instanceof StateData) {
2134
			element = new StateDataElement(this, parentElement,
2135
					(StateData) entity, removeListener, style);
2136
		} else if (entity instanceof StatisticalMeasurementValue) {
2137
			element = new StatisticalMeasurementValueElement(this,
2138
					parentElement, (StatisticalMeasurementValue) entity,
2139
					removeListener, style);
2140
		} else if (entity instanceof DerivedUnit) {
2141
			element = new DerivedUnitElement(this, parentElement,
2142
					(DerivedUnit) entity, removeListener, style);
2143
		} else if (entity instanceof NamedArea) {
2144
			element = new NamedAreaDetailElement(this, parentElement,
2145
					(NamedArea) entity, removeListener, style);
2146
		} else if (entity instanceof DeterminationEvent) {
2147
			element = new DeterminationEventDetailElement(this, parentElement,
2148
					(DeterminationEvent) entity, removeListener, style);
2149
		} else if (entity instanceof Specimen) {
2150
			element = new SpecimenCollectionDetailElement(this, parentElement,
2151
					(Specimen) entity, removeListener, style);
2152
		} else if (entity instanceof User) {
2153
			element = new MemberDetailElement(this, parentElement,
2154
					(User) entity, removeListener, style);
2155
		} else if (entity instanceof GrantedAuthority) {
2156
			element = new GrantedAuthorityDetailElement(this, parentElement,
2157
					(GrantedAuthority) entity, removeListener, style);
2158
		} else if (entity instanceof Group) {
2159
			element = new GroupsByUserDetailElement(this, parentElement,
2160
					(Group) entity, removeListener, style);
2161
		} else if (entity instanceof Taxon) {
2162
			element = new TaxonDetailElement(this, parentElement,
2163
					(Taxon) entity, removeListener, style);
2164
		} else if (entity instanceof DescriptionElementBase) {
2165
			// this is the special case for protologs, maybe we can do this
2166
			// differently when API improves
2167
			DescriptionElementBase descriptionElement = (DescriptionElementBase) entity;
2168
			if (descriptionElement.getFeature().equals(Feature.PROTOLOGUE())) {
2169
				element = new ProtologueElement(this, parentElement,
2170
						descriptionElement, removeListener, style);
2171
			}
2172
		}
2173

    
2174
		if (element == null) {
2175
			StoreUtil
2176
					.errorDialog(
2177
							"No element for entity",
2178
							this,
2179
							"Could not generate element for entity. "
2180
									+ "Looks like the case is not handled already. Check implementation. Entity: "
2181
									+ entity, null);
2182

    
2183
		}
2184

    
2185
		if (backgroundColor != null && !backgroundColor.isDisposed()) {
2186
			element.setPersistentBackground(backgroundColor);
2187
		}
2188

    
2189
		adapt(element);
2190
		parentElement.addElement(element);
2191
		return element;
2192
	}
2193

    
2194
	/**
2195
	 * <p>
2196
	 * createSelectionElement
2197
	 * </p>
2198
	 * 
2199
	 * @param selectionType
2200
	 *            a
2201
	 *            {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.SelectionType}
2202
	 *            object.
2203
	 * @param parentElement
2204
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
2205
	 *            object.
2206
	 * @param labelString
2207
	 *            a {@link java.lang.String} object.
2208
	 * @param selectionType
2209
	 * @param selection
2210
	 *            a {@link eu.etaxonomy.cdm.model.common.IAnnotatableEntity}
2211
	 *            object.
2212
	 * @param style
2213
	 *            a int.
2214
	 * @param conversation
2215
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
2216
	 *            object.
2217
	 * @return a
2218
	 *         {@link eu.etaxonomy.taxeditor.ui.selection.AbstractSelectionElement}
2219
	 *         object.
2220
	 */
2221
	public AbstractSelectionElement createSelectionElement(
2222
			SelectionType selectionType, ConversationHolder conversation,
2223
			ICdmFormElement parentElement, String labelString,
2224
			ICdmBase selection, int mode, int style) {
2225
		AbstractSelectionElement element = null;
2226

    
2227
		IAnnotatableEntity entity = (IAnnotatableEntity) HibernateProxyHelper
2228
				.deproxy(selection);
2229

    
2230
		switch (selectionType) {
2231
		case AGENT:
2232
			element = new AgentSelectionElement(this, conversation,
2233
					parentElement, labelString, (TeamOrPersonBase) entity,
2234
					mode, style);
2235
			break;
2236
		case PERSON:
2237
			element = new PersonSelectionElement(this, conversation,
2238
					parentElement, labelString, (Person) entity, mode, style);
2239
			break;
2240
		case TEAM:
2241
			element = new TeamSelectionElement(this, conversation,
2242
					parentElement, labelString, (Team) entity, mode, style);
2243
			break;
2244
		case AUTHOR_TEAM:
2245
			element = new NomenclaturalAuthorTeamSelectionElement(this,
2246
					conversation, parentElement, labelString, (Team) entity,
2247
					mode, style);
2248
			break;
2249
		case INSTITUTION:
2250
			element = new InstitutionSelectionElement(this, conversation,
2251
					parentElement, labelString, (Institution) entity, mode,
2252
					style);
2253
			break;
2254
		case NAME:
2255
			element = new NameSelectionElement(this, conversation,
2256
					parentElement, labelString, (TaxonNameBase) entity, mode,
2257
					style);
2258
			break;
2259
		case REFERENCE:
2260
			element = new ReferenceSelectionElement(this, conversation,
2261
					parentElement, labelString, (Reference) entity, mode, style);
2262
			break;
2263
		case TAXON_BASE:
2264
			element = new TaxonBaseSelectionElement(this, conversation,
2265
					parentElement, labelString, (TaxonBase) entity, mode, style);
2266
			break;
2267
		case TAXON:
2268
			element = new TaxonSelectionElement(this, conversation,
2269
					parentElement, labelString, (Taxon) entity, mode, style);
2270
			break;
2271
		case SYNONYM:
2272
			element = new SynonymSelectionElement(this, conversation,
2273
					parentElement, labelString, (Synonym) entity, mode, style);
2274
			break;
2275
		case DERIVED_UNIT:
2276
			element = new DerivedUnitBaseSelectionElement(this, conversation,
2277
					parentElement, labelString, (DerivedUnitBase) entity, mode,
2278
					style);
2279
			break;
2280
		case FIELD_OBSERVATION:
2281
			element = new FieldObservationSelectionElement(this, conversation,
2282
					parentElement, labelString, (FieldObservation) entity,
2283
					mode, style);
2284
			break;
2285
		case FEATURE_TREE:
2286
			element = new FeatureTreeSelectionElement(this, conversation,
2287
					parentElement, labelString, (FeatureTree) entity, mode,
2288
					style);
2289
			break;
2290
		case CLASSIFICATION:
2291
			element = new ClassificationSelectionElement(this, conversation,
2292
					parentElement, labelString, (Classification) entity, mode,
2293
					style);
2294
			break;
2295
		case TAXON_NODE:
2296
			element = new TaxonNodeSelectionElement(this, conversation,
2297
					parentElement, labelString, (TaxonNode) entity, mode, style);
2298
			break;
2299
		case COLLECTION:
2300
			element = new CollectionSelectionElement(this, conversation,
2301
					parentElement, labelString, (Collection) entity, mode,
2302
					style);
2303
			break;
2304
		case FEATURE:
2305
			element = new FeatureSelectionElement(this, conversation,
2306
					parentElement, labelString, (Feature) entity, mode, style);
2307
			break;
2308
		case POLYTOMOUS_KEY:
2309
			element = new PolytomousKeySelectionElement(this, conversation,
2310
					parentElement, labelString, (PolytomousKey) entity, mode,
2311
					style);
2312
			break;
2313
		case POLYTOMOUS_KEY_NODE:
2314
			element = new PolytomousKeyNodeSelectionElement(this, conversation,
2315
					parentElement, labelString, (PolytomousKeyNode) entity,
2316
					mode, style);
2317
			break;
2318
		case USER:
2319
			element = new UserSelectionElement(this, conversation,
2320
					parentElement, labelString, (User) entity, mode, style);
2321
			break;
2322
		case GROUP:
2323
			element = new GroupSelectionElement(this, conversation,
2324
					parentElement, labelString, (Group) entity, mode, style);
2325
			break;
2326
		default:
2327
			new RuntimeException(
2328
					"There is no selection composite for the desired selection type.");
2329
			break;
2330
		}
2331

    
2332
		adapt(element);
2333
		parentElement.addElement(element);
2334
		return element;
2335
	}
2336

    
2337
	/**
2338
	 * <p>
2339
	 * createNamedAreaSelectionElement
2340
	 * </p>
2341
	 * 
2342
	 * @param parentElement
2343
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
2344
	 *            object.
2345
	 * @param conversation
2346
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
2347
	 *            object.
2348
	 * @param labelString
2349
	 *            a {@link java.lang.String} object.
2350
	 * @param selection
2351
	 *            a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
2352
	 * @param style
2353
	 *            a int.
2354
	 * @return a
2355
	 *         {@link eu.etaxonomy.taxeditor.ui.selection.NamedAreaSelectionElement}
2356
	 *         object.
2357
	 */
2358
	public NamedAreaSelectionElement createNamedAreaSelectionElement(
2359
			ICdmFormElement parentElement, ConversationHolder conversation,
2360
			String labelString, NamedArea selection, int style) {
2361
		NamedAreaSelectionElement element = new NamedAreaSelectionElement(this,
2362
				conversation, parentElement, labelString, selection,
2363
				AbstractSelectionElement.NOTHING, style);
2364
		adapt(element);
2365
		parentElement.addElement(element);
2366
		return element;
2367
	}
2368

    
2369
	/** {@inheritDoc} */
2370
	public LabelElement createLabel(ICdmFormElement parentElement, String text) {
2371
		LabelElement labelElement = new LabelElement(this, parentElement, text);
2372
		adapt(labelElement);
2373
		parentElement.addElement(labelElement);
2374
		return labelElement;
2375
	}
2376

    
2377
	/**
2378
	 * <p>
2379
	 * Getter for the field <code>selectionProvider</code>.
2380
	 * </p>
2381
	 * 
2382
	 * @return a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
2383
	 */
2384
	public ISelectionProvider getSelectionProvider() {
2385
		return selectionProvider;
2386
	}
2387

    
2388
	/**
2389
	 * <p>
2390
	 * createDetailedDescriptionDetailElement
2391
	 * </p>
2392
	 * 
2393
	 * @param parentElement
2394
	 *            a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
2395
	 *            object.
2396
	 * @param entity
2397
	 *            a
2398
	 *            {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase}
2399
	 *            object.
2400
	 * @param style
2401
	 *            a int.
2402
	 * @return a
2403
	 *         {@link eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement}
2404
	 *         object.
2405
	 */
2406
	public AbstractDetailedDescriptionDetailElement createDetailedDescriptionDetailElement(
2407
			ICdmFormElement parentElement, DescriptionElementBase entity,
2408
			int style) {
2409
		AbstractDetailedDescriptionDetailElement detailedDescriptionElement = null;
2410

    
2411
		if (entity instanceof CategoricalData) {
2412
			detailedDescriptionElement = new CategoricalDataDetailElement(this,
2413
					parentElement, (CategoricalData) entity, style);
2414
		} else if (entity instanceof CommonTaxonName) {
2415
			detailedDescriptionElement = new CommonNameDetailElement(this,
2416
					parentElement, (CommonTaxonName) entity, style);
2417
		} else if (entity instanceof Distribution) {
2418
			detailedDescriptionElement = new DistributionDetailElement(this,
2419
					parentElement, (Distribution) entity, style);
2420
		} else if (entity instanceof IndividualsAssociation) {
2421
			detailedDescriptionElement = new IndividualsAssociationDetailElement(
2422
					this, parentElement, (IndividualsAssociation) entity, style);
2423
		} else if (entity instanceof QuantitativeData) {
2424
			detailedDescriptionElement = new QuantitativeDataDetailElement(
2425
					this, parentElement, (QuantitativeData) entity, style);
2426
		} else if (entity instanceof TaxonInteraction) {
2427
			detailedDescriptionElement = new TaxonInteractionDetailElement(
2428
					this, parentElement, (TaxonInteraction) entity, style);
2429
		} else if (entity instanceof TextData) {
2430
			detailedDescriptionElement = new TextDataDetailElement(this,
2431
					parentElement, (TextData) entity, style);
2432
		} else {
2433
			throw new IllegalStateException(
2434
					"There is no interface for the given description element");
2435
		}
2436
		adapt(detailedDescriptionElement);
2437
		parentElement.addElement(detailedDescriptionElement);
2438
		return detailedDescriptionElement;
2439

    
2440
	}
2441

    
2442
	/*public AbstractDetailedDescriptionDetailElement createUseRecordDetailElement(
2443
			ICdmFormElement parentElement, DescriptionElementBase entity,
2444
			int style) {
2445
		AbstractDetailedDescriptionDetailElement useRecordElement = null;
2446
		if (entity instanceof CategoricalData) {
2447
			useRecordElement = new UseRecordDetailElement(this,
2448
					parentElement, (CategoricalData) entity, style);
2449
		} else {
2450
			throw new IllegalStateException(
2451
					"There is no interface for the given description element");
2452
		}
2453
		adapt(useRecordElement);
2454
		parentElement.addElement(useRecordElement);
2455
		return useRecordElement;
2456
	}*/
2457

    
2458
	/**
2459
	 * Creates a styled text as a part of the form.
2460
	 * 
2461
	 * @param parent
2462
	 *            the text parent
2463
	 * @param value
2464
	 *            the text initial value
2465
	 * @param style
2466
	 *            the text style
2467
	 * @return the text widget
2468
	 */
2469
	public StyledText createStyledText(Composite parent, String value, int style) {
2470
		StyledText text = new StyledText(parent, getBorderStyle() | style
2471
				| getOrientation());
2472
		if (value != null)
2473
			text.setText(value);
2474
		text.setForeground(getColors().getForeground());
2475
		text.setBackground(getColors().getBackground());
2476
		// text.addFocusListener(visibilityHandler);
2477
		return text;
2478
	}
2479

    
2480
}
(6-6/35)