5d76b0d0cba79d577d53532437574c2f9f341825
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / forms / CdmFormFactory.java
1 /**
2 *
3 */
4 package eu.etaxonomy.taxeditor.forms;
5
6 import java.net.URI;
7 import java.util.ArrayList;
8 import java.util.HashSet;
9 import java.util.List;
10 import java.util.Map;
11 import java.util.Set;
12
13 import org.eclipse.jface.util.IPropertyChangeListener;
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.jface.viewers.ISelectionProvider;
16 import org.eclipse.jface.window.Window;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.custom.StyledText;
19 import org.eclipse.swt.events.FocusAdapter;
20 import org.eclipse.swt.events.FocusEvent;
21 import org.eclipse.swt.events.FocusListener;
22 import org.eclipse.swt.events.MouseAdapter;
23 import org.eclipse.swt.events.MouseEvent;
24 import org.eclipse.swt.events.MouseListener;
25 import org.eclipse.swt.events.SelectionEvent;
26 import org.eclipse.swt.events.SelectionListener;
27 import org.eclipse.swt.events.TypedEvent;
28 import org.eclipse.swt.graphics.Color;
29 import org.eclipse.swt.graphics.Font;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Display;
33 import org.eclipse.swt.widgets.Event;
34 import org.eclipse.swt.widgets.Label;
35 import org.eclipse.ui.forms.IFormColors;
36 import org.eclipse.ui.forms.widgets.FormToolkit;
37 import org.eclipse.ui.forms.widgets.Section;
38 import org.eclipse.ui.forms.widgets.TableWrapData;
39 import org.eclipse.ui.forms.widgets.TableWrapLayout;
40 import org.eclipse.ui.internal.forms.widgets.FormFonts;
41 import org.joda.time.Partial;
42
43 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
44 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
45 import eu.etaxonomy.cdm.model.agent.Institution;
46 import eu.etaxonomy.cdm.model.agent.Person;
47 import eu.etaxonomy.cdm.model.agent.Team;
48 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
49 import eu.etaxonomy.cdm.model.common.Annotation;
50 import eu.etaxonomy.cdm.model.common.AnnotationType;
51 import eu.etaxonomy.cdm.model.common.Credit;
52 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
53 import eu.etaxonomy.cdm.model.common.DescriptionElementSource;
54 import eu.etaxonomy.cdm.model.common.Extension;
55 import eu.etaxonomy.cdm.model.common.ExtensionType;
56 import eu.etaxonomy.cdm.model.common.IAnnotatableEntity;
57 import eu.etaxonomy.cdm.model.common.ICdmBase;
58 import eu.etaxonomy.cdm.model.common.IVersionableEntity;
59 import eu.etaxonomy.cdm.model.common.IdentifiableSource;
60 import eu.etaxonomy.cdm.model.common.Language;
61 import eu.etaxonomy.cdm.model.common.LanguageString;
62 import eu.etaxonomy.cdm.model.common.Marker;
63 import eu.etaxonomy.cdm.model.common.MarkerType;
64 import eu.etaxonomy.cdm.model.common.TimePeriod;
65 import eu.etaxonomy.cdm.model.common.VersionableEntity;
66 import eu.etaxonomy.cdm.model.description.CategoricalData;
67 import eu.etaxonomy.cdm.model.description.CommonTaxonName;
68 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
69 import eu.etaxonomy.cdm.model.description.Distribution;
70 import eu.etaxonomy.cdm.model.description.Feature;
71 import eu.etaxonomy.cdm.model.description.FeatureTree;
72 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
73 import eu.etaxonomy.cdm.model.description.KeyStatement;
74 import eu.etaxonomy.cdm.model.description.MeasurementUnit;
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.PresenceAbsenceTermBase;
79 import eu.etaxonomy.cdm.model.description.QuantitativeData;
80 import eu.etaxonomy.cdm.model.description.Scope;
81 import eu.etaxonomy.cdm.model.description.Sex;
82 import eu.etaxonomy.cdm.model.description.Stage;
83 import eu.etaxonomy.cdm.model.description.State;
84 import eu.etaxonomy.cdm.model.description.StateData;
85 import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
86 import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
87 import eu.etaxonomy.cdm.model.description.TaxonInteraction;
88 import eu.etaxonomy.cdm.model.description.TextData;
89 import eu.etaxonomy.cdm.model.location.NamedArea;
90 import eu.etaxonomy.cdm.model.location.NamedAreaType;
91 import eu.etaxonomy.cdm.model.location.Point;
92 import eu.etaxonomy.cdm.model.location.ReferenceSystem;
93 import eu.etaxonomy.cdm.model.media.ImageFile;
94 import eu.etaxonomy.cdm.model.media.Media;
95 import eu.etaxonomy.cdm.model.media.MediaRepresentation;
96 import eu.etaxonomy.cdm.model.media.Rights;
97 import eu.etaxonomy.cdm.model.media.RightsTerm;
98 import eu.etaxonomy.cdm.model.name.NameRelationship;
99 import eu.etaxonomy.cdm.model.name.NameRelationshipType;
100 import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
101 import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
102 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
103 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
104 import eu.etaxonomy.cdm.model.name.Rank;
105 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
106 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
107 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
108 import eu.etaxonomy.cdm.model.occurrence.Collection;
109 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
110 import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
111 import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
112 import eu.etaxonomy.cdm.model.occurrence.DeterminationModifier;
113 import eu.etaxonomy.cdm.model.occurrence.FieldObservation;
114 import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
115 import eu.etaxonomy.cdm.model.occurrence.Specimen;
116 import eu.etaxonomy.cdm.model.reference.Reference;
117 import eu.etaxonomy.cdm.model.taxon.Classification;
118 import eu.etaxonomy.cdm.model.taxon.Synonym;
119 import eu.etaxonomy.cdm.model.taxon.Taxon;
120 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
121 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
122 import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
123 import eu.etaxonomy.taxeditor.editor.EditorUtil;
124 import eu.etaxonomy.taxeditor.forms.selection.AbstractSelectionElement;
125 import eu.etaxonomy.taxeditor.forms.selection.AgentSelectionElement;
126 import eu.etaxonomy.taxeditor.forms.selection.ClassificationSelectionElement;
127 import eu.etaxonomy.taxeditor.forms.selection.CollectionSelectionElement;
128 import eu.etaxonomy.taxeditor.forms.selection.DerivedUnitBaseSelectionElement;
129 import eu.etaxonomy.taxeditor.forms.selection.FeatureSelectionElement;
130 import eu.etaxonomy.taxeditor.forms.selection.FeatureTreeSelectionElement;
131 import eu.etaxonomy.taxeditor.forms.selection.FieldObservationSelectionElement;
132 import eu.etaxonomy.taxeditor.forms.selection.InstitutionSelectionElement;
133 import eu.etaxonomy.taxeditor.forms.selection.NameSelectionElement;
134 import eu.etaxonomy.taxeditor.forms.selection.NamedAreaSelectionElement;
135 import eu.etaxonomy.taxeditor.forms.selection.NomenclaturalAuthorTeamSelectionElement;
136 import eu.etaxonomy.taxeditor.forms.selection.PersonSelectionElement;
137 import eu.etaxonomy.taxeditor.forms.selection.PolytomousKeyNodeSelectionElement;
138 import eu.etaxonomy.taxeditor.forms.selection.PolytomousKeySelectionElement;
139 import eu.etaxonomy.taxeditor.forms.selection.ReferenceSelectionElement;
140 import eu.etaxonomy.taxeditor.forms.selection.SynonymSelectionElement;
141 import eu.etaxonomy.taxeditor.forms.selection.TaxonBaseSelectionElement;
142 import eu.etaxonomy.taxeditor.forms.selection.TaxonNodeSelectionElement;
143 import eu.etaxonomy.taxeditor.forms.selection.TaxonSelectionElement;
144 import eu.etaxonomy.taxeditor.forms.selection.TeamSelectionElement;
145 import eu.etaxonomy.taxeditor.forms.term.AbstractEnumComboElement;
146 import eu.etaxonomy.taxeditor.forms.term.AbstractTermComboElement;
147 import eu.etaxonomy.taxeditor.forms.term.AnnotationTypeComboElement;
148 import eu.etaxonomy.taxeditor.forms.term.DeterminationModifierComboElement;
149 import eu.etaxonomy.taxeditor.forms.term.EmptyComboElement;
150 import eu.etaxonomy.taxeditor.forms.term.ExtensionTypeComboElement;
151 import eu.etaxonomy.taxeditor.forms.term.LanguageComboElement;
152 import eu.etaxonomy.taxeditor.forms.term.MarkerTypeComboElement;
153 import eu.etaxonomy.taxeditor.forms.term.MeasurementUnitComboElement;
154 import eu.etaxonomy.taxeditor.forms.term.ModifierComboElement;
155 import eu.etaxonomy.taxeditor.forms.term.NameRelationshipTypeComboElement;
156 import eu.etaxonomy.taxeditor.forms.term.NameTypeDesignationStatusComboElement;
157 import eu.etaxonomy.taxeditor.forms.term.NamedAreaTypeComboElement;
158 import eu.etaxonomy.taxeditor.forms.term.NomenclaturalCodeComboElement;
159 import eu.etaxonomy.taxeditor.forms.term.NomenclaturalStatusTypeComboElement;
160 import eu.etaxonomy.taxeditor.forms.term.PresenceAbsenceTermComboElement;
161 import eu.etaxonomy.taxeditor.forms.term.PreservationMethodComboElement;
162 import eu.etaxonomy.taxeditor.forms.term.RankComboElement;
163 import eu.etaxonomy.taxeditor.forms.term.ReferenceSystemComboElement;
164 import eu.etaxonomy.taxeditor.forms.term.ReferenceTypeComboElement;
165 import eu.etaxonomy.taxeditor.forms.term.RightsTypeComboElement;
166 import eu.etaxonomy.taxeditor.forms.term.ScopeComboElement;
167 import eu.etaxonomy.taxeditor.forms.term.SexComboElement;
168 import eu.etaxonomy.taxeditor.forms.term.SpecimenTypeDesignationStatusComboElement;
169 import eu.etaxonomy.taxeditor.forms.term.StageComboElement;
170 import eu.etaxonomy.taxeditor.forms.term.StateComboElement;
171 import eu.etaxonomy.taxeditor.forms.term.StatisticalMeasureComboElement;
172 import eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement;
173 import eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement;
174 import eu.etaxonomy.taxeditor.section.EmptyElement;
175 import eu.etaxonomy.taxeditor.section.agent.InstitutionDetailElement;
176 import eu.etaxonomy.taxeditor.section.agent.InstitutionDetailSection;
177 import eu.etaxonomy.taxeditor.section.agent.PersonDetailElement;
178 import eu.etaxonomy.taxeditor.section.agent.PersonDetailSection;
179 import eu.etaxonomy.taxeditor.section.agent.TeamDetailElement;
180 import eu.etaxonomy.taxeditor.section.agent.TeamDetailSection;
181 import eu.etaxonomy.taxeditor.section.agent.TeamMemberElement;
182 import eu.etaxonomy.taxeditor.section.agent.TeamMemberSection;
183 import eu.etaxonomy.taxeditor.section.agent.TeamOrPersonBaseDetailSection;
184 import eu.etaxonomy.taxeditor.section.classification.ClassificationDetailElement;
185 import eu.etaxonomy.taxeditor.section.classification.ClassificationDetailSection;
186 import eu.etaxonomy.taxeditor.section.classification.TaxonNodeDetailElement;
187 import eu.etaxonomy.taxeditor.section.classification.TaxonNodeDetailSection;
188 import eu.etaxonomy.taxeditor.section.description.DerivedUnitElement;
189 import eu.etaxonomy.taxeditor.section.description.DescribedSpecimenSection;
190 import eu.etaxonomy.taxeditor.section.description.DescriptionDetailElement;
191 import eu.etaxonomy.taxeditor.section.description.DescriptionDetailSection;
192 import eu.etaxonomy.taxeditor.section.description.DescriptionElementDetailElement;
193 import eu.etaxonomy.taxeditor.section.description.DescriptionElementDetailSection;
194 import eu.etaxonomy.taxeditor.section.description.DescriptionElementMediaSection;
195 import eu.etaxonomy.taxeditor.section.description.DescriptionElementSourceElement;
196 import eu.etaxonomy.taxeditor.section.description.DescriptionElementSourceSection;
197 import eu.etaxonomy.taxeditor.section.description.DescriptionSourceElement;
198 import eu.etaxonomy.taxeditor.section.description.DescriptionSourceSection;
199 import eu.etaxonomy.taxeditor.section.description.ModifierElement;
200 import eu.etaxonomy.taxeditor.section.description.ModifierSection;
201 import eu.etaxonomy.taxeditor.section.description.NaturalLanguageDetailElement;
202 import eu.etaxonomy.taxeditor.section.description.NaturalLanguageSection;
203 import eu.etaxonomy.taxeditor.section.description.ScopeElement;
204 import eu.etaxonomy.taxeditor.section.description.ScopeSection;
205 import eu.etaxonomy.taxeditor.section.description.StateDataElement;
206 import eu.etaxonomy.taxeditor.section.description.StateDataSection;
207 import eu.etaxonomy.taxeditor.section.description.StatisticalMeasurementValueElement;
208 import eu.etaxonomy.taxeditor.section.description.StatisticalMeasurementValueSection;
209 import eu.etaxonomy.taxeditor.section.description.detail.AbstractDetailedDescriptionDetailElement;
210 import eu.etaxonomy.taxeditor.section.description.detail.CategoricalDataDetailElement;
211 import eu.etaxonomy.taxeditor.section.description.detail.CommonNameDetailElement;
212 import eu.etaxonomy.taxeditor.section.description.detail.DistributionDetailElement;
213 import eu.etaxonomy.taxeditor.section.description.detail.IndividualsAssociationDetailElement;
214 import eu.etaxonomy.taxeditor.section.description.detail.QuantitativeDataDetailElement;
215 import eu.etaxonomy.taxeditor.section.description.detail.TaxonInteractionDetailElement;
216 import eu.etaxonomy.taxeditor.section.description.detail.TextDataDetailElement;
217 import eu.etaxonomy.taxeditor.section.feature.FeatureDistributionDetailElement;
218 import eu.etaxonomy.taxeditor.section.feature.FeatureDistributionDetailSection;
219 import eu.etaxonomy.taxeditor.section.key.GeographicalScopeDetailSection;
220 import eu.etaxonomy.taxeditor.section.key.PolytomousKeyDetailElement;
221 import eu.etaxonomy.taxeditor.section.key.PolytomousKeyDetailSection;
222 import eu.etaxonomy.taxeditor.section.key.PolytomousKeyNodeDetailElement;
223 import eu.etaxonomy.taxeditor.section.key.PolytomousKeyNodeDetailSection;
224 import eu.etaxonomy.taxeditor.section.key.ScopeRestrictionSection;
225 import eu.etaxonomy.taxeditor.section.name.AuthorshipDetailElement;
226 import eu.etaxonomy.taxeditor.section.name.AuthorshipDetailSection;
227 import eu.etaxonomy.taxeditor.section.name.HybridDetailElement;
228 import eu.etaxonomy.taxeditor.section.name.HybridDetailSection;
229 import eu.etaxonomy.taxeditor.section.name.NameDetailElement;
230 import eu.etaxonomy.taxeditor.section.name.NameDetailSection;
231 import eu.etaxonomy.taxeditor.section.name.NameRelationshipDetailElement;
232 import eu.etaxonomy.taxeditor.section.name.NameRelationshipDetailSection;
233 import eu.etaxonomy.taxeditor.section.name.NameTypeDesignationElement;
234 import eu.etaxonomy.taxeditor.section.name.NomenclaturalStatusElement;
235 import eu.etaxonomy.taxeditor.section.name.NomenclaturalStatusSection;
236 import eu.etaxonomy.taxeditor.section.name.NonViralNameDetailElement;
237 import eu.etaxonomy.taxeditor.section.name.NonViralNameDetailSection;
238 import eu.etaxonomy.taxeditor.section.name.ProtologueElement;
239 import eu.etaxonomy.taxeditor.section.name.ProtologueSection;
240 import eu.etaxonomy.taxeditor.section.name.SpecimenTypeDesignationElement;
241 import eu.etaxonomy.taxeditor.section.name.TypeDesignationSection;
242 import eu.etaxonomy.taxeditor.section.occurrence.CollectingAreasDetailSection;
243 import eu.etaxonomy.taxeditor.section.occurrence.CollectionDetailElement;
244 import eu.etaxonomy.taxeditor.section.occurrence.DerivedUnitBaseDetailElement;
245 import eu.etaxonomy.taxeditor.section.occurrence.DerivedUnitBaseDetailSection;
246 import eu.etaxonomy.taxeditor.section.occurrence.DerivedUnitFacadeDetailElement;
247 import eu.etaxonomy.taxeditor.section.occurrence.DerivedUnitFacadeDetailSection;
248 import eu.etaxonomy.taxeditor.section.occurrence.DeterminationEventDetailElement;
249 import eu.etaxonomy.taxeditor.section.occurrence.DeterminationEventDetailSection;
250 import eu.etaxonomy.taxeditor.section.occurrence.FieldObservationDetailElement;
251 import eu.etaxonomy.taxeditor.section.occurrence.FieldObservationDetailSection;
252 import eu.etaxonomy.taxeditor.section.occurrence.GatheringEventDetailElement;
253 import eu.etaxonomy.taxeditor.section.occurrence.GatheringEventDetailSection;
254 import eu.etaxonomy.taxeditor.section.occurrence.GeneralDetailElement;
255 import eu.etaxonomy.taxeditor.section.occurrence.GeneralDetailSection;
256 import eu.etaxonomy.taxeditor.section.occurrence.NamedAreaDetailElement;
257 import eu.etaxonomy.taxeditor.section.occurrence.SourceCollectionDetailSection;
258 import eu.etaxonomy.taxeditor.section.occurrence.SpecimenCollectionDetailElement;
259 import eu.etaxonomy.taxeditor.section.occurrence.SpecimenCollectionDetailSection;
260 import eu.etaxonomy.taxeditor.section.reference.NomenclaturalReferenceDetailElement;
261 import eu.etaxonomy.taxeditor.section.reference.NomenclaturalReferenceDetailSection;
262 import eu.etaxonomy.taxeditor.section.reference.ReferenceDetailElement;
263 import eu.etaxonomy.taxeditor.section.reference.ReferenceDetailSection;
264 import eu.etaxonomy.taxeditor.section.supplemental.AnnotationElement;
265 import eu.etaxonomy.taxeditor.section.supplemental.AnnotationSection;
266 import eu.etaxonomy.taxeditor.section.supplemental.CreditElement;
267 import eu.etaxonomy.taxeditor.section.supplemental.CreditSection;
268 import eu.etaxonomy.taxeditor.section.supplemental.ExtensionElement;
269 import eu.etaxonomy.taxeditor.section.supplemental.ExtensionSection;
270 import eu.etaxonomy.taxeditor.section.supplemental.HeadlineSection;
271 import eu.etaxonomy.taxeditor.section.supplemental.IdentifiableSourceElement;
272 import eu.etaxonomy.taxeditor.section.supplemental.ImageFileElement;
273 import eu.etaxonomy.taxeditor.section.supplemental.MarkerElement;
274 import eu.etaxonomy.taxeditor.section.supplemental.MarkerSection;
275 import eu.etaxonomy.taxeditor.section.supplemental.MediaElement;
276 import eu.etaxonomy.taxeditor.section.supplemental.MediaRepresentationElement;
277 import eu.etaxonomy.taxeditor.section.supplemental.MediaRepresentationPartSection;
278 import eu.etaxonomy.taxeditor.section.supplemental.MediaRepresentationSection;
279 import eu.etaxonomy.taxeditor.section.supplemental.MediaSection;
280 import eu.etaxonomy.taxeditor.section.supplemental.RightsElement;
281 import eu.etaxonomy.taxeditor.section.supplemental.RightsSection;
282 import eu.etaxonomy.taxeditor.section.supplemental.SourceSection;
283 import eu.etaxonomy.taxeditor.section.supplemental.VersionElement;
284 import eu.etaxonomy.taxeditor.section.supplemental.VersionSection;
285 import eu.etaxonomy.taxeditor.section.taxon.ParsingMessageElement;
286 import eu.etaxonomy.taxeditor.section.taxon.ParsingMessagesSection;
287 import eu.etaxonomy.taxeditor.section.taxon.TaxonBaseDetailElement;
288 import eu.etaxonomy.taxeditor.section.taxon.TaxonBaseDetailSection;
289
290 /**
291 * <p>CdmFormFactory class.</p>
292 *
293 * @author n.hoffmann
294 * @created Feb 24, 2010
295 * @version 1.0
296 */
297 public class CdmFormFactory extends FormToolkit{
298
299 private BoldFontHolder2 boldFontHolder2;
300 private MouseListener selectionMouseHandler;
301 private FocusListener selectionFocusHandler;
302
303 private Set selectionListenerList = new HashSet();
304
305 private List<IPropertyChangeListener> propertyChangeListeners = new ArrayList<IPropertyChangeListener>();
306
307 private int orientation = Window.getDefaultOrientation();
308 private ISelectionProvider selectionProvider;
309
310 /**
311 * <p>LAYOUT</p>
312 *
313 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapLayout} object.
314 */
315 public static final TableWrapLayout LAYOUT(){
316 return LAYOUT(1, false);
317 }
318
319 /**
320 * <p>LAYOUT</p>
321 *
322 * @param columns a int.
323 * @param equalWidth a boolean.
324 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapLayout} object.
325 */
326 public static final TableWrapLayout LAYOUT(int columns, boolean equalWidth){
327 TableWrapLayout layout = new TableWrapLayout();
328 layout.topMargin = 0;
329 layout.rightMargin = 0;
330 layout.bottomMargin = 0;
331 layout.leftMargin = 0;
332 layout.numColumns = columns;
333 layout.makeColumnsEqualWidth = equalWidth;
334 layout.verticalSpacing = 0;
335 layout.horizontalSpacing = 0;
336 return layout;
337 }
338
339 /**
340 * <p>FILL</p>
341 *
342 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
343 */
344 public static final TableWrapData FILL(){
345 return FILL(1, 1);
346 }
347
348 /**
349 * <p>FILL</p>
350 *
351 * @param horizontalSpan a int.
352 * @param verticalSpan a int.
353 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
354 */
355 public static final TableWrapData FILL(int horizontalSpan, int verticalSpan){
356 TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL_GRAB);
357 layoutData.colspan = horizontalSpan;
358 layoutData.rowspan = verticalSpan;
359 return layoutData;
360 }
361
362 /**
363 * <p>LEFT</p>
364 *
365 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
366 */
367 public static final TableWrapData LEFT(){
368 return new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP);
369 }
370
371 /**
372 * <p>RIGHT</p>
373 *
374 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
375 */
376 public static final TableWrapData RIGHT(){
377 return new TableWrapData(TableWrapData.RIGHT, TableWrapData.TOP);
378 }
379
380 /**
381 * <p>FILL_HORIZONTALLY</p>
382 *
383 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
384 */
385 public static final TableWrapData FILL_HORIZONTALLY(){
386 return FILL_HORIZONTALLY(1, 1);
387 }
388
389 /**
390 * <p>FILL_HORIZONTALLY</p>
391 *
392 * @param horizontalSpan a int.
393 * @param verticalSpan a int.
394 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
395 */
396 public static final TableWrapData FILL_HORIZONTALLY(int horizontalSpan, int verticalSpan){
397 TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP);
398 layoutData.colspan = horizontalSpan;
399 layoutData.rowspan = verticalSpan;
400 return layoutData;
401 }
402
403 /** Constant <code>EMPTY_SELECTION</code> */
404 public static ISelection EMPTY_SELECTION = new ISelection() {
405 public boolean isEmpty() {
406 return true;
407 }
408 };
409
410 private class SelectionMouseHandler extends MouseAdapter{
411 @Override
412 public void mouseDown(MouseEvent e) {
413 notifySelectionListeners(e);
414 }
415 }
416
417 private class SelectionFocusHandler extends FocusAdapter{
418 @Override
419 public void focusGained(FocusEvent e) {
420 notifySelectionListeners(e);
421 }
422 }
423
424 private void notifySelectionListeners(TypedEvent e){
425 Event event = new Event();
426 event.widget = e.widget;
427 SelectionEvent selectionEvent = new SelectionEvent(event);
428
429 for(Object listener : selectionListenerList){
430 ((SelectionListener) listener).widgetSelected(selectionEvent);
431 }
432 }
433
434 /**
435 * <p>Constructor for CdmFormFactory.</p>
436 *
437 * @param display a {@link org.eclipse.swt.widgets.Display} object.
438 * @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
439 */
440 public CdmFormFactory(Display display, ISelectionProvider selectionProvider) {
441 super(display);
442 this.selectionProvider = selectionProvider;
443 init();
444 }
445
446 /**
447 * <p>Constructor for CdmFormFactory.</p>
448 *
449 * @param display a {@link org.eclipse.swt.widgets.Display} object.
450 */
451 public CdmFormFactory(Display display){
452 super(display);
453 init();
454 }
455
456 /**
457 *
458 */
459 private void init() {
460 boldFontHolder2 = new BoldFontHolder2();
461 selectionMouseHandler = new SelectionMouseHandler();
462 selectionFocusHandler = new SelectionFocusHandler();
463 }
464
465 /**
466 * Creates an instance initialized with the correct selectionProvider
467 *
468 * Make sure to remove the instance when the entityComposite disposes via
469 * destroySelectionArbitrator(..)
470 *
471 * @param entityElement a {@link eu.etaxonomy.taxeditor.forms.IEntityElement} object.
472 * @return a {@link eu.etaxonomy.taxeditor.forms.SelectionArbitrator} object.
473 */
474 public SelectionArbitrator createSelectionArbitrator(IEntityElement entityElement){
475 SelectionArbitrator selectionArbitrator = new SelectionArbitrator(entityElement);
476 selectionArbitrator.addSelectionProvider(selectionProvider);
477 selectionProvider.addSelectionChangedListener(selectionArbitrator);
478 addSelectionListener(selectionArbitrator);
479 return selectionArbitrator;
480 }
481
482 /**
483 * <p>destroySelectionArbitrator</p>
484 *
485 * @param selectionArbitrator a {@link eu.etaxonomy.taxeditor.forms.SelectionArbitrator} object.
486 */
487 public void destroySelectionArbitrator(SelectionArbitrator selectionArbitrator){
488 removeSelectionListener(selectionArbitrator);
489 if(selectionProvider != null){
490 selectionProvider.removeSelectionChangedListener(selectionArbitrator);
491 }else{
492 EditorUtil.error(this.getClass(), "Tried to destroy a selection listener from this factories listeners but was null", null);
493 }
494 }
495
496 /** {@inheritDoc} */
497 @Override
498 public void adapt(Composite composite) {
499 composite.addMouseListener(selectionMouseHandler);
500 super.adapt(composite);
501 }
502
503 /**
504 * <p>adapt</p>
505 *
506 * @param formElement a {@link eu.etaxonomy.taxeditor.forms.AbstractCdmFormElement} object.
507 */
508 public void adapt(AbstractCdmFormElement formElement){
509 formElement.setPropertyChangeListeners(propertyChangeListeners);
510 }
511
512 /** {@inheritDoc} */
513 @Override
514 public void adapt(Control control, boolean trackFocus, boolean trackKeyboard) {
515 if(trackFocus){
516 control.addFocusListener(selectionFocusHandler);
517 }
518 super.adapt(control, trackFocus, trackKeyboard);
519 }
520
521 /**
522 * <p>destroyElement</p>
523 *
524 * @param formElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
525 */
526 public void destroyElement(ICdmFormElement formElement){
527 // return if element was not initialized
528 if(formElement == null){
529 return;
530 }
531 // destroy selection arbitrator, if any
532 if(formElement instanceof ISelectableElement){
533 destroySelectionArbitrator(((ISelectableElement) formElement).getSelectionArbitrator());
534 }
535 // remove this element form its parents list of elements
536 // ICdmFormElement parentElement = formElement.getParentElement();
537 // if(parentElement != null){
538 // parentElement.removeElement(formElement);
539 // }
540 // call destroy on child elements recursively
541 for(ICdmFormElement childElement : formElement.getElements()){
542 destroyElement(childElement);
543 }
544 // dispose of the controls
545 for(Control control : formElement.getControls()){
546 // we added the layoutComposite of the parental element as the layout composite to this formElement
547 // but we do not want to destroy it.
548 if(control.equals(formElement.getLayoutComposite())){
549 continue;
550 }else{
551 control.dispose();
552 control = null;
553 }
554 }
555 }
556
557
558 /**
559 * <p>createEmptyCell</p>
560 *
561 * @param parent a {@link org.eclipse.swt.widgets.Composite} object.
562 * @return a {@link org.eclipse.swt.widgets.Label} object.
563 */
564 public Label createEmptyCell(Composite parent){
565 return this.createLabel(parent, null);
566 }
567
568 /**
569 * <p>createMultilineTextWithLabel</p>
570 *
571 * @param labelString a {@link java.lang.String} object.
572 * @param textHeight a int.
573 * @param style a int.
574 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
575 * @return a {@link eu.etaxonomy.taxeditor.forms.TextWithLabelElement} object.
576 */
577 public TextWithLabelElement createMultilineTextWithLabel(ICdmFormElement parentElement, String labelString, int textHeight, int style){
578 TextWithLabelElement element = new TextWithLabelElement(this, parentElement, labelString, "", textHeight, style);
579 adapt(element);
580 parentElement.addElement(element);
581 return element;
582 }
583
584
585 /**
586 * <p>createMultiLanguageTextElement</p>
587 *
588 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
589 * @param labelString a {@link java.lang.String} object.
590 * @param multilanguageText a {@link java.util.Map} object.
591 * @param textHeight a int.
592 * @param style a int.
593 * @return a {@link eu.etaxonomy.taxeditor.forms.MultilanguageTextElement} object.
594 */
595 public MultilanguageTextElement createMultiLanguageTextElement(
596 ICdmFormElement parentElement, String labelString, Map<Language, LanguageString> multilanguageText, int textHeight,
597 int style) {
598 MultilanguageTextElement element = new MultilanguageTextElement(this, parentElement, labelString, multilanguageText, textHeight, style);
599 adapt(element);
600 parentElement.addElement(element);
601 return element;
602 }
603
604 public KeyStatementElement createKeyStatementElement(ICdmFormElement parentElement, String labelString,
605 KeyStatement keyStatement, int textHeight, int style){
606 KeyStatementElement element = new KeyStatementElement(this, parentElement, labelString, keyStatement, textHeight, style);
607 adapt(element);
608 parentElement.addElement(element);
609 return element;
610 }
611
612
613 /**
614 * <p>createTextWithLabelElement</p>
615 *
616 * @param labelString a {@link java.lang.String} object.
617 * @param initialText a {@link java.lang.String} object.
618 * @param style a int.
619 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
620 * @return a {@link eu.etaxonomy.taxeditor.forms.TextWithLabelElement} object.
621 */
622 public TextWithLabelElement createTextWithLabelElement(ICdmFormElement parentElement, String labelString, String initialText, int style){
623 TextWithLabelElement element = new TextWithLabelElement(this, parentElement, labelString, initialText, null, style);
624 adapt(element);
625 parentElement.addElement(element);
626 return element;
627 }
628
629 public UriWithLabelElement createUriWithLabelElement(ICdmFormElement parentElement, String labelString, URI initialUri, int style){
630 UriWithLabelElement element = new UriWithLabelElement(this, parentElement, labelString, initialUri, null, style);
631 adapt(element);
632 parentElement.addElement(element);
633 return element;
634 }
635
636 /**
637 * <p>createIntegerTextWithLabelElement</p>
638 *
639 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
640 * @param labelString a {@link java.lang.String} object.
641 * @param initialInteger a {@link java.lang.Integer} object.
642 * @param style a int.
643 * @return a {@link eu.etaxonomy.taxeditor.forms.NumberWithLabelElement} object.
644 */
645 public NumberWithLabelElement createIntegerTextWithLabelElement(ICdmFormElement parentElement, String labelString, Integer initialInteger, int style){
646 NumberWithLabelElement element = new NumberWithLabelElement(this, parentElement, labelString, initialInteger, style);
647 adapt(element);
648 parentElement.addElement(element);
649 return element;
650 }
651
652
653 /**
654 * <p>createFloatTextWithLabelElement</p>
655 *
656 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
657 * @param labelString a {@link java.lang.String} object.
658 * @param initialFloat a float.
659 * @param style a int.
660 * @return a {@link eu.etaxonomy.taxeditor.forms.NumberWithLabelElement} object.
661 */
662 public NumberWithLabelElement createFloatTextWithLabelElement(
663 ICdmFormElement parentElement, String labelString, float initialFloat,
664 int style) {
665 NumberWithLabelElement element = new NumberWithLabelElement(this, parentElement, labelString, initialFloat, style);
666 adapt(element);
667 parentElement.addElement(element);
668 return element;
669 }
670
671 /**
672 * <p>createLanguageStringWithLabelElement</p>
673 *
674 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
675 * @param labelString a {@link java.lang.String} object.
676 * @param languageString a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
677 * @param style a int.
678 * @return a {@link eu.etaxonomy.taxeditor.forms.LanguageStringWithLabelElement} object.
679 */
680 public LanguageStringWithLabelElement createLanguageStringWithLabelElement(ICdmFormElement parentElement, String labelString, LanguageString languageString, int style){
681 LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(this, parentElement, labelString, languageString, style);
682 adapt(element);
683 parentElement.addElement(element);
684 return element;
685 }
686
687 /**
688 * <p>createLanguageStringWithLabelElement</p>
689 *
690 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
691 * @param labelString a {@link java.lang.String} object.
692 * @param languageString a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
693 * @param height a int.
694 * @param style a int.
695 * @return a {@link eu.etaxonomy.taxeditor.forms.LanguageStringWithLabelElement} object.
696 */
697 public LanguageStringWithLabelElement createLanguageStringWithLabelElement(ICdmFormElement parentElement, String labelString, LanguageString languageString, int height, int style){
698 LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(this, parentElement, labelString, languageString, height, style);
699 adapt(element);
700 parentElement.addElement(element);
701 return element;
702 }
703
704 /**
705 * <p>createTextElement</p>
706 *
707 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
708 * @param initialText a {@link java.lang.String} object.
709 * @param style a int.
710 * @return a {@link eu.etaxonomy.taxeditor.forms.TextWithLabelElement} object.
711 */
712 public TextWithLabelElement createTextElement(ICdmFormElement parentElement, String initialText, int style){
713 TextWithLabelElement element = new TextWithLabelElement(this, parentElement, null, initialText, null, style);
714 adapt(element);
715 parentElement.addElement(element);
716 return element;
717 }
718
719 /**
720 * <p>createKeyValueViewerElement</p>
721 *
722 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
723 * @param keyHeading a {@link java.lang.String} object.
724 * @param valueHeading a {@link java.lang.String} object.
725 * @param map a {@link java.util.Map} object.
726 * @return a {@link eu.etaxonomy.taxeditor.forms.KeyValueViewerElement} object.
727 */
728 public KeyValueViewerElement createKeyValueViewerElement(ICdmFormElement parentElement, String keyHeading, String valueHeading, Map<Object, Object> map){
729 KeyValueViewerElement element = new KeyValueViewerElement(this, parentElement, keyHeading, valueHeading, map);
730 adapt(element);
731 parentElement.addElement(element);
732 return element;
733 }
734
735
736 public static enum TermComboType{
737 EXTENSIONTYPE,
738 LANGUAGE,
739 MARKERTYPE,
740 NOMENCLATURALSTATUSTYPE,
741 RANK,
742 RIGHTSTYPE,
743 NAMERELATIONSHIP,
744 NAMEDAREATYPE,
745 PRESENCEABSENCESTATUS,
746 ANNOTATIONTYPE,
747 NAMETYPEDESIGNATIONSTATUS,
748 SPECIMENTYPEDESIGNATIONSTATUS,
749 SEX,
750 STAGE,
751 PRESERVATION_METHOD,
752 MEASUREMENT_UNIT,
753 STATE,
754 MODIFIER,
755 STATISTICAL_MEASURE,
756 SCOPE,
757 EMPTY,
758 DETERMINATION_MODIFIER,
759 REFERENCE_SYSTEM
760 }
761
762 /**
763 * <p>createTermComboElement</p>
764 *
765 * @param termComboType a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory.TermComboType} object.
766 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
767 * @param labelString a {@link java.lang.String} object.
768 * @param selection a {@link eu.etaxonomy.cdm.model.common.DefinedTermBase} object.
769 * @param style a int.
770 * @return a {@link eu.etaxonomy.taxeditor.forms.term.AbstractTermComboElement} object.
771 */
772 public AbstractTermComboElement createTermComboElement(TermComboType termComboType, ICdmFormElement parentElement, String labelString, DefinedTermBase selection, int style){
773 AbstractTermComboElement element = null;
774
775 switch(termComboType){
776 case EMPTY:
777 element = new EmptyComboElement<DefinedTermBase>(this, parentElement, labelString, style);
778 break;
779 case EXTENSIONTYPE:
780 element = new ExtensionTypeComboElement(this, parentElement, labelString, (ExtensionType) selection, style);
781 break;
782 case LANGUAGE:
783 element = new LanguageComboElement(this, parentElement, labelString, (Language) selection, style);
784 break;
785 case MARKERTYPE:
786 element = new MarkerTypeComboElement(this, parentElement, labelString, (MarkerType) selection, style);
787 break;
788 case NOMENCLATURALSTATUSTYPE:
789 element = new NomenclaturalStatusTypeComboElement(this, parentElement, labelString, (NomenclaturalStatusType) selection, style);
790 break;
791 case RANK:
792 element = new RankComboElement(this, parentElement, labelString, (Rank) selection, style);
793 break;
794 case RIGHTSTYPE:
795 element = new RightsTypeComboElement(this, parentElement, labelString, (RightsTerm) selection, style);
796 break;
797 case NAMERELATIONSHIP:
798 element = new NameRelationshipTypeComboElement(this, parentElement, labelString, (NameRelationshipType) selection, style);
799 break;
800 case NAMEDAREATYPE:
801 element = new NamedAreaTypeComboElement(this, parentElement, labelString, (NamedAreaType) selection, style);
802 break;
803 case ANNOTATIONTYPE:
804 element = new AnnotationTypeComboElement(this, parentElement, labelString, (AnnotationType) selection, style);
805 break;
806 case PRESENCEABSENCESTATUS:
807 element = new PresenceAbsenceTermComboElement(this, parentElement, labelString, (PresenceAbsenceTermBase) selection, style);
808 break;
809 case NAMETYPEDESIGNATIONSTATUS:
810 element = new NameTypeDesignationStatusComboElement(this, parentElement, labelString, (NameTypeDesignationStatus) selection, style);
811 break;
812 case SPECIMENTYPEDESIGNATIONSTATUS:
813 element = new SpecimenTypeDesignationStatusComboElement(this, parentElement, labelString, (SpecimenTypeDesignationStatus) selection, style);
814 break;
815 case SEX:
816 element = new SexComboElement(this, parentElement, labelString, (Sex) selection, style);
817 break;
818 case STAGE:
819 element = new StageComboElement(this, parentElement, labelString, (Stage) selection, style);
820 break;
821 case PRESERVATION_METHOD:
822 element = new PreservationMethodComboElement(this, parentElement, labelString, (PreservationMethod) selection, style);
823 break;
824 case MEASUREMENT_UNIT:
825 element = new MeasurementUnitComboElement(this, parentElement, labelString, (MeasurementUnit) selection, style);
826 break;
827 case STATE:
828 element = new StateComboElement(this, parentElement, labelString, (State) selection, style);
829 break;
830 case SCOPE:
831 element = new ScopeComboElement(this, parentElement, labelString, (Scope) selection, style);
832 break;
833 case MODIFIER:
834 element = new ModifierComboElement(this, parentElement, labelString, (Modifier) selection, style);
835 break;
836 case STATISTICAL_MEASURE:
837 element = new StatisticalMeasureComboElement(this, parentElement, labelString, (StatisticalMeasure) selection, style);
838 break;
839 case DETERMINATION_MODIFIER:
840 element = new DeterminationModifierComboElement(this, parentElement, labelString, (DeterminationModifier) selection, style);
841 break;
842 case REFERENCE_SYSTEM:
843 element = new ReferenceSystemComboElement(this, parentElement, labelString, (ReferenceSystem) selection, style);
844 break;
845 }
846
847 adapt(element);
848 parentElement.addElement(element);
849 return element;
850 }
851
852 public static enum EnumComboType{
853 REFERENCETYPE,
854 NOMENCLATURALCODE
855 }
856
857 /**
858 * <p>createEnumComboElement</p>
859 *
860 * @param enumComboType a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory.EnumComboType} object.
861 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
862 * @param style a int.
863 * @return a {@link eu.etaxonomy.taxeditor.forms.term.AbstractEnumComboElement} object.
864 */
865 public AbstractEnumComboElement createEnumComboElement(EnumComboType enumComboType, ICdmFormElement parentElement, int style){
866 AbstractEnumComboElement element = null;
867
868 switch(enumComboType){
869 case REFERENCETYPE:
870 element = new ReferenceTypeComboElement(this, parentElement, "Reference Type", null, style);
871 break;
872 case NOMENCLATURALCODE:
873 element = new NomenclaturalCodeComboElement(this, parentElement, "Nomenclatural Code", null, style);
874 break;
875 }
876 adapt(element);
877 parentElement.addElement(element);
878 return element;
879 }
880
881 /**
882 * <p>createBrowserElement</p>
883 *
884 * @param imageUri a {@link java.net.URI} object.
885 * @param style a int.
886 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
887 * @return a {@link eu.etaxonomy.taxeditor.forms.BrowserElement} object.
888 */
889 public BrowserElement createBrowserElement(ICdmFormElement parentElement, URI imageUri, int style){
890 BrowserElement element = new BrowserElement(this, parentElement, imageUri, style);
891 adapt(element);
892 parentElement.addElement(element);
893 return element;
894 }
895
896 /**
897 * <p>createImageElement</p>
898 *
899 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
900 * @param imageUri a {@link java.net.URI} object.
901 * @param style a int.
902 * @return a {@link eu.etaxonomy.taxeditor.forms.ImageElement} object.
903 */
904 public ImageElement createImageElement(ICdmFormElement parentElement, URI imageUri, int style) {
905 ImageElement element = new ImageElement(this, parentElement, imageUri, style);
906 adapt(element);
907 parentElement.addElement(element);
908 return element;
909 }
910
911 /**
912 * <p>createTextActionElement</p>
913 *
914 * @param labelString a {@link java.lang.String} object.
915 * @param initialText a {@link java.lang.String} object.
916 * @param style a int.
917 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
918 * @param buttonLabel a {@link java.lang.String} object.
919 * @return a {@link eu.etaxonomy.taxeditor.forms.TextActionElement} object.
920 */
921 public TextActionElement createTextActionElement(ICdmFormElement parentElement, String labelString, String buttonLabel, String initialText, int style){
922 TextActionElement element = new TextActionElement(this, parentElement, labelString, buttonLabel, initialText, style);
923 adapt(element);
924 parentElement.addElement(element);
925 return element;
926 }
927
928 /**
929 *
930 * @author n.hoffmann
931 * @created Mar 5, 2010
932 * @version 1.0
933 */
934 public static enum SelectionType{
935 AGENT,
936 INSTITUTION,
937 NAME,
938 REFERENCE,
939 TAXON_BASE,
940 TAXON,
941 SYNONYM,
942 TEAM,
943 AUTHOR_TEAM,
944 PERSON,
945 DERIVED_UNIT,
946 FIELD_OBSERVATION,
947 FEATURE_TREE,
948 CLASSIFICATION,
949 TAXON_NODE,
950 COLLECTION,
951 FEATURE,
952 POLYTOMOUS_KEY,
953 POLYTOMOUS_KEY_NODE
954 }
955
956 /**
957 * <p>createCheckbox</p>
958 *
959 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
960 * @param label a {@link java.lang.String} object.
961 * @param initialState a boolean.
962 * @param style a int.
963 * @return a {@link eu.etaxonomy.taxeditor.forms.CheckboxElement} object.
964 */
965 public CheckboxElement createCheckbox(ICdmFormElement parentElement, String label, boolean initialState, int style) {
966 CheckboxElement element = new CheckboxElement(this, parentElement, label, initialState, style | orientation);
967 adapt(element);
968 parentElement.addElement(element);
969 return element;
970 }
971
972
973
974 /**
975 * Creates a section as a part of the form.
976 *
977 * @return the section widget
978 * @param section a {@link eu.etaxonomy.taxeditor.forms.AbstractFormSection} object.
979 */
980 public Section adapt(AbstractFormSection section) {
981 section.setMenu(section.getLayoutComposite().getMenu());
982 adapt(section, true, true);
983
984 // handle focus and property change events for cdm use
985 section.addFocusListener(selectionFocusHandler);
986 section.setPropertyChangeListeners(propertyChangeListeners);
987
988 if (section.getToggle() != null) {
989 section.getToggle().setHoverDecorationColor(getColors()
990 .getColor(IFormColors.TB_TOGGLE_HOVER));
991 section.getToggle().setDecorationColor(getColors()
992 .getColor(IFormColors.TB_TOGGLE));
993 }
994
995 section.setFont(boldFontHolder2.getBoldFont(section.getLayoutComposite().getFont()));
996
997 if ((section.getStyle() & Section.TITLE_BAR) != 0
998 || (section.getStyle() & Section.SHORT_TITLE_BAR) != 0) {
999 getColors().initializeSectionToolBarColors();
1000 section.setTitleBarBackground(getColors().getColor(IFormColors.TB_BG));
1001 section.setTitleBarBorderColor(getColors()
1002 .getColor(IFormColors.TB_BORDER));
1003 }
1004 // call setTitleBarForeground regardless as it also sets the label color
1005 section.setTitleBarForeground(getColors()
1006 .getColor(IFormColors.TB_TOGGLE));
1007 return section;
1008 }
1009
1010 private class BoldFontHolder2 {
1011 private Font normalFont;
1012
1013 private Font boldFont;
1014
1015 public BoldFontHolder2() {
1016 }
1017
1018 public Font getBoldFont(Font font) {
1019 createBoldFont(font);
1020 return boldFont;
1021 }
1022
1023 private void createBoldFont(Font font) {
1024 if (normalFont == null || !normalFont.equals(font)) {
1025 normalFont = font;
1026 dispose();
1027 }
1028 if (boldFont == null) {
1029 boldFont = FormFonts.getInstance().getBoldFont(getColors().getDisplay(),
1030 normalFont);
1031 }
1032 }
1033
1034 public void dispose() {
1035 if (boldFont != null) {
1036 FormFonts.getInstance().markFinished(boldFont, getColors().getDisplay());
1037 boldFont = null;
1038 }
1039 }
1040 }
1041
1042 /**
1043 * <p>createToggleableTextField</p>
1044 *
1045 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1046 * @param labelString a {@link java.lang.String} object.
1047 * @param initialText a {@link java.lang.String} object.
1048 * @param initialState a boolean.
1049 * @param style a int.
1050 * @return a {@link eu.etaxonomy.taxeditor.forms.ToggleableTextElement} object.
1051 */
1052 public ToggleableTextElement createToggleableTextField(ICdmFormElement parentElement,
1053 String labelString, String initialText, boolean initialState, int style) {
1054 ToggleableTextElement element = new ToggleableTextElement(this, parentElement,
1055 labelString, initialText, initialState, style | orientation);
1056 adapt(element);
1057 parentElement.addElement(element);
1058 return element;
1059 }
1060
1061 /**
1062 * <p>createTimePeriodElement</p>
1063 *
1064 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1065 * @param labelString a {@link java.lang.String} object.
1066 * @param timePeriod a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
1067 * @param style a int.
1068 * @return a {@link eu.etaxonomy.taxeditor.forms.TimePeriodElement} object.
1069 */
1070 public TimePeriodElement createTimePeriodElement(
1071 ICdmFormElement parentElement, String labelString, TimePeriod timePeriod, int style) {
1072 TimePeriodElement element = new TimePeriodElement(this, parentElement, labelString, timePeriod, style);
1073 adapt(element);
1074 parentElement.addElement(element);
1075 return element;
1076 }
1077
1078
1079 /**
1080 * <p>createPointElement</p>
1081 *
1082 * @param style a int.
1083 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1084 * @param point a {@link eu.etaxonomy.cdm.model.location.Point} object.
1085 * @return a {@link eu.etaxonomy.taxeditor.forms.PointElement} object.
1086 */
1087 public PointElement createPointElement(ICdmFormElement parentElement,
1088 Point point, int style) {
1089 PointElement element = new PointElement(this, parentElement, point, style);
1090 adapt(element);
1091 parentElement.addElement(element);
1092 return element;
1093 }
1094
1095 /**
1096 * <p>createDateDetailSection</p>
1097 *
1098 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1099 * @param style a int.
1100 * @return a {@link eu.etaxonomy.taxeditor.forms.DateDetailSection} object.
1101 */
1102 public DateDetailSection createDateDetailSection(ICdmFormElement parentElement, int style){
1103 DateDetailSection section = new DateDetailSection(this, parentElement, style);
1104 parentElement.addElement(section);
1105 adapt(section);
1106 return section;
1107 }
1108
1109 /**
1110 * <p>createPartialElement</p>
1111 *
1112 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1113 * @param labelString a {@link java.lang.String} object.
1114 * @param partial a {@link org.joda.time.Partial} object.
1115 * @param style a int.
1116 * @return a {@link eu.etaxonomy.taxeditor.forms.PartialElement} object.
1117 */
1118 public PartialElement createPartialElement(ICdmFormElement parentElement, String labelString, Partial partial, int style){
1119 PartialElement element = new PartialElement(this, parentElement, labelString, style);
1120 adapt(element);
1121 parentElement.addElement(element);
1122 return element;
1123 }
1124
1125 /**
1126 * <p>addSelectionListener</p>
1127 *
1128 * @param listener a {@link org.eclipse.swt.events.SelectionListener} object.
1129 */
1130 public void addSelectionListener(SelectionListener listener){
1131 selectionListenerList.add(listener);
1132 }
1133
1134 /**
1135 * <p>removeSelectionListener</p>
1136 *
1137 * @param listener a {@link org.eclipse.swt.events.SelectionListener} object.
1138 */
1139 public void removeSelectionListener(SelectionListener listener){
1140 if(listener == null){
1141 EditorUtil.error(this.getClass(), "Tried to remove a selection listener from this factories listeners but was null", null);
1142 }else{
1143 selectionListenerList.remove(listener);
1144 }
1145 }
1146
1147 /**
1148 * <p>addPropertyChangeListener</p>
1149 *
1150 * @param listener a {@link org.eclipse.jface.util.IPropertyChangeListener} object.
1151 */
1152 public void addPropertyChangeListener(IPropertyChangeListener listener) {
1153 propertyChangeListeners.add(0, listener);
1154 }
1155
1156 /**
1157 * <p>removePropertyChangeListener</p>
1158 *
1159 * @param listener a {@link org.eclipse.jface.util.IPropertyChangeListener} object.
1160 */
1161 public void removePropertyChangeListener(IPropertyChangeListener listener){
1162 propertyChangeListeners.remove(listener);
1163 }
1164
1165
1166
1167 /**
1168 * <p>createHorizontalSeparator</p>
1169 *
1170 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1171 * @param style a int.
1172 * @return a {@link org.eclipse.swt.widgets.Label} object.
1173 */
1174 public Label createHorizontalSeparator(ICdmFormElement parentElement, int style) {
1175 Label separator = this.createSeparator(parentElement.getLayoutComposite(), SWT.HORIZONTAL | style);
1176 separator.setLayoutData(FILL_HORIZONTALLY());
1177 return separator;
1178 }
1179
1180 /**
1181 * <p>createVersionElement</p>
1182 *
1183 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1184 * @param entity a {@link eu.etaxonomy.cdm.model.common.VersionableEntity} object.
1185 * @param style a int.
1186 * @return a {@link eu.etaxonomy.taxeditor.section.supplemental.VersionElement} object.
1187 */
1188 public VersionElement createVersionElement(ICdmFormElement parentElement, VersionableEntity entity,
1189 int style) {
1190 VersionElement element = new VersionElement(this, parentElement, entity, style);
1191 adapt(element);
1192 parentElement.addElement(element);
1193 return element;
1194 }
1195
1196 /**
1197 * <p>createVersionSection</p>
1198 *
1199 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1200 * @param style a int.
1201 * @return a {@link eu.etaxonomy.taxeditor.section.supplemental.VersionSection} object.
1202 */
1203 public VersionSection createVersionSection(ICdmFormElement parentElement, int style) {
1204 VersionSection section = new VersionSection(this, parentElement, style);
1205 parentElement.addElement(section);
1206 adapt(section);
1207 return section;
1208 }
1209
1210 /**
1211 * <p>createEmptyElement</p>
1212 *
1213 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1214 * @return a {@link eu.etaxonomy.taxeditor.section.EmptyElement} object.
1215 */
1216 public EmptyElement createEmptyElement(ICdmFormElement parentElement) {
1217 EmptyElement element = new EmptyElement(this, parentElement, null, SWT.NULL);
1218 adapt(element);
1219 parentElement.addElement(element);
1220 return element;
1221 }
1222
1223 /**
1224 * <p>createHeadlineSection</p>
1225 *
1226 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1227 * @return a {@link eu.etaxonomy.taxeditor.section.supplemental.HeadlineSection} object.
1228 */
1229 public HeadlineSection createHeadlineSection(ICdmFormElement parentElement) {
1230 HeadlineSection section = new HeadlineSection(this, parentElement, SWT.NULL);
1231 parentElement.addElement(section);
1232 adapt(section);
1233 return section;
1234 }
1235
1236
1237 /**
1238 * <p>createParsingMessageElement</p>
1239 *
1240 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1241 * @param parserProblem a {@link eu.etaxonomy.cdm.strategy.parser.ParserProblem} object.
1242 * @param style a int.
1243 * @return a {@link eu.etaxonomy.taxeditor.section.taxon.ParsingMessageElement} object.
1244 */
1245 public ParsingMessageElement createParsingMessageElement(
1246 ICdmFormElement parentElement, ParserProblem parserProblem, int style) {
1247 ParsingMessageElement element = new ParsingMessageElement(this, parentElement, parserProblem, style);
1248 adapt(element);
1249 parentElement.addElement(element);
1250 return element;
1251 }
1252
1253
1254 // SIMPLIFY
1255
1256 /**
1257 *
1258 */
1259 public static enum DetailType{
1260 NONVIRALNAME,
1261 SCIENTIFICNAME,
1262 REFERENCEBASE,
1263 NOMENCLATURALREFERENCE,
1264 TAXONBASE,
1265 AUTHORSHIP,
1266 TEAM,
1267 PERSON,
1268 DESCRIPTION,
1269 DESCRIPTIONELEMENT,
1270 PARSINGMESSAGE,
1271 NAMERELATIONSHIP,
1272 TEAMORPERSONBASE,
1273 MEDIA,
1274 FIELD_OBSERVATION,
1275 DERIVED_UNIT_FACADE,
1276 GATHERING_EVENT,
1277 DERIVED_UNIT, NATURAL_LANGUAGE,
1278 FEATURE_DISTRIBUTION,
1279 CLASSIFICATION,
1280 TAXON_NODE,
1281 COLLECTION,
1282 POLYTOMOUS_KEY,
1283 POLYTOMOUS_KEY_NODE,
1284 INSTITUTION,
1285 DERIVED_UNIT_GENERAL,
1286 HYBRID
1287 }
1288
1289 /**
1290 * <p>createCdmDetailSection</p>
1291 *
1292 * @param detailType a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory.DetailType} object.
1293 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1294 * @param selectionProvider a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
1295 * @param style a int.
1296 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
1297 * @return a {@link eu.etaxonomy.taxeditor.forms.AbstractFormSection} object.
1298 */
1299 public AbstractFormSection createCdmDetailSection(DetailType detailType, ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
1300 AbstractFormSection section = null;
1301
1302 switch(detailType){
1303 case SCIENTIFICNAME:
1304 section = new NameDetailSection(this, conversation, parentElement, selectionProvider, style);
1305 break;
1306 case REFERENCEBASE:
1307 section = new ReferenceDetailSection(this, conversation, parentElement, selectionProvider, style);
1308 break;
1309 case NOMENCLATURALREFERENCE:
1310 section = new NomenclaturalReferenceDetailSection(this, conversation, parentElement, selectionProvider, style);
1311 break;
1312 case TAXONBASE:
1313 section = new TaxonBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
1314 break;
1315 case AUTHORSHIP:
1316 section = new AuthorshipDetailSection(this, conversation, parentElement, selectionProvider, style);
1317 break;
1318 case TEAMORPERSONBASE:
1319 section = new TeamOrPersonBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
1320 break;
1321 case TEAM:
1322 section = new TeamDetailSection(this, conversation, parentElement, null, style);
1323 break;
1324 case PERSON:
1325 section = new PersonDetailSection(this, conversation, parentElement, null, style);
1326 break;
1327 case DESCRIPTION:
1328 section = new DescriptionDetailSection(this, conversation, parentElement, selectionProvider, style);
1329 break;
1330 case DESCRIPTIONELEMENT:
1331 section = new DescriptionElementDetailSection(this, conversation, parentElement, selectionProvider, style);
1332 break;
1333 case PARSINGMESSAGE:
1334 section = new ParsingMessagesSection(this, conversation, parentElement, selectionProvider, style);
1335 break;
1336 case NONVIRALNAME:
1337 section = new NonViralNameDetailSection(this, conversation, parentElement, selectionProvider, style);
1338 break;
1339 case MEDIA:
1340 section = new eu.etaxonomy.taxeditor.section.description.MediaDetailsSection(this, conversation, parentElement, selectionProvider, style);
1341 break;
1342 case DERIVED_UNIT_FACADE:
1343 section = new DerivedUnitFacadeDetailSection(this, conversation, parentElement, selectionProvider, style);
1344 break;
1345 case FIELD_OBSERVATION:
1346 section = new FieldObservationDetailSection(this, conversation, parentElement, selectionProvider, style);
1347 break;
1348 case GATHERING_EVENT:
1349 section = new GatheringEventDetailSection(this, conversation, parentElement, selectionProvider, style);
1350 break;
1351 case DERIVED_UNIT:
1352 section = new DerivedUnitBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
1353 break;
1354 case NATURAL_LANGUAGE:
1355 section = new NaturalLanguageSection(this, conversation, parentElement, selectionProvider, style);
1356 break;
1357 case FEATURE_DISTRIBUTION:
1358 section = new FeatureDistributionDetailSection(this, conversation, parentElement, selectionProvider, style);
1359 break;
1360 case CLASSIFICATION:
1361 section = new ClassificationDetailSection(this, conversation, parentElement, selectionProvider, style);
1362 break;
1363 case TAXON_NODE:
1364 section = new TaxonNodeDetailSection(this, conversation, parentElement, selectionProvider, style);
1365 break;
1366 case POLYTOMOUS_KEY:
1367 section = new PolytomousKeyDetailSection(this, conversation, parentElement, selectionProvider, style);
1368 break;
1369 case POLYTOMOUS_KEY_NODE:
1370 section = new PolytomousKeyNodeDetailSection(this, conversation, parentElement, selectionProvider, style);
1371 break;
1372 case INSTITUTION:
1373 section = new InstitutionDetailSection(this, conversation, parentElement, selectionProvider, style);
1374 break;
1375 case DERIVED_UNIT_GENERAL:
1376 section = new GeneralDetailSection(this, conversation, parentElement, selectionProvider, style);
1377 break;
1378 case HYBRID:
1379 section = new HybridDetailSection(this, conversation, parentElement, selectionProvider, style);
1380 break;
1381 }
1382
1383 if(section == null){
1384 throw new RuntimeException("You tried to create a cdm detail section that is not implemented yet.");
1385 }
1386
1387 parentElement.addElement(section);
1388 adapt(section);
1389 return section;
1390 }
1391
1392 /**
1393 * <p>createCdmDetailElement</p>
1394 *
1395 * @param detailType a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory.DetailType} object.
1396 * @param style a int.
1397 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1398 * @return a {@link eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement} object.
1399 */
1400 public AbstractCdmDetailElement createCdmDetailElement(DetailType detailType, ICdmFormElement parentElement, int style){
1401 AbstractCdmDetailElement element = null;
1402
1403 switch(detailType){
1404 case SCIENTIFICNAME:
1405 element = new NameDetailElement(this, parentElement, style);
1406 break;
1407 case REFERENCEBASE:
1408 element = new ReferenceDetailElement(this, parentElement, style);
1409 break;
1410 case NOMENCLATURALREFERENCE:
1411 element = new NomenclaturalReferenceDetailElement(this, parentElement, style);
1412 break;
1413 case TAXONBASE:
1414 element = new TaxonBaseDetailElement(this, parentElement, style);
1415 break;
1416 case AUTHORSHIP:
1417 element = new AuthorshipDetailElement(this, parentElement, style);
1418 break;
1419 case TEAM:
1420 element = new TeamDetailElement(this, parentElement, style);
1421 break;
1422 case PERSON:
1423 element = new PersonDetailElement(this, parentElement, style);
1424 break;
1425 case DESCRIPTION:
1426 element = new DescriptionDetailElement(this, parentElement, style);
1427 break;
1428 case DESCRIPTIONELEMENT:
1429 element = new DescriptionElementDetailElement(this, parentElement, style);
1430 break;
1431 case NONVIRALNAME:
1432 element = new NonViralNameDetailElement(this, parentElement);
1433 break;
1434 case DERIVED_UNIT_FACADE:
1435 element = new DerivedUnitFacadeDetailElement(this, parentElement);
1436 break;
1437 case FIELD_OBSERVATION:
1438 element = new FieldObservationDetailElement(this, parentElement);
1439 break;
1440 case GATHERING_EVENT:
1441 element = new GatheringEventDetailElement(this, parentElement);
1442 break;
1443 case DERIVED_UNIT:
1444 element = new DerivedUnitBaseDetailElement(this, parentElement);
1445 break;
1446 case NATURAL_LANGUAGE:
1447 element = new NaturalLanguageDetailElement(this, parentElement);
1448 break;
1449 case FEATURE_DISTRIBUTION:
1450 element = new FeatureDistributionDetailElement(this, parentElement);
1451 break;
1452 case CLASSIFICATION:
1453 element = new ClassificationDetailElement(this, parentElement);
1454 break;
1455 case TAXON_NODE:
1456 element = new TaxonNodeDetailElement(this, parentElement);
1457 break;
1458 case COLLECTION:
1459 element = new CollectionDetailElement(this, parentElement);
1460 break;
1461 case POLYTOMOUS_KEY:
1462 element = new PolytomousKeyDetailElement(this, parentElement);
1463 break;
1464 case POLYTOMOUS_KEY_NODE:
1465 element = new PolytomousKeyNodeDetailElement(this, parentElement);
1466 break;
1467 case INSTITUTION:
1468 element = new InstitutionDetailElement(this, parentElement);
1469 break;
1470 case DERIVED_UNIT_GENERAL:
1471 element = new GeneralDetailElement(this, parentElement);
1472 break;
1473 case HYBRID:
1474 element = new HybridDetailElement(this, parentElement);
1475 break;
1476 }
1477
1478 if(element == null){
1479 EditorUtil.error(this.getClass(), "Detail element was not created. Seems like the case was not implemented for the requested detail type: " + detailType, null);
1480 }
1481
1482 adapt(element);
1483 parentElement.addElement(element);
1484 return element;
1485 }
1486
1487 /**
1488 *
1489 * @author n.hoffmann
1490 * @created Mar 5, 2010
1491 * @version 1.0
1492 */
1493 public static enum EntityDetailType{
1494 TEAM,
1495 TEAMMEMBER,
1496 ANNOTATION,
1497 CREDIT,
1498 DESCRIPTIONELEMENTSOURCE,
1499 EXTENSION,
1500 MARKER,
1501 MEDIA,
1502 DESCRIPTIONELEMENTMEDIA,
1503 MEDIAREPRESENTATION,
1504 MEDIAREPRESENTATIONPART,
1505 MODIFIER,
1506 NOMENCLATURALSTATUS,
1507 NAME_RELATIONSHIP,
1508 PROTOLOG,
1509 RIGHTS,
1510 SOURCE,
1511 SCOPE,
1512 DESCRIPTIONSOURCE,
1513 TYPEDESIGNATION,
1514 STATE_DATA,
1515 STATISTICAL_MEASUREMENT_VALUE,
1516 DESCRIBED_SPECIMEN,
1517 COLLECTING_AREA,
1518 DETERMINATION_EVENT,
1519 SPECIMEN_COLLECTION,
1520 IDENTIFIABLE_SOURCE_COLLECTION,
1521 GEOGRAPHICAL_SCOPE,
1522 SCOPE_RESTRICTION
1523 }
1524
1525 /**
1526 * <p>createEntityDetailSection</p>
1527 *
1528 * @param entityDetailType a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory.EntityDetailType} object.
1529 * @param style a int.
1530 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
1531 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1532 * @return a {@link eu.etaxonomy.taxeditor.forms.AbstractFormSection} object.
1533 */
1534 public AbstractFormSection createEntityDetailSection(EntityDetailType entityDetailType, ConversationHolder conversation, ICdmFormElement parentElement, int style){
1535 AbstractFormSection section = null;
1536
1537 switch(entityDetailType){
1538 case TEAM:
1539 section = new TeamDetailSection(this, conversation, parentElement, null, style);
1540 break;
1541 case TEAMMEMBER:
1542 section = new TeamMemberSection(this, conversation, parentElement, style);
1543 break;
1544 case ANNOTATION:
1545 section = new AnnotationSection(this, conversation, parentElement, style);
1546 break;
1547 case CREDIT:
1548 section = new CreditSection(this, conversation, parentElement, style);
1549 break;
1550 case DESCRIPTIONELEMENTSOURCE:
1551 section = new DescriptionElementSourceSection(this, conversation, parentElement, style);
1552 break;
1553 case EXTENSION:
1554 section = new ExtensionSection(this, conversation, parentElement, style);
1555 break;
1556 case MARKER:
1557 section = new MarkerSection(this, conversation, parentElement, style);
1558 break;
1559 case MEDIA:
1560 section = new MediaSection(this, conversation, parentElement, style);
1561 break;
1562 case DESCRIPTIONELEMENTMEDIA:
1563 section = new DescriptionElementMediaSection(this, conversation, parentElement, style);
1564 break;
1565 case MEDIAREPRESENTATION:
1566 section = new MediaRepresentationSection(this, conversation, parentElement, style);
1567 break;
1568 case MEDIAREPRESENTATIONPART:
1569 section = new MediaRepresentationPartSection(this, conversation, parentElement, style);
1570 break;
1571 case MODIFIER:
1572 section = new ModifierSection(this, conversation, parentElement, style);
1573 break;
1574 case NOMENCLATURALSTATUS:
1575 section = new NomenclaturalStatusSection(this, conversation, parentElement, style);
1576 break;
1577 case NAME_RELATIONSHIP:
1578 section = new NameRelationshipDetailSection(this, conversation, parentElement, style);
1579 break;
1580 case PROTOLOG:
1581 section = new ProtologueSection(this, conversation, parentElement, style);
1582 break;
1583 case RIGHTS:
1584 section = new RightsSection(this, conversation, parentElement, style);
1585 break;
1586 case SOURCE:
1587 section = new SourceSection(this, conversation, parentElement, style);
1588 break;
1589 case SCOPE:
1590 section = new ScopeSection(this, conversation, parentElement, style);
1591 break;
1592 case DESCRIPTIONSOURCE:
1593 section = new DescriptionSourceSection(this, conversation, parentElement, style);
1594 break;
1595 case TYPEDESIGNATION:
1596 section = new TypeDesignationSection(this, conversation, parentElement, style);
1597 break;
1598 case STATE_DATA:
1599 section = new StateDataSection(this, conversation, parentElement, style);
1600 break;
1601 case STATISTICAL_MEASUREMENT_VALUE:
1602 section = new StatisticalMeasurementValueSection(this, conversation, parentElement, style);
1603 break;
1604 case DESCRIBED_SPECIMEN:
1605 section = new DescribedSpecimenSection(this, conversation, parentElement, style);
1606 break;
1607 case COLLECTING_AREA:
1608 section = new CollectingAreasDetailSection(this, conversation, parentElement, style);
1609 break;
1610 case DETERMINATION_EVENT:
1611 section = new DeterminationEventDetailSection(this, conversation, parentElement, style);
1612 break;
1613 case SPECIMEN_COLLECTION:
1614 section = new SpecimenCollectionDetailSection(this, conversation, parentElement, style);
1615 break;
1616 case IDENTIFIABLE_SOURCE_COLLECTION:
1617 section = new SourceCollectionDetailSection(this, conversation, parentElement, style);
1618 break;
1619 case GEOGRAPHICAL_SCOPE:
1620 section = new GeographicalScopeDetailSection(this, conversation, parentElement, style);
1621 break;
1622 case SCOPE_RESTRICTION:
1623 section = new ScopeRestrictionSection(this, conversation, parentElement, style);
1624 break;
1625 }
1626 parentElement.addElement(section);
1627 adapt(section);
1628 return section;
1629 }
1630
1631 /**
1632 * <p>createEntityCollectionElement</p>
1633 *
1634 * @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
1635 * @param style a int.
1636 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.AbstractFormSection} object.
1637 * @param versionableEntity a {@link eu.etaxonomy.cdm.model.common.IVersionableEntity} object.
1638 * @param backgroundColor a {@link org.eclipse.swt.graphics.Color} object.
1639 * @return a {@link eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement} object.
1640 */
1641 public AbstractEntityCollectionElement createEntityCollectionElement(AbstractFormSection parentElement, IVersionableEntity versionableEntity, SelectionListener removeListener, Color backgroundColor, int style){
1642 AbstractEntityCollectionElement element = null;
1643
1644 VersionableEntity entity = (VersionableEntity) HibernateProxyHelper.deproxy(versionableEntity);
1645
1646 if(entity instanceof Annotation){
1647 element = new AnnotationElement(this, parentElement, (Annotation) entity, removeListener, style);
1648 }
1649 else if(entity instanceof Person){
1650 element = new TeamMemberElement(this, parentElement, (Person) entity, removeListener, style);
1651 }
1652 else if(entity instanceof Credit){
1653 element = new CreditElement(this, parentElement, (Credit) entity, removeListener, style);
1654 }
1655 else if(entity instanceof Extension){
1656 element = new ExtensionElement(this, parentElement, (Extension) entity, removeListener, style);
1657 }
1658 else if(entity instanceof Marker){
1659 element = new MarkerElement(this, parentElement, (Marker) entity, removeListener, style);
1660 }
1661 else if(entity instanceof Media){
1662 element = new MediaElement(this, parentElement, (Media) entity, removeListener, style);
1663 }
1664 else if(entity instanceof MediaRepresentation){
1665 element = new MediaRepresentationElement(this, parentElement, (MediaRepresentation) entity, removeListener, style);
1666 }
1667 else if(entity instanceof ImageFile){
1668 element = new ImageFileElement(this, parentElement, (ImageFile) entity, removeListener, style);
1669 }
1670 else if(entity instanceof NomenclaturalStatus){
1671 element = new NomenclaturalStatusElement(this, parentElement, (NomenclaturalStatus) entity, removeListener, style);
1672 }
1673 else if(entity instanceof Rights){
1674 element = new RightsElement(this, parentElement, (Rights) entity, removeListener, style);
1675 }
1676 else if(entity instanceof DescriptionElementSource){
1677 element = new DescriptionElementSourceElement(this, parentElement, (DescriptionElementSource) entity, removeListener, style);
1678 }
1679 else if(entity instanceof IdentifiableSource){
1680 element = new IdentifiableSourceElement(this, parentElement, (IdentifiableSource) entity, removeListener, style);
1681 }
1682 else if(entity instanceof Scope){
1683 element = new ScopeElement(this, parentElement, (Scope) entity, removeListener, style);
1684 }
1685 else if(entity instanceof Modifier){
1686 element = new ModifierElement(this, parentElement, (Modifier) entity, removeListener, style);
1687 }
1688 else if(entity instanceof Reference){
1689 element = new DescriptionSourceElement(this, parentElement, (Reference) entity, removeListener, style);
1690 }
1691 else if(entity instanceof NameTypeDesignation){
1692 element = new NameTypeDesignationElement(this, parentElement, (NameTypeDesignation) entity, removeListener, style);
1693 }
1694 else if(entity instanceof NameRelationship){
1695 element = new NameRelationshipDetailElement(this, parentElement, (NameRelationship) entity, removeListener, style);
1696 }
1697 else if(entity instanceof SpecimenTypeDesignation){
1698 element = new SpecimenTypeDesignationElement(this, parentElement, (SpecimenTypeDesignation) entity, removeListener, style);
1699 }
1700 else if(entity instanceof StateData){
1701 element = new StateDataElement(this, parentElement, (StateData) entity, removeListener, style);
1702 }
1703 else if(entity instanceof StatisticalMeasurementValue){
1704 element = new StatisticalMeasurementValueElement(this, parentElement, (StatisticalMeasurementValue) entity, removeListener, style);
1705 }
1706 else if(entity instanceof DerivedUnit){
1707 element = new DerivedUnitElement(this, parentElement, (DerivedUnit) entity, removeListener, style);
1708 }
1709 else if(entity instanceof NamedArea){
1710 element = new NamedAreaDetailElement(this, parentElement, (NamedArea) entity, removeListener, style);
1711 }
1712 else if(entity instanceof DeterminationEvent){
1713 element = new DeterminationEventDetailElement(this, parentElement, (DeterminationEvent) entity, removeListener, style);
1714 }
1715 else if(entity instanceof Specimen){
1716 element = new SpecimenCollectionDetailElement(this, parentElement, (Specimen) entity, removeListener, style);
1717 }
1718
1719 else if(entity instanceof DescriptionElementBase){
1720 // this is the special case for protologs, maybe we can do this differently when API improves
1721 DescriptionElementBase descriptionElement = (DescriptionElementBase) entity;
1722 if(descriptionElement.getFeature().equals(Feature.PROTOLOGUE())){
1723 element = new ProtologueElement(this, parentElement, descriptionElement, removeListener, style);
1724 }
1725 }
1726
1727 if(element == null){
1728 EditorUtil.errorDialog("No element for entity", this, "Could not generate element for entity. " +
1729 "Looks like the case is not handled already. Check implementation. Entity: " + entity, null);
1730 }
1731
1732 if(backgroundColor != null && !backgroundColor.isDisposed()){
1733 element.setBackgroundColor(backgroundColor);
1734 }
1735
1736 adapt(element);
1737 parentElement.addElement(element);
1738 return element;
1739 }
1740
1741 /**
1742 * <p>createSelectionElement</p>
1743 *
1744 * @param selectionType a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory.SelectionType} object.
1745 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1746 * @param labelString a {@link java.lang.String} object.
1747 * @param selectionType
1748 * @param selection a {@link eu.etaxonomy.cdm.model.common.IAnnotatableEntity} object.
1749 * @param style a int.
1750 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
1751 * @return a {@link eu.etaxonomy.taxeditor.forms.selection.AbstractSelectionElement} object.
1752 */
1753 public AbstractSelectionElement createSelectionElement(SelectionType selectionType, ConversationHolder conversation, ICdmFormElement parentElement, String labelString, ICdmBase selection, int style){
1754 AbstractSelectionElement element = null;
1755
1756 IAnnotatableEntity entity = (IAnnotatableEntity) HibernateProxyHelper.deproxy(selection);
1757
1758 switch (selectionType) {
1759 case AGENT:
1760 element = new AgentSelectionElement(this, conversation, parentElement, labelString, (TeamOrPersonBase) entity, style);
1761 break;
1762 case PERSON:
1763 element = new PersonSelectionElement(this, conversation, parentElement, labelString, (Person) entity, style);
1764 break;
1765 case TEAM:
1766 element = new TeamSelectionElement(this, conversation, parentElement, labelString, (Team) entity, style);
1767 break;
1768 case AUTHOR_TEAM:
1769 element = new NomenclaturalAuthorTeamSelectionElement(this, conversation, parentElement, labelString, (Team) entity, style);
1770 break;
1771 case INSTITUTION:
1772 element = new InstitutionSelectionElement(this, conversation, parentElement, labelString, (Institution) entity, style);
1773 break;
1774 case NAME:
1775 element = new NameSelectionElement(this, conversation, parentElement, labelString, (TaxonNameBase) entity, style);
1776 break;
1777 case REFERENCE:
1778 element = new ReferenceSelectionElement(this, conversation, parentElement, labelString, (Reference) entity, style);
1779 break;
1780 case TAXON_BASE:
1781 element = new TaxonBaseSelectionElement(this, conversation, parentElement, labelString, (TaxonBase) entity, style);
1782 break;
1783 case TAXON:
1784 element = new TaxonSelectionElement(this, conversation, parentElement, labelString, (Taxon) entity, style);
1785 break;
1786 case SYNONYM:
1787 element = new SynonymSelectionElement(this, conversation, parentElement, labelString, (Synonym) entity, style);
1788 break;
1789 case DERIVED_UNIT:
1790 element = new DerivedUnitBaseSelectionElement(this, conversation, parentElement, labelString, (DerivedUnitBase) entity, style);
1791 break;
1792 case FIELD_OBSERVATION:
1793 element = new FieldObservationSelectionElement(this, conversation, parentElement, labelString, (FieldObservation) entity, style);
1794 break;
1795 case FEATURE_TREE:
1796 element = new FeatureTreeSelectionElement(this, conversation, parentElement, labelString, (FeatureTree) entity, style);
1797 break;
1798 case CLASSIFICATION:
1799 element = new ClassificationSelectionElement(this, conversation, parentElement, labelString, (Classification) entity, style);
1800 break;
1801 case TAXON_NODE:
1802 element = new TaxonNodeSelectionElement(this, conversation, parentElement, labelString, (TaxonNode) entity, style);
1803 break;
1804 case COLLECTION:
1805 element = new CollectionSelectionElement(this, conversation, parentElement, labelString, (Collection) entity, style);
1806 break;
1807 case FEATURE:
1808 element = new FeatureSelectionElement(this, conversation, parentElement, labelString, (Feature) entity, style);
1809 break;
1810 case POLYTOMOUS_KEY:
1811 element = new PolytomousKeySelectionElement(this, conversation, parentElement, labelString, (PolytomousKey) entity, style);
1812 break;
1813 case POLYTOMOUS_KEY_NODE:
1814 element = new PolytomousKeyNodeSelectionElement(this, conversation, parentElement, labelString, (PolytomousKeyNode) entity, style);
1815 break;
1816 default:
1817 new RuntimeException("There is no selection composite for the desired selection type.");
1818 break;
1819 }
1820
1821 adapt(element);
1822 parentElement.addElement(element);
1823 return element;
1824 }
1825
1826 /**
1827 * <p>createNamedAreaSelectionElement</p>
1828 *
1829 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1830 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
1831 * @param labelString a {@link java.lang.String} object.
1832 * @param selection a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
1833 * @param style a int.
1834 * @return a {@link eu.etaxonomy.taxeditor.forms.selection.NamedAreaSelectionElement} object.
1835 */
1836 public NamedAreaSelectionElement createNamedAreaSelectionElement(ICdmFormElement parentElement, ConversationHolder conversation, String labelString, NamedArea selection, int style){
1837 NamedAreaSelectionElement element = new NamedAreaSelectionElement(this, conversation, parentElement, labelString, selection, style);
1838 adapt(element);
1839 parentElement.addElement(element);
1840 return element;
1841 }
1842
1843 /** {@inheritDoc} */
1844 public LabelElement createLabel(ICdmFormElement parentElement, String text) {
1845 LabelElement labelElement = new LabelElement(this, parentElement, text);
1846 adapt(labelElement);
1847 parentElement.addElement(labelElement);
1848 return labelElement;
1849 }
1850
1851 /**
1852 * <p>Getter for the field <code>selectionProvider</code>.</p>
1853 *
1854 * @return a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
1855 */
1856 public ISelectionProvider getSelectionProvider() {
1857 return selectionProvider;
1858 }
1859
1860 /**
1861 * <p>createDetailedDescriptionDetailElement</p>
1862 *
1863 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
1864 * @param entity a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
1865 * @param style a int.
1866 * @return a {@link eu.etaxonomy.taxeditor.section.description.detail.AbstractDetailedDescriptionDetailElement} object.
1867 */
1868 public AbstractDetailedDescriptionDetailElement createDetailedDescriptionDetailElement(
1869 ICdmFormElement parentElement, DescriptionElementBase entity, int style) {
1870 AbstractDetailedDescriptionDetailElement detailedDescriptionElement = null;
1871
1872
1873 if(entity instanceof CategoricalData){
1874 detailedDescriptionElement = new CategoricalDataDetailElement(this, parentElement, (CategoricalData) entity, style);
1875 }
1876 else if(entity instanceof CommonTaxonName){
1877 detailedDescriptionElement = new CommonNameDetailElement(this, parentElement, (CommonTaxonName) entity, style);
1878 }
1879 else if(entity instanceof Distribution){
1880 detailedDescriptionElement = new DistributionDetailElement(this, parentElement, (Distribution) entity, style);
1881 }
1882 else if(entity instanceof IndividualsAssociation){
1883 detailedDescriptionElement = new IndividualsAssociationDetailElement(this, parentElement, (IndividualsAssociation) entity, style);
1884 }
1885 else if(entity instanceof QuantitativeData){
1886 detailedDescriptionElement = new QuantitativeDataDetailElement(this, parentElement, (QuantitativeData) entity, style);
1887 }
1888 else if(entity instanceof TaxonInteraction){
1889 detailedDescriptionElement = new TaxonInteractionDetailElement(this, parentElement, (TaxonInteraction) entity, style);
1890 }
1891 else if(entity instanceof TextData){
1892 detailedDescriptionElement = new TextDataDetailElement(this, parentElement, (TextData) entity, style);
1893 }
1894 else{
1895 throw new IllegalStateException("There is no interface for the given description element");
1896 }
1897 adapt(detailedDescriptionElement);
1898 parentElement.addElement(detailedDescriptionElement);
1899 return detailedDescriptionElement;
1900
1901 }
1902
1903
1904 /**
1905 * Creates a styled text as a part of the form.
1906 *
1907 * @param parent
1908 * the text parent
1909 * @param value
1910 * the text initial value
1911 * @param style
1912 * the text style
1913 * @return the text widget
1914 */
1915 public StyledText createStyledText(Composite parent, String value, int style) {
1916 StyledText text = new StyledText(parent, getBorderStyle() | style | getOrientation());
1917 if (value != null)
1918 text.setText(value);
1919 text.setForeground(getColors().getForeground());
1920 text.setBackground(getColors().getBackground());
1921 // text.addFocusListener(visibilityHandler);
1922 return text;
1923 }
1924 }