Project

General

Profile

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

    
6
import java.net.URI;
7
import java.util.HashSet;
8
import java.util.Map;
9
import java.util.Set;
10

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

    
42
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
43
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
44
import eu.etaxonomy.cdm.model.agent.Institution;
45
import eu.etaxonomy.cdm.model.agent.Person;
46
import eu.etaxonomy.cdm.model.agent.Team;
47
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
48
import eu.etaxonomy.cdm.model.common.Annotation;
49
import eu.etaxonomy.cdm.model.common.AnnotationType;
50
import eu.etaxonomy.cdm.model.common.Credit;
51
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
52
import eu.etaxonomy.cdm.model.common.DescriptionElementSource;
53
import eu.etaxonomy.cdm.model.common.Extension;
54
import eu.etaxonomy.cdm.model.common.ExtensionType;
55
import eu.etaxonomy.cdm.model.common.IAnnotatableEntity;
56
import eu.etaxonomy.cdm.model.common.IVersionableEntity;
57
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
58
import eu.etaxonomy.cdm.model.common.Language;
59
import eu.etaxonomy.cdm.model.common.LanguageString;
60
import eu.etaxonomy.cdm.model.common.Marker;
61
import eu.etaxonomy.cdm.model.common.MarkerType;
62
import eu.etaxonomy.cdm.model.common.TimePeriod;
63
import eu.etaxonomy.cdm.model.common.VersionableEntity;
64
import eu.etaxonomy.cdm.model.description.CategoricalData;
65
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
66
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
67
import eu.etaxonomy.cdm.model.description.Distribution;
68
import eu.etaxonomy.cdm.model.description.Feature;
69
import eu.etaxonomy.cdm.model.description.FeatureTree;
70
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
71
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
72
import eu.etaxonomy.cdm.model.description.Modifier;
73
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
74
import eu.etaxonomy.cdm.model.description.QuantitativeData;
75
import eu.etaxonomy.cdm.model.description.Scope;
76
import eu.etaxonomy.cdm.model.description.Sex;
77
import eu.etaxonomy.cdm.model.description.Stage;
78
import eu.etaxonomy.cdm.model.description.State;
79
import eu.etaxonomy.cdm.model.description.StateData;
80
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
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.NamedAreaType;
86
import eu.etaxonomy.cdm.model.location.Point;
87
import eu.etaxonomy.cdm.model.location.ReferenceSystem;
88
import eu.etaxonomy.cdm.model.media.ImageFile;
89
import eu.etaxonomy.cdm.model.media.Media;
90
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
91
import eu.etaxonomy.cdm.model.media.Rights;
92
import eu.etaxonomy.cdm.model.media.RightsTerm;
93
import eu.etaxonomy.cdm.model.name.NameRelationship;
94
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
95
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
96
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
97
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
98
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
99
import eu.etaxonomy.cdm.model.name.Rank;
100
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
101
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
102
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
103
import eu.etaxonomy.cdm.model.occurrence.Collection;
104
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
105
import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
106
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
107
import eu.etaxonomy.cdm.model.occurrence.DeterminationModifier;
108
import eu.etaxonomy.cdm.model.occurrence.FieldObservation;
109
import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
110
import eu.etaxonomy.cdm.model.occurrence.Specimen;
111
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
112
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
113
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
114
import eu.etaxonomy.cdm.model.taxon.TaxonomicTree;
115
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
116
import eu.etaxonomy.taxeditor.editor.EditorUtil;
117
import eu.etaxonomy.taxeditor.forms.selection.AbstractSelectionElement;
118
import eu.etaxonomy.taxeditor.forms.selection.AgentSelectionElement;
119
import eu.etaxonomy.taxeditor.forms.selection.ClassificationSelectionElement;
120
import eu.etaxonomy.taxeditor.forms.selection.CollectionSelectionElement;
121
import eu.etaxonomy.taxeditor.forms.selection.DerivedUnitBaseSelectionElement;
122
import eu.etaxonomy.taxeditor.forms.selection.FeatureTreeSelectionElement;
123
import eu.etaxonomy.taxeditor.forms.selection.FieldObservationSelectionElement;
124
import eu.etaxonomy.taxeditor.forms.selection.InstitutionSelectionElement;
125
import eu.etaxonomy.taxeditor.forms.selection.NameSelectionElement;
126
import eu.etaxonomy.taxeditor.forms.selection.NamedAreaSelectionElement;
127
import eu.etaxonomy.taxeditor.forms.selection.NomenclaturalAuthorTeamSelectionElement;
128
import eu.etaxonomy.taxeditor.forms.selection.PersonSelectionElement;
129
import eu.etaxonomy.taxeditor.forms.selection.ReferenceSelectionElement;
130
import eu.etaxonomy.taxeditor.forms.selection.TaxonBaseSelectionElement;
131
import eu.etaxonomy.taxeditor.forms.selection.TaxonNodeSelectionElement;
132
import eu.etaxonomy.taxeditor.forms.selection.TeamSelectionElement;
133
import eu.etaxonomy.taxeditor.forms.term.AbstractEnumComboElement;
134
import eu.etaxonomy.taxeditor.forms.term.AbstractTermComboElement;
135
import eu.etaxonomy.taxeditor.forms.term.AnnotationTypeComboElement;
136
import eu.etaxonomy.taxeditor.forms.term.DeterminationModifierComboElement;
137
import eu.etaxonomy.taxeditor.forms.term.EmptyComboElement;
138
import eu.etaxonomy.taxeditor.forms.term.ExtensionTypeComboElement;
139
import eu.etaxonomy.taxeditor.forms.term.LanguageComboElement;
140
import eu.etaxonomy.taxeditor.forms.term.MarkerTypeComboElement;
141
import eu.etaxonomy.taxeditor.forms.term.MeasurementUnitComboElement;
142
import eu.etaxonomy.taxeditor.forms.term.ModifierComboElement;
143
import eu.etaxonomy.taxeditor.forms.term.NameRelationshipTypeComboElement;
144
import eu.etaxonomy.taxeditor.forms.term.NameTypeDesignationStatusComboElement;
145
import eu.etaxonomy.taxeditor.forms.term.NamedAreaTypeComboElement;
146
import eu.etaxonomy.taxeditor.forms.term.NomenclaturalCodeComboElement;
147
import eu.etaxonomy.taxeditor.forms.term.NomenclaturalStatusTypeComboElement;
148
import eu.etaxonomy.taxeditor.forms.term.PresenceAbsenceTermComboElement;
149
import eu.etaxonomy.taxeditor.forms.term.PreservationMethodComboElement;
150
import eu.etaxonomy.taxeditor.forms.term.RankComboElement;
151
import eu.etaxonomy.taxeditor.forms.term.ReferenceSystemComboElement;
152
import eu.etaxonomy.taxeditor.forms.term.ReferenceTypeComboElement;
153
import eu.etaxonomy.taxeditor.forms.term.RightsTypeComboElement;
154
import eu.etaxonomy.taxeditor.forms.term.ScopeComboElement;
155
import eu.etaxonomy.taxeditor.forms.term.SexComboElement;
156
import eu.etaxonomy.taxeditor.forms.term.SpecimenTypeDesignationStatusComboElement;
157
import eu.etaxonomy.taxeditor.forms.term.StageComboElement;
158
import eu.etaxonomy.taxeditor.forms.term.StateComboElement;
159
import eu.etaxonomy.taxeditor.forms.term.StatisticalMeasureComboElement;
160
import eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement;
161
import eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement;
162
import eu.etaxonomy.taxeditor.section.EmptyElement;
163
import eu.etaxonomy.taxeditor.section.agent.PersonDetailElement;
164
import eu.etaxonomy.taxeditor.section.agent.PersonDetailSection;
165
import eu.etaxonomy.taxeditor.section.agent.TeamDetailElement;
166
import eu.etaxonomy.taxeditor.section.agent.TeamDetailSection;
167
import eu.etaxonomy.taxeditor.section.agent.TeamMemberElement;
168
import eu.etaxonomy.taxeditor.section.agent.TeamMemberSection;
169
import eu.etaxonomy.taxeditor.section.agent.TeamOrPersonBaseDetailSection;
170
import eu.etaxonomy.taxeditor.section.classification.ClassificationDetailElement;
171
import eu.etaxonomy.taxeditor.section.classification.ClassificationDetailSection;
172
import eu.etaxonomy.taxeditor.section.classification.TaxonNodeDetailElement;
173
import eu.etaxonomy.taxeditor.section.classification.TaxonNodeDetailSection;
174
import eu.etaxonomy.taxeditor.section.description.DerivedUnitElement;
175
import eu.etaxonomy.taxeditor.section.description.DescribedSpecimenSection;
176
import eu.etaxonomy.taxeditor.section.description.DescriptionDetailElement;
177
import eu.etaxonomy.taxeditor.section.description.DescriptionDetailSection;
178
import eu.etaxonomy.taxeditor.section.description.DescriptionElementDetailElement;
179
import eu.etaxonomy.taxeditor.section.description.DescriptionElementDetailSection;
180
import eu.etaxonomy.taxeditor.section.description.DescriptionElementMediaSection;
181
import eu.etaxonomy.taxeditor.section.description.DescriptionElementSourceElement;
182
import eu.etaxonomy.taxeditor.section.description.DescriptionElementSourceSection;
183
import eu.etaxonomy.taxeditor.section.description.DescriptionSourceElement;
184
import eu.etaxonomy.taxeditor.section.description.DescriptionSourceSection;
185
import eu.etaxonomy.taxeditor.section.description.ModifierElement;
186
import eu.etaxonomy.taxeditor.section.description.ModifierSection;
187
import eu.etaxonomy.taxeditor.section.description.NaturalLanguageDetailElement;
188
import eu.etaxonomy.taxeditor.section.description.NaturalLanguageSection;
189
import eu.etaxonomy.taxeditor.section.description.ScopeElement;
190
import eu.etaxonomy.taxeditor.section.description.ScopeSection;
191
import eu.etaxonomy.taxeditor.section.description.StateDataElement;
192
import eu.etaxonomy.taxeditor.section.description.StateDataSection;
193
import eu.etaxonomy.taxeditor.section.description.StatisticalMeasurementValueElement;
194
import eu.etaxonomy.taxeditor.section.description.StatisticalMeasurementValueSection;
195
import eu.etaxonomy.taxeditor.section.description.detail.AbstractDetailedDescriptionDetailElement;
196
import eu.etaxonomy.taxeditor.section.description.detail.CategoricalDataDetailElement;
197
import eu.etaxonomy.taxeditor.section.description.detail.CommonNameDetailElement;
198
import eu.etaxonomy.taxeditor.section.description.detail.DistributionDetailElement;
199
import eu.etaxonomy.taxeditor.section.description.detail.IndividualsAssociationDetailElement;
200
import eu.etaxonomy.taxeditor.section.description.detail.QuantitativeDataDetailElement;
201
import eu.etaxonomy.taxeditor.section.description.detail.TaxonInteractionDetailElement;
202
import eu.etaxonomy.taxeditor.section.description.detail.TextDataDetailElement;
203
import eu.etaxonomy.taxeditor.section.feature.FeatureDistributionDetailElement;
204
import eu.etaxonomy.taxeditor.section.feature.FeatureDistributionDetailSection;
205
import eu.etaxonomy.taxeditor.section.name.AuthorshipDetailElement;
206
import eu.etaxonomy.taxeditor.section.name.AuthorshipDetailSection;
207
import eu.etaxonomy.taxeditor.section.name.NameDetailElement;
208
import eu.etaxonomy.taxeditor.section.name.NameDetailSection;
209
import eu.etaxonomy.taxeditor.section.name.NameRelationshipDetailElement;
210
import eu.etaxonomy.taxeditor.section.name.NameRelationshipDetailSection;
211
import eu.etaxonomy.taxeditor.section.name.NameTypeDesignationElement;
212
import eu.etaxonomy.taxeditor.section.name.NomenclaturalStatusElement;
213
import eu.etaxonomy.taxeditor.section.name.NomenclaturalStatusSection;
214
import eu.etaxonomy.taxeditor.section.name.NonViralNameDetailElement;
215
import eu.etaxonomy.taxeditor.section.name.NonViralNameDetailSection;
216
import eu.etaxonomy.taxeditor.section.name.ProtologueElement;
217
import eu.etaxonomy.taxeditor.section.name.ProtologueSection;
218
import eu.etaxonomy.taxeditor.section.name.SpecimenTypeDesignationElement;
219
import eu.etaxonomy.taxeditor.section.name.TypeDesignationSection;
220
import eu.etaxonomy.taxeditor.section.occurrence.CollectingAreasDetailElement;
221
import eu.etaxonomy.taxeditor.section.occurrence.CollectingAreasDetailSection;
222
import eu.etaxonomy.taxeditor.section.occurrence.CollectionDetailElement;
223
import eu.etaxonomy.taxeditor.section.occurrence.DerivedUnitBaseDetailElement;
224
import eu.etaxonomy.taxeditor.section.occurrence.DerivedUnitBaseDetailSection;
225
import eu.etaxonomy.taxeditor.section.occurrence.DerivedUnitFacadeDetailElement;
226
import eu.etaxonomy.taxeditor.section.occurrence.DerivedUnitFacadeDetailSection;
227
import eu.etaxonomy.taxeditor.section.occurrence.DeterminationEventDetailElement;
228
import eu.etaxonomy.taxeditor.section.occurrence.DeterminationEventDetailSection;
229
import eu.etaxonomy.taxeditor.section.occurrence.FieldObservationDetailElement;
230
import eu.etaxonomy.taxeditor.section.occurrence.FieldObservationDetailSection;
231
import eu.etaxonomy.taxeditor.section.occurrence.GatheringEventDetailElement;
232
import eu.etaxonomy.taxeditor.section.occurrence.GatheringEventDetailSection;
233
import eu.etaxonomy.taxeditor.section.occurrence.SourceCollectionDetailSection;
234
import eu.etaxonomy.taxeditor.section.occurrence.SpecimenCollectionDetailElement;
235
import eu.etaxonomy.taxeditor.section.occurrence.SpecimenCollectionDetailSection;
236
import eu.etaxonomy.taxeditor.section.reference.NomenclaturalReferenceDetailElement;
237
import eu.etaxonomy.taxeditor.section.reference.NomenclaturalReferenceDetailSection;
238
import eu.etaxonomy.taxeditor.section.reference.ReferenceBaseDetailElement;
239
import eu.etaxonomy.taxeditor.section.reference.ReferenceBaseDetailSection;
240
import eu.etaxonomy.taxeditor.section.supplemental.AnnotationElement;
241
import eu.etaxonomy.taxeditor.section.supplemental.AnnotationSection;
242
import eu.etaxonomy.taxeditor.section.supplemental.CreditElement;
243
import eu.etaxonomy.taxeditor.section.supplemental.CreditSection;
244
import eu.etaxonomy.taxeditor.section.supplemental.ExtensionElement;
245
import eu.etaxonomy.taxeditor.section.supplemental.ExtensionSection;
246
import eu.etaxonomy.taxeditor.section.supplemental.HeadlineSection;
247
import eu.etaxonomy.taxeditor.section.supplemental.IdentifiableSourceElement;
248
import eu.etaxonomy.taxeditor.section.supplemental.ImageFileElement;
249
import eu.etaxonomy.taxeditor.section.supplemental.MarkerElement;
250
import eu.etaxonomy.taxeditor.section.supplemental.MarkerSection;
251
import eu.etaxonomy.taxeditor.section.supplemental.MediaElement;
252
import eu.etaxonomy.taxeditor.section.supplemental.MediaRepresentationElement;
253
import eu.etaxonomy.taxeditor.section.supplemental.MediaRepresentationPartSection;
254
import eu.etaxonomy.taxeditor.section.supplemental.MediaRepresentationSection;
255
import eu.etaxonomy.taxeditor.section.supplemental.MediaSection;
256
import eu.etaxonomy.taxeditor.section.supplemental.RightsElement;
257
import eu.etaxonomy.taxeditor.section.supplemental.RightsSection;
258
import eu.etaxonomy.taxeditor.section.supplemental.SourceSection;
259
import eu.etaxonomy.taxeditor.section.supplemental.VersionElement;
260
import eu.etaxonomy.taxeditor.section.supplemental.VersionSection;
261
import eu.etaxonomy.taxeditor.section.taxon.ParsingMessageElement;
262
import eu.etaxonomy.taxeditor.section.taxon.ParsingMessagesSection;
263
import eu.etaxonomy.taxeditor.section.taxon.TaxonBaseDetailElement;
264
import eu.etaxonomy.taxeditor.section.taxon.TaxonBaseDetailSection;
265

    
266
/**
267
 * <p>CdmFormFactory class.</p>
268
 *
269
 * @author n.hoffmann
270
 * @created Feb 24, 2010
271
 * @version 1.0
272
 */
273
public class CdmFormFactory extends FormToolkit{
274
	
275
	private BoldFontHolder2 boldFontHolder2;
276
	private MouseListener selectionMouseHandler;
277
	private FocusListener selectionFocusHandler;
278
	
279
	private Set selectionListenerList = new HashSet();
280
	
281
	private Set<IPropertyChangeListener> propertyChangeListeners = new HashSet<IPropertyChangeListener>();
282
	
283
	private int orientation = Window.getDefaultOrientation();
284
	private ISelectionProvider selectionProvider;
285
	
286
	/**
287
	 * <p>LAYOUT</p>
288
	 *
289
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapLayout} object.
290
	 */
291
	public static final TableWrapLayout LAYOUT(){
292
		return LAYOUT(1, false);
293
	}
294
	
295
	/**
296
	 * <p>LAYOUT</p>
297
	 *
298
	 * @param columns a int.
299
	 * @param equalWidth a boolean.
300
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapLayout} object.
301
	 */
302
	public static final TableWrapLayout LAYOUT(int columns, boolean equalWidth){
303
		TableWrapLayout layout = new TableWrapLayout();
304
		layout.topMargin = 0;
305
		layout.rightMargin = 0;
306
		layout.bottomMargin = 0;
307
		layout.leftMargin = 0;
308
		layout.numColumns = columns;
309
		layout.makeColumnsEqualWidth = equalWidth;
310
		layout.verticalSpacing = 0;
311
		layout.horizontalSpacing = 0;
312
		return layout;
313
	}
314
	
315
	/**
316
	 * <p>FILL</p>
317
	 *
318
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
319
	 */
320
	public static final TableWrapData FILL(){
321
		return FILL(1, 1);
322
	}
323
	
324
	/**
325
	 * <p>FILL</p>
326
	 *
327
	 * @param horizontalSpan a int.
328
	 * @param verticalSpan a int.
329
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
330
	 */
331
	public static final TableWrapData FILL(int horizontalSpan, int verticalSpan){
332
		TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL_GRAB);
333
		layoutData.colspan = horizontalSpan;
334
		layoutData.rowspan = verticalSpan;
335
		return layoutData;
336
	}
337
	
338
	/**
339
	 * <p>LEFT</p>
340
	 *
341
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
342
	 */
343
	public static final TableWrapData LEFT(){
344
		return new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP);
345
	}
346
	
347
	/**
348
	 * <p>RIGHT</p>
349
	 *
350
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
351
	 */
352
	public static final TableWrapData RIGHT(){
353
		return new TableWrapData(TableWrapData.RIGHT, TableWrapData.TOP);
354
	}
355
	
356
	/**
357
	 * <p>FILL_HORIZONTALLY</p>
358
	 *
359
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
360
	 */
361
	public static final TableWrapData FILL_HORIZONTALLY(){
362
		return FILL_HORIZONTALLY(1, 1);
363
	}
364
	
365
	/**
366
	 * <p>FILL_HORIZONTALLY</p>
367
	 *
368
	 * @param horizontalSpan a int.
369
	 * @param verticalSpan a int.
370
	 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
371
	 */
372
	public static final TableWrapData FILL_HORIZONTALLY(int horizontalSpan, int verticalSpan){
373
		TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP);
374
		layoutData.colspan = horizontalSpan;
375
		layoutData.rowspan = verticalSpan;
376
		return layoutData;
377
	}
378
	
379
	/** Constant <code>EMPTY_SELECTION</code> */
380
	public static ISelection EMPTY_SELECTION = new ISelection() {
381
		public boolean isEmpty() {
382
			return true;
383
		}
384
	};
385
	
386
	private class SelectionMouseHandler extends MouseAdapter{
387
		@Override
388
		public void mouseDown(MouseEvent e) {
389
			notifySelectionListeners(e);
390
		}
391
	}
392
	
393
	private class SelectionFocusHandler extends FocusAdapter{
394
		@Override
395
		public void focusGained(FocusEvent e) {
396
			notifySelectionListeners(e);
397
		}
398
	}
399
	
400
	private void notifySelectionListeners(TypedEvent e){
401
		Event event = new Event();
402
		event.widget = e.widget;
403
		SelectionEvent selectionEvent = new SelectionEvent(event);
404
		
405
		for(Object listener : selectionListenerList){
406
			((SelectionListener) listener).widgetSelected(selectionEvent);
407
		}
408
	}
409
	
410
	/**
411
	 * <p>Constructor for CdmFormFactory.</p>
412
	 *
413
	 * @param display a {@link org.eclipse.swt.widgets.Display} object.
414
	 * @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
415
	 */
416
	public CdmFormFactory(Display display, ISelectionProvider selectionProvider) {
417
		super(display);
418
		this.selectionProvider = selectionProvider;
419
		init();
420
	}
421
	
422
	/**
423
	 * <p>Constructor for CdmFormFactory.</p>
424
	 *
425
	 * @param display a {@link org.eclipse.swt.widgets.Display} object.
426
	 */
427
	public CdmFormFactory(Display display){
428
		super(display);
429
		init();
430
	}
431
	
432
	/**
433
	 * 
434
	 */
435
	private void init() {
436
		boldFontHolder2 = new BoldFontHolder2();
437
		selectionMouseHandler = new SelectionMouseHandler();
438
		selectionFocusHandler = new SelectionFocusHandler();
439
	}
440
	
441
	/**
442
	 * Creates an instance initialized with the correct selectionProvider
443
	 *
444
	 * Make sure to remove the instance when the entityComposite disposes via
445
	 * destroySelectionArbitrator(..)
446
	 *
447
	 * @param entityElement a {@link eu.etaxonomy.taxeditor.forms.IEntityElement} object.
448
	 * @return a {@link eu.etaxonomy.taxeditor.forms.SelectionArbitrator} object.
449
	 */
450
	public SelectionArbitrator createSelectionArbitrator(IEntityElement entityElement){
451
		SelectionArbitrator selectionArbitrator = new SelectionArbitrator(entityElement);
452
		selectionArbitrator.addSelectionProvider(selectionProvider);
453
		selectionProvider.addSelectionChangedListener(selectionArbitrator);
454
		addSelectionListener(selectionArbitrator);
455
		return selectionArbitrator;
456
	}
457
	
458
	/**
459
	 * <p>destroySelectionArbitrator</p>
460
	 *
461
	 * @param selectionArbitrator a {@link eu.etaxonomy.taxeditor.forms.SelectionArbitrator} object.
462
	 */
463
	public void destroySelectionArbitrator(SelectionArbitrator selectionArbitrator){
464
		removeSelectionListener(selectionArbitrator);
465
		if(selectionProvider != null){
466
			selectionProvider.removeSelectionChangedListener(selectionArbitrator);
467
		}else{
468
			EditorUtil.error(this.getClass(), "Tried to destroy a selection listener from this factories listeners but was null", null);
469
		}
470
	}
471

    
472
	/** {@inheritDoc} */
473
	@Override
474
	public void adapt(Composite composite) {
475
		composite.addMouseListener(selectionMouseHandler);
476
		super.adapt(composite);
477
	}
478
	
479
	/**
480
	 * <p>adapt</p>
481
	 *
482
	 * @param formElement a {@link eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement} object.
483
	 */
484
	public void adapt(AbstractCdmFormElement formElement){		
485
		formElement.setPropertyChangeListeners(propertyChangeListeners);
486
	}
487
	
488
	/** {@inheritDoc} */
489
	@Override
490
	public void adapt(Control control, boolean trackFocus, boolean trackKeyboard) {
491
		if(trackFocus){
492
			control.addFocusListener(selectionFocusHandler);
493
		}
494
		super.adapt(control, trackFocus, trackKeyboard);
495
	}
496
	
497
	/**
498
	 * <p>destroyElement</p>
499
	 *
500
	 * @param formElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
501
	 */
502
	public void destroyElement(ICdmFormElement formElement){
503
		// return if element was not initialized
504
		if(formElement == null){
505
			return;
506
		}
507
		// destroy selection arbitrator, if any
508
		if(formElement instanceof ISelectableElement){
509
			destroySelectionArbitrator(((ISelectableElement) formElement).getSelectionArbitrator());
510
		}
511
		// remove this element form its parents list of elements
512
//		ICdmFormElement parentElement = formElement.getParentElement();
513
//		if(parentElement != null){
514
//			parentElement.removeElement(formElement);
515
//		}
516
		// call destroy on child elements recursively
517
		for(ICdmFormElement childElement : formElement.getElements()){
518
			destroyElement(childElement);
519
		}
520
		// dispose of the controls
521
		for(Control control : formElement.getControls()){
522
			// we added the layoutComposite of the parental element as the layout composite to this formElement
523
			// but we do not want to destroy it.
524
			if(control.equals(formElement.getLayoutComposite())){
525
				continue;
526
			}else{
527
				control.dispose();
528
				control = null;
529
			}
530
		}
531
	}
532
	
533
	
534
	/**
535
	 * <p>createEmptyCell</p>
536
	 *
537
	 * @param parent a {@link org.eclipse.swt.widgets.Composite} object.
538
	 * @return a {@link org.eclipse.swt.widgets.Label} object.
539
	 */
540
	public Label createEmptyCell(Composite parent){
541
		return this.createLabel(parent, null);
542
	}
543
	
544
	/**
545
	 * <p>createMultilineTextWithLabel</p>
546
	 *
547
	 * @param labelString a {@link java.lang.String} object.
548
	 * @param textHeight a int.
549
	 * @param style a int.
550
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
551
	 * @return a {@link eu.etaxonomy.taxeditor.forms.TextWithLabelElement} object.
552
	 */
553
	public TextWithLabelElement createMultilineTextWithLabel(ICdmFormElement parentElement, String labelString, int textHeight, int style){
554
		TextWithLabelElement element = new TextWithLabelElement(this, parentElement, labelString, "", textHeight, style);
555
		adapt(element);
556
		parentElement.addElement(element);
557
		return element;
558
	}
559

    
560

    
561
	/**
562
	 * <p>createMultiLanguageTextElement</p>
563
	 *
564
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
565
	 * @param labelString a {@link java.lang.String} object.
566
	 * @param multilanguageText a {@link java.util.Map} object.
567
	 * @param textHeight a int.
568
	 * @param style a int.
569
	 * @return a {@link eu.etaxonomy.taxeditor.forms.MultilanguageTextElement} object.
570
	 */
571
	public MultilanguageTextElement createMultiLanguageTextElement(
572
			ICdmFormElement parentElement, String labelString, Map<Language, LanguageString> multilanguageText, int textHeight,
573
			int style) {
574
		MultilanguageTextElement element = new MultilanguageTextElement(this, parentElement, labelString, multilanguageText, textHeight, style);
575
		adapt(element);
576
		parentElement.addElement(element);
577
		return element;
578
	}
579
	
580
	
581
	/**
582
	 * <p>createTextWithLabelElement</p>
583
	 *
584
	 * @param labelString a {@link java.lang.String} object.
585
	 * @param initialText a {@link java.lang.String} object.
586
	 * @param style a int.
587
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
588
	 * @return a {@link eu.etaxonomy.taxeditor.forms.TextWithLabelElement} object.
589
	 */
590
	public TextWithLabelElement createTextWithLabelElement(ICdmFormElement parentElement, String labelString, String initialText, int style){
591
		TextWithLabelElement element = new TextWithLabelElement(this, parentElement, labelString, initialText, null, style);
592
		adapt(element);
593
		parentElement.addElement(element);
594
		return element;
595
	}
596
	
597
	/**
598
	 * <p>createIntegerTextWithLabelElement</p>
599
	 *
600
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
601
	 * @param labelString a {@link java.lang.String} object.
602
	 * @param initialInteger a {@link java.lang.Integer} object.
603
	 * @param style a int.
604
	 * @return a {@link eu.etaxonomy.taxeditor.forms.NumberWithLabelElement} object.
605
	 */
606
	public NumberWithLabelElement createIntegerTextWithLabelElement(ICdmFormElement parentElement, String labelString, Integer initialInteger, int style){
607
		NumberWithLabelElement element = new NumberWithLabelElement(this, parentElement, labelString, initialInteger, style);
608
		adapt(element);
609
		parentElement.addElement(element);
610
		return element;
611
	}
612
	
613

    
614
	/**
615
	 * <p>createFloatTextWithLabelElement</p>
616
	 *
617
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
618
	 * @param labelString a {@link java.lang.String} object.
619
	 * @param initialFloat a float.
620
	 * @param style a int.
621
	 * @return a {@link eu.etaxonomy.taxeditor.forms.NumberWithLabelElement} object.
622
	 */
623
	public NumberWithLabelElement createFloatTextWithLabelElement(
624
			ICdmFormElement parentElement, String labelString, float initialFloat,
625
			int style) {
626
		NumberWithLabelElement element = new NumberWithLabelElement(this, parentElement, labelString, initialFloat, style);
627
		adapt(element);
628
		parentElement.addElement(element);
629
		return element;
630
	}
631
	
632
	/**
633
	 * <p>createLanguageStringWithLabelElement</p>
634
	 *
635
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
636
	 * @param labelString a {@link java.lang.String} object.
637
	 * @param languageString a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
638
	 * @param style a int.
639
	 * @return a {@link eu.etaxonomy.taxeditor.forms.LanguageStringWithLabelElement} object.
640
	 */
641
	public LanguageStringWithLabelElement createLanguageStringWithLabelElement(ICdmFormElement parentElement, String labelString, LanguageString languageString, int style){
642
		LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(this, parentElement, labelString, languageString, style);
643
		adapt(element);
644
		parentElement.addElement(element);
645
		return element;
646
	}
647
	
648
	/**
649
	 * <p>createLanguageStringWithLabelElement</p>
650
	 *
651
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
652
	 * @param labelString a {@link java.lang.String} object.
653
	 * @param languageString a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
654
	 * @param height a int.
655
	 * @param style a int.
656
	 * @return a {@link eu.etaxonomy.taxeditor.forms.LanguageStringWithLabelElement} object.
657
	 */
658
	public LanguageStringWithLabelElement createLanguageStringWithLabelElement(ICdmFormElement parentElement, String labelString, LanguageString languageString, int height, int style){
659
		LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(this, parentElement, labelString, languageString, height, style);
660
		adapt(element);
661
		parentElement.addElement(element);
662
		return element;
663
	}
664
	
665
	/**
666
	 * <p>createTextElement</p>
667
	 *
668
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
669
	 * @param initialText a {@link java.lang.String} object.
670
	 * @param style a int.
671
	 * @return a {@link eu.etaxonomy.taxeditor.forms.TextWithLabelElement} object.
672
	 */
673
	public TextWithLabelElement createTextElement(ICdmFormElement parentElement, String initialText, int style){
674
		TextWithLabelElement element = new TextWithLabelElement(this, parentElement, null, initialText, null, style);
675
		adapt(element);
676
		parentElement.addElement(element);
677
		return element;
678
	}
679
	
680
	/**
681
	 * <p>createKeyValueViewerElement</p>
682
	 *
683
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
684
	 * @param keyHeading a {@link java.lang.String} object.
685
	 * @param valueHeading a {@link java.lang.String} object.
686
	 * @param map a {@link java.util.Map} object.
687
	 * @return a {@link eu.etaxonomy.taxeditor.forms.KeyValueViewerElement} object.
688
	 */
689
	public KeyValueViewerElement createKeyValueViewerElement(ICdmFormElement parentElement, String keyHeading, String valueHeading, Map<Object, Object> map){
690
		KeyValueViewerElement element = new KeyValueViewerElement(this, parentElement, keyHeading, valueHeading, map);
691
		adapt(element);
692
		parentElement.addElement(element);
693
		return element;
694
	}
695
	
696
	
697
	public static enum TermComboType{
698
		EXTENSIONTYPE,
699
		LANGUAGE,
700
		MARKERTYPE,
701
		NOMENCLATURALSTATUSTYPE,
702
		RANK,
703
		RIGHTSTYPE, 
704
		NAMERELATIONSHIP, 
705
		NAMEDAREATYPE, 
706
		PRESENCEABSENCESTATUS, 
707
		ANNOTATIONTYPE,
708
		NAMETYPEDESIGNATIONSTATUS,
709
		SPECIMENTYPEDESIGNATIONSTATUS,
710
		SEX,
711
		STAGE,
712
		PRESERVATION_METHOD,
713
		MEASUREMENT_UNIT,
714
		STATE, 
715
		MODIFIER, 
716
		STATISTICAL_MEASURE, 
717
		SCOPE,
718
		EMPTY, 
719
		DETERMINATION_MODIFIER, 
720
		REFERENCE_SYSTEM
721
	}
722
	
723
	/**
724
	 * <p>createTermComboElement</p>
725
	 *
726
	 * @param termComboType a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory.TermComboType} object.
727
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
728
	 * @param labelString a {@link java.lang.String} object.
729
	 * @param selection a {@link eu.etaxonomy.cdm.model.common.DefinedTermBase} object.
730
	 * @param style a int.
731
	 * @return a {@link eu.etaxonomy.taxeditor.forms.term.AbstractTermComboElement} object.
732
	 */
733
	public AbstractTermComboElement createTermComboElement(TermComboType termComboType, ICdmFormElement parentElement, String labelString, DefinedTermBase selection, int style){
734
		AbstractTermComboElement element = null;
735
		
736
		switch(termComboType){
737
		case EMPTY:
738
			element = new EmptyComboElement<DefinedTermBase>(this, parentElement, labelString, style);
739
			break;
740
		case EXTENSIONTYPE:
741
			element = new ExtensionTypeComboElement(this, parentElement, labelString, (ExtensionType) selection, style);
742
			break;
743
		case LANGUAGE:
744
			element = new LanguageComboElement(this, parentElement, labelString, (Language) selection, style);
745
			break;
746
		case MARKERTYPE:
747
			element = new MarkerTypeComboElement(this, parentElement, labelString, (MarkerType) selection, style);
748
			break;
749
		case NOMENCLATURALSTATUSTYPE:
750
			element = new NomenclaturalStatusTypeComboElement(this, parentElement, labelString, (NomenclaturalStatusType) selection, style);
751
			break;
752
		case RANK:
753
			element = new RankComboElement(this, parentElement, labelString, (Rank) selection, style);
754
			break;
755
		case RIGHTSTYPE:
756
			element = new RightsTypeComboElement(this, parentElement, labelString, (RightsTerm) selection, style);
757
			break;
758
		case NAMERELATIONSHIP:
759
			element = new NameRelationshipTypeComboElement(this, parentElement, labelString, (NameRelationshipType) selection, style);
760
			break;
761
		case NAMEDAREATYPE:
762
			element = new NamedAreaTypeComboElement(this, parentElement, labelString, (NamedAreaType) selection, style);
763
			break;
764
		case ANNOTATIONTYPE:
765
			element = new AnnotationTypeComboElement(this, parentElement, labelString, (AnnotationType) selection, style);
766
			break;
767
		case PRESENCEABSENCESTATUS:
768
			element = new PresenceAbsenceTermComboElement(this, parentElement, labelString, (PresenceAbsenceTermBase) selection, style);
769
			break;
770
		case NAMETYPEDESIGNATIONSTATUS:
771
			element = new NameTypeDesignationStatusComboElement(this, parentElement, labelString, (NameTypeDesignationStatus) selection, style);
772
			break;
773
		case SPECIMENTYPEDESIGNATIONSTATUS:
774
			element = new SpecimenTypeDesignationStatusComboElement(this, parentElement, labelString, (SpecimenTypeDesignationStatus) selection, style);
775
			break;
776
		case SEX:
777
			element = new SexComboElement(this, parentElement, labelString, (Sex) selection, style);
778
			break;
779
		case STAGE:
780
			element = new StageComboElement(this, parentElement, labelString, (Stage) selection, style);
781
			break;
782
		case PRESERVATION_METHOD:
783
			element = new PreservationMethodComboElement(this, parentElement, labelString, (PreservationMethod) selection, style);
784
			break;
785
		case MEASUREMENT_UNIT:
786
			element = new MeasurementUnitComboElement(this, parentElement, labelString, (MeasurementUnit) selection, style);
787
			break;
788
		case STATE:
789
			element = new StateComboElement(this, parentElement, labelString, (State) selection, style);
790
			break;
791
		case SCOPE:
792
			element = new ScopeComboElement(this, parentElement, labelString, (Scope) selection, style);
793
			break;
794
		case MODIFIER:
795
			element = new ModifierComboElement(this, parentElement, labelString, (Modifier) selection, style);
796
			break;
797
		case STATISTICAL_MEASURE:
798
			element = new StatisticalMeasureComboElement(this, parentElement, labelString, (StatisticalMeasure) selection, style);
799
			break;
800
		case DETERMINATION_MODIFIER:
801
			element = new DeterminationModifierComboElement(this, parentElement, labelString, (DeterminationModifier) selection, style);
802
			break;
803
		case REFERENCE_SYSTEM:
804
			element = new ReferenceSystemComboElement(this, parentElement, labelString, (ReferenceSystem) selection, style);
805
			break;
806
		}
807
		
808
		adapt(element);
809
		parentElement.addElement(element);
810
		return element;
811
	}
812
	
813
	public static enum EnumComboType{
814
		REFERENCETYPE, 
815
		NOMENCLATURALCODE
816
	}
817
	
818
	/**
819
	 * <p>createEnumComboElement</p>
820
	 *
821
	 * @param enumComboType a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory.EnumComboType} object.
822
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
823
	 * @param style a int.
824
	 * @return a {@link eu.etaxonomy.taxeditor.forms.term.AbstractEnumComboElement} object.
825
	 */
826
	public AbstractEnumComboElement createEnumComboElement(EnumComboType enumComboType, ICdmFormElement parentElement, int style){
827
		AbstractEnumComboElement element = null;
828

    
829
		switch(enumComboType){
830
		case REFERENCETYPE:
831
			element = new ReferenceTypeComboElement(this, parentElement, "Reference Type", null, style);
832
			break;
833
		case NOMENCLATURALCODE:
834
			element = new NomenclaturalCodeComboElement(this, parentElement, "Nomenclatural Code", null, style);
835
			break;
836
		}
837
		adapt(element);
838
		parentElement.addElement(element);
839
		return element;
840
	}	
841
	
842
	/**
843
	 * <p>createBrowserElement</p>
844
	 *
845
	 * @param imageUri a {@link java.net.URI} object.
846
	 * @param style a int.
847
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
848
	 * @return a {@link eu.etaxonomy.taxeditor.forms.BrowserElement} object.
849
	 */
850
	public BrowserElement createBrowserElement(ICdmFormElement parentElement, URI imageUri, int style){
851
		BrowserElement element = new BrowserElement(this, parentElement, imageUri, style);
852
		adapt(element);
853
		parentElement.addElement(element);
854
		return element;
855
	}
856
	
857
	/**
858
	 * <p>createImageElement</p>
859
	 *
860
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
861
	 * @param imageUri a {@link java.net.URI} object.
862
	 * @param style a int.
863
	 * @return a {@link eu.etaxonomy.taxeditor.forms.ImageElement} object.
864
	 */
865
	public ImageElement createImageElement(ICdmFormElement parentElement, URI imageUri, int style) {
866
		ImageElement element = new ImageElement(this, parentElement, imageUri, style);
867
		adapt(element);
868
		parentElement.addElement(element);
869
		return element;
870
	}
871
	
872
	/**
873
	 * <p>createTextActionElement</p>
874
	 *
875
	 * @param labelString a {@link java.lang.String} object.
876
	 * @param initialText a {@link java.lang.String} object.
877
	 * @param style a int.
878
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
879
	 * @param buttonLabel a {@link java.lang.String} object.
880
	 * @return a {@link eu.etaxonomy.taxeditor.forms.TextActionElement} object.
881
	 */
882
	public TextActionElement createTextActionElement(ICdmFormElement parentElement, String labelString, String buttonLabel, String initialText, int style){
883
		TextActionElement element = new TextActionElement(this, parentElement, labelString, buttonLabel, initialText, style);
884
		adapt(element);
885
		parentElement.addElement(element);
886
		return element;
887
	}
888
	
889
	/**
890
	 * 	
891
	 * @author n.hoffmann
892
	 * @created Mar 5, 2010
893
	 * @version 1.0
894
	 */
895
	public static enum SelectionType{
896
		AGENT,
897
		INSTITUTION,
898
		NAME,
899
		REFERENCE,
900
		TAXON_BASE,
901
		TEAM, 
902
		AUTHOR_TEAM,
903
		PERSON, 
904
		DERIVED_UNIT, 
905
		FIELD_OBSERVATION, 
906
		FEATURE_TREE,
907
		CLASSIFICATION,
908
		TAXON_NODE,
909
		COLLECTION
910
	}	
911
		
912
	/**
913
	 * <p>createCheckbox</p>
914
	 *
915
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
916
	 * @param label a {@link java.lang.String} object.
917
	 * @param initialState a boolean.
918
	 * @param style a int.
919
	 * @return a {@link eu.etaxonomy.taxeditor.forms.CheckboxElement} object.
920
	 */
921
	public CheckboxElement createCheckbox(ICdmFormElement parentElement, String label, boolean initialState, int style) {
922
		CheckboxElement element = new CheckboxElement(this, parentElement, label, initialState, style | orientation);
923
		adapt(element);
924
		parentElement.addElement(element);
925
		return element;
926
	}
927

    
928
	
929
	
930
	/**
931
	 * Creates a section as a part of the form.
932
	 *
933
	 * @return the section widget
934
	 * @param section a {@link eu.etaxonomy.taxeditor.forms.AbstractFormSection} object.
935
	 */
936
	public Section adapt(AbstractFormSection section) {
937
		section.setMenu(section.getLayoutComposite().getMenu());
938
		adapt(section, true, true);
939
		
940
		// handle focus and property change events for cdm use
941
		section.addFocusListener(selectionFocusHandler);
942
		section.setPropertyChangeListeners(propertyChangeListeners);
943
		
944
		if (section.getToggle() != null) {
945
			section.getToggle().setHoverDecorationColor(getColors()
946
					.getColor(IFormColors.TB_TOGGLE_HOVER));
947
			section.getToggle().setDecorationColor(getColors()
948
					.getColor(IFormColors.TB_TOGGLE));
949
		}
950
		
951
		section.setFont(boldFontHolder2.getBoldFont(section.getLayoutComposite().getFont()));
952

    
953
		if ((section.getStyle() & Section.TITLE_BAR) != 0
954
				|| (section.getStyle() & Section.SHORT_TITLE_BAR) != 0) {
955
			getColors().initializeSectionToolBarColors();
956
			section.setTitleBarBackground(getColors().getColor(IFormColors.TB_BG));
957
			section.setTitleBarBorderColor(getColors()
958
					.getColor(IFormColors.TB_BORDER));
959
		}
960
		// call setTitleBarForeground regardless as it also sets the label color
961
		section.setTitleBarForeground(getColors()
962
				.getColor(IFormColors.TB_TOGGLE));
963
		return section;
964
	}
965
	
966
	private class BoldFontHolder2 {
967
		private Font normalFont;
968

    
969
		private Font boldFont;
970

    
971
		public BoldFontHolder2() {
972
		}
973

    
974
		public Font getBoldFont(Font font) {
975
			createBoldFont(font);
976
			return boldFont;
977
		}
978

    
979
		private void createBoldFont(Font font) {
980
			if (normalFont == null || !normalFont.equals(font)) {
981
				normalFont = font;
982
				dispose();
983
			}
984
			if (boldFont == null) {
985
				boldFont = FormFonts.getInstance().getBoldFont(getColors().getDisplay(),
986
						normalFont);
987
			}
988
		}
989

    
990
		public void dispose() {
991
			if (boldFont != null) {
992
				FormFonts.getInstance().markFinished(boldFont, getColors().getDisplay());
993
				boldFont = null;
994
			}
995
		}
996
	}
997
	
998
	/**
999
	 * <p>createToggleableTextField</p>
1000
	 *
1001
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1002
	 * @param labelString a {@link java.lang.String} object.
1003
	 * @param initialText a {@link java.lang.String} object.
1004
	 * @param initialState a boolean.
1005
	 * @param style a int.
1006
	 * @return a {@link eu.etaxonomy.taxeditor.forms.ToggleableTextElement} object.
1007
	 */
1008
	public ToggleableTextElement createToggleableTextField(ICdmFormElement parentElement,
1009
			String labelString,	String initialText, boolean initialState, int style) {
1010
		ToggleableTextElement element = new ToggleableTextElement(this, parentElement,
1011
				labelString, initialText, initialState, style | orientation);
1012
		adapt(element);
1013
		parentElement.addElement(element);
1014
		return element;
1015
	}
1016
	
1017
	/**
1018
	 * <p>createTimePeriodElement</p>
1019
	 *
1020
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1021
	 * @param labelString a {@link java.lang.String} object.
1022
	 * @param timePeriod a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
1023
	 * @param style a int.
1024
	 * @return a {@link eu.etaxonomy.taxeditor.forms.TimePeriodElement} object.
1025
	 */
1026
	public TimePeriodElement createTimePeriodElement(
1027
			ICdmFormElement parentElement, String labelString, TimePeriod timePeriod, int style) {
1028
		TimePeriodElement element = new TimePeriodElement(this, parentElement, labelString, timePeriod, style);
1029
		adapt(element);
1030
		parentElement.addElement(element);
1031
		return element;
1032
	}
1033
	
1034

    
1035
	/**
1036
	 * <p>createPointElement</p>
1037
	 *
1038
	 * @param style a int.
1039
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1040
	 * @param point a {@link eu.etaxonomy.cdm.model.location.Point} object.
1041
	 * @return a {@link eu.etaxonomy.taxeditor.forms.PointElement} object.
1042
	 */
1043
	public PointElement createPointElement(ICdmFormElement parentElement,
1044
			Point point, int style) {
1045
		PointElement element = new PointElement(this, parentElement, point, style);
1046
		adapt(element);
1047
		parentElement.addElement(element);
1048
		return element;
1049
	}
1050
	
1051
	/**
1052
	 * <p>createDateDetailSection</p>
1053
	 *
1054
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1055
	 * @param style a int.
1056
	 * @return a {@link eu.etaxonomy.taxeditor.forms.DateDetailSection} object.
1057
	 */
1058
	public DateDetailSection createDateDetailSection(ICdmFormElement parentElement, int style){
1059
		DateDetailSection section = new DateDetailSection(this, parentElement, style);
1060
		parentElement.addElement(section);
1061
		adapt(section);
1062
		return section;
1063
	}
1064
	
1065
	/**
1066
	 * <p>createPartialElement</p>
1067
	 *
1068
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1069
	 * @param labelString a {@link java.lang.String} object.
1070
	 * @param partial a {@link org.joda.time.Partial} object.
1071
	 * @param style a int.
1072
	 * @return a {@link eu.etaxonomy.taxeditor.forms.PartialElement} object.
1073
	 */
1074
	public PartialElement createPartialElement(ICdmFormElement parentElement, String labelString, Partial partial, int style){
1075
		PartialElement element = new PartialElement(this, parentElement, labelString, style);
1076
		adapt(element);
1077
		parentElement.addElement(element);
1078
		return element;
1079
	}
1080

    
1081
	/**
1082
	 * <p>addSelectionListener</p>
1083
	 *
1084
	 * @param listener a {@link org.eclipse.swt.events.SelectionListener} object.
1085
	 */
1086
	public void addSelectionListener(SelectionListener listener){
1087
		selectionListenerList.add(listener);
1088
	}
1089
	
1090
	/**
1091
	 * <p>removeSelectionListener</p>
1092
	 *
1093
	 * @param listener a {@link org.eclipse.swt.events.SelectionListener} object.
1094
	 */
1095
	public void removeSelectionListener(SelectionListener listener){
1096
		if(listener == null){
1097
			EditorUtil.error(this.getClass(), "Tried to remove a selection listener from this factories listeners but was null", null);
1098
		}else{
1099
			selectionListenerList.remove(listener);
1100
		}
1101
	}
1102
	
1103
	/**
1104
	 * <p>addPropertyChangeListener</p>
1105
	 *
1106
	 * @param listener a {@link org.eclipse.jface.util.IPropertyChangeListener} object.
1107
	 */
1108
	public void addPropertyChangeListener(IPropertyChangeListener listener) {
1109
		propertyChangeListeners.add(listener);
1110
	}
1111
	
1112
	/**
1113
	 * <p>removePropertyChangeListener</p>
1114
	 *
1115
	 * @param listener a {@link org.eclipse.jface.util.IPropertyChangeListener} object.
1116
	 */
1117
	public void removePropertyChangeListener(IPropertyChangeListener listener){
1118
		propertyChangeListeners.remove(listener);
1119
	}
1120

    
1121

    
1122

    
1123
	/**
1124
	 * <p>createHorizontalSeparator</p>
1125
	 *
1126
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1127
	 * @param style a int.
1128
	 * @return a {@link org.eclipse.swt.widgets.Label} object.
1129
	 */
1130
	public Label createHorizontalSeparator(ICdmFormElement parentElement, int style) {
1131
		Label separator = this.createSeparator(parentElement.getLayoutComposite(), SWT.HORIZONTAL | style);
1132
		separator.setLayoutData(FILL_HORIZONTALLY());
1133
		return separator;
1134
	}
1135
	
1136
	/**
1137
	 * <p>createVersionElement</p>
1138
	 *
1139
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1140
	 * @param entity a {@link eu.etaxonomy.cdm.model.common.VersionableEntity} object.
1141
	 * @param style a int.
1142
	 * @return a {@link eu.etaxonomy.taxeditor.section.supplemental.VersionElement} object.
1143
	 */
1144
	public VersionElement createVersionElement(ICdmFormElement parentElement, VersionableEntity entity,
1145
			int style) {
1146
		VersionElement element = new VersionElement(this, parentElement, entity, style);
1147
		adapt(element);
1148
		parentElement.addElement(element);
1149
		return element;
1150
	}
1151

    
1152
	/**
1153
	 * <p>createVersionSection</p>
1154
	 *
1155
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1156
	 * @param style a int.
1157
	 * @return a {@link eu.etaxonomy.taxeditor.section.supplemental.VersionSection} object.
1158
	 */
1159
	public VersionSection createVersionSection(ICdmFormElement parentElement, int style) {
1160
		VersionSection section = new VersionSection(this, parentElement, style);
1161
		parentElement.addElement(section);
1162
		adapt(section);
1163
		return section;
1164
	}
1165
	
1166
	/**
1167
	 * <p>createEmptyElement</p>
1168
	 *
1169
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1170
	 * @return a {@link eu.etaxonomy.taxeditor.section.EmptyElement} object.
1171
	 */
1172
	public EmptyElement createEmptyElement(ICdmFormElement parentElement) {
1173
		EmptyElement element = new EmptyElement(this, parentElement, null, SWT.NULL);
1174
		adapt(element);
1175
		parentElement.addElement(element);
1176
		return element;
1177
	}
1178
	
1179
	/**
1180
	 * <p>createHeadlineSection</p>
1181
	 *
1182
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1183
	 * @return a {@link eu.etaxonomy.taxeditor.section.supplemental.HeadlineSection} object.
1184
	 */
1185
	public HeadlineSection createHeadlineSection(ICdmFormElement parentElement) {
1186
		HeadlineSection section = new HeadlineSection(this, parentElement, SWT.NULL);
1187
		parentElement.addElement(section);
1188
		adapt(section);
1189
		return section;
1190
	}
1191

    
1192

    
1193
	/**
1194
	 * <p>createParsingMessageElement</p>
1195
	 *
1196
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1197
	 * @param parserProblem a {@link eu.etaxonomy.cdm.strategy.parser.ParserProblem} object.
1198
	 * @param style a int.
1199
	 * @return a {@link eu.etaxonomy.taxeditor.section.taxon.ParsingMessageElement} object.
1200
	 */
1201
	public ParsingMessageElement createParsingMessageElement(
1202
			ICdmFormElement parentElement, ParserProblem parserProblem, int style) {
1203
		ParsingMessageElement element = new ParsingMessageElement(this, parentElement, parserProblem, style);
1204
		adapt(element);
1205
		parentElement.addElement(element);
1206
		return element;
1207
	}
1208

    
1209
	
1210
	// SIMPLIFY
1211
	
1212
	/**
1213
	 * 
1214
	 */
1215
	public static enum DetailType{
1216
		NONVIRALNAME,
1217
		SCIENTIFICNAME,
1218
		REFERENCEBASE,
1219
		NOMENCLATURALREFERENCE,
1220
		TAXONBASE,
1221
		AUTHORSHIP,
1222
		TEAM,
1223
		PERSON,
1224
		DESCRIPTION,
1225
		DESCRIPTIONELEMENT, 
1226
		PARSINGMESSAGE,
1227
		NAMERELATIONSHIP, 
1228
		TEAMORPERSONBASE,
1229
		MEDIA, 
1230
		FIELD_OBSERVATION, 
1231
		DERIVED_UNIT_FACADE, 
1232
		GATHERING_EVENT, 
1233
		DERIVED_UNIT, NATURAL_LANGUAGE, 
1234
		FEATURE_DISTRIBUTION,
1235
		CLASSIFICATION,
1236
		TAXON_NODE, 
1237
		COLLECTION
1238
	}
1239
	
1240
	/**
1241
	 * <p>createCdmDetailSection</p>
1242
	 *
1243
	 * @param detailType a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory.DetailType} object.
1244
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1245
	 * @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
1246
	 * @param style a int.
1247
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
1248
	 * @return a {@link eu.etaxonomy.taxeditor.forms.AbstractFormSection} object.
1249
	 */
1250
	public AbstractFormSection createCdmDetailSection(DetailType detailType, ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1251
		AbstractFormSection section = null;
1252
		
1253
		switch(detailType){
1254
		case SCIENTIFICNAME:
1255
			section = new NameDetailSection(this, conversation, parentElement, selectionProvider, style);
1256
			break;
1257
		case REFERENCEBASE:
1258
			section = new ReferenceBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
1259
			break;
1260
		case NOMENCLATURALREFERENCE:
1261
			section = new NomenclaturalReferenceDetailSection(this, conversation, parentElement, selectionProvider, style);
1262
			break;
1263
		case TAXONBASE:
1264
			section = new TaxonBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
1265
			break;
1266
		case AUTHORSHIP:
1267
			section = new AuthorshipDetailSection(this, conversation, parentElement, selectionProvider, style);
1268
			break;
1269
		case TEAMORPERSONBASE:
1270
			section = new TeamOrPersonBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
1271
			break;
1272
		case TEAM:
1273
			section = new TeamDetailSection(this, conversation, parentElement, null, style);
1274
			break;
1275
		case PERSON:
1276
			section = new PersonDetailSection(this, conversation, parentElement, null, style);
1277
			break;
1278
		case DESCRIPTION:
1279
			section = new DescriptionDetailSection(this, conversation, parentElement, selectionProvider, style);
1280
			break;
1281
		case DESCRIPTIONELEMENT:
1282
			section = new DescriptionElementDetailSection(this, conversation, parentElement, selectionProvider, style);
1283
			break;
1284
		case PARSINGMESSAGE:
1285
			section = new ParsingMessagesSection(this, conversation, parentElement, selectionProvider, style);
1286
			break;
1287
		case NONVIRALNAME:
1288
			section = new NonViralNameDetailSection(this, conversation, parentElement, selectionProvider, style);
1289
			break;
1290
		case MEDIA:
1291
			section = new eu.etaxonomy.taxeditor.section.description.MediaDetailsSection(this, conversation, parentElement, selectionProvider, style);
1292
			break;
1293
		case DERIVED_UNIT_FACADE:
1294
			section = new DerivedUnitFacadeDetailSection(this, conversation, parentElement, selectionProvider, style);
1295
			break;
1296
		case FIELD_OBSERVATION:
1297
			section = new FieldObservationDetailSection(this, conversation, parentElement, selectionProvider, style);
1298
			break;
1299
		case GATHERING_EVENT:
1300
			section = new GatheringEventDetailSection(this, conversation, parentElement, selectionProvider, style);
1301
			break;
1302
		case DERIVED_UNIT:
1303
			section = new DerivedUnitBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
1304
			break;
1305
		case NATURAL_LANGUAGE:
1306
			section = new NaturalLanguageSection(this, conversation, parentElement, selectionProvider, style);
1307
			break;
1308
		case FEATURE_DISTRIBUTION:
1309
			section = new FeatureDistributionDetailSection(this, conversation, parentElement, selectionProvider, style);
1310
			break;
1311
		case CLASSIFICATION:
1312
			section = new ClassificationDetailSection(this, conversation, parentElement, selectionProvider, style);
1313
			break;
1314
		case TAXON_NODE:
1315
			section = new TaxonNodeDetailSection(this, conversation, parentElement, selectionProvider, style);
1316
			break;
1317
		}
1318
		parentElement.addElement(section);
1319
		adapt(section);
1320
		return section;
1321
	}
1322
	
1323
	/**
1324
	 * <p>createCdmDetailElement</p>
1325
	 *
1326
	 * @param detailType a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory.DetailType} object.
1327
	 * @param style a int.
1328
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1329
	 * @return a {@link eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement} object.
1330
	 */
1331
	public AbstractCdmDetailElement createCdmDetailElement(DetailType detailType, ICdmFormElement parentElement, int style){
1332
		AbstractCdmDetailElement element = null;
1333
		
1334
		switch(detailType){
1335
		case SCIENTIFICNAME:
1336
			element = new NameDetailElement(this, parentElement, style);
1337
			break;
1338
		case REFERENCEBASE:
1339
			element = new ReferenceBaseDetailElement(this, parentElement, style);
1340
			break;
1341
		case NOMENCLATURALREFERENCE:
1342
			element = new NomenclaturalReferenceDetailElement(this, parentElement, style);
1343
			break;
1344
		case TAXONBASE:
1345
			element = new TaxonBaseDetailElement(this, parentElement, style);
1346
			break;
1347
		case AUTHORSHIP:
1348
			element = new AuthorshipDetailElement(this, parentElement, style);
1349
			break;
1350
		case TEAM:
1351
			element = new TeamDetailElement(this, parentElement, style);
1352
			break;
1353
		case PERSON:
1354
			element = new PersonDetailElement(this, parentElement, style);
1355
			break;
1356
		case DESCRIPTION:
1357
			element = new DescriptionDetailElement(this, parentElement, style);
1358
			break;
1359
		case DESCRIPTIONELEMENT:
1360
			element = new DescriptionElementDetailElement(this, parentElement, style);
1361
			break;
1362
		case NONVIRALNAME:
1363
			element = new NonViralNameDetailElement(this, parentElement);
1364
			break;
1365
		case DERIVED_UNIT_FACADE:
1366
			element = new DerivedUnitFacadeDetailElement(this, parentElement);
1367
			break;
1368
		case FIELD_OBSERVATION:
1369
			element = new FieldObservationDetailElement(this, parentElement);
1370
			break;
1371
		case GATHERING_EVENT:
1372
			element = new GatheringEventDetailElement(this, parentElement);
1373
			break;
1374
		case DERIVED_UNIT:
1375
			element = new DerivedUnitBaseDetailElement(this, parentElement);
1376
			break;
1377
		case NATURAL_LANGUAGE:
1378
			element = new NaturalLanguageDetailElement(this, parentElement);
1379
			break;
1380
		case FEATURE_DISTRIBUTION:
1381
			element = new FeatureDistributionDetailElement(this, parentElement);
1382
			break;
1383
		case CLASSIFICATION:
1384
			element = new ClassificationDetailElement(this, parentElement);
1385
			break;
1386
		case TAXON_NODE:
1387
			element = new TaxonNodeDetailElement(this, parentElement);
1388
			break;
1389
		case COLLECTION:
1390
			element = new CollectionDetailElement(this, parentElement);
1391
			break;
1392
		}
1393
		
1394
		if(element == null){
1395
			EditorUtil.error(this.getClass(), "Detail element was not created. Seems like the case was not implemented for the requested detail type: " + detailType, null);
1396
		}
1397
		
1398
		adapt(element);
1399
		parentElement.addElement(element);
1400
		return element;
1401
	}
1402
	
1403
	/**
1404
	 * 
1405
	 * @author n.hoffmann
1406
	 * @created Mar 5, 2010
1407
	 * @version 1.0
1408
	 */
1409
	public static enum EntityDetailType{
1410
		TEAM,
1411
		TEAMMEMBER,
1412
		ANNOTATION,
1413
		CREDIT,
1414
		DESCRIPTIONELEMENTSOURCE,
1415
		EXTENSION,
1416
		MARKER,
1417
		MEDIA, 
1418
		DESCRIPTIONELEMENTMEDIA,
1419
		MEDIAREPRESENTATION,
1420
		MEDIAREPRESENTATIONPART,
1421
		MODIFIER,
1422
		NOMENCLATURALSTATUS,
1423
		NAME_RELATIONSHIP,
1424
		PROTOLOG,
1425
		RIGHTS,
1426
		SOURCE, 
1427
		SCOPE, 
1428
		DESCRIPTIONSOURCE, 
1429
		TYPEDESIGNATION,
1430
		STATE_DATA, 
1431
		STATISTICAL_MEASUREMENT_VALUE, 
1432
		DESCRIBED_SPECIMEN, 
1433
		COLLECTING_AREA, 
1434
		DETERMINATION_EVENT, 
1435
		SPECIMEN_COLLECTION, 
1436
		IDENTIFIABLE_SOURCE_COLLECTION
1437
	}
1438
	
1439
	/**
1440
	 * <p>createEntityDetailSection</p>
1441
	 *
1442
	 * @param entityDetailType a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory.EntityDetailType} object.
1443
	 * @param style a int.
1444
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
1445
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1446
	 * @return a {@link eu.etaxonomy.taxeditor.forms.AbstractFormSection} object.
1447
	 */
1448
	public AbstractFormSection createEntityDetailSection(EntityDetailType entityDetailType, ConversationHolder conversation, ICdmFormElement parentElement, int style){
1449
		AbstractFormSection section = null;
1450
		
1451
		switch(entityDetailType){
1452
		case TEAM:
1453
			section = new TeamDetailSection(this, conversation, parentElement, null, style);
1454
			break;
1455
		case TEAMMEMBER:
1456
			section = new TeamMemberSection(this, conversation, parentElement, style);
1457
			break;
1458
		case ANNOTATION:
1459
			section = new AnnotationSection(this, conversation, parentElement, style);
1460
			break;
1461
		case CREDIT:
1462
			section = new CreditSection(this, conversation, parentElement, style);
1463
			break;
1464
		case DESCRIPTIONELEMENTSOURCE:
1465
			section = new DescriptionElementSourceSection(this, conversation, parentElement, style);
1466
			break;
1467
		case EXTENSION:
1468
			section = new ExtensionSection(this, conversation, parentElement, style);
1469
			break;
1470
		case MARKER:
1471
			section = new MarkerSection(this, conversation, parentElement, style);
1472
			break;
1473
		case MEDIA:
1474
			section = new MediaSection(this, conversation, parentElement, style);
1475
			break;
1476
		case DESCRIPTIONELEMENTMEDIA:
1477
			section = new DescriptionElementMediaSection(this, conversation, parentElement, style);
1478
			break;
1479
		case MEDIAREPRESENTATION:
1480
			section = new MediaRepresentationSection(this, conversation, parentElement, style);
1481
			break;
1482
		case MEDIAREPRESENTATIONPART:
1483
			section = new MediaRepresentationPartSection(this, conversation, parentElement, style);
1484
			break;
1485
		case MODIFIER:
1486
			section = new ModifierSection(this, conversation, parentElement, style);
1487
			break;
1488
		case NOMENCLATURALSTATUS:
1489
			section = new NomenclaturalStatusSection(this, conversation, parentElement, style);
1490
			break;
1491
		case NAME_RELATIONSHIP:
1492
			section = new NameRelationshipDetailSection(this, conversation, parentElement, style);
1493
			break;
1494
		case PROTOLOG:
1495
			section = new ProtologueSection(this, conversation, parentElement, style);
1496
			break;
1497
		case RIGHTS:
1498
			section = new RightsSection(this, conversation, parentElement, style);
1499
			break;
1500
		case SOURCE:
1501
			section = new SourceSection(this, conversation, parentElement, style);
1502
			break;
1503
		case SCOPE:
1504
			section = new ScopeSection(this, conversation, parentElement, style);
1505
			break;
1506
		case DESCRIPTIONSOURCE:
1507
			section = new DescriptionSourceSection(this, conversation, parentElement, style);
1508
			break;
1509
		case TYPEDESIGNATION:
1510
			section = new TypeDesignationSection(this, conversation, parentElement, style);
1511
			break;
1512
		case STATE_DATA:
1513
			section = new StateDataSection(this, conversation, parentElement, style);
1514
			break;
1515
		case STATISTICAL_MEASUREMENT_VALUE:
1516
			section = new StatisticalMeasurementValueSection(this, conversation, parentElement, style);
1517
			break;
1518
		case DESCRIBED_SPECIMEN:
1519
			section = new DescribedSpecimenSection(this, conversation, parentElement, style);
1520
			break;
1521
		case COLLECTING_AREA:
1522
			section = new CollectingAreasDetailSection(this, conversation, parentElement, style);
1523
			break;
1524
		case DETERMINATION_EVENT:
1525
			section = new DeterminationEventDetailSection(this, conversation, parentElement, style);
1526
			break;
1527
		case SPECIMEN_COLLECTION:
1528
			section = new SpecimenCollectionDetailSection(this, conversation, parentElement, style);
1529
			break;
1530
		case IDENTIFIABLE_SOURCE_COLLECTION:
1531
			section = new SourceCollectionDetailSection(this, conversation, parentElement, style);
1532
			break;
1533
			
1534
		}
1535
		parentElement.addElement(section);
1536
		adapt(section);
1537
		return section;
1538
	}
1539
	
1540
	/**
1541
	 * <p>createEntityCollectionElement</p>
1542
	 *
1543
	 * @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
1544
	 * @param style a int.
1545
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.AbstractFormSection} object.
1546
	 * @param versionableEntity a {@link eu.etaxonomy.cdm.model.common.IVersionableEntity} object.
1547
	 * @param backgroundColor a {@link org.eclipse.swt.graphics.Color} object.
1548
	 * @return a {@link eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement} object.
1549
	 */
1550
	public AbstractEntityCollectionElement createEntityCollectionElement(AbstractFormSection parentElement, IVersionableEntity versionableEntity, SelectionListener removeListener, Color backgroundColor, int style){
1551
		AbstractEntityCollectionElement element = null;
1552
		
1553
		VersionableEntity entity = (VersionableEntity) HibernateProxyHelper.deproxy(versionableEntity);
1554
		
1555
		if(entity instanceof Annotation){
1556
			element = new AnnotationElement(this, parentElement, (Annotation) entity, removeListener, style);
1557
		}
1558
		else if(entity instanceof Person){
1559
			element = new TeamMemberElement(this, parentElement, (Person) entity, removeListener, style);
1560
		}
1561
		else if(entity instanceof Credit){
1562
			element = new CreditElement(this, parentElement, (Credit) entity, removeListener, style);
1563
		}
1564
		else if(entity instanceof Extension){
1565
			element = new ExtensionElement(this, parentElement, (Extension) entity, removeListener, style);
1566
		}
1567
		else if(entity instanceof Marker){
1568
			element = new MarkerElement(this, parentElement, (Marker) entity, removeListener, style);
1569
		}
1570
		else if(entity instanceof Media){
1571
			element = new MediaElement(this, parentElement, (Media) entity, removeListener, style);
1572
		}
1573
		else if(entity instanceof MediaRepresentation){
1574
			element = new MediaRepresentationElement(this, parentElement, (MediaRepresentation) entity, removeListener, style);
1575
		}
1576
		else if(entity instanceof ImageFile){
1577
			element = new ImageFileElement(this, parentElement, (ImageFile) entity, removeListener, style);
1578
		}
1579
		else if(entity instanceof NomenclaturalStatus){
1580
			element = new NomenclaturalStatusElement(this, parentElement, (NomenclaturalStatus) entity, removeListener, style);
1581
		}
1582
		else if(entity instanceof Rights){
1583
			element = new RightsElement(this, parentElement, (Rights) entity, removeListener, style);
1584
		}
1585
		else if(entity instanceof DescriptionElementSource){
1586
			element = new DescriptionElementSourceElement(this, parentElement, (DescriptionElementSource) entity, removeListener, style);
1587
		}
1588
		else if(entity instanceof IdentifiableSource){
1589
			element = new IdentifiableSourceElement(this, parentElement, (IdentifiableSource) entity, removeListener, style);
1590
		}
1591
		else if(entity instanceof Scope){
1592
			element = new ScopeElement(this, parentElement, (Scope) entity, removeListener, style);
1593
		}
1594
		else if(entity instanceof Modifier){
1595
			element = new ModifierElement(this, parentElement, (Modifier) entity, removeListener, style);
1596
		}
1597
		else if(entity instanceof ReferenceBase){
1598
			element = new DescriptionSourceElement(this, parentElement, (ReferenceBase) entity, removeListener, style);
1599
		}
1600
		else if(entity instanceof NameTypeDesignation){
1601
			element = new NameTypeDesignationElement(this, parentElement, (NameTypeDesignation) entity, removeListener, style);
1602
		}
1603
		else if(entity instanceof NameRelationship){
1604
			element = new NameRelationshipDetailElement(this, parentElement, (NameRelationship) entity, removeListener, style);
1605
		}
1606
		else if(entity instanceof SpecimenTypeDesignation){
1607
			element = new SpecimenTypeDesignationElement(this, parentElement, (SpecimenTypeDesignation) entity, removeListener, style);
1608
		}
1609
		else if(entity instanceof StateData){
1610
			element = new StateDataElement(this, parentElement, (StateData) entity, removeListener, style);
1611
		}
1612
		else if(entity instanceof StatisticalMeasurementValue){
1613
			element = new StatisticalMeasurementValueElement(this, parentElement, (StatisticalMeasurementValue) entity, removeListener, style);
1614
		}
1615
		else if(entity instanceof DerivedUnit){
1616
			element = new DerivedUnitElement(this, parentElement, (DerivedUnit) entity, removeListener,  style);
1617
		}
1618
		else if(entity instanceof NamedArea){
1619
			element = new CollectingAreasDetailElement(this, parentElement, (NamedArea) entity, removeListener, style);
1620
		}
1621
		else if(entity instanceof DeterminationEvent){
1622
			element = new DeterminationEventDetailElement(this, parentElement, (DeterminationEvent) entity, removeListener, style);
1623
		}
1624
		else if(entity instanceof Specimen){
1625
			element = new SpecimenCollectionDetailElement(this, parentElement, (Specimen) entity, removeListener, style);
1626
		}
1627
		
1628
		else if(entity instanceof DescriptionElementBase){
1629
			// this is the special case for protologs, maybe we can do this differently when API improves
1630
			DescriptionElementBase descriptionElement = (DescriptionElementBase) entity;
1631
			if(descriptionElement.getFeature().equals(Feature.PROTOLOGUE())){
1632
				element = new ProtologueElement(this, parentElement, descriptionElement, removeListener, style);
1633
			}
1634
		}
1635
		
1636
		if(element == null){
1637
			EditorUtil.errorDialog("No element for entity", this, "Could not generate element for entity. " +
1638
					"Looks like the case is not handled already. Check implementation. Entity: " + entity, null);
1639
		}
1640
		
1641
		if(backgroundColor != null && !backgroundColor.isDisposed()){
1642
			element.setBackgroundColor(backgroundColor);
1643
		}
1644
		
1645
		adapt(element);
1646
		parentElement.addElement(element);
1647
		return element;
1648
	}
1649
	
1650
	/**
1651
	 * <p>createSelectionElement</p>
1652
	 *
1653
	 * @param selectionType a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory.SelectionType} object.
1654
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1655
	 * @param labelString a {@link java.lang.String} object.
1656
	 * @param selectionType
1657
	 * @param selection a {@link eu.etaxonomy.cdm.model.common.IAnnotatableEntity} object.
1658
	 * @param style a int.
1659
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
1660
	 * @return a {@link eu.etaxonomy.taxeditor.forms.selection.AbstractSelectionElement} object.
1661
	 */
1662
	public AbstractSelectionElement createSelectionElement(SelectionType selectionType,  ConversationHolder conversation, ICdmFormElement parentElement, String labelString, IAnnotatableEntity selection, int style){
1663
		AbstractSelectionElement element = null;
1664
		
1665
		IAnnotatableEntity entity = (IAnnotatableEntity) HibernateProxyHelper.deproxy(selection);
1666
		
1667
		switch (selectionType) {
1668
		case AGENT:
1669
			element = new AgentSelectionElement(this, conversation, parentElement, labelString, (TeamOrPersonBase) entity, style);
1670
			break;
1671
		case PERSON:
1672
			element = new PersonSelectionElement(this, conversation, parentElement, labelString, (Person) entity, style);
1673
			break;
1674
		case TEAM:
1675
			element = new TeamSelectionElement(this, conversation, parentElement, labelString, (Team) entity, style);
1676
			break;
1677
		case AUTHOR_TEAM:
1678
			element = new NomenclaturalAuthorTeamSelectionElement(this, conversation, parentElement, labelString, (Team) entity, style);
1679
			break;
1680
		case INSTITUTION:
1681
			element = new InstitutionSelectionElement(this, conversation, parentElement, labelString, (Institution) entity, style);
1682
			break;
1683
		case NAME:
1684
			element = new NameSelectionElement(this, conversation, parentElement, labelString, (TaxonNameBase) entity, style);
1685
			break;
1686
		case REFERENCE:
1687
			element = new ReferenceSelectionElement(this, conversation, parentElement, labelString, (ReferenceBase) entity, style);
1688
			break;
1689
		case TAXON_BASE:
1690
			element = new TaxonBaseSelectionElement(this, conversation, parentElement, labelString, (TaxonBase) entity, style);
1691
			break;
1692
		case DERIVED_UNIT:
1693
			element = new DerivedUnitBaseSelectionElement(this, conversation, parentElement, labelString, (DerivedUnitBase) entity, style);
1694
			break;
1695
		case FIELD_OBSERVATION:
1696
			element = new FieldObservationSelectionElement(this, conversation, parentElement, labelString, (FieldObservation) entity, style);
1697
			break;
1698
		case FEATURE_TREE:
1699
			element = new FeatureTreeSelectionElement(this, conversation, parentElement, labelString, (FeatureTree) entity, style);
1700
			break;
1701
		case CLASSIFICATION:
1702
			element = new ClassificationSelectionElement(this, conversation, parentElement, labelString, (TaxonomicTree) entity, style);
1703
			break;
1704
		case TAXON_NODE:
1705
			element = new TaxonNodeSelectionElement(this, conversation, parentElement, labelString, (TaxonNode) entity, style);
1706
			break;
1707
		case COLLECTION:
1708
			element = new CollectionSelectionElement(this, conversation, parentElement, labelString, (Collection) entity, style);
1709
			break;
1710
		default:
1711
			new RuntimeException("There is no selection composite for the desired selection type.");
1712
			break;
1713
		}
1714
		
1715
		adapt(element);
1716
		parentElement.addElement(element);
1717
		return element;
1718
	}
1719
	
1720
	/**
1721
	 * <p>createNamedAreaSelectionElement</p>
1722
	 *
1723
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1724
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
1725
	 * @param labelString a {@link java.lang.String} object.
1726
	 * @param selection a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
1727
	 * @param style a int.
1728
	 * @return a {@link eu.etaxonomy.taxeditor.forms.selection.NamedAreaSelectionElement} object.
1729
	 */
1730
	public NamedAreaSelectionElement createNamedAreaSelectionElement(ICdmFormElement parentElement, ConversationHolder conversation, String labelString, NamedArea selection, int style){
1731
		NamedAreaSelectionElement element = new NamedAreaSelectionElement(this, conversation, parentElement, labelString, selection, style);
1732
		adapt(element);
1733
		parentElement.addElement(element);
1734
		return element;
1735
	}
1736

    
1737
	/** {@inheritDoc} */
1738
	public LabelElement createLabel(ICdmFormElement parentElement, String text) {
1739
		LabelElement labelElement = new LabelElement(this, parentElement, text);
1740
		adapt(labelElement);
1741
		parentElement.addElement(labelElement);
1742
		return labelElement;
1743
	}
1744

    
1745
	/**
1746
	 * <p>Getter for the field <code>selectionProvider</code>.</p>
1747
	 *
1748
	 * @return a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
1749
	 */
1750
	public ISelectionProvider getSelectionProvider() {
1751
		return selectionProvider;
1752
	}
1753

    
1754
	/**
1755
	 * <p>createDetailedDescriptionDetailElement</p>
1756
	 *
1757
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1758
	 * @param entity a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
1759
	 * @param style a int.
1760
	 * @return a {@link eu.etaxonomy.taxeditor.section.description.detail.AbstractDetailedDescriptionDetailElement} object.
1761
	 */
1762
	public AbstractDetailedDescriptionDetailElement createDetailedDescriptionDetailElement(
1763
			ICdmFormElement parentElement, DescriptionElementBase entity, int style) {
1764
		AbstractDetailedDescriptionDetailElement detailedDescriptionElement = null;
1765
		
1766
		
1767
		if(entity instanceof CategoricalData){
1768
			detailedDescriptionElement = new CategoricalDataDetailElement(this, parentElement, (CategoricalData) entity, style);
1769
		}
1770
		else if(entity instanceof CommonTaxonName){
1771
			detailedDescriptionElement = new CommonNameDetailElement(this, parentElement, (CommonTaxonName) entity, style);
1772
		}
1773
		else if(entity instanceof Distribution){
1774
			detailedDescriptionElement = new DistributionDetailElement(this, parentElement, (Distribution) entity, style);
1775
		}
1776
		else if(entity instanceof IndividualsAssociation){
1777
			detailedDescriptionElement = new IndividualsAssociationDetailElement(this, parentElement, (IndividualsAssociation) entity, style);
1778
		}
1779
		else if(entity instanceof QuantitativeData){
1780
			detailedDescriptionElement = new QuantitativeDataDetailElement(this, parentElement, (QuantitativeData) entity, style);
1781
		}
1782
		else if(entity instanceof TaxonInteraction){
1783
			detailedDescriptionElement = new TaxonInteractionDetailElement(this, parentElement, (TaxonInteraction) entity, style);
1784
		}
1785
		else if(entity instanceof TextData){
1786
			detailedDescriptionElement = new TextDataDetailElement(this, parentElement, (TextData) entity, style);
1787
		}
1788
		else{
1789
			throw new IllegalStateException("There is no interface for the given description element");
1790
		}
1791
		adapt(detailedDescriptionElement);
1792
		parentElement.addElement(detailedDescriptionElement);
1793
		return detailedDescriptionElement;
1794
		
1795
	}
1796

    
1797
	
1798
	/**
1799
	 * Creates a styled text as a part of the form.
1800
	 *
1801
	 * @param parent
1802
	 *            the text parent
1803
	 * @param value
1804
	 *            the text initial value
1805
	 * @param style
1806
	 *            the text style
1807
	 * @return the text widget
1808
	 */
1809
	public StyledText createStyledText(Composite parent, String value, int style) {
1810
		StyledText text = new StyledText(parent, getBorderStyle() | style | getOrientation());
1811
		if (value != null)
1812
			text.setText(value);
1813
		text.setForeground(getColors().getForeground());
1814
		text.setBackground(getColors().getBackground());
1815
//		text.addFocusListener(visibilityHandler);
1816
		return text;
1817
	}
1818
}
(6-6/33)