Project

General

Profile

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

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

    
285
/**
286
 * <p>
287
 * CdmFormFactory class.
288
 * </p>
289
 * 
290
 * @author n.hoffmann
291
 * @created Feb 24, 2010
292
 * @version 1.0
293
 */
294
public class CdmFormFactory extends FormToolkit {
295

    
296
	private BoldFontHolder2 boldFontHolder2;
297
	private MouseListener selectionMouseHandler;
298
	private FocusListener selectionFocusHandler;
299

    
300
	private final Set selectionListenerList = new HashSet();
301

    
302
	private final List<IPropertyChangeListener> propertyChangeListeners = new ArrayList<IPropertyChangeListener>();
303

    
304
	private final int orientation = Window.getDefaultOrientation();
305
	private ISelectionProvider selectionProvider;
306

    
307
	/**
308
	 * <p>
309
	 * LAYOUT
310
	 * </p>
311
	 * 
312
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapLayout} object.
313
	 */
314
	public static final TableWrapLayout LAYOUT() {
315
		return LAYOUT(1, false);
316
	}
317

    
318
	/**
319
	 * <p>
320
	 * LAYOUT
321
	 * </p>
322
	 * 
323
	 * @param columns
324
	 *            a int.
325
	 * @param equalWidth
326
	 *            a boolean.
327
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapLayout} object.
328
	 */
329
	public static final TableWrapLayout LAYOUT(int columns, boolean equalWidth) {
330
		TableWrapLayout layout = new TableWrapLayout();
331
		layout.topMargin = 0;
332
		layout.rightMargin = 0;
333
		layout.bottomMargin = 0;
334
		layout.leftMargin = 0;
335
		layout.numColumns = columns;
336
		layout.makeColumnsEqualWidth = equalWidth;
337
		layout.verticalSpacing = 0;
338
		layout.horizontalSpacing = 0;
339
		return layout;
340
	}
341

    
342
	/**
343
	 * <p>
344
	 * FILL
345
	 * </p>
346
	 * 
347
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
348
	 */
349
	public static final TableWrapData FILL() {
350
		return FILL(1, 1);
351
	}
352

    
353
	/**
354
	 * <p>
355
	 * FILL
356
	 * </p>
357
	 * 
358
	 * @param horizontalSpan
359
	 *            a int.
360
	 * @param verticalSpan
361
	 *            a int.
362
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
363
	 */
364
	public static final TableWrapData FILL(int horizontalSpan, int verticalSpan) {
365
		TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB,
366
				TableWrapData.FILL_GRAB);
367
		layoutData.colspan = horizontalSpan;
368
		layoutData.rowspan = verticalSpan;
369
		return layoutData;
370
	}
371

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

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

    
394
	/**
395
	 * <p>
396
	 * FILL_HORIZONTALLY
397
	 * </p>
398
	 * 
399
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
400
	 */
401
	public static final TableWrapData FILL_HORIZONTALLY() {
402
		return FILL_HORIZONTALLY(1, 1);
403
	}
404

    
405
	/**
406
	 * <p>
407
	 * FILL_HORIZONTALLY
408
	 * </p>
409
	 * 
410
	 * @param horizontalSpan
411
	 *            a int.
412
	 * @param verticalSpan
413
	 *            a int.
414
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
415
	 */
416
	public static final TableWrapData FILL_HORIZONTALLY(int horizontalSpan,
417
			int verticalSpan) {
418
		TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB,
419
				TableWrapData.TOP);
420
		layoutData.colspan = horizontalSpan;
421
		layoutData.rowspan = verticalSpan;
422
		return layoutData;
423
	}
424

    
425
	/** Constant <code>EMPTY_SELECTION</code> */
426
	public static ISelection EMPTY_SELECTION = new ISelection() {
427
		@Override
428
		public boolean isEmpty() {
429
			return true;
430
		}
431
	};
432
	
433
	private class SelectionMouseHandler extends MouseAdapter {
434
		@Override
435
		public void mouseDown(MouseEvent e) {
436
			notifySelectionListeners(e);
437
		}
438
	}
439

    
440
	private class SelectionFocusHandler extends FocusAdapter {
441
		@Override
442
		public void focusGained(FocusEvent e) {
443
			notifySelectionListeners(e);
444
		}
445
	}
446

    
447
	private void notifySelectionListeners(TypedEvent e) {
448
		Event event = new Event();
449
		event.widget = e.widget;
450
		SelectionEvent selectionEvent = new SelectionEvent(event);
451

    
452
		for (Object listener : selectionListenerList) {
453
			((SelectionListener) listener).widgetSelected(selectionEvent);
454
		}
455
	}
456

    
457
	/**
458
	 * <p>
459
	 * Constructor for CdmFormFactory.
460
	 * </p>
461
	 * 
462
	 * @param display
463
	 *            a {@link org.eclipse.swt.widgets.Display} object.
464
	 * @param selectionProvider
465
	 *            a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
466
	 */
467
	public CdmFormFactory(Display display, ISelectionProvider selectionProvider) {
468
		super(display);
469
		this.selectionProvider = selectionProvider;
470
		init();
471
	}
472

    
473
	/**
474
	 * <p>
475
	 * Constructor for CdmFormFactory.
476
	 * </p>
477
	 * 
478
	 * @param display
479
	 *            a {@link org.eclipse.swt.widgets.Display} object.
480
	 */
481
	public CdmFormFactory(Display display) {
482
		super(display);
483
		init();
484
	}
485

    
486
	/**
487
	 * 
488
	 */
489
	private void init() {
490
		boldFontHolder2 = new BoldFontHolder2();
491
		selectionMouseHandler = new SelectionMouseHandler();
492
		selectionFocusHandler = new SelectionFocusHandler();
493
	}
494

    
495
	/**
496
	 * Creates an instance initialized with the correct selectionProvider
497
	 * 
498
	 * Make sure to remove the instance when the entityComposite disposes via
499
	 * destroySelectionArbitrator(..)
500
	 * 
501
	 * @param entityElement
502
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.IEntityElement}
503
	 *            object.
504
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator}
505
	 *         object.
506
	 */
507
	public SelectionArbitrator createSelectionArbitrator(
508
			IEntityElement entityElement) {
509
		SelectionArbitrator selectionArbitrator = new SelectionArbitrator(
510
				entityElement);
511
		selectionArbitrator.addSelectionProvider(selectionProvider);
512
		selectionProvider.addSelectionChangedListener(selectionArbitrator);
513
		addSelectionListener(selectionArbitrator);
514
		return selectionArbitrator;
515
	}
516

    
517
	/**
518
	 * <p>
519
	 * destroySelectionArbitrator
520
	 * </p>
521
	 * 
522
	 * @param selectionArbitrator
523
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator}
524
	 *            object.
525
	 */
526
	public void destroySelectionArbitrator(
527
			SelectionArbitrator selectionArbitrator) {
528
		removeSelectionListener(selectionArbitrator);
529
		if (selectionProvider != null) {
530
			selectionProvider
531
					.removeSelectionChangedListener(selectionArbitrator);
532
		} else {
533
			StoreUtil
534
					.error(this.getClass(),
535
							"Tried to destroy a selection listener from this factories listeners but was null",
536
							null);
537
		}
538
	}
539

    
540
	/** {@inheritDoc} */
541
	@Override
542
	public void adapt(Composite composite) {
543
		composite.addMouseListener(selectionMouseHandler);
544
		super.adapt(composite);
545
	}
546

    
547
	/**
548
	 * <p>
549
	 * adapt
550
	 * </p>
551
	 * 
552
	 * @param formElement
553
	 *            a
554
	 *            {@link eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement}
555
	 *            object.
556
	 */
557
	public void adapt(AbstractCdmFormElement formElement) {
558
		formElement.setPropertyChangeListeners(propertyChangeListeners);
559
	}
560

    
561
	/** {@inheritDoc} */
562
	@Override
563
	public void adapt(Control control, boolean trackFocus, boolean trackKeyboard) {
564
		if (trackFocus) {
565
			control.addFocusListener(selectionFocusHandler);
566
		}
567
		super.adapt(control, trackFocus, trackKeyboard);
568
	}
569

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

    
612
	/**
613
	 * <p>
614
	 * createEmptyCell
615
	 * </p>
616
	 * 
617
	 * @param parent
618
	 *            a {@link org.eclipse.swt.widgets.Composite} object.
619
	 * @return a {@link org.eclipse.swt.widgets.Label} object.
620
	 */
621
	public Label createEmptyCell(Composite parent) {
622
		return this.createLabel(parent, null);
623
	}
624

    
625
	/**
626
	 * <p>
627
	 * createMultilineTextWithLabel
628
	 * </p>
629
	 * 
630
	 * @param labelString
631
	 *            a {@link java.lang.String} object.
632
	 * @param textHeight
633
	 *            a int.
634
	 * @param style
635
	 *            a int.
636
	 * @param parentElement
637
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
638
	 *            object.
639
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
640
	 *         object.
641
	 */
642
	public TextWithLabelElement createMultilineTextWithLabel(
643
			ICdmFormElement parentElement, String labelString, int textHeight,
644
			int style) {
645
		TextWithLabelElement element = new TextWithLabelElement(this,
646
				parentElement, labelString, "", textHeight, style);
647
		adapt(element);
648
		parentElement.addElement(element);
649
		return element;
650
	}
651

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

    
684
	public KeyStatementElement createKeyStatementElement(
685
			ICdmFormElement parentElement, String labelString,
686
			KeyStatement keyStatement, int textHeight, int style) {
687
		KeyStatementElement element = new KeyStatementElement(this,
688
				parentElement, labelString, keyStatement, textHeight, style);
689
		adapt(element);
690
		parentElement.addElement(element);
691
		return element;
692
	}
693

    
694
	/**
695
	 * <p>
696
	 * createTextWithLabelElement
697
	 * </p>
698
	 * 
699
	 * @param labelString
700
	 *            a {@link java.lang.String} object.
701
	 * @param initialText
702
	 *            a {@link java.lang.String} object.
703
	 * @param style
704
	 *            a int.
705
	 * @param parentElement
706
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
707
	 *            object.
708
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
709
	 *         object.
710
	 */
711
	public TextWithLabelElement createTextWithLabelElement(
712
			ICdmFormElement parentElement, String labelString,
713
			String initialText, int style) {
714
		TextWithLabelElement element = new TextWithLabelElement(this,
715
				parentElement, labelString, initialText, null, style);
716
		adapt(element);
717
		parentElement.addElement(element);
718
		return element;
719
	}
720

    
721
	public UriWithLabelElement createUriWithLabelElement(
722
			ICdmFormElement parentElement, String labelString, URI initialUri,
723
			int style) {
724
		UriWithLabelElement element = new UriWithLabelElement(this,
725
				parentElement, labelString, initialUri, null, style);
726
		adapt(element);
727
		parentElement.addElement(element);
728
		return element;
729
	}
730

    
731
	/**
732
	 * @param element
733
	 * @param string
734
	 * @param uri
735
	 * @param style
736
	 * @return
737
	 */
738
	public OpenUrlSelectorElement createOpenUrlSelectorElement(
739
			ICdmFormElement parentElement, String labelString,
740
			IOpenUrlEnabled openUrlEnabled, int style) {
741
		OpenUrlSelectorElement element = new OpenUrlSelectorElement(this,
742
				parentElement, labelString, openUrlEnabled, style);
743
		adapt(element);
744
		parentElement.addElement(element);
745
		return element;
746
	}
747

    
748
	/**
749
	 * 
750
	 * @param parentElement
751
	 * @param labelString
752
	 * @param conversationEnabled
753
	 * @param user
754
	 * @param style
755
	 * @return
756
	 */
757
	public EditPasswordElement createEditPasswordElement(
758
			ICdmFormElement parentElement, String labelString,
759
			ConversationHolder conversation, User user, int style) {
760
		EditPasswordElement element = new EditPasswordElement(this,
761
				parentElement, labelString, user, conversation);
762
		adapt(element);
763
		parentElement.addElement(element);
764
		return element;
765
	}
766

    
767
	/**
768
	 * <p>
769
	 * createIntegerTextWithLabelElement
770
	 * </p>
771
	 * 
772
	 * @param parentElement
773
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
774
	 *            object.
775
	 * @param labelString
776
	 *            a {@link java.lang.String} object.
777
	 * @param initialInteger
778
	 *            a {@link java.lang.Integer} object.
779
	 * @param style
780
	 *            a int.
781
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement}
782
	 *         object.
783
	 */
784
	public NumberWithLabelElement createIntegerTextWithLabelElement(
785
			ICdmFormElement parentElement, String labelString,
786
			Integer initialInteger, int style) {
787
		NumberWithLabelElement element = new NumberWithLabelElement(this,
788
				parentElement, labelString, initialInteger, style);
789
		adapt(element);
790
		parentElement.addElement(element);
791
		return element;
792
	}
793

    
794
	/**
795
	 * <p>
796
	 * createFloatTextWithLabelElement
797
	 * </p>
798
	 * 
799
	 * @param parentElement
800
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
801
	 *            object.
802
	 * @param labelString
803
	 *            a {@link java.lang.String} object.
804
	 * @param initialFloat
805
	 *            a float.
806
	 * @param style
807
	 *            a int.
808
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement}
809
	 *         object.
810
	 */
811
	public NumberWithLabelElement createFloatTextWithLabelElement(
812
			ICdmFormElement parentElement, String labelString,
813
			float initialFloat, int style) {
814
		NumberWithLabelElement element = new NumberWithLabelElement(this,
815
				parentElement, labelString, initialFloat, style);
816
		adapt(element);
817
		parentElement.addElement(element);
818
		return element;
819
	}
820

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

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

    
879
	/**
880
	 * <p>
881
	 * createTextElement
882
	 * </p>
883
	 * 
884
	 * @param parentElement
885
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
886
	 *            object.
887
	 * @param initialText
888
	 *            a {@link java.lang.String} object.
889
	 * @param style
890
	 *            a int.
891
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
892
	 *         object.
893
	 */
894
	public TextWithLabelElement createTextElement(
895
			ICdmFormElement parentElement, String initialText, int style) {
896
		TextWithLabelElement element = new TextWithLabelElement(this,
897
				parentElement, null, initialText, null, style);
898
		adapt(element);
899
		parentElement.addElement(element);
900
		return element;
901
	}
902

    
903
	/**
904
	 * <p>
905
	 * createKeyValueViewerElement
906
	 * </p>
907
	 * 
908
	 * @param parentElement
909
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
910
	 *            object.
911
	 * @param keyHeading
912
	 *            a {@link java.lang.String} object.
913
	 * @param valueHeading
914
	 *            a {@link java.lang.String} object.
915
	 * @param map
916
	 *            a {@link java.util.Map} object.
917
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.KeyValueViewerElement}
918
	 *         object.
919
	 */
920
	public KeyValueViewerElement createKeyValueViewerElement(
921
			ICdmFormElement parentElement, String keyHeading,
922
			String valueHeading, Map<Object, Object> map) {
923
		KeyValueViewerElement element = new KeyValueViewerElement(this,
924
				parentElement, keyHeading, valueHeading, map);
925
		adapt(element);
926
		parentElement.addElement(element);
927
		return element;
928
	}
929

    
930
	/**
931
	 * <p>
932
	 * createTermComboElement
933
	 * </p>
934
	 * 
935
	 * @param termComboType
936
	 *            a
937
	 *            {@link eu.eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.TermComboType}
938
	 *            object.
939
	 * @param parentElement
940
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
941
	 *            object.
942
	 * @param labelString
943
	 *            a {@link java.lang.String} object.
944
	 * @param selection
945
	 *            a {@link eu.etaxonomy.cdm.model.common.DefinedTermBase}
946
	 *            object.
947
	 * @param style
948
	 *            a int.
949
	 * @return a {@link eu.etaxonomy.taxeditor.ui.combo.TermComboElement}
950
	 *         object.
951
	 */
952
	
953
	public <T extends DefinedTermBase> TermComboElement<T> createTermComboElement(
954
			Class<T> termComboType, ICdmFormElement parentElement,
955
			String labelString, T selection, int style) {
956
		TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termComboType, labelString, selection, style);
957
		adapt(element);
958
		parentElement.addElement(element);
959
		return element;
960
	}
961

    
962
	/**
963
	 * <p>
964
	 * createEnumComboElement
965
	 * </p>
966
	 * 
967
	 * @param enumComboType
968
	 *            a
969
	 *            {@link eu.eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.EnumComboType}
970
	 *            object.
971
	 * @param parentElement
972
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
973
	 *            object.
974
	 * @param style
975
	 *            a int.
976
	 * @return a {@link eu.etaxonomy.taxeditor.ui.term.AbstractEnumComboElement}
977
	 *         object.
978
	 */
979
	public <T extends IDefinedTerm> EnumComboElement<T> createEnumComboElement(
980
			Class<T> enumComboType, ICdmFormElement parentElement,
981
			int style) {
982
		EnumComboElement<T> element = new EnumComboElement<T>(this, parentElement, enumComboType, style);
983
		adapt(element);
984
		parentElement.addElement(element);
985
		return element;
986
	}
987

    
988
	/**
989
	 * <p>
990
	 * createBrowserElement
991
	 * </p>
992
	 * 
993
	 * @param imageUri
994
	 *            a {@link java.net.URI} object.
995
	 * @param style
996
	 *            a int.
997
	 * @param parentElement
998
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
999
	 *            object.
1000
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.BrowserElement} object.
1001
	 */
1002
	public BrowserElement createBrowserElement(ICdmFormElement parentElement,
1003
			URI imageUri, int style) {
1004
		BrowserElement element = new BrowserElement(this, parentElement,
1005
				imageUri, style);
1006
		adapt(element);
1007
		parentElement.addElement(element);
1008
		return element;
1009
	}
1010

    
1011
	/**
1012
	 * <p>
1013
	 * createImageElement
1014
	 * </p>
1015
	 * 
1016
	 * @param parentElement
1017
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1018
	 *            object.
1019
	 * @param imageUri
1020
	 *            a {@link java.net.URI} object.
1021
	 * @param style
1022
	 *            a int.
1023
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.ImageElement} object.
1024
	 */
1025
	public ImageElement createImageElement(ICdmFormElement parentElement,
1026
			URI imageUri, int style) {
1027
		ImageElement element = new ImageElement(this, parentElement, imageUri,
1028
				style);
1029
		adapt(element);
1030
		parentElement.addElement(element);
1031
		return element;
1032
	}
1033

    
1034
	/**
1035
	 * <p>
1036
	 * createTextActionElement
1037
	 * </p>
1038
	 * 
1039
	 * @param labelString
1040
	 *            a {@link java.lang.String} object.
1041
	 * @param initialText
1042
	 *            a {@link java.lang.String} object.
1043
	 * @param style
1044
	 *            a int.
1045
	 * @param parentElement
1046
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1047
	 *            object.
1048
	 * @param buttonLabel
1049
	 *            a {@link java.lang.String} object.
1050
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextActionElement}
1051
	 *         object.
1052
	 */
1053
	public TextActionElement createTextActionElement(
1054
			ICdmFormElement parentElement, String labelString,
1055
			String buttonLabel, String initialText, int style) {
1056
		TextActionElement element = new TextActionElement(this, parentElement,
1057
				labelString, buttonLabel, initialText, style);
1058
		adapt(element);
1059
		parentElement.addElement(element);
1060
		return element;
1061
	}
1062

    
1063
	/**
1064
	 * 
1065
	 * @author n.hoffmann
1066
	 * @created Mar 5, 2010
1067
	 * @version 1.0
1068
	 */
1069
	public static enum SelectionType {
1070
		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
1071
	}
1072

    
1073
	/**
1074
	 * <p>
1075
	 * createCheckbox
1076
	 * </p>
1077
	 * 
1078
	 * @param parentElement
1079
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1080
	 *            object.
1081
	 * @param label
1082
	 *            a {@link java.lang.String} object.
1083
	 * @param initialState
1084
	 *            a boolean.
1085
	 * @param style
1086
	 *            a int.
1087
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.CheckboxElement} object.
1088
	 */
1089
	public CheckboxElement createCheckbox(ICdmFormElement parentElement,
1090
			String label, boolean initialState, int style) {
1091
		CheckboxElement element = new CheckboxElement(this, parentElement,
1092
				label, initialState, style | orientation);
1093
		adapt(element);
1094
		parentElement.addElement(element);
1095
		return element;
1096
	}
1097

    
1098
	/**
1099
	 * Creates a section as a part of the form.
1100
	 * 
1101
	 * @return the section widget
1102
	 * @param section
1103
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1104
	 *            object.
1105
	 */
1106
	public Section adapt(AbstractFormSection section) {
1107
		section.setMenu(section.getLayoutComposite().getMenu());
1108
		adapt(section, true, true);
1109

    
1110
		// handle focus and property change events for cdm use
1111
		section.addFocusListener(selectionFocusHandler);
1112
		section.setPropertyChangeListeners(propertyChangeListeners);
1113

    
1114
		if (section.getToggle() != null) {
1115
			section.getToggle().setHoverDecorationColor(
1116
					getColors().getColor(IFormColors.TB_TOGGLE_HOVER));
1117
			section.getToggle().setDecorationColor(
1118
					getColors().getColor(IFormColors.TB_TOGGLE));
1119
		}
1120

    
1121
		section.setFont(boldFontHolder2.getBoldFont(section
1122
				.getLayoutComposite().getFont()));
1123

    
1124
		if ((section.getStyle() & Section.TITLE_BAR) != 0
1125
				|| (section.getStyle() & Section.SHORT_TITLE_BAR) != 0) {
1126
			getColors().initializeSectionToolBarColors();
1127
			section.setTitleBarBackground(getColors().getColor(
1128
					IFormColors.TB_BG));
1129
			section.setTitleBarBorderColor(getColors().getColor(
1130
					IFormColors.TB_BORDER));
1131
		}
1132
		// call setTitleBarForeground regardless as it also sets the label color
1133
		section.setTitleBarForeground(getColors().getColor(
1134
				IFormColors.TB_TOGGLE));
1135
		return section;
1136
	}
1137

    
1138
	private class BoldFontHolder2 {
1139
		private Font normalFont;
1140

    
1141
		private Font boldFont;
1142

    
1143
		public BoldFontHolder2() {
1144
		}
1145

    
1146
		public Font getBoldFont(Font font) {
1147
			createBoldFont(font);
1148
			return boldFont;
1149
		}
1150

    
1151
		private void createBoldFont(Font font) {
1152
			if (normalFont == null || !normalFont.equals(font)) {
1153
				normalFont = font;
1154
				dispose();
1155
			}
1156
			if (boldFont == null) {
1157
				boldFont = FormFonts.getInstance().getBoldFont(
1158
						getColors().getDisplay(), normalFont);
1159
			}
1160
		}
1161

    
1162
		public void dispose() {
1163
			if (boldFont != null) {
1164
				FormFonts.getInstance().markFinished(boldFont,
1165
						getColors().getDisplay());
1166
				boldFont = null;
1167
			}
1168
		}
1169
	}
1170

    
1171
	/**
1172
	 * <p>
1173
	 * createToggleableTextField
1174
	 * </p>
1175
	 * 
1176
	 * @param parentElement
1177
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1178
	 *            object.
1179
	 * @param labelString
1180
	 *            a {@link java.lang.String} object.
1181
	 * @param initialText
1182
	 *            a {@link java.lang.String} object.
1183
	 * @param initialState
1184
	 *            a boolean.
1185
	 * @param style
1186
	 *            a int.
1187
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement}
1188
	 *         object.
1189
	 */
1190
	public ToggleableTextElement createToggleableTextField(
1191
			ICdmFormElement parentElement, String labelString,
1192
			String initialText, boolean initialState, int style) {
1193
		ToggleableTextElement element = new ToggleableTextElement(this,
1194
				parentElement, labelString, initialText, initialState, style
1195
						| orientation);
1196
		adapt(element);
1197
		parentElement.addElement(element);
1198
		return element;
1199
	}
1200

    
1201
	/**
1202
	 * <p>
1203
	 * createTimePeriodElement
1204
	 * </p>
1205
	 * 
1206
	 * @param parentElement
1207
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1208
	 *            object.
1209
	 * @param labelString
1210
	 *            a {@link java.lang.String} object.
1211
	 * @param timePeriod
1212
	 *            a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
1213
	 * @param style
1214
	 *            a int.
1215
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.TimePeriodElement}
1216
	 *         object.
1217
	 */
1218
	public TimePeriodElement createTimePeriodElement(
1219
			ICdmFormElement parentElement, String labelString,
1220
			TimePeriod timePeriod, int style) {
1221
		TimePeriodElement element = new TimePeriodElement(this, parentElement,
1222
				labelString, timePeriod, style);
1223
		adapt(element);
1224
		parentElement.addElement(element);
1225
		return element;
1226
	}
1227

    
1228
	/**
1229
	 * <p>
1230
	 * createPointElement
1231
	 * </p>
1232
	 * 
1233
	 * @param style
1234
	 *            a int.
1235
	 * @param parentElement
1236
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1237
	 *            object.
1238
	 * @param point
1239
	 *            a {@link eu.etaxonomy.cdm.model.location.Point} object.
1240
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.PointElement} object.
1241
	 */
1242
	public PointElement createPointElement(ICdmFormElement parentElement,
1243
			Point point, int style) {
1244
		PointElement element = new PointElement(this, parentElement, point,
1245
				style);
1246
		adapt(element);
1247
		parentElement.addElement(element);
1248
		return element;
1249
	}
1250

    
1251
	/**
1252
	 * <p>
1253
	 * createDateDetailSection
1254
	 * </p>
1255
	 * 
1256
	 * @param parentElement
1257
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1258
	 *            object.
1259
	 * @param style
1260
	 *            a int.
1261
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.DateDetailSection}
1262
	 *         object.
1263
	 */
1264
	public DateDetailSection createDateDetailSection(
1265
			ICdmFormElement parentElement, int style) {
1266
		DateDetailSection section = new DateDetailSection(this, parentElement,
1267
				style);
1268
		parentElement.addElement(section);
1269
		adapt(section);
1270
		return section;
1271
	}
1272

    
1273
	/**
1274
	 * <p>
1275
	 * createPartialElement
1276
	 * </p>
1277
	 * 
1278
	 * @param parentElement
1279
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1280
	 *            object.
1281
	 * @param labelString
1282
	 *            a {@link java.lang.String} object.
1283
	 * @param partial
1284
	 *            a {@link org.joda.time.Partial} object.
1285
	 * @param style
1286
	 *            a int.
1287
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.PartialElement} object.
1288
	 */
1289
	public PartialElement createPartialElement(ICdmFormElement parentElement,
1290
			String labelString, Partial partial, int style) {
1291
		PartialElement element = new PartialElement(this, parentElement,
1292
				labelString, style);
1293
		adapt(element);
1294
		parentElement.addElement(element);
1295
		return element;
1296
	}
1297

    
1298
	/**
1299
	 * <p>
1300
	 * addSelectionListener
1301
	 * </p>
1302
	 * 
1303
	 * @param listener
1304
	 *            a {@link org.eclipse.swt.events.SelectionListener} object.
1305
	 */
1306
	public void addSelectionListener(SelectionListener listener) {
1307
		selectionListenerList.add(listener);
1308
	}
1309

    
1310
	/**
1311
	 * <p>
1312
	 * removeSelectionListener
1313
	 * </p>
1314
	 * 
1315
	 * @param listener
1316
	 *            a {@link org.eclipse.swt.events.SelectionListener} object.
1317
	 */
1318
	public void removeSelectionListener(SelectionListener listener) {
1319
		if (listener == null) {
1320
			StoreUtil
1321
					.error(this.getClass(),
1322
							"Tried to remove a selection listener from this factories listeners but was null",
1323
							null);
1324
		} else {
1325
			selectionListenerList.remove(listener);
1326
		}
1327
	}
1328

    
1329
	/**
1330
	 * <p>
1331
	 * addPropertyChangeListener
1332
	 * </p>
1333
	 * 
1334
	 * @param listener
1335
	 *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1336
	 *            object.
1337
	 */
1338
	public void addPropertyChangeListener(IPropertyChangeListener listener) {
1339
		if(propertyChangeListeners.contains(listener)){
1340
			return;
1341
		}
1342
		propertyChangeListeners.add(0, listener);
1343
	}
1344

    
1345
	/**
1346
	 * <p>
1347
	 * removePropertyChangeListener
1348
	 * </p>
1349
	 * 
1350
	 * @param listener
1351
	 *            a {@link org.eclipse.jface.util.IPropertyChangeListener}
1352
	 *            object.
1353
	 */
1354
	public void removePropertyChangeListener(IPropertyChangeListener listener) {
1355
		propertyChangeListeners.remove(listener);
1356
	}
1357

    
1358
	/**
1359
	 * <p>
1360
	 * createHorizontalSeparator
1361
	 * </p>
1362
	 * 
1363
	 * @param parentElement
1364
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1365
	 *            object.
1366
	 * @param style
1367
	 *            a int.
1368
	 * @return a {@link org.eclipse.swt.widgets.Label} object.
1369
	 */
1370
	public Label createHorizontalSeparator(ICdmFormElement parentElement,
1371
			int style) {
1372
		Label separator = this.createSeparator(
1373
				parentElement.getLayoutComposite(), SWT.HORIZONTAL | style);
1374
		separator.setLayoutData(FILL_HORIZONTALLY());
1375
		return separator;
1376
	}
1377

    
1378
	/**
1379
	 * <p>
1380
	 * createVersionElement
1381
	 * </p>
1382
	 * 
1383
	 * @param parentElement
1384
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1385
	 *            object.
1386
	 * @param entity
1387
	 *            a {@link eu.etaxonomy.cdm.model.common.VersionableEntity}
1388
	 *            object.
1389
	 * @param style
1390
	 *            a int.
1391
	 * @return a
1392
	 *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionElement}
1393
	 *         object.
1394
	 */
1395
	public VersionElement createVersionElement(ICdmFormElement parentElement,
1396
			VersionableEntity entity, int style) {
1397
		VersionElement element = new VersionElement(this, parentElement,
1398
				entity, style);
1399
		adapt(element);
1400
		parentElement.addElement(element);
1401
		return element;
1402
	}
1403
	
1404
	/**
1405
	 * @param cdmBaseSection
1406
	 * @param object
1407
	 * @param style
1408
	 * @return
1409
	 */
1410
	public CdmBaseElement createCdmBaseElement(ICdmFormElement parentElement,
1411
			CdmBase entity, int style) {
1412
		CdmBaseElement element = new CdmBaseElement(this, parentElement,
1413
				entity, style);
1414
		adapt(element);
1415
		parentElement.addElement(element);
1416
		return element;
1417
	}
1418

    
1419

    
1420
	/**
1421
	 * <p>
1422
	 * createVersionSection
1423
	 * </p>
1424
	 * 
1425
	 * @param parentElement
1426
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1427
	 *            object.
1428
	 * @param style
1429
	 *            a int.
1430
	 * @return a
1431
	 *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection}
1432
	 *         object.
1433
	 */
1434
	public VersionSection createVersionSection(ICdmFormElement parentElement,
1435
			int style) {
1436
		VersionSection section = new VersionSection(this, parentElement, style);
1437
		parentElement.addElement(section);
1438
		adapt(section);
1439
		return section;
1440
	}
1441
	
1442
	/**
1443
	 * @param parent
1444
	 * @param i
1445
	 * @return
1446
	 */
1447
	public CdmBaseSection createCdmBaseSection(ICdmFormElement parentElement, int style) {
1448
		CdmBaseSection section = new CdmBaseSection(this, parentElement, style);
1449
		parentElement.addElement(section);
1450
		adapt(section);
1451
		return section;
1452
	}
1453

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

    
1472
	/**
1473
	 * <p>
1474
	 * createHeadlineSection
1475
	 * </p>
1476
	 * 
1477
	 * @param parentElement
1478
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1479
	 *            object.
1480
	 * @return a
1481
	 *         {@link eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection}
1482
	 *         object.
1483
	 */
1484
	public HeadlineSection createHeadlineSection(ICdmFormElement parentElement) {
1485
		HeadlineSection section = new HeadlineSection(this, parentElement,
1486
				SWT.NULL);
1487
		parentElement.addElement(section);
1488
		adapt(section);
1489
		return section;
1490
	}
1491

    
1492
	/**
1493
	 * <p>
1494
	 * createParsingMessageElement
1495
	 * </p>
1496
	 * 
1497
	 * @param parentElement
1498
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1499
	 *            object.
1500
	 * @param parserProblem
1501
	 *            a {@link eu.etaxonomy.cdm.strategy.parser.ParserProblem}
1502
	 *            object.
1503
	 * @param style
1504
	 *            a int.
1505
	 * @return a
1506
	 *         {@link eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessageElement}
1507
	 *         object.
1508
	 */
1509
	public ParsingMessageElement createParsingMessageElement(
1510
			ICdmFormElement parentElement, ParserProblem parserProblem,
1511
			int style) {
1512
		ParsingMessageElement element = new ParsingMessageElement(this,
1513
				parentElement, parserProblem, style);
1514
		adapt(element);
1515
		parentElement.addElement(element);
1516
		return element;
1517
	}
1518

    
1519
	// SIMPLIFY
1520

    
1521
	/**
1522
	 * 
1523
	 */
1524
	public static enum DetailType {
1525
		NONVIRALNAME, 
1526
		SCIENTIFICNAME, 
1527
		REFERENCEBASE, 
1528
		NOMENCLATURALREFERENCE, 
1529
		TAXONBASE, 
1530
		AUTHORSHIP, 
1531
		TEAM, 
1532
		PERSON, 
1533
		DESCRIPTION, 
1534
		DESCRIPTIONELEMENT, 
1535
		PARSINGMESSAGE, 
1536
		NAMERELATIONSHIP, 
1537
		TEAMORPERSONBASE, 
1538
		MEDIA, 
1539
		FIELD_OBSERVATION, 
1540
		DERIVED_UNIT_FACADE, 
1541
		GATHERING_EVENT, 
1542
		DERIVED_UNIT, 
1543
		NATURAL_LANGUAGE, 
1544
		FEATURE_DISTRIBUTION, 
1545
		CLASSIFICATION, 
1546
		TAXON_NODE, 
1547
		COLLECTION, 
1548
		POLYTOMOUS_KEY, 
1549
		POLYTOMOUS_KEY_NODE, 
1550
		INSTITUTION, 
1551
		DERIVED_UNIT_GENERAL, 
1552
		HYBRID, 
1553
		USER, 
1554
		GROUP, 
1555
		DETERMINATION, 
1556
		TAXON_RELATIONSHIP, 
1557
		REFERENCED_ENTITY, 
1558
		TERM_VOCABULARY,
1559
		NAMED_AREA, 
1560
		NAMED_AREA_LEVEL
1561
	}
1562
	
1563
	public AbstractFormSection createDefinedTermDetailSection(Class definedTermClass,
1564
			ConversationHolder conversation, ICdmFormElement parentElement,
1565
			ISelectionProvider selectionProvider, int style) {
1566
		
1567
		AbstractFormSection section = new DefinedTermDetailSection(this, definedTermClass, conversation, parentElement, selectionProvider, style);
1568
			
1569
		parentElement.addElement(section);
1570
		adapt(section);
1571
		return section;
1572
		
1573
	}
1574
	
1575
	/**
1576
	 * @param definedTermClass
1577
	 * @param formElement
1578
	 * @param style
1579
	 * @return
1580
	 */
1581
	public AbstractCdmDetailElement createDefinedTermDetailElement(
1582
			Class definedTermClass, AbstractCdmDetailSection parentElement,
1583
			int style) {
1584
		AbstractCdmDetailElement element = null;
1585
		
1586
		if (NamedArea.class.isAssignableFrom(definedTermClass)){
1587
			element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
1588
		}
1589
		else {
1590
			element = new DefinedTermDetailElement(this, parentElement);
1591
		}
1592
		
1593
		adapt(element);
1594
		parentElement.addElement(element);
1595
		return element;
1596
	}
1597

    
1598
	/**
1599
	 * <p>
1600
	 * createCdmDetailSection
1601
	 * </p>
1602
	 * 
1603
	 * @param detailType
1604
	 *            a
1605
	 *            {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType}
1606
	 *            object.
1607
	 * @param parentElement
1608
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1609
	 *            object.
1610
	 * @param selectionProvider
1611
	 *            a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
1612
	 * @param style
1613
	 *            a int.
1614
	 * @param conversation
1615
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1616
	 *            object.
1617
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1618
	 *         object.
1619
	 */
1620
	public AbstractFormSection createCdmDetailSection(DetailType detailType,
1621
			ConversationHolder conversation, ICdmFormElement parentElement,
1622
			ISelectionProvider selectionProvider, int style) {
1623
		AbstractFormSection section = null;
1624

    
1625
		switch (detailType) {
1626
		case SCIENTIFICNAME:
1627
			section = new NameDetailSection(this, conversation, parentElement,
1628
					selectionProvider, style);
1629
			break;
1630
		case REFERENCEBASE:
1631
			section = new ReferenceDetailSection(this, conversation,
1632
					parentElement, selectionProvider, style);
1633
			break;
1634
		case NOMENCLATURALREFERENCE:
1635
			section = new NomenclaturalReferenceDetailSection(this,
1636
					conversation, parentElement, selectionProvider, style);
1637
			break;
1638
		case TAXONBASE:
1639
			section = new TaxonBaseDetailSection(this, conversation,
1640
					parentElement, selectionProvider, style);
1641
			break;
1642
		case AUTHORSHIP:
1643
			section = new AuthorshipDetailSection(this, conversation,
1644
					parentElement, selectionProvider, style);
1645
			break;
1646
		case TEAMORPERSONBASE:
1647
			section = new TeamOrPersonBaseDetailSection(this, conversation,
1648
					parentElement, selectionProvider, style);
1649
			break;
1650
		case TEAM:
1651
			section = new TeamDetailSection(this, conversation, parentElement,
1652
					null, style);
1653
			break;
1654
		case PERSON:
1655
			section = new PersonDetailSection(this, conversation,
1656
					parentElement, null, style);
1657
			break;
1658
		case DESCRIPTION:
1659
			section = new DescriptionDetailSection(this, conversation,
1660
					parentElement, selectionProvider, style);
1661
			break;
1662
		case DESCRIPTIONELEMENT:
1663
			section = new DescriptionElementDetailSection(this, conversation,
1664
					parentElement, selectionProvider, style);
1665
			break;
1666
		case PARSINGMESSAGE:
1667
			section = new ParsingMessagesSection(this, conversation,
1668
					parentElement, selectionProvider, style);
1669
			break;
1670
		case NONVIRALNAME:
1671
			section = new NonViralNameDetailSection(this, conversation,
1672
					parentElement, selectionProvider, style);
1673
			break;
1674
		case MEDIA:
1675
			section = new eu.etaxonomy.taxeditor.ui.section.description.MediaDetailsSection(
1676
					this, conversation, parentElement, selectionProvider, style);
1677
			break;
1678
		case DERIVED_UNIT_FACADE:
1679
			section = new DerivedUnitFacadeDetailSection(this, conversation,
1680
					parentElement, selectionProvider, style);
1681
			break;
1682
		case FIELD_OBSERVATION:
1683
			section = new FieldObservationDetailSection(this, conversation,
1684
					parentElement, selectionProvider, style);
1685
			break;
1686
		case GATHERING_EVENT:
1687
			section = new GatheringEventDetailSection(this, conversation,
1688
					parentElement, selectionProvider, style);
1689
			break;
1690
		case DERIVED_UNIT:
1691
			section = new DerivedUnitBaseDetailSection(this, conversation,
1692
					parentElement, selectionProvider, style);
1693
			break;
1694
		case NATURAL_LANGUAGE:
1695
			section = new NaturalLanguageSection(this, conversation,
1696
					parentElement, selectionProvider, style);
1697
			break;
1698
		case FEATURE_DISTRIBUTION:
1699
			section = new FeatureDistributionDetailSection(this, conversation,
1700
					parentElement, selectionProvider, style);
1701
			break;
1702
		case CLASSIFICATION:
1703
			section = new ClassificationDetailSection(this, conversation,
1704
					parentElement, selectionProvider, style);
1705
			break;
1706
		case TAXON_NODE:
1707
			section = new TaxonNodeDetailSection(this, conversation,
1708
					parentElement, selectionProvider, style);
1709
			break;
1710
		case POLYTOMOUS_KEY:
1711
			section = new PolytomousKeyDetailSection(this, conversation,
1712
					parentElement, selectionProvider, style);
1713
			break;
1714
		case POLYTOMOUS_KEY_NODE:
1715
			section = new PolytomousKeyNodeDetailSection(this, conversation,
1716
					parentElement, selectionProvider, style);
1717
			break;
1718
		case INSTITUTION:
1719
			section = new InstitutionDetailSection(this, conversation,
1720
					parentElement, selectionProvider, style);
1721
			break;
1722
		case DERIVED_UNIT_GENERAL:
1723
			section = new GeneralDetailSection(this, conversation,
1724
					parentElement, selectionProvider, style);
1725
			break;
1726
		case HYBRID:
1727
			section = new HybridDetailSection(this, conversation,
1728
					parentElement, selectionProvider, style);
1729
			break;
1730
		case USER:
1731
			section = new UserDetailSection(this, conversation, parentElement,
1732
					selectionProvider, style);
1733
			break;
1734
		case GROUP:
1735
			section = new GroupDetailSection(this, conversation, parentElement,
1736
					selectionProvider, style);
1737
			break;
1738
		case DETERMINATION:
1739
			section = new DeterminationDetailSection(this, conversation, parentElement,
1740
					selectionProvider, style);
1741
			break;
1742
		case TAXON_RELATIONSHIP:
1743
			section = new TaxonRelationshipDetailSection(this, conversation, parentElement, 
1744
					selectionProvider, style);
1745
			break;
1746
		case REFERENCED_ENTITY:
1747
			section = new ReferencedEntityDetailSection(this, conversation, parentElement, 
1748
					selectionProvider, style);
1749
			break;
1750
		case TERM_VOCABULARY:
1751
			section = new TermVocabularyDetailSection(this, conversation, parentElement, 
1752
					selectionProvider, style);
1753
			break;
1754
		case NAMED_AREA:
1755
			section = new NamedAreaDetailSection(this, conversation, parentElement, 
1756
					selectionProvider, style);
1757
			break;
1758
		}
1759

    
1760
		if (section == null) {
1761
			throw new RuntimeException(
1762
					"You tried to create a cdm detail section that is not implemented yet.");
1763
		}
1764

    
1765
		parentElement.addElement(section);
1766
		adapt(section);
1767
		return section;
1768
	}
1769

    
1770
	
1771
	
1772
	/**
1773
	 * <p>
1774
	 * createCdmDetailElement
1775
	 * </p>
1776
	 * 
1777
	 * @param detailType
1778
	 *            a
1779
	 *            {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType}
1780
	 *            object.
1781
	 * @param style
1782
	 *            a int.
1783
	 * @param parentElement
1784
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1785
	 *            object.
1786
	 * @return a
1787
	 *         {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
1788
	 *         object.
1789
	 */
1790
	public AbstractCdmDetailElement createCdmDetailElement(
1791
			DetailType detailType, ICdmFormElement parentElement, int style) {
1792
		AbstractCdmDetailElement element = null;
1793

    
1794
		switch (detailType) {
1795
		case SCIENTIFICNAME:
1796
			element = new NameDetailElement(this, parentElement, style);
1797
			break;
1798
		case REFERENCEBASE:
1799
			element = new ReferenceDetailElement(this, parentElement, style);
1800
			break;
1801
		case NOMENCLATURALREFERENCE:
1802
			element = new NomenclaturalReferenceDetailElement(this,
1803
					parentElement, style);
1804
			break;
1805
		case TAXONBASE:
1806
			element = new TaxonBaseDetailElement(this, parentElement, style);
1807
			break;
1808
		case AUTHORSHIP:
1809
			element = new AuthorshipDetailElement(this, parentElement, style);
1810
			break;
1811
		case TEAM:
1812
			element = new TeamDetailElement(this, parentElement, style);
1813
			break;
1814
		case PERSON:
1815
			element = new PersonDetailElement(this, parentElement, style);
1816
			break;
1817
		case DESCRIPTION:
1818
			element = new DescriptionDetailElement(this, parentElement, style);
1819
			break;
1820
		case DESCRIPTIONELEMENT:
1821
			element = new DescriptionElementDetailElement(this, parentElement,
1822
					style);
1823
			break;
1824
		case NONVIRALNAME:
1825
			element = new NonViralNameDetailElement(this, parentElement);
1826
			break;
1827
		case DERIVED_UNIT_FACADE:
1828
			element = new DerivedUnitFacadeDetailElement(this, parentElement);
1829
			break;
1830
		case FIELD_OBSERVATION:
1831
			element = new FieldObservationDetailElement(this, parentElement);
1832
			break;
1833
		case GATHERING_EVENT:
1834
			element = new GatheringEventDetailElement(this, parentElement);
1835
			break;
1836
		case DERIVED_UNIT:
1837
			element = new DerivedUnitBaseDetailElement(this, parentElement);
1838
			break;
1839
		case NATURAL_LANGUAGE:
1840
			element = new NaturalLanguageDetailElement(this, parentElement);
1841
			break;
1842
		case FEATURE_DISTRIBUTION:
1843
			element = new FeatureDistributionDetailElement(this, parentElement);
1844
			break;
1845
		case CLASSIFICATION:
1846
			element = new ClassificationDetailElement(this, parentElement);
1847
			break;
1848
		case TAXON_NODE:
1849
			element = new TaxonNodeDetailElement(this, parentElement);
1850
			break;
1851
		case COLLECTION:
1852
			element = new CollectionDetailElement(this, parentElement);
1853
			break;
1854
		case POLYTOMOUS_KEY:
1855
			element = new PolytomousKeyDetailElement(this, parentElement);
1856
			break;
1857
		case POLYTOMOUS_KEY_NODE:
1858
			element = new PolytomousKeyNodeDetailElement(this, parentElement);
1859
			break;
1860
		case INSTITUTION:
1861
			element = new InstitutionDetailElement(this, parentElement);
1862
			break;
1863
		case DERIVED_UNIT_GENERAL:
1864
			element = new GeneralDetailElement(this, parentElement);
1865
			break;
1866
		case HYBRID:
1867
			element = new HybridDetailElement(this, parentElement);
1868
			break;
1869
		case USER:
1870
			element = new UserDetailElement(this, parentElement);
1871
			break;
1872
		case GROUP:
1873
			element = new GroupDetailElement(this, parentElement);
1874
			break;
1875
		case DETERMINATION:
1876
			element = new DeterminationDetailElement(this, parentElement);
1877
			break;
1878
		case TAXON_RELATIONSHIP:
1879
			element = new TaxonRelationshipDetailElement(this, parentElement);
1880
			break;
1881
		case REFERENCED_ENTITY:
1882
			element = new RefereneEntityDetailElement(this, parentElement);
1883
			break;
1884
		case TERM_VOCABULARY:
1885
			element = new TermVocabularyDetailElement(this, parentElement);
1886
			break;
1887
		case NAMED_AREA:
1888
			element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
1889
			break;
1890
		case NAMED_AREA_LEVEL:
1891
			element = new DefinedTermDetailElement<NamedAreaLevel>(this, parentElement);
1892
			break;
1893
		}
1894

    
1895
		if (element == null) {
1896
			StoreUtil
1897
					.error(this.getClass(),
1898
							"Detail element was not created. Seems like the case was not implemented for the requested detail type: "
1899
									+ detailType, null);
1900
		}
1901

    
1902
		adapt(element);
1903
		parentElement.addElement(element);
1904
		return element;
1905
	}
1906

    
1907
	/**
1908
	 * 
1909
	 * @author n.hoffmann
1910
	 * @created Mar 5, 2010
1911
	 * @version 1.0
1912
	 */
1913
	public static enum EntityDetailType {
1914
		TEAM, 
1915
		TEAMMEMBER, 
1916
		ANNOTATION, 
1917
		CREDIT, 
1918
		DESCRIPTIONELEMENTSOURCE, 
1919
		EXTENSION, 
1920
		MARKER, 
1921
		MEDIA, 
1922
		DESCRIPTIONELEMENTMEDIA, 
1923
		MEDIAREPRESENTATION, 
1924
		MEDIAREPRESENTATIONPART, 
1925
		MODIFIER, 
1926
		NOMENCLATURALSTATUS, 
1927
		NAME_RELATIONSHIP, 
1928
		PROTOLOG, 
1929
		RIGHTS, 
1930
		SOURCE, 
1931
		SCOPE, 
1932
		DESCRIPTIONSOURCE, 
1933
		TYPEDESIGNATION, 
1934
		STATE_DATA, 
1935
		STATISTICAL_MEASUREMENT_VALUE, 
1936
		DESCRIBED_SPECIMEN, 
1937
		COLLECTING_AREA, 
1938
		DETERMINATION_EVENT, 
1939
		SPECIMEN_COLLECTION, 
1940
		IDENTIFIABLE_SOURCE_COLLECTION, 
1941
		GEOGRAPHICAL_SCOPE, 
1942
		SCOPE_RESTRICTION, 
1943
		MEMBER, 
1944
		GRANTED_AUTHORITY, 
1945
		GROUPS_BY_USER, 
1946
		TAXONOMIC_SCOPE, 
1947
		DETERMINATION_CURRENT, 
1948
		DETERMINATION_HISTORY
1949
	}
1950

    
1951
	/**
1952
	 * <p>
1953
	 * createEntityDetailSection
1954
	 * </p>
1955
	 * 
1956
	 * @param entityDetailType
1957
	 *            a
1958
	 *            {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.EntityDetailType}
1959
	 *            object.
1960
	 * @param style
1961
	 *            a int.
1962
	 * @param conversation
1963
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1964
	 *            object.
1965
	 * @param parentElement
1966
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1967
	 *            object.
1968
	 * @return a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1969
	 *         object.
1970
	 */
1971
	public AbstractFormSection createEntityDetailSection(
1972
			EntityDetailType entityDetailType, ConversationHolder conversation,
1973
			ICdmFormElement parentElement, int style) {
1974
		AbstractFormSection section = null;
1975

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

    
2117
	/**
2118
	 * <p>
2119
	 * createEntityCollectionElement
2120
	 * </p>
2121
	 * 
2122
	 * @param removeListener
2123
	 *            a {@link org.eclipse.swt.events.SelectionListener} object.
2124
	 * @param style
2125
	 *            a int.
2126
	 * @param parentElement
2127
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
2128
	 *            object.
2129
	 * @param versionableEntity
2130
	 *            a {@link eu.etaxonomy.cdm.model.common.IVersionableEntity}
2131
	 *            object.
2132
	 * @param backgroundColor
2133
	 *            a {@link org.eclipse.swt.graphics.Color} object.
2134
	 * @return a
2135
	 *         {@link eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement}
2136
	 *         object.
2137
	 */
2138
	public AbstractEntityCollectionElement createEntityCollectionElement(
2139
			AbstractFormSection parentElement, Object versionableEntity,
2140
			SelectionListener removeListener, Color backgroundColor, int style) {
2141
		AbstractEntityCollectionElement element = null;
2142

    
2143
		Object entity = HibernateProxyHelper.deproxy(versionableEntity);
2144

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

    
2243
		if (element == null) {
2244
			StoreUtil
2245
					.errorDialog(
2246
							"No element for entity",
2247
							this,
2248
							"Could not generate element for entity. "
2249
									+ "Looks like the case is not handled already. Check implementation. Entity: "
2250
									+ entity, null);
2251

    
2252
		}
2253

    
2254
		if (backgroundColor != null && !backgroundColor.isDisposed()) {
2255
			element.setPersistentBackground(backgroundColor);
2256
		}
2257

    
2258
		adapt(element);
2259
		parentElement.addElement(element);
2260
		return element;
2261
	}
2262

    
2263
	/**
2264
	 * <p>
2265
	 * createSelectionElement
2266
	 * </p>
2267
	 * 
2268
	 * @param selectionType
2269
	 *            a
2270
	 *            {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.SelectionType}
2271
	 *            object.
2272
	 * @param parentElement
2273
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
2274
	 *            object.
2275
	 * @param labelString
2276
	 *            a {@link java.lang.String} object.
2277
	 * @param selectionType
2278
	 * @param selection
2279
	 *            a {@link eu.etaxonomy.cdm.model.common.IAnnotatableEntity}
2280
	 *            object.
2281
	 * @param style
2282
	 *            a int.
2283
	 * @param conversation
2284
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
2285
	 *            object.
2286
	 * @return a
2287
	 *         {@link eu.etaxonomy.taxeditor.ui.selection.AbstractSelectionElement}
2288
	 *         object.
2289
	 */
2290
	public AbstractSelectionElement createSelectionElement(
2291
			SelectionType selectionType, ConversationHolder conversation,
2292
			ICdmFormElement parentElement, String labelString,
2293
			ICdmBase selection, int mode, int style) {
2294
		AbstractSelectionElement element = null;
2295

    
2296
		IAnnotatableEntity entity = (IAnnotatableEntity) HibernateProxyHelper
2297
				.deproxy(selection);
2298

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

    
2401
		adapt(element);
2402
		parentElement.addElement(element);
2403
		return element;
2404
	}
2405

    
2406
	/**
2407
	 * <p>
2408
	 * createNamedAreaSelectionElement
2409
	 * </p>
2410
	 * 
2411
	 * @param parentElement
2412
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
2413
	 *            object.
2414
	 * @param conversation
2415
	 *            a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
2416
	 *            object.
2417
	 * @param labelString
2418
	 *            a {@link java.lang.String} object.
2419
	 * @param selection
2420
	 *            a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
2421
	 * @param style
2422
	 *            a int.
2423
	 * @return a
2424
	 *         {@link eu.etaxonomy.taxeditor.ui.selection.NamedAreaSelectionElement}
2425
	 *         object.
2426
	 */
2427
	public NamedAreaSelectionElement createNamedAreaSelectionElement(
2428
			ICdmFormElement parentElement, ConversationHolder conversation,
2429
			String labelString, NamedArea selection, int style) {
2430
		NamedAreaSelectionElement element = new NamedAreaSelectionElement(this,
2431
				conversation, parentElement, labelString, selection,
2432
				AbstractSelectionElement.NOTHING, style);
2433
		adapt(element);
2434
		parentElement.addElement(element);
2435
		return element;
2436
	}
2437

    
2438
	/** {@inheritDoc} */
2439
	public LabelElement createLabel(ICdmFormElement parentElement, String text) {
2440
		LabelElement labelElement = new LabelElement(this, parentElement, text);
2441
		adapt(labelElement);
2442
		parentElement.addElement(labelElement);
2443
		return labelElement;
2444
	}
2445

    
2446
	/**
2447
	 * <p>
2448
	 * Getter for the field <code>selectionProvider</code>.
2449
	 * </p>
2450
	 * 
2451
	 * @return a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
2452
	 */
2453
	public ISelectionProvider getSelectionProvider() {
2454
		return selectionProvider;
2455
	}
2456

    
2457
	/**
2458
	 * <p>
2459
	 * createDetailedDescriptionDetailElement
2460
	 * </p>
2461
	 * 
2462
	 * @param parentElement
2463
	 *            a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
2464
	 *            object.
2465
	 * @param entity
2466
	 *            a
2467
	 *            {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase}
2468
	 *            object.
2469
	 * @param style
2470
	 *            a int.
2471
	 * @return a
2472
	 *         {@link eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement}
2473
	 *         object.
2474
	 */
2475
	public AbstractDetailedDescriptionDetailElement createDetailedDescriptionDetailElement(
2476
			ICdmFormElement parentElement, DescriptionElementBase entity,
2477
			int style) {
2478
		AbstractDetailedDescriptionDetailElement detailedDescriptionElement = null;
2479

    
2480
		if (entity instanceof CategoricalData) {
2481
			detailedDescriptionElement = new CategoricalDataDetailElement(this,
2482
					parentElement, (CategoricalData) entity, style);
2483
		} else if (entity instanceof CommonTaxonName) {
2484
			detailedDescriptionElement = new CommonNameDetailElement(this,
2485
					parentElement, (CommonTaxonName) entity, style);
2486
		} else if (entity instanceof Distribution) {
2487
			detailedDescriptionElement = new DistributionDetailElement(this,
2488
					parentElement, (Distribution) entity, style);
2489
		} else if (entity instanceof IndividualsAssociation) {
2490
			detailedDescriptionElement = new IndividualsAssociationDetailElement(
2491
					this, parentElement, (IndividualsAssociation) entity, style);
2492
		} else if (entity instanceof QuantitativeData) {
2493
			detailedDescriptionElement = new QuantitativeDataDetailElement(
2494
					this, parentElement, (QuantitativeData) entity, style);
2495
		} else if (entity instanceof TaxonInteraction) {
2496
			detailedDescriptionElement = new TaxonInteractionDetailElement(
2497
					this, parentElement, (TaxonInteraction) entity, style);
2498
		} else if (entity instanceof TextData) {
2499
			detailedDescriptionElement = new TextDataDetailElement(this,
2500
					parentElement, (TextData) entity, style);
2501
		} else {
2502
			throw new IllegalStateException(
2503
					"There is no interface for the given description element");
2504
		}
2505
		adapt(detailedDescriptionElement);
2506
		parentElement.addElement(detailedDescriptionElement);
2507
		return detailedDescriptionElement;
2508

    
2509
	}
2510

    
2511
	/**
2512
	 * Creates a styled text as a part of the form.
2513
	 * 
2514
	 * @param parent
2515
	 *            the text parent
2516
	 * @param value
2517
	 *            the text initial value
2518
	 * @param style
2519
	 *            the text style
2520
	 * @return the text widget
2521
	 */
2522
	public StyledText createStyledText(Composite parent, String value, int style) {
2523
		StyledText text = new StyledText(parent, getBorderStyle() | style
2524
				| getOrientation());
2525
		if (value != null)
2526
			text.setText(value);
2527
		text.setForeground(getColors().getForeground());
2528
		text.setBackground(getColors().getBackground());
2529
		// text.addFocusListener(visibilityHandler);
2530
		return text;
2531
	}
2532

    
2533

    
2534

    
2535

    
2536

    
2537

    
2538
}
(6-6/35)