Fixing background color logic as it was kind of broken
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / forms / CdmFormFactory.java
1 /**
2 *
3 */
4 package eu.etaxonomy.taxeditor.ui.forms;
5
6 import java.net.URI;
7 import java.util.ArrayList;
8 import java.util.HashSet;
9 import java.util.List;
10 import java.util.Map;
11 import java.util.Set;
12
13 import org.eclipse.jface.util.IPropertyChangeListener;
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.jface.viewers.ISelectionProvider;
16 import org.eclipse.jface.window.Window;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.custom.StyledText;
19 import org.eclipse.swt.events.FocusAdapter;
20 import org.eclipse.swt.events.FocusEvent;
21 import org.eclipse.swt.events.FocusListener;
22 import org.eclipse.swt.events.MouseAdapter;
23 import org.eclipse.swt.events.MouseEvent;
24 import org.eclipse.swt.events.MouseListener;
25 import org.eclipse.swt.events.SelectionEvent;
26 import org.eclipse.swt.events.SelectionListener;
27 import org.eclipse.swt.events.TypedEvent;
28 import org.eclipse.swt.graphics.Color;
29 import org.eclipse.swt.graphics.Font;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Display;
33 import org.eclipse.swt.widgets.Event;
34 import org.eclipse.swt.widgets.Label;
35 import org.eclipse.ui.forms.IFormColors;
36 import org.eclipse.ui.forms.widgets.FormToolkit;
37 import org.eclipse.ui.forms.widgets.Section;
38 import org.eclipse.ui.forms.widgets.TableWrapData;
39 import org.eclipse.ui.forms.widgets.TableWrapLayout;
40 import org.eclipse.ui.internal.forms.widgets.FormFonts;
41 import org.joda.time.Partial;
42 import org.springframework.security.core.GrantedAuthority;
43
44 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
45 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
46 import eu.etaxonomy.cdm.model.agent.Institution;
47 import eu.etaxonomy.cdm.model.agent.Person;
48 import eu.etaxonomy.cdm.model.agent.Team;
49 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
50 import eu.etaxonomy.cdm.model.common.Annotation;
51 import eu.etaxonomy.cdm.model.common.AnnotationType;
52 import eu.etaxonomy.cdm.model.common.Credit;
53 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
54 import eu.etaxonomy.cdm.model.common.DescriptionElementSource;
55 import eu.etaxonomy.cdm.model.common.Extension;
56 import eu.etaxonomy.cdm.model.common.ExtensionType;
57 import eu.etaxonomy.cdm.model.common.Group;
58 import eu.etaxonomy.cdm.model.common.IAnnotatableEntity;
59 import eu.etaxonomy.cdm.model.common.ICdmBase;
60 import eu.etaxonomy.cdm.model.common.IdentifiableSource;
61 import eu.etaxonomy.cdm.model.common.Language;
62 import eu.etaxonomy.cdm.model.common.LanguageString;
63 import eu.etaxonomy.cdm.model.common.Marker;
64 import eu.etaxonomy.cdm.model.common.MarkerType;
65 import eu.etaxonomy.cdm.model.common.TimePeriod;
66 import eu.etaxonomy.cdm.model.common.User;
67 import eu.etaxonomy.cdm.model.common.VersionableEntity;
68 import eu.etaxonomy.cdm.model.description.CategoricalData;
69 import eu.etaxonomy.cdm.model.description.CommonTaxonName;
70 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
71 import eu.etaxonomy.cdm.model.description.Distribution;
72 import eu.etaxonomy.cdm.model.description.Feature;
73 import eu.etaxonomy.cdm.model.description.FeatureTree;
74 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
75 import eu.etaxonomy.cdm.model.description.KeyStatement;
76 import eu.etaxonomy.cdm.model.description.MeasurementUnit;
77 import eu.etaxonomy.cdm.model.description.Modifier;
78 import eu.etaxonomy.cdm.model.description.PolytomousKey;
79 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
80 import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
81 import eu.etaxonomy.cdm.model.description.QuantitativeData;
82 import eu.etaxonomy.cdm.model.description.Scope;
83 import eu.etaxonomy.cdm.model.description.Sex;
84 import eu.etaxonomy.cdm.model.description.Stage;
85 import eu.etaxonomy.cdm.model.description.State;
86 import eu.etaxonomy.cdm.model.description.StateData;
87 import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
88 import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
89 import eu.etaxonomy.cdm.model.description.TaxonInteraction;
90 import eu.etaxonomy.cdm.model.description.TextData;
91 import eu.etaxonomy.cdm.model.location.NamedArea;
92 import eu.etaxonomy.cdm.model.location.NamedAreaType;
93 import eu.etaxonomy.cdm.model.location.Point;
94 import eu.etaxonomy.cdm.model.location.ReferenceSystem;
95 import eu.etaxonomy.cdm.model.media.ImageFile;
96 import eu.etaxonomy.cdm.model.media.Media;
97 import eu.etaxonomy.cdm.model.media.MediaRepresentation;
98 import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
99 import eu.etaxonomy.cdm.model.media.Rights;
100 import eu.etaxonomy.cdm.model.media.RightsTerm;
101 import eu.etaxonomy.cdm.model.name.NameRelationship;
102 import eu.etaxonomy.cdm.model.name.NameRelationshipType;
103 import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
104 import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
105 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
106 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
107 import eu.etaxonomy.cdm.model.name.Rank;
108 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
109 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
110 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
111 import eu.etaxonomy.cdm.model.occurrence.Collection;
112 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
113 import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
114 import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
115 import eu.etaxonomy.cdm.model.occurrence.DeterminationModifier;
116 import eu.etaxonomy.cdm.model.occurrence.FieldObservation;
117 import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
118 import eu.etaxonomy.cdm.model.occurrence.Specimen;
119 import eu.etaxonomy.cdm.model.reference.Reference;
120 import eu.etaxonomy.cdm.model.taxon.Classification;
121 import eu.etaxonomy.cdm.model.taxon.Synonym;
122 import eu.etaxonomy.cdm.model.taxon.Taxon;
123 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
124 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
125 import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
126 import eu.etaxonomy.taxeditor.store.StoreUtil;
127 import eu.etaxonomy.taxeditor.ui.forms.password.EditPasswordElement;
128 import eu.etaxonomy.taxeditor.ui.openurl.IOpenUrlEnabled;
129 import eu.etaxonomy.taxeditor.ui.openurl.OpenUrlSelectorElement;
130 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
131 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
132 import eu.etaxonomy.taxeditor.ui.section.EmptyElement;
133 import eu.etaxonomy.taxeditor.ui.section.agent.InstitutionDetailElement;
134 import eu.etaxonomy.taxeditor.ui.section.agent.InstitutionDetailSection;
135 import eu.etaxonomy.taxeditor.ui.section.agent.PersonDetailElement;
136 import eu.etaxonomy.taxeditor.ui.section.agent.PersonDetailSection;
137 import eu.etaxonomy.taxeditor.ui.section.agent.TeamDetailElement;
138 import eu.etaxonomy.taxeditor.ui.section.agent.TeamDetailSection;
139 import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberElement;
140 import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberSection;
141 import eu.etaxonomy.taxeditor.ui.section.agent.TeamOrPersonBaseDetailSection;
142 import eu.etaxonomy.taxeditor.ui.section.classification.ClassificationDetailElement;
143 import eu.etaxonomy.taxeditor.ui.section.classification.ClassificationDetailSection;
144 import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailElement;
145 import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailSection;
146 import eu.etaxonomy.taxeditor.ui.section.description.DerivedUnitElement;
147 import eu.etaxonomy.taxeditor.ui.section.description.DescribedSpecimenSection;
148 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionDetailElement;
149 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionDetailSection;
150 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementDetailElement;
151 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementDetailSection;
152 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementMediaSection;
153 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementSourceElement;
154 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementSourceSection;
155 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionSourceElement;
156 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionSourceSection;
157 import eu.etaxonomy.taxeditor.ui.section.description.ModifierElement;
158 import eu.etaxonomy.taxeditor.ui.section.description.ModifierSection;
159 import eu.etaxonomy.taxeditor.ui.section.description.NaturalLanguageDetailElement;
160 import eu.etaxonomy.taxeditor.ui.section.description.NaturalLanguageSection;
161 import eu.etaxonomy.taxeditor.ui.section.description.ScopeElement;
162 import eu.etaxonomy.taxeditor.ui.section.description.ScopeSection;
163 import eu.etaxonomy.taxeditor.ui.section.description.StateDataElement;
164 import eu.etaxonomy.taxeditor.ui.section.description.StateDataSection;
165 import eu.etaxonomy.taxeditor.ui.section.description.StatisticalMeasurementValueElement;
166 import eu.etaxonomy.taxeditor.ui.section.description.StatisticalMeasurementValueSection;
167 import eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement;
168 import eu.etaxonomy.taxeditor.ui.section.description.detail.CategoricalDataDetailElement;
169 import eu.etaxonomy.taxeditor.ui.section.description.detail.CommonNameDetailElement;
170 import eu.etaxonomy.taxeditor.ui.section.description.detail.DistributionDetailElement;
171 import eu.etaxonomy.taxeditor.ui.section.description.detail.IndividualsAssociationDetailElement;
172 import eu.etaxonomy.taxeditor.ui.section.description.detail.QuantitativeDataDetailElement;
173 import eu.etaxonomy.taxeditor.ui.section.description.detail.TaxonInteractionDetailElement;
174 import eu.etaxonomy.taxeditor.ui.section.description.detail.TextDataDetailElement;
175 import eu.etaxonomy.taxeditor.ui.section.feature.FeatureDistributionDetailElement;
176 import eu.etaxonomy.taxeditor.ui.section.feature.FeatureDistributionDetailSection;
177 import eu.etaxonomy.taxeditor.ui.section.group.GrantedAuthorityDetailElement;
178 import eu.etaxonomy.taxeditor.ui.section.group.GrantedAuthorityDetailSection;
179 import eu.etaxonomy.taxeditor.ui.section.group.GroupDetailElement;
180 import eu.etaxonomy.taxeditor.ui.section.group.GroupDetailSection;
181 import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailElement;
182 import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailSection;
183 import eu.etaxonomy.taxeditor.ui.section.key.GeographicalScopeDetailSection;
184 import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyDetailElement;
185 import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyDetailSection;
186 import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyNodeDetailElement;
187 import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyNodeDetailSection;
188 import eu.etaxonomy.taxeditor.ui.section.key.ScopeRestrictionSection;
189 import eu.etaxonomy.taxeditor.ui.section.key.TaxonomicScopeSection;
190 import eu.etaxonomy.taxeditor.ui.section.media.ImageFileElement;
191 import eu.etaxonomy.taxeditor.ui.section.media.MediaElement;
192 import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationElement;
193 import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationPartElement;
194 import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationPartSection;
195 import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationSection;
196 import eu.etaxonomy.taxeditor.ui.section.media.MediaSection;
197 import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailElement;
198 import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailSection;
199 import eu.etaxonomy.taxeditor.ui.section.name.HybridDetailElement;
200 import eu.etaxonomy.taxeditor.ui.section.name.HybridDetailSection;
201 import eu.etaxonomy.taxeditor.ui.section.name.NameDetailElement;
202 import eu.etaxonomy.taxeditor.ui.section.name.NameDetailSection;
203 import eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailElement;
204 import eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailSection;
205 import eu.etaxonomy.taxeditor.ui.section.name.NameTypeDesignationElement;
206 import eu.etaxonomy.taxeditor.ui.section.name.NomenclaturalStatusElement;
207 import eu.etaxonomy.taxeditor.ui.section.name.NomenclaturalStatusSection;
208 import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameDetailElement;
209 import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameDetailSection;
210 import eu.etaxonomy.taxeditor.ui.section.name.ProtologueElement;
211 import eu.etaxonomy.taxeditor.ui.section.name.ProtologueSection;
212 import eu.etaxonomy.taxeditor.ui.section.name.SpecimenTypeDesignationElement;
213 import eu.etaxonomy.taxeditor.ui.section.name.TypeDesignationSection;
214 import eu.etaxonomy.taxeditor.ui.section.occurrence.CollectingAreasDetailSection;
215 import eu.etaxonomy.taxeditor.ui.section.occurrence.CollectionDetailElement;
216 import eu.etaxonomy.taxeditor.ui.section.occurrence.CurrentDeterminationDetailSection;
217 import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseDetailElement;
218 import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseDetailSection;
219 import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitFacadeDetailElement;
220 import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitFacadeDetailSection;
221 import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationDetailElement;
222 import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationDetailSection;
223 import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationEventDetailElement;
224 import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationHistoryDetailSection;
225 import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldObservationDetailElement;
226 import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldObservationDetailSection;
227 import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventDetailElement;
228 import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventDetailSection;
229 import eu.etaxonomy.taxeditor.ui.section.occurrence.GeneralDetailElement;
230 import eu.etaxonomy.taxeditor.ui.section.occurrence.GeneralDetailSection;
231 import eu.etaxonomy.taxeditor.ui.section.occurrence.NamedAreaDetailElement;
232 import eu.etaxonomy.taxeditor.ui.section.occurrence.SourceCollectionDetailSection;
233 import eu.etaxonomy.taxeditor.ui.section.occurrence.SpecimenCollectionDetailElement;
234 import eu.etaxonomy.taxeditor.ui.section.occurrence.SpecimenCollectionDetailSection;
235 import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailElement;
236 import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailSection;
237 import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailElement;
238 import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailSection;
239 import eu.etaxonomy.taxeditor.ui.section.supplemental.AnnotationElement;
240 import eu.etaxonomy.taxeditor.ui.section.supplemental.AnnotationSection;
241 import eu.etaxonomy.taxeditor.ui.section.supplemental.CreditElement;
242 import eu.etaxonomy.taxeditor.ui.section.supplemental.CreditSection;
243 import eu.etaxonomy.taxeditor.ui.section.supplemental.ExtensionElement;
244 import eu.etaxonomy.taxeditor.ui.section.supplemental.ExtensionSection;
245 import eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection;
246 import eu.etaxonomy.taxeditor.ui.section.supplemental.IdentifiableSourceElement;
247 import eu.etaxonomy.taxeditor.ui.section.supplemental.MarkerElement;
248 import eu.etaxonomy.taxeditor.ui.section.supplemental.MarkerSection;
249 import eu.etaxonomy.taxeditor.ui.section.supplemental.RightsElement;
250 import eu.etaxonomy.taxeditor.ui.section.supplemental.RightsSection;
251 import eu.etaxonomy.taxeditor.ui.section.supplemental.SourceSection;
252 import eu.etaxonomy.taxeditor.ui.section.supplemental.VersionElement;
253 import eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection;
254 import eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessageElement;
255 import eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessagesSection;
256 import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonBaseDetailElement;
257 import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonBaseDetailSection;
258 import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonDetailElement;
259 import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailElement;
260 import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailSection;
261 import eu.etaxonomy.taxeditor.ui.section.user.UserDetailElement;
262 import eu.etaxonomy.taxeditor.ui.section.user.UserDetailSection;
263 import eu.etaxonomy.taxeditor.ui.selection.AbstractSelectionElement;
264 import eu.etaxonomy.taxeditor.ui.selection.AgentSelectionElement;
265 import eu.etaxonomy.taxeditor.ui.selection.ClassificationSelectionElement;
266 import eu.etaxonomy.taxeditor.ui.selection.CollectionSelectionElement;
267 import eu.etaxonomy.taxeditor.ui.selection.DerivedUnitBaseSelectionElement;
268 import eu.etaxonomy.taxeditor.ui.selection.FeatureSelectionElement;
269 import eu.etaxonomy.taxeditor.ui.selection.FeatureTreeSelectionElement;
270 import eu.etaxonomy.taxeditor.ui.selection.FieldObservationSelectionElement;
271 import eu.etaxonomy.taxeditor.ui.selection.GroupSelectionElement;
272 import eu.etaxonomy.taxeditor.ui.selection.InstitutionSelectionElement;
273 import eu.etaxonomy.taxeditor.ui.selection.NameSelectionElement;
274 import eu.etaxonomy.taxeditor.ui.selection.NamedAreaSelectionElement;
275 import eu.etaxonomy.taxeditor.ui.selection.NomenclaturalAuthorTeamSelectionElement;
276 import eu.etaxonomy.taxeditor.ui.selection.PersonSelectionElement;
277 import eu.etaxonomy.taxeditor.ui.selection.PolytomousKeyNodeSelectionElement;
278 import eu.etaxonomy.taxeditor.ui.selection.PolytomousKeySelectionElement;
279 import eu.etaxonomy.taxeditor.ui.selection.ReferenceSelectionElement;
280 import eu.etaxonomy.taxeditor.ui.selection.SynonymSelectionElement;
281 import eu.etaxonomy.taxeditor.ui.selection.TaxonBaseSelectionElement;
282 import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
283 import eu.etaxonomy.taxeditor.ui.selection.TaxonSelectionElement;
284 import eu.etaxonomy.taxeditor.ui.selection.TeamSelectionElement;
285 import eu.etaxonomy.taxeditor.ui.selection.UserSelectionElement;
286 import eu.etaxonomy.taxeditor.ui.term.AbstractEnumComboElement;
287 import eu.etaxonomy.taxeditor.ui.term.AbstractTermComboElement;
288 import eu.etaxonomy.taxeditor.ui.term.AnnotationTypeComboElement;
289 import eu.etaxonomy.taxeditor.ui.term.DeterminationModifierComboElement;
290 import eu.etaxonomy.taxeditor.ui.term.EmptyComboElement;
291 import eu.etaxonomy.taxeditor.ui.term.ExtensionTypeComboElement;
292 import eu.etaxonomy.taxeditor.ui.term.LanguageComboElement;
293 import eu.etaxonomy.taxeditor.ui.term.MarkerTypeComboElement;
294 import eu.etaxonomy.taxeditor.ui.term.MeasurementUnitComboElement;
295 import eu.etaxonomy.taxeditor.ui.term.ModifierComboElement;
296 import eu.etaxonomy.taxeditor.ui.term.NameRelationshipTypeComboElement;
297 import eu.etaxonomy.taxeditor.ui.term.NameTypeDesignationStatusComboElement;
298 import eu.etaxonomy.taxeditor.ui.term.NamedAreaTypeComboElement;
299 import eu.etaxonomy.taxeditor.ui.term.NomenclaturalCodeComboElement;
300 import eu.etaxonomy.taxeditor.ui.term.NomenclaturalStatusTypeComboElement;
301 import eu.etaxonomy.taxeditor.ui.term.PresenceAbsenceTermComboElement;
302 import eu.etaxonomy.taxeditor.ui.term.PreservationMethodComboElement;
303 import eu.etaxonomy.taxeditor.ui.term.RankComboElement;
304 import eu.etaxonomy.taxeditor.ui.term.ReferenceSystemComboElement;
305 import eu.etaxonomy.taxeditor.ui.term.ReferenceTypeComboElement;
306 import eu.etaxonomy.taxeditor.ui.term.RightsTypeComboElement;
307 import eu.etaxonomy.taxeditor.ui.term.ScopeComboElement;
308 import eu.etaxonomy.taxeditor.ui.term.SexComboElement;
309 import eu.etaxonomy.taxeditor.ui.term.SpecimenTypeDesignationStatusComboElement;
310 import eu.etaxonomy.taxeditor.ui.term.StageComboElement;
311 import eu.etaxonomy.taxeditor.ui.term.StateComboElement;
312 import eu.etaxonomy.taxeditor.ui.term.StatisticalMeasureComboElement;
313
314 /**
315 * <p>
316 * CdmFormFactory class.
317 * </p>
318 *
319 * @author n.hoffmann
320 * @created Feb 24, 2010
321 * @version 1.0
322 */
323 public class CdmFormFactory extends FormToolkit {
324
325 private BoldFontHolder2 boldFontHolder2;
326 private MouseListener selectionMouseHandler;
327 private FocusListener selectionFocusHandler;
328
329 private final Set selectionListenerList = new HashSet();
330
331 private final List<IPropertyChangeListener> propertyChangeListeners = new ArrayList<IPropertyChangeListener>();
332
333 private final int orientation = Window.getDefaultOrientation();
334 private ISelectionProvider selectionProvider;
335
336 /**
337 * <p>
338 * LAYOUT
339 * </p>
340 *
341 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapLayout} object.
342 */
343 public static final TableWrapLayout LAYOUT() {
344 return LAYOUT(1, false);
345 }
346
347 /**
348 * <p>
349 * LAYOUT
350 * </p>
351 *
352 * @param columns
353 * a int.
354 * @param equalWidth
355 * a boolean.
356 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapLayout} object.
357 */
358 public static final TableWrapLayout LAYOUT(int columns, boolean equalWidth) {
359 TableWrapLayout layout = new TableWrapLayout();
360 layout.topMargin = 0;
361 layout.rightMargin = 0;
362 layout.bottomMargin = 0;
363 layout.leftMargin = 0;
364 layout.numColumns = columns;
365 layout.makeColumnsEqualWidth = equalWidth;
366 layout.verticalSpacing = 0;
367 layout.horizontalSpacing = 0;
368 return layout;
369 }
370
371 /**
372 * <p>
373 * FILL
374 * </p>
375 *
376 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
377 */
378 public static final TableWrapData FILL() {
379 return FILL(1, 1);
380 }
381
382 /**
383 * <p>
384 * FILL
385 * </p>
386 *
387 * @param horizontalSpan
388 * a int.
389 * @param verticalSpan
390 * a int.
391 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
392 */
393 public static final TableWrapData FILL(int horizontalSpan, int verticalSpan) {
394 TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB,
395 TableWrapData.FILL_GRAB);
396 layoutData.colspan = horizontalSpan;
397 layoutData.rowspan = verticalSpan;
398 return layoutData;
399 }
400
401 /**
402 * <p>
403 * LEFT
404 * </p>
405 *
406 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
407 */
408 public static final TableWrapData LEFT() {
409 return new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP);
410 }
411
412 /**
413 * <p>
414 * RIGHT
415 * </p>
416 *
417 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
418 */
419 public static final TableWrapData RIGHT() {
420 return new TableWrapData(TableWrapData.RIGHT, TableWrapData.TOP);
421 }
422
423 /**
424 * <p>
425 * FILL_HORIZONTALLY
426 * </p>
427 *
428 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
429 */
430 public static final TableWrapData FILL_HORIZONTALLY() {
431 return FILL_HORIZONTALLY(1, 1);
432 }
433
434 /**
435 * <p>
436 * FILL_HORIZONTALLY
437 * </p>
438 *
439 * @param horizontalSpan
440 * a int.
441 * @param verticalSpan
442 * a int.
443 * @return a {@link org.eclipse.ui.forms.widgets.TableWrapData} object.
444 */
445 public static final TableWrapData FILL_HORIZONTALLY(int horizontalSpan,
446 int verticalSpan) {
447 TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB,
448 TableWrapData.TOP);
449 layoutData.colspan = horizontalSpan;
450 layoutData.rowspan = verticalSpan;
451 return layoutData;
452 }
453
454 /** Constant <code>EMPTY_SELECTION</code> */
455 public static ISelection EMPTY_SELECTION = new ISelection() {
456 @Override
457 public boolean isEmpty() {
458 return true;
459 }
460 };
461
462 private class SelectionMouseHandler extends MouseAdapter {
463 @Override
464 public void mouseDown(MouseEvent e) {
465 notifySelectionListeners(e);
466 }
467 }
468
469 private class SelectionFocusHandler extends FocusAdapter {
470 @Override
471 public void focusGained(FocusEvent e) {
472 notifySelectionListeners(e);
473 }
474 }
475
476 private void notifySelectionListeners(TypedEvent e) {
477 Event event = new Event();
478 event.widget = e.widget;
479 SelectionEvent selectionEvent = new SelectionEvent(event);
480
481 for (Object listener : selectionListenerList) {
482 ((SelectionListener) listener).widgetSelected(selectionEvent);
483 }
484 }
485
486 /**
487 * <p>
488 * Constructor for CdmFormFactory.
489 * </p>
490 *
491 * @param display
492 * a {@link org.eclipse.swt.widgets.Display} object.
493 * @param selectionProvider
494 * a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
495 */
496 public CdmFormFactory(Display display, ISelectionProvider selectionProvider) {
497 super(display);
498 this.selectionProvider = selectionProvider;
499 init();
500 }
501
502 /**
503 * <p>
504 * Constructor for CdmFormFactory.
505 * </p>
506 *
507 * @param display
508 * a {@link org.eclipse.swt.widgets.Display} object.
509 */
510 public CdmFormFactory(Display display) {
511 super(display);
512 init();
513 }
514
515 /**
516 *
517 */
518 private void init() {
519 boldFontHolder2 = new BoldFontHolder2();
520 selectionMouseHandler = new SelectionMouseHandler();
521 selectionFocusHandler = new SelectionFocusHandler();
522 }
523
524 /**
525 * Creates an instance initialized with the correct selectionProvider
526 *
527 * Make sure to remove the instance when the entityComposite disposes via
528 * destroySelectionArbitrator(..)
529 *
530 * @param entityElement
531 * a {@link eu.etaxonomy.taxeditor.ui.forms.IEntityElement}
532 * object.
533 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.SelectionArbitrator}
534 * object.
535 */
536 public SelectionArbitrator createSelectionArbitrator(
537 IEntityElement entityElement) {
538 SelectionArbitrator selectionArbitrator = new SelectionArbitrator(
539 entityElement);
540 selectionArbitrator.addSelectionProvider(selectionProvider);
541 selectionProvider.addSelectionChangedListener(selectionArbitrator);
542 addSelectionListener(selectionArbitrator);
543 return selectionArbitrator;
544 }
545
546 /**
547 * <p>
548 * destroySelectionArbitrator
549 * </p>
550 *
551 * @param selectionArbitrator
552 * a {@link eu.etaxonomy.taxeditor.ui.forms.SelectionArbitrator}
553 * object.
554 */
555 public void destroySelectionArbitrator(
556 SelectionArbitrator selectionArbitrator) {
557 removeSelectionListener(selectionArbitrator);
558 if (selectionProvider != null) {
559 selectionProvider
560 .removeSelectionChangedListener(selectionArbitrator);
561 } else {
562 StoreUtil
563 .error(this.getClass(),
564 "Tried to destroy a selection listener from this factories listeners but was null",
565 null);
566 }
567 }
568
569 /** {@inheritDoc} */
570 @Override
571 public void adapt(Composite composite) {
572 composite.addMouseListener(selectionMouseHandler);
573 super.adapt(composite);
574 }
575
576 /**
577 * <p>
578 * adapt
579 * </p>
580 *
581 * @param formElement
582 * a
583 * {@link eu.etaxonomy.taxeditor.ui.forms.AbstractCdmFormElement}
584 * object.
585 */
586 public void adapt(AbstractCdmFormElement formElement) {
587 formElement.setPropertyChangeListeners(propertyChangeListeners);
588 }
589
590 /** {@inheritDoc} */
591 @Override
592 public void adapt(Control control, boolean trackFocus, boolean trackKeyboard) {
593 if (trackFocus) {
594 control.addFocusListener(selectionFocusHandler);
595 }
596 super.adapt(control, trackFocus, trackKeyboard);
597 }
598
599 /**
600 * <p>
601 * destroyElement
602 * </p>
603 *
604 * @param formElement
605 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
606 * object.
607 */
608 public void destroyElement(ICdmFormElement formElement) {
609 // return if element was not initialized
610 if (formElement == null) {
611 return;
612 }
613 // destroy selection arbitrator, if any
614 if (formElement instanceof ISelectableElement) {
615 destroySelectionArbitrator(((ISelectableElement) formElement)
616 .getSelectionArbitrator());
617 }
618 // remove this element form its parents list of elements
619 // ICdmFormElement parentElement = formElement.getParentElement();
620 // if(parentElement != null){
621 // parentElement.removeElement(formElement);
622 // }
623 // call destroy on child elements recursively
624 for (ICdmFormElement childElement : formElement.getElements()) {
625 destroyElement(childElement);
626 }
627 // dispose of the controls
628 for (Control control : formElement.getControls()) {
629 // we added the layoutComposite of the parental element as the
630 // layout composite to this formElement
631 // but we do not want to destroy it.
632 if (control.equals(formElement.getLayoutComposite())) {
633 continue;
634 } else {
635 control.dispose();
636 control = null;
637 }
638 }
639 }
640
641 /**
642 * <p>
643 * createEmptyCell
644 * </p>
645 *
646 * @param parent
647 * a {@link org.eclipse.swt.widgets.Composite} object.
648 * @return a {@link org.eclipse.swt.widgets.Label} object.
649 */
650 public Label createEmptyCell(Composite parent) {
651 return this.createLabel(parent, null);
652 }
653
654 /**
655 * <p>
656 * createMultilineTextWithLabel
657 * </p>
658 *
659 * @param labelString
660 * a {@link java.lang.String} object.
661 * @param textHeight
662 * a int.
663 * @param style
664 * a int.
665 * @param parentElement
666 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
667 * object.
668 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement}
669 * object.
670 */
671 public TextWithLabelElement createMultilineTextWithLabel(
672 ICdmFormElement parentElement, String labelString, int textHeight,
673 int style) {
674 TextWithLabelElement element = new TextWithLabelElement(this,
675 parentElement, labelString, "", textHeight, style);
676 adapt(element);
677 parentElement.addElement(element);
678 return element;
679 }
680
681 /**
682 * <p>
683 * createMultiLanguageTextElement
684 * </p>
685 *
686 * @param parentElement
687 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
688 * object.
689 * @param labelString
690 * a {@link java.lang.String} object.
691 * @param multilanguageText
692 * a {@link java.util.Map} object.
693 * @param textHeight
694 * a int.
695 * @param style
696 * a int.
697 * @return a
698 * {@link eu.etaxonomy.taxeditor.ui.forms.MultilanguageTextElement}
699 * object.
700 */
701 public MultilanguageTextElement createMultiLanguageTextElement(
702 ICdmFormElement parentElement, String labelString,
703 Map<Language, LanguageString> multilanguageText, int textHeight,
704 int style) {
705 MultilanguageTextElement element = new MultilanguageTextElement(this,
706 parentElement, labelString, multilanguageText, textHeight,
707 style);
708 adapt(element);
709 parentElement.addElement(element);
710 return element;
711 }
712
713 public KeyStatementElement createKeyStatementElement(
714 ICdmFormElement parentElement, String labelString,
715 KeyStatement keyStatement, int textHeight, int style) {
716 KeyStatementElement element = new KeyStatementElement(this,
717 parentElement, labelString, keyStatement, textHeight, style);
718 adapt(element);
719 parentElement.addElement(element);
720 return element;
721 }
722
723 /**
724 * <p>
725 * createTextWithLabelElement
726 * </p>
727 *
728 * @param labelString
729 * a {@link java.lang.String} object.
730 * @param initialText
731 * a {@link java.lang.String} object.
732 * @param style
733 * a int.
734 * @param parentElement
735 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
736 * object.
737 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement}
738 * object.
739 */
740 public TextWithLabelElement createTextWithLabelElement(
741 ICdmFormElement parentElement, String labelString,
742 String initialText, int style) {
743 TextWithLabelElement element = new TextWithLabelElement(this,
744 parentElement, labelString, initialText, null, style);
745 adapt(element);
746 parentElement.addElement(element);
747 return element;
748 }
749
750 public UriWithLabelElement createUriWithLabelElement(
751 ICdmFormElement parentElement, String labelString, URI initialUri,
752 int style) {
753 UriWithLabelElement element = new UriWithLabelElement(this,
754 parentElement, labelString, initialUri, null, style);
755 adapt(element);
756 parentElement.addElement(element);
757 return element;
758 }
759
760 /**
761 * @param element
762 * @param string
763 * @param uri
764 * @param style
765 * @return
766 */
767 public OpenUrlSelectorElement createOpenUrlSelectorElement(
768 ICdmFormElement parentElement, String labelString,
769 IOpenUrlEnabled openUrlEnabled, int style) {
770 OpenUrlSelectorElement element = new OpenUrlSelectorElement(this,
771 parentElement, labelString, openUrlEnabled, style);
772 adapt(element);
773 parentElement.addElement(element);
774 return element;
775 }
776
777 /**
778 *
779 * @param parentElement
780 * @param labelString
781 * @param conversationEnabled
782 * @param user
783 * @param style
784 * @return
785 */
786 public EditPasswordElement createEditPasswordElement(
787 ICdmFormElement parentElement, String labelString,
788 ConversationHolder conversation, User user, int style) {
789 EditPasswordElement element = new EditPasswordElement(this,
790 parentElement, labelString, user, conversation);
791 adapt(element);
792 parentElement.addElement(element);
793 return element;
794 }
795
796 /**
797 * <p>
798 * createIntegerTextWithLabelElement
799 * </p>
800 *
801 * @param parentElement
802 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
803 * object.
804 * @param labelString
805 * a {@link java.lang.String} object.
806 * @param initialInteger
807 * a {@link java.lang.Integer} object.
808 * @param style
809 * a int.
810 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElement}
811 * object.
812 */
813 public NumberWithLabelElement createIntegerTextWithLabelElement(
814 ICdmFormElement parentElement, String labelString,
815 Integer initialInteger, int style) {
816 NumberWithLabelElement element = new NumberWithLabelElement(this,
817 parentElement, labelString, initialInteger, style);
818 adapt(element);
819 parentElement.addElement(element);
820 return element;
821 }
822
823 /**
824 * <p>
825 * createFloatTextWithLabelElement
826 * </p>
827 *
828 * @param parentElement
829 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
830 * object.
831 * @param labelString
832 * a {@link java.lang.String} object.
833 * @param initialFloat
834 * a float.
835 * @param style
836 * a int.
837 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElement}
838 * object.
839 */
840 public NumberWithLabelElement createFloatTextWithLabelElement(
841 ICdmFormElement parentElement, String labelString,
842 float initialFloat, int style) {
843 NumberWithLabelElement element = new NumberWithLabelElement(this,
844 parentElement, labelString, initialFloat, style);
845 adapt(element);
846 parentElement.addElement(element);
847 return element;
848 }
849
850 /**
851 * <p>
852 * createLanguageStringWithLabelElement
853 * </p>
854 *
855 * @param parentElement
856 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
857 * object.
858 * @param labelString
859 * a {@link java.lang.String} object.
860 * @param languageString
861 * a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
862 * @param style
863 * a int.
864 * @return a
865 * {@link eu.etaxonomy.taxeditor.ui.forms.LanguageStringWithLabelElement}
866 * object.
867 */
868 public LanguageStringWithLabelElement createLanguageStringWithLabelElement(
869 ICdmFormElement parentElement, String labelString,
870 LanguageString languageString, int style) {
871 LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(
872 this, parentElement, labelString, languageString, style);
873 adapt(element);
874 parentElement.addElement(element);
875 return element;
876 }
877
878 /**
879 * <p>
880 * createLanguageStringWithLabelElement
881 * </p>
882 *
883 * @param parentElement
884 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
885 * object.
886 * @param labelString
887 * a {@link java.lang.String} object.
888 * @param languageString
889 * a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
890 * @param height
891 * a int.
892 * @param style
893 * a int.
894 * @return a
895 * {@link eu.etaxonomy.taxeditor.ui.forms.LanguageStringWithLabelElement}
896 * object.
897 */
898 public LanguageStringWithLabelElement createLanguageStringWithLabelElement(
899 ICdmFormElement parentElement, String labelString,
900 LanguageString languageString, int height, int style) {
901 LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(
902 this, parentElement, labelString, languageString, height, style);
903 adapt(element);
904 parentElement.addElement(element);
905 return element;
906 }
907
908 /**
909 * <p>
910 * createTextElement
911 * </p>
912 *
913 * @param parentElement
914 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
915 * object.
916 * @param initialText
917 * a {@link java.lang.String} object.
918 * @param style
919 * a int.
920 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement}
921 * object.
922 */
923 public TextWithLabelElement createTextElement(
924 ICdmFormElement parentElement, String initialText, int style) {
925 TextWithLabelElement element = new TextWithLabelElement(this,
926 parentElement, null, initialText, null, style);
927 adapt(element);
928 parentElement.addElement(element);
929 return element;
930 }
931
932 /**
933 * <p>
934 * createKeyValueViewerElement
935 * </p>
936 *
937 * @param parentElement
938 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
939 * object.
940 * @param keyHeading
941 * a {@link java.lang.String} object.
942 * @param valueHeading
943 * a {@link java.lang.String} object.
944 * @param map
945 * a {@link java.util.Map} object.
946 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.KeyValueViewerElement}
947 * object.
948 */
949 public KeyValueViewerElement createKeyValueViewerElement(
950 ICdmFormElement parentElement, String keyHeading,
951 String valueHeading, Map<Object, Object> map) {
952 KeyValueViewerElement element = new KeyValueViewerElement(this,
953 parentElement, keyHeading, valueHeading, map);
954 adapt(element);
955 parentElement.addElement(element);
956 return element;
957 }
958
959 public static enum TermComboType {
960 EXTENSIONTYPE, LANGUAGE, MARKERTYPE, NOMENCLATURALSTATUSTYPE, RANK, RIGHTSTYPE, NAMERELATIONSHIP, NAMEDAREATYPE, PRESENCEABSENCESTATUS, ANNOTATIONTYPE, NAMETYPEDESIGNATIONSTATUS, SPECIMENTYPEDESIGNATIONSTATUS, SEX, STAGE, PRESERVATION_METHOD, MEASUREMENT_UNIT, STATE, MODIFIER, STATISTICAL_MEASURE, SCOPE, EMPTY, DETERMINATION_MODIFIER, REFERENCE_SYSTEM
961 }
962
963 /**
964 * <p>
965 * createTermComboElement
966 * </p>
967 *
968 * @param termComboType
969 * a
970 * {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.TermComboType}
971 * object.
972 * @param parentElement
973 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
974 * object.
975 * @param labelString
976 * a {@link java.lang.String} object.
977 * @param selection
978 * a {@link eu.etaxonomy.cdm.model.common.DefinedTermBase}
979 * object.
980 * @param style
981 * a int.
982 * @return a {@link eu.etaxonomy.taxeditor.ui.term.AbstractTermComboElement}
983 * object.
984 */
985 public AbstractTermComboElement createTermComboElement(
986 TermComboType termComboType, ICdmFormElement parentElement,
987 String labelString, DefinedTermBase selection, int style) {
988 AbstractTermComboElement element = null;
989
990 switch (termComboType) {
991 case EMPTY:
992 element = new EmptyComboElement<DefinedTermBase>(this,
993 parentElement, labelString, style);
994 break;
995 case EXTENSIONTYPE:
996 element = new ExtensionTypeComboElement(this, parentElement,
997 labelString, (ExtensionType) selection, style);
998 break;
999 case LANGUAGE:
1000 element = new LanguageComboElement(this, parentElement,
1001 labelString, (Language) selection, style);
1002 break;
1003 case MARKERTYPE:
1004 element = new MarkerTypeComboElement(this, parentElement,
1005 labelString, (MarkerType) selection, style);
1006 break;
1007 case NOMENCLATURALSTATUSTYPE:
1008 element = new NomenclaturalStatusTypeComboElement(this,
1009 parentElement, labelString,
1010 (NomenclaturalStatusType) selection, style);
1011 break;
1012 case RANK:
1013 element = new RankComboElement(this, parentElement, labelString,
1014 (Rank) selection, style);
1015 break;
1016 case RIGHTSTYPE:
1017 element = new RightsTypeComboElement(this, parentElement,
1018 labelString, (RightsTerm) selection, style);
1019 break;
1020 case NAMERELATIONSHIP:
1021 element = new NameRelationshipTypeComboElement(this, parentElement,
1022 labelString, (NameRelationshipType) selection, style);
1023 break;
1024 case NAMEDAREATYPE:
1025 element = new NamedAreaTypeComboElement(this, parentElement,
1026 labelString, (NamedAreaType) selection, style);
1027 break;
1028 case ANNOTATIONTYPE:
1029 element = new AnnotationTypeComboElement(this, parentElement,
1030 labelString, (AnnotationType) selection, style);
1031 break;
1032 case PRESENCEABSENCESTATUS:
1033 element = new PresenceAbsenceTermComboElement(this, parentElement,
1034 labelString, (PresenceAbsenceTermBase) selection, style);
1035 break;
1036 case NAMETYPEDESIGNATIONSTATUS:
1037 element = new NameTypeDesignationStatusComboElement(this,
1038 parentElement, labelString,
1039 (NameTypeDesignationStatus) selection, style);
1040 break;
1041 case SPECIMENTYPEDESIGNATIONSTATUS:
1042 element = new SpecimenTypeDesignationStatusComboElement(this,
1043 parentElement, labelString,
1044 (SpecimenTypeDesignationStatus) selection, style);
1045 break;
1046 case SEX:
1047 element = new SexComboElement(this, parentElement, labelString,
1048 (Sex) selection, style);
1049 break;
1050 case STAGE:
1051 element = new StageComboElement(this, parentElement, labelString,
1052 (Stage) selection, style);
1053 break;
1054 case PRESERVATION_METHOD:
1055 element = new PreservationMethodComboElement(this, parentElement,
1056 labelString, (PreservationMethod) selection, style);
1057 break;
1058 case MEASUREMENT_UNIT:
1059 element = new MeasurementUnitComboElement(this, parentElement,
1060 labelString, (MeasurementUnit) selection, style);
1061 break;
1062 case STATE:
1063 element = new StateComboElement(this, parentElement, labelString,
1064 (State) selection, style);
1065 break;
1066 case SCOPE:
1067 element = new ScopeComboElement(this, parentElement, labelString,
1068 (Scope) selection, style);
1069 break;
1070 case MODIFIER:
1071 element = new ModifierComboElement(this, parentElement,
1072 labelString, (Modifier) selection, style);
1073 break;
1074 case STATISTICAL_MEASURE:
1075 element = new StatisticalMeasureComboElement(this, parentElement,
1076 labelString, (StatisticalMeasure) selection, style);
1077 break;
1078 case DETERMINATION_MODIFIER:
1079 element = new DeterminationModifierComboElement(this,
1080 parentElement, labelString,
1081 (DeterminationModifier) selection, style);
1082 break;
1083 case REFERENCE_SYSTEM:
1084 element = new ReferenceSystemComboElement(this, parentElement,
1085 labelString, (ReferenceSystem) selection, style);
1086 break;
1087 }
1088
1089 adapt(element);
1090 parentElement.addElement(element);
1091 return element;
1092 }
1093
1094 public static enum EnumComboType {
1095 REFERENCETYPE, NOMENCLATURALCODE
1096 }
1097
1098 /**
1099 * <p>
1100 * createEnumComboElement
1101 * </p>
1102 *
1103 * @param enumComboType
1104 * a
1105 * {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EnumComboType}
1106 * object.
1107 * @param parentElement
1108 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1109 * object.
1110 * @param style
1111 * a int.
1112 * @return a {@link eu.etaxonomy.taxeditor.ui.term.AbstractEnumComboElement}
1113 * object.
1114 */
1115 public AbstractEnumComboElement createEnumComboElement(
1116 EnumComboType enumComboType, ICdmFormElement parentElement,
1117 int style) {
1118 AbstractEnumComboElement element = null;
1119
1120 switch (enumComboType) {
1121 case REFERENCETYPE:
1122 element = new ReferenceTypeComboElement(this, parentElement,
1123 "Reference Type", null, style);
1124 break;
1125 case NOMENCLATURALCODE:
1126 element = new NomenclaturalCodeComboElement(this, parentElement,
1127 "Nomenclatural Code", null, style);
1128 break;
1129 }
1130 adapt(element);
1131 parentElement.addElement(element);
1132 return element;
1133 }
1134
1135 /**
1136 * <p>
1137 * createBrowserElement
1138 * </p>
1139 *
1140 * @param imageUri
1141 * a {@link java.net.URI} object.
1142 * @param style
1143 * a int.
1144 * @param parentElement
1145 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1146 * object.
1147 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.BrowserElement} object.
1148 */
1149 public BrowserElement createBrowserElement(ICdmFormElement parentElement,
1150 URI imageUri, int style) {
1151 BrowserElement element = new BrowserElement(this, parentElement,
1152 imageUri, style);
1153 adapt(element);
1154 parentElement.addElement(element);
1155 return element;
1156 }
1157
1158 /**
1159 * <p>
1160 * createImageElement
1161 * </p>
1162 *
1163 * @param parentElement
1164 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1165 * object.
1166 * @param imageUri
1167 * a {@link java.net.URI} object.
1168 * @param style
1169 * a int.
1170 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.ImageElement} object.
1171 */
1172 public ImageElement createImageElement(ICdmFormElement parentElement,
1173 URI imageUri, int style) {
1174 ImageElement element = new ImageElement(this, parentElement, imageUri,
1175 style);
1176 adapt(element);
1177 parentElement.addElement(element);
1178 return element;
1179 }
1180
1181 /**
1182 * <p>
1183 * createTextActionElement
1184 * </p>
1185 *
1186 * @param labelString
1187 * a {@link java.lang.String} object.
1188 * @param initialText
1189 * a {@link java.lang.String} object.
1190 * @param style
1191 * a int.
1192 * @param parentElement
1193 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1194 * object.
1195 * @param buttonLabel
1196 * a {@link java.lang.String} object.
1197 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TextActionElement}
1198 * object.
1199 */
1200 public TextActionElement createTextActionElement(
1201 ICdmFormElement parentElement, String labelString,
1202 String buttonLabel, String initialText, int style) {
1203 TextActionElement element = new TextActionElement(this, parentElement,
1204 labelString, buttonLabel, initialText, style);
1205 adapt(element);
1206 parentElement.addElement(element);
1207 return element;
1208 }
1209
1210 /**
1211 *
1212 * @author n.hoffmann
1213 * @created Mar 5, 2010
1214 * @version 1.0
1215 */
1216 public static enum SelectionType {
1217 AGENT, INSTITUTION, NAME, REFERENCE, TAXON_BASE, TAXON, SYNONYM, TEAM, AUTHOR_TEAM, PERSON, DERIVED_UNIT, FIELD_OBSERVATION, FEATURE_TREE, CLASSIFICATION, TAXON_NODE, COLLECTION, FEATURE, POLYTOMOUS_KEY, POLYTOMOUS_KEY_NODE, USER, GROUP
1218 }
1219
1220 /**
1221 * <p>
1222 * createCheckbox
1223 * </p>
1224 *
1225 * @param parentElement
1226 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1227 * object.
1228 * @param label
1229 * a {@link java.lang.String} object.
1230 * @param initialState
1231 * a boolean.
1232 * @param style
1233 * a int.
1234 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.CheckboxElement} object.
1235 */
1236 public CheckboxElement createCheckbox(ICdmFormElement parentElement,
1237 String label, boolean initialState, int style) {
1238 CheckboxElement element = new CheckboxElement(this, parentElement,
1239 label, initialState, style | orientation);
1240 adapt(element);
1241 parentElement.addElement(element);
1242 return element;
1243 }
1244
1245 /**
1246 * Creates a section as a part of the form.
1247 *
1248 * @return the section widget
1249 * @param section
1250 * a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
1251 * object.
1252 */
1253 public Section adapt(AbstractFormSection section) {
1254 section.setMenu(section.getLayoutComposite().getMenu());
1255 adapt(section, true, true);
1256
1257 // handle focus and property change events for cdm use
1258 section.addFocusListener(selectionFocusHandler);
1259 section.setPropertyChangeListeners(propertyChangeListeners);
1260
1261 if (section.getToggle() != null) {
1262 section.getToggle().setHoverDecorationColor(
1263 getColors().getColor(IFormColors.TB_TOGGLE_HOVER));
1264 section.getToggle().setDecorationColor(
1265 getColors().getColor(IFormColors.TB_TOGGLE));
1266 }
1267
1268 section.setFont(boldFontHolder2.getBoldFont(section
1269 .getLayoutComposite().getFont()));
1270
1271 if ((section.getStyle() & Section.TITLE_BAR) != 0
1272 || (section.getStyle() & Section.SHORT_TITLE_BAR) != 0) {
1273 getColors().initializeSectionToolBarColors();
1274 section.setTitleBarBackground(getColors().getColor(
1275 IFormColors.TB_BG));
1276 section.setTitleBarBorderColor(getColors().getColor(
1277 IFormColors.TB_BORDER));
1278 }
1279 // call setTitleBarForeground regardless as it also sets the label color
1280 section.setTitleBarForeground(getColors().getColor(
1281 IFormColors.TB_TOGGLE));
1282 return section;
1283 }
1284
1285 private class BoldFontHolder2 {
1286 private Font normalFont;
1287
1288 private Font boldFont;
1289
1290 public BoldFontHolder2() {
1291 }
1292
1293 public Font getBoldFont(Font font) {
1294 createBoldFont(font);
1295 return boldFont;
1296 }
1297
1298 private void createBoldFont(Font font) {
1299 if (normalFont == null || !normalFont.equals(font)) {
1300 normalFont = font;
1301 dispose();
1302 }
1303 if (boldFont == null) {
1304 boldFont = FormFonts.getInstance().getBoldFont(
1305 getColors().getDisplay(), normalFont);
1306 }
1307 }
1308
1309 public void dispose() {
1310 if (boldFont != null) {
1311 FormFonts.getInstance().markFinished(boldFont,
1312 getColors().getDisplay());
1313 boldFont = null;
1314 }
1315 }
1316 }
1317
1318 /**
1319 * <p>
1320 * createToggleableTextField
1321 * </p>
1322 *
1323 * @param parentElement
1324 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1325 * object.
1326 * @param labelString
1327 * a {@link java.lang.String} object.
1328 * @param initialText
1329 * a {@link java.lang.String} object.
1330 * @param initialState
1331 * a boolean.
1332 * @param style
1333 * a int.
1334 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.ToggleableTextElement}
1335 * object.
1336 */
1337 public ToggleableTextElement createToggleableTextField(
1338 ICdmFormElement parentElement, String labelString,
1339 String initialText, boolean initialState, int style) {
1340 ToggleableTextElement element = new ToggleableTextElement(this,
1341 parentElement, labelString, initialText, initialState, style
1342 | orientation);
1343 adapt(element);
1344 parentElement.addElement(element);
1345 return element;
1346 }
1347
1348 /**
1349 * <p>
1350 * createTimePeriodElement
1351 * </p>
1352 *
1353 * @param parentElement
1354 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1355 * object.
1356 * @param labelString
1357 * a {@link java.lang.String} object.
1358 * @param timePeriod
1359 * a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
1360 * @param style
1361 * a int.
1362 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.TimePeriodElement}
1363 * object.
1364 */
1365 public TimePeriodElement createTimePeriodElement(
1366 ICdmFormElement parentElement, String labelString,
1367 TimePeriod timePeriod, int style) {
1368 TimePeriodElement element = new TimePeriodElement(this, parentElement,
1369 labelString, timePeriod, style);
1370 adapt(element);
1371 parentElement.addElement(element);
1372 return element;
1373 }
1374
1375 /**
1376 * <p>
1377 * createPointElement
1378 * </p>
1379 *
1380 * @param style
1381 * a int.
1382 * @param parentElement
1383 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1384 * object.
1385 * @param point
1386 * a {@link eu.etaxonomy.cdm.model.location.Point} object.
1387 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.PointElement} object.
1388 */
1389 public PointElement createPointElement(ICdmFormElement parentElement,
1390 Point point, int style) {
1391 PointElement element = new PointElement(this, parentElement, point,
1392 style);
1393 adapt(element);
1394 parentElement.addElement(element);
1395 return element;
1396 }
1397
1398 /**
1399 * <p>
1400 * createDateDetailSection
1401 * </p>
1402 *
1403 * @param parentElement
1404 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1405 * object.
1406 * @param style
1407 * a int.
1408 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.DateDetailSection}
1409 * object.
1410 */
1411 public DateDetailSection createDateDetailSection(
1412 ICdmFormElement parentElement, int style) {
1413 DateDetailSection section = new DateDetailSection(this, parentElement,
1414 style);
1415 parentElement.addElement(section);
1416 adapt(section);
1417 return section;
1418 }
1419
1420 /**
1421 * <p>
1422 * createPartialElement
1423 * </p>
1424 *
1425 * @param parentElement
1426 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1427 * object.
1428 * @param labelString
1429 * a {@link java.lang.String} object.
1430 * @param partial
1431 * a {@link org.joda.time.Partial} object.
1432 * @param style
1433 * a int.
1434 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.PartialElement} object.
1435 */
1436 public PartialElement createPartialElement(ICdmFormElement parentElement,
1437 String labelString, Partial partial, int style) {
1438 PartialElement element = new PartialElement(this, parentElement,
1439 labelString, style);
1440 adapt(element);
1441 parentElement.addElement(element);
1442 return element;
1443 }
1444
1445 /**
1446 * <p>
1447 * addSelectionListener
1448 * </p>
1449 *
1450 * @param listener
1451 * a {@link org.eclipse.swt.events.SelectionListener} object.
1452 */
1453 public void addSelectionListener(SelectionListener listener) {
1454 selectionListenerList.add(listener);
1455 }
1456
1457 /**
1458 * <p>
1459 * removeSelectionListener
1460 * </p>
1461 *
1462 * @param listener
1463 * a {@link org.eclipse.swt.events.SelectionListener} object.
1464 */
1465 public void removeSelectionListener(SelectionListener listener) {
1466 if (listener == null) {
1467 StoreUtil
1468 .error(this.getClass(),
1469 "Tried to remove a selection listener from this factories listeners but was null",
1470 null);
1471 } else {
1472 selectionListenerList.remove(listener);
1473 }
1474 }
1475
1476 /**
1477 * <p>
1478 * addPropertyChangeListener
1479 * </p>
1480 *
1481 * @param listener
1482 * a {@link org.eclipse.jface.util.IPropertyChangeListener}
1483 * object.
1484 */
1485 public void addPropertyChangeListener(IPropertyChangeListener listener) {
1486 if(propertyChangeListeners.contains(listener)){
1487 return;
1488 }
1489 propertyChangeListeners.add(0, listener);
1490 }
1491
1492 /**
1493 * <p>
1494 * removePropertyChangeListener
1495 * </p>
1496 *
1497 * @param listener
1498 * a {@link org.eclipse.jface.util.IPropertyChangeListener}
1499 * object.
1500 */
1501 public void removePropertyChangeListener(IPropertyChangeListener listener) {
1502 propertyChangeListeners.remove(listener);
1503 }
1504
1505 /**
1506 * <p>
1507 * createHorizontalSeparator
1508 * </p>
1509 *
1510 * @param parentElement
1511 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1512 * object.
1513 * @param style
1514 * a int.
1515 * @return a {@link org.eclipse.swt.widgets.Label} object.
1516 */
1517 public Label createHorizontalSeparator(ICdmFormElement parentElement,
1518 int style) {
1519 Label separator = this.createSeparator(
1520 parentElement.getLayoutComposite(), SWT.HORIZONTAL | style);
1521 separator.setLayoutData(FILL_HORIZONTALLY());
1522 return separator;
1523 }
1524
1525 /**
1526 * <p>
1527 * createVersionElement
1528 * </p>
1529 *
1530 * @param parentElement
1531 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1532 * object.
1533 * @param entity
1534 * a {@link eu.etaxonomy.cdm.model.common.VersionableEntity}
1535 * object.
1536 * @param style
1537 * a int.
1538 * @return a
1539 * {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionElement}
1540 * object.
1541 */
1542 public VersionElement createVersionElement(ICdmFormElement parentElement,
1543 VersionableEntity entity, int style) {
1544 VersionElement element = new VersionElement(this, parentElement,
1545 entity, style);
1546 adapt(element);
1547 parentElement.addElement(element);
1548 return element;
1549 }
1550
1551 /**
1552 * <p>
1553 * createVersionSection
1554 * </p>
1555 *
1556 * @param parentElement
1557 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1558 * object.
1559 * @param style
1560 * a int.
1561 * @return a
1562 * {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection}
1563 * object.
1564 */
1565 public VersionSection createVersionSection(ICdmFormElement parentElement,
1566 int style) {
1567 VersionSection section = new VersionSection(this, parentElement, style);
1568 parentElement.addElement(section);
1569 adapt(section);
1570 return section;
1571 }
1572
1573 /**
1574 * <p>
1575 * createEmptyElement
1576 * </p>
1577 *
1578 * @param parentElement
1579 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1580 * object.
1581 * @return a {@link eu.etaxonomy.taxeditor.ui.section.EmptyElement} object.
1582 */
1583 public EmptyElement createEmptyElement(ICdmFormElement parentElement) {
1584 EmptyElement element = new EmptyElement(this, parentElement, null,
1585 SWT.NULL);
1586 adapt(element);
1587 parentElement.addElement(element);
1588 return element;
1589 }
1590
1591 /**
1592 * <p>
1593 * createHeadlineSection
1594 * </p>
1595 *
1596 * @param parentElement
1597 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1598 * object.
1599 * @return a
1600 * {@link eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection}
1601 * object.
1602 */
1603 public HeadlineSection createHeadlineSection(ICdmFormElement parentElement) {
1604 HeadlineSection section = new HeadlineSection(this, parentElement,
1605 SWT.NULL);
1606 parentElement.addElement(section);
1607 adapt(section);
1608 return section;
1609 }
1610
1611 /**
1612 * <p>
1613 * createParsingMessageElement
1614 * </p>
1615 *
1616 * @param parentElement
1617 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1618 * object.
1619 * @param parserProblem
1620 * a {@link eu.etaxonomy.cdm.strategy.parser.ParserProblem}
1621 * object.
1622 * @param style
1623 * a int.
1624 * @return a
1625 * {@link eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessageElement}
1626 * object.
1627 */
1628 public ParsingMessageElement createParsingMessageElement(
1629 ICdmFormElement parentElement, ParserProblem parserProblem,
1630 int style) {
1631 ParsingMessageElement element = new ParsingMessageElement(this,
1632 parentElement, parserProblem, style);
1633 adapt(element);
1634 parentElement.addElement(element);
1635 return element;
1636 }
1637
1638 // SIMPLIFY
1639
1640 /**
1641 *
1642 */
1643 public static enum DetailType {
1644 NONVIRALNAME,
1645 SCIENTIFICNAME,
1646 REFERENCEBASE,
1647 NOMENCLATURALREFERENCE,
1648 TAXONBASE,
1649 AUTHORSHIP,
1650 TEAM,
1651 PERSON,
1652 DESCRIPTION,
1653 DESCRIPTIONELEMENT,
1654 PARSINGMESSAGE,
1655 NAMERELATIONSHIP,
1656 TEAMORPERSONBASE,
1657 MEDIA,
1658 FIELD_OBSERVATION,
1659 DERIVED_UNIT_FACADE,
1660 GATHERING_EVENT,
1661 DERIVED_UNIT,
1662 NATURAL_LANGUAGE,
1663 FEATURE_DISTRIBUTION,
1664 CLASSIFICATION,
1665 TAXON_NODE,
1666 COLLECTION,
1667 POLYTOMOUS_KEY,
1668 POLYTOMOUS_KEY_NODE,
1669 INSTITUTION,
1670 DERIVED_UNIT_GENERAL,
1671 HYBRID,
1672 USER,
1673 GROUP,
1674 DETERMINATION
1675 }
1676
1677 /**
1678 * <p>
1679 * createCdmDetailSection
1680 * </p>
1681 *
1682 * @param detailType
1683 * a
1684 * {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType}
1685 * object.
1686 * @param parentElement
1687 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1688 * object.
1689 * @param selectionProvider
1690 * a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
1691 * @param style
1692 * a int.
1693 * @param conversation
1694 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1695 * object.
1696 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
1697 * object.
1698 */
1699 public AbstractFormSection createCdmDetailSection(DetailType detailType,
1700 ConversationHolder conversation, ICdmFormElement parentElement,
1701 ISelectionProvider selectionProvider, int style) {
1702 AbstractFormSection section = null;
1703
1704 switch (detailType) {
1705 case SCIENTIFICNAME:
1706 section = new NameDetailSection(this, conversation, parentElement,
1707 selectionProvider, style);
1708 break;
1709 case REFERENCEBASE:
1710 section = new ReferenceDetailSection(this, conversation,
1711 parentElement, selectionProvider, style);
1712 break;
1713 case NOMENCLATURALREFERENCE:
1714 section = new NomenclaturalReferenceDetailSection(this,
1715 conversation, parentElement, selectionProvider, style);
1716 break;
1717 case TAXONBASE:
1718 section = new TaxonBaseDetailSection(this, conversation,
1719 parentElement, selectionProvider, style);
1720 break;
1721 case AUTHORSHIP:
1722 section = new AuthorshipDetailSection(this, conversation,
1723 parentElement, selectionProvider, style);
1724 break;
1725 case TEAMORPERSONBASE:
1726 section = new TeamOrPersonBaseDetailSection(this, conversation,
1727 parentElement, selectionProvider, style);
1728 break;
1729 case TEAM:
1730 section = new TeamDetailSection(this, conversation, parentElement,
1731 null, style);
1732 break;
1733 case PERSON:
1734 section = new PersonDetailSection(this, conversation,
1735 parentElement, null, style);
1736 break;
1737 case DESCRIPTION:
1738 section = new DescriptionDetailSection(this, conversation,
1739 parentElement, selectionProvider, style);
1740 break;
1741 case DESCRIPTIONELEMENT:
1742 section = new DescriptionElementDetailSection(this, conversation,
1743 parentElement, selectionProvider, style);
1744 break;
1745 case PARSINGMESSAGE:
1746 section = new ParsingMessagesSection(this, conversation,
1747 parentElement, selectionProvider, style);
1748 break;
1749 case NONVIRALNAME:
1750 section = new NonViralNameDetailSection(this, conversation,
1751 parentElement, selectionProvider, style);
1752 break;
1753 case MEDIA:
1754 section = new eu.etaxonomy.taxeditor.ui.section.description.MediaDetailsSection(
1755 this, conversation, parentElement, selectionProvider, style);
1756 break;
1757 case DERIVED_UNIT_FACADE:
1758 section = new DerivedUnitFacadeDetailSection(this, conversation,
1759 parentElement, selectionProvider, style);
1760 break;
1761 case FIELD_OBSERVATION:
1762 section = new FieldObservationDetailSection(this, conversation,
1763 parentElement, selectionProvider, style);
1764 break;
1765 case GATHERING_EVENT:
1766 section = new GatheringEventDetailSection(this, conversation,
1767 parentElement, selectionProvider, style);
1768 break;
1769 case DERIVED_UNIT:
1770 section = new DerivedUnitBaseDetailSection(this, conversation,
1771 parentElement, selectionProvider, style);
1772 break;
1773 case NATURAL_LANGUAGE:
1774 section = new NaturalLanguageSection(this, conversation,
1775 parentElement, selectionProvider, style);
1776 break;
1777 case FEATURE_DISTRIBUTION:
1778 section = new FeatureDistributionDetailSection(this, conversation,
1779 parentElement, selectionProvider, style);
1780 break;
1781 case CLASSIFICATION:
1782 section = new ClassificationDetailSection(this, conversation,
1783 parentElement, selectionProvider, style);
1784 break;
1785 case TAXON_NODE:
1786 section = new TaxonNodeDetailSection(this, conversation,
1787 parentElement, selectionProvider, style);
1788 break;
1789 case POLYTOMOUS_KEY:
1790 section = new PolytomousKeyDetailSection(this, conversation,
1791 parentElement, selectionProvider, style);
1792 break;
1793 case POLYTOMOUS_KEY_NODE:
1794 section = new PolytomousKeyNodeDetailSection(this, conversation,
1795 parentElement, selectionProvider, style);
1796 break;
1797 case INSTITUTION:
1798 section = new InstitutionDetailSection(this, conversation,
1799 parentElement, selectionProvider, style);
1800 break;
1801 case DERIVED_UNIT_GENERAL:
1802 section = new GeneralDetailSection(this, conversation,
1803 parentElement, selectionProvider, style);
1804 break;
1805 case HYBRID:
1806 section = new HybridDetailSection(this, conversation,
1807 parentElement, selectionProvider, style);
1808 break;
1809 case USER:
1810 section = new UserDetailSection(this, conversation, parentElement,
1811 selectionProvider, style);
1812 break;
1813 case GROUP:
1814 section = new GroupDetailSection(this, conversation, parentElement,
1815 selectionProvider, style);
1816 break;
1817 case DETERMINATION:
1818 section = new DeterminationDetailSection(this, conversation, parentElement,
1819 selectionProvider, style);
1820 }
1821
1822 if (section == null) {
1823 throw new RuntimeException(
1824 "You tried to create a cdm detail section that is not implemented yet.");
1825 }
1826
1827 parentElement.addElement(section);
1828 adapt(section);
1829 return section;
1830 }
1831
1832 /**
1833 * <p>
1834 * createCdmDetailElement
1835 * </p>
1836 *
1837 * @param detailType
1838 * a
1839 * {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.DetailType}
1840 * object.
1841 * @param style
1842 * a int.
1843 * @param parentElement
1844 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1845 * object.
1846 * @return a
1847 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
1848 * object.
1849 */
1850 public AbstractCdmDetailElement createCdmDetailElement(
1851 DetailType detailType, ICdmFormElement parentElement, int style) {
1852 AbstractCdmDetailElement element = null;
1853
1854 switch (detailType) {
1855 case SCIENTIFICNAME:
1856 element = new NameDetailElement(this, parentElement, style);
1857 break;
1858 case REFERENCEBASE:
1859 element = new ReferenceDetailElement(this, parentElement, style);
1860 break;
1861 case NOMENCLATURALREFERENCE:
1862 element = new NomenclaturalReferenceDetailElement(this,
1863 parentElement, style);
1864 break;
1865 case TAXONBASE:
1866 element = new TaxonBaseDetailElement(this, parentElement, style);
1867 break;
1868 case AUTHORSHIP:
1869 element = new AuthorshipDetailElement(this, parentElement, style);
1870 break;
1871 case TEAM:
1872 element = new TeamDetailElement(this, parentElement, style);
1873 break;
1874 case PERSON:
1875 element = new PersonDetailElement(this, parentElement, style);
1876 break;
1877 case DESCRIPTION:
1878 element = new DescriptionDetailElement(this, parentElement, style);
1879 break;
1880 case DESCRIPTIONELEMENT:
1881 element = new DescriptionElementDetailElement(this, parentElement,
1882 style);
1883 break;
1884 case NONVIRALNAME:
1885 element = new NonViralNameDetailElement(this, parentElement);
1886 break;
1887 case DERIVED_UNIT_FACADE:
1888 element = new DerivedUnitFacadeDetailElement(this, parentElement);
1889 break;
1890 case FIELD_OBSERVATION:
1891 element = new FieldObservationDetailElement(this, parentElement);
1892 break;
1893 case GATHERING_EVENT:
1894 element = new GatheringEventDetailElement(this, parentElement);
1895 break;
1896 case DERIVED_UNIT:
1897 element = new DerivedUnitBaseDetailElement(this, parentElement);
1898 break;
1899 case NATURAL_LANGUAGE:
1900 element = new NaturalLanguageDetailElement(this, parentElement);
1901 break;
1902 case FEATURE_DISTRIBUTION:
1903 element = new FeatureDistributionDetailElement(this, parentElement);
1904 break;
1905 case CLASSIFICATION:
1906 element = new ClassificationDetailElement(this, parentElement);
1907 break;
1908 case TAXON_NODE:
1909 element = new TaxonNodeDetailElement(this, parentElement);
1910 break;
1911 case COLLECTION:
1912 element = new CollectionDetailElement(this, parentElement);
1913 break;
1914 case POLYTOMOUS_KEY:
1915 element = new PolytomousKeyDetailElement(this, parentElement);
1916 break;
1917 case POLYTOMOUS_KEY_NODE:
1918 element = new PolytomousKeyNodeDetailElement(this, parentElement);
1919 break;
1920 case INSTITUTION:
1921 element = new InstitutionDetailElement(this, parentElement);
1922 break;
1923 case DERIVED_UNIT_GENERAL:
1924 element = new GeneralDetailElement(this, parentElement);
1925 break;
1926 case HYBRID:
1927 element = new HybridDetailElement(this, parentElement);
1928 break;
1929 case USER:
1930 element = new UserDetailElement(this, parentElement);
1931 break;
1932 case GROUP:
1933 element = new GroupDetailElement(this, parentElement);
1934 break;
1935 case DETERMINATION:
1936 element = new DeterminationDetailElement(this, parentElement);
1937 break;
1938 }
1939
1940 if (element == null) {
1941 StoreUtil
1942 .error(this.getClass(),
1943 "Detail element was not created. Seems like the case was not implemented for the requested detail type: "
1944 + detailType, null);
1945 }
1946
1947 adapt(element);
1948 parentElement.addElement(element);
1949 return element;
1950 }
1951
1952 /**
1953 *
1954 * @author n.hoffmann
1955 * @created Mar 5, 2010
1956 * @version 1.0
1957 */
1958 public static enum EntityDetailType {
1959 TEAM, TEAMMEMBER, ANNOTATION, CREDIT, DESCRIPTIONELEMENTSOURCE, EXTENSION, MARKER, MEDIA, DESCRIPTIONELEMENTMEDIA, MEDIAREPRESENTATION, MEDIAREPRESENTATIONPART, MODIFIER, NOMENCLATURALSTATUS, NAME_RELATIONSHIP, PROTOLOG, RIGHTS, SOURCE, SCOPE, DESCRIPTIONSOURCE, TYPEDESIGNATION, STATE_DATA, STATISTICAL_MEASUREMENT_VALUE, DESCRIBED_SPECIMEN, COLLECTING_AREA, DETERMINATION_EVENT, SPECIMEN_COLLECTION, IDENTIFIABLE_SOURCE_COLLECTION, GEOGRAPHICAL_SCOPE, SCOPE_RESTRICTION, MEMBER, GRANTED_AUTHORITY, GROUPS_BY_USER, TAXONOMIC_SCOPE, DETERMINATION_CURRENT, DETERMINATION_HISTORY
1960 }
1961
1962 /**
1963 * <p>
1964 * createEntityDetailSection
1965 * </p>
1966 *
1967 * @param entityDetailType
1968 * a
1969 * {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EntityDetailType}
1970 * object.
1971 * @param style
1972 * a int.
1973 * @param conversation
1974 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1975 * object.
1976 * @param parentElement
1977 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
1978 * object.
1979 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
1980 * object.
1981 */
1982 public AbstractFormSection createEntityDetailSection(
1983 EntityDetailType entityDetailType, ConversationHolder conversation,
1984 ICdmFormElement parentElement, int style) {
1985 AbstractFormSection section = null;
1986
1987 switch (entityDetailType) {
1988 case TEAM:
1989 section = new TeamDetailSection(this, conversation, parentElement,
1990 null, style);
1991 break;
1992 case TEAMMEMBER:
1993 section = new TeamMemberSection(this, conversation, parentElement,
1994 style);
1995 break;
1996 case ANNOTATION:
1997 section = new AnnotationSection(this, conversation, parentElement,
1998 style);
1999 break;
2000 case CREDIT:
2001 section = new CreditSection(this, conversation, parentElement,
2002 style);
2003 break;
2004 case DESCRIPTIONELEMENTSOURCE:
2005 section = new DescriptionElementSourceSection(this, conversation,
2006 parentElement, style);
2007 break;
2008 case EXTENSION:
2009 section = new ExtensionSection(this, conversation, parentElement,
2010 style);
2011 break;
2012 case MARKER:
2013 section = new MarkerSection(this, conversation, parentElement,
2014 style);
2015 break;
2016 case MEDIA:
2017 section = new MediaSection(this, conversation, parentElement, style);
2018 break;
2019 case DESCRIPTIONELEMENTMEDIA:
2020 section = new DescriptionElementMediaSection(this, conversation,
2021 parentElement, style);
2022 break;
2023 case MEDIAREPRESENTATION:
2024 section = new MediaRepresentationSection(this, conversation,
2025 parentElement, style);
2026 break;
2027 case MEDIAREPRESENTATIONPART:
2028 section = new MediaRepresentationPartSection(this, conversation,
2029 parentElement, style);
2030 break;
2031 case MODIFIER:
2032 section = new ModifierSection(this, conversation, parentElement,
2033 style);
2034 break;
2035 case NOMENCLATURALSTATUS:
2036 section = new NomenclaturalStatusSection(this, conversation,
2037 parentElement, style);
2038 break;
2039 case NAME_RELATIONSHIP:
2040 section = new NameRelationshipDetailSection(this, conversation,
2041 parentElement, style);
2042 break;
2043 case PROTOLOG:
2044 section = new ProtologueSection(this, conversation, parentElement,
2045 style);
2046 break;
2047 case RIGHTS:
2048 section = new RightsSection(this, conversation, parentElement,
2049 style);
2050 break;
2051 case SOURCE:
2052 section = new SourceSection(this, conversation, parentElement,
2053 style);
2054 break;
2055 case SCOPE:
2056 section = new ScopeSection(this, conversation, parentElement, style);
2057 break;
2058 case DESCRIPTIONSOURCE:
2059 section = new DescriptionSourceSection(this, conversation,
2060 parentElement, style);
2061 break;
2062 case TYPEDESIGNATION:
2063 section = new TypeDesignationSection(this, conversation,
2064 parentElement, style);
2065 break;
2066 case STATE_DATA:
2067 section = new StateDataSection(this, conversation, parentElement,
2068 style);
2069 break;
2070 case STATISTICAL_MEASUREMENT_VALUE:
2071 section = new StatisticalMeasurementValueSection(this,
2072 conversation, parentElement, style);
2073 break;
2074 case DESCRIBED_SPECIMEN:
2075 section = new DescribedSpecimenSection(this, conversation,
2076 parentElement, style);
2077 break;
2078 case COLLECTING_AREA:
2079 section = new CollectingAreasDetailSection(this, conversation,
2080 parentElement, style);
2081 break;
2082 case DETERMINATION_CURRENT:
2083 section = new CurrentDeterminationDetailSection(this, conversation,
2084 parentElement, style);
2085 break;
2086 case DETERMINATION_HISTORY:
2087 section = new DeterminationHistoryDetailSection(this, conversation,
2088 parentElement, style);
2089 break;
2090 case SPECIMEN_COLLECTION:
2091 section = new SpecimenCollectionDetailSection(this, conversation,
2092 parentElement, style);
2093 break;
2094 case IDENTIFIABLE_SOURCE_COLLECTION:
2095 section = new SourceCollectionDetailSection(this, conversation,
2096 parentElement, style);
2097 break;
2098 case GEOGRAPHICAL_SCOPE:
2099 section = new GeographicalScopeDetailSection(this, conversation,
2100 parentElement, style);
2101 break;
2102 case SCOPE_RESTRICTION:
2103 section = new ScopeRestrictionSection(this, conversation,
2104 parentElement, style);
2105 break;
2106 case MEMBER:
2107 section = new MemberDetailSection(this, conversation,
2108 parentElement, style);
2109 break;
2110 case GRANTED_AUTHORITY:
2111 section = new GrantedAuthorityDetailSection(this, conversation,
2112 parentElement, style);
2113 break;
2114 case GROUPS_BY_USER:
2115 section = new GroupsByUserDetailSection(this, conversation,
2116 parentElement, style);
2117 break;
2118 case TAXONOMIC_SCOPE:
2119 section = new TaxonomicScopeSection(this, conversation,
2120 parentElement, style);
2121 break;
2122 }
2123 parentElement.addElement(section);
2124 adapt(section);
2125 return section;
2126 }
2127
2128 /**
2129 * <p>
2130 * createEntityCollectionElement
2131 * </p>
2132 *
2133 * @param removeListener
2134 * a {@link org.eclipse.swt.events.SelectionListener} object.
2135 * @param style
2136 * a int.
2137 * @param parentElement
2138 * a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
2139 * object.
2140 * @param versionableEntity
2141 * a {@link eu.etaxonomy.cdm.model.common.IVersionableEntity}
2142 * object.
2143 * @param backgroundColor
2144 * a {@link org.eclipse.swt.graphics.Color} object.
2145 * @return a
2146 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement}
2147 * object.
2148 */
2149 public AbstractEntityCollectionElement createEntityCollectionElement(
2150 AbstractFormSection parentElement, Object versionableEntity,
2151 SelectionListener removeListener, Color backgroundColor, int style) {
2152 AbstractEntityCollectionElement element = null;
2153
2154 Object entity = HibernateProxyHelper.deproxy(versionableEntity);
2155
2156 if (entity instanceof Annotation) {
2157 element = new AnnotationElement(this, parentElement,
2158 (Annotation) entity, removeListener, style);
2159 } else if (entity instanceof Person) {
2160 element = new TeamMemberElement(this, parentElement,
2161 (Person) entity, removeListener, style);
2162 } else if (entity instanceof Credit) {
2163 element = new CreditElement(this, parentElement, (Credit) entity,
2164 removeListener, style);
2165 } else if (entity instanceof Extension) {
2166 element = new ExtensionElement(this, parentElement,
2167 (Extension) entity, removeListener, style);
2168 } else if (entity instanceof Marker) {
2169 element = new MarkerElement(this, parentElement, (Marker) entity,
2170 removeListener, style);
2171 } else if (entity instanceof Media) {
2172 element = new MediaElement(this, parentElement, (Media) entity,
2173 removeListener, style);
2174 } else if (entity instanceof MediaRepresentation) {
2175 element = new MediaRepresentationElement(this, parentElement,
2176 (MediaRepresentation) entity, removeListener, style);
2177 } else if (entity instanceof ImageFile) {
2178 element = new ImageFileElement(this, parentElement,
2179 (ImageFile) entity, removeListener, style);
2180 } else if (entity instanceof MediaRepresentationPart){
2181 element = new MediaRepresentationPartElement(this, parentElement,
2182 (MediaRepresentationPart) entity, removeListener, style);
2183 } else if (entity instanceof NomenclaturalStatus) {
2184 element = new NomenclaturalStatusElement(this, parentElement,
2185 (NomenclaturalStatus) entity, removeListener, style);
2186 } else if (entity instanceof Rights) {
2187 element = new RightsElement(this, parentElement, (Rights) entity,
2188 removeListener, style);
2189 } else if (entity instanceof DescriptionElementSource) {
2190 element = new DescriptionElementSourceElement(this, parentElement,
2191 (DescriptionElementSource) entity, removeListener, style);
2192 } else if (entity instanceof IdentifiableSource) {
2193 element = new IdentifiableSourceElement(this, parentElement,
2194 (IdentifiableSource) entity, removeListener, style);
2195 } else if (entity instanceof Scope) {
2196 element = new ScopeElement(this, parentElement, (Scope) entity,
2197 removeListener, style);
2198 } else if (entity instanceof Modifier) {
2199 element = new ModifierElement(this, parentElement,
2200 (Modifier) entity, removeListener, style);
2201 } else if (entity instanceof Reference) {
2202 element = new DescriptionSourceElement(this, parentElement,
2203 (Reference) entity, removeListener, style);
2204 } else if (entity instanceof NameTypeDesignation) {
2205 element = new NameTypeDesignationElement(this, parentElement,
2206 (NameTypeDesignation) entity, removeListener, style);
2207 } else if (entity instanceof NameRelationship) {
2208 element = new NameRelationshipDetailElement(this, parentElement,
2209 (NameRelationship) entity, removeListener, style);
2210 } else if (entity instanceof SpecimenTypeDesignation) {
2211 element = new SpecimenTypeDesignationElement(this, parentElement,
2212 (SpecimenTypeDesignation) entity, removeListener, style);
2213 } else if (entity instanceof StateData) {
2214 element = new StateDataElement(this, parentElement,
2215 (StateData) entity, removeListener, style);
2216 } else if (entity instanceof StatisticalMeasurementValue) {
2217 element = new StatisticalMeasurementValueElement(this,
2218 parentElement, (StatisticalMeasurementValue) entity,
2219 removeListener, style);
2220 } else if (entity instanceof DerivedUnit) {
2221 element = new DerivedUnitElement(this, parentElement,
2222 (DerivedUnit) entity, removeListener, style);
2223 } else if (entity instanceof NamedArea) {
2224 element = new NamedAreaDetailElement(this, parentElement,
2225 (NamedArea) entity, removeListener, style);
2226 } else if (entity instanceof DeterminationEvent) {
2227 element = new DeterminationEventDetailElement(this, parentElement,
2228 (DeterminationEvent) entity, removeListener, style);
2229 } else if (entity instanceof Specimen) {
2230 element = new SpecimenCollectionDetailElement(this, parentElement,
2231 (Specimen) entity, removeListener, style);
2232 } else if (entity instanceof User) {
2233 element = new MemberDetailElement(this, parentElement,
2234 (User) entity, removeListener, style);
2235 } else if (entity instanceof GrantedAuthority) {
2236 element = new GrantedAuthorityDetailElement(this, parentElement,
2237 (GrantedAuthority) entity, removeListener, style);
2238 } else if (entity instanceof Group) {
2239 element = new GroupsByUserDetailElement(this, parentElement,
2240 (Group) entity, removeListener, style);
2241 } else if (entity instanceof Taxon) {
2242 element = new TaxonDetailElement(this, parentElement,
2243 (Taxon) entity, removeListener, style);
2244 } else if (entity instanceof DescriptionElementBase) {
2245 // this is the special case for protologs, maybe we can do this
2246 // differently when API improves
2247 DescriptionElementBase descriptionElement = (DescriptionElementBase) entity;
2248 if (descriptionElement.getFeature().equals(Feature.PROTOLOGUE())) {
2249 element = new ProtologueElement(this, parentElement,
2250 descriptionElement, removeListener, style);
2251 }
2252 }
2253
2254 if (element == null) {
2255 StoreUtil
2256 .errorDialog(
2257 "No element for entity",
2258 this,
2259 "Could not generate element for entity. "
2260 + "Looks like the case is not handled already. Check implementation. Entity: "
2261 + entity, null);
2262
2263 }
2264
2265 if (backgroundColor != null && !backgroundColor.isDisposed()) {
2266 element.setPersistentBackground(backgroundColor);
2267 }
2268
2269 adapt(element);
2270 parentElement.addElement(element);
2271 return element;
2272 }
2273
2274 /**
2275 * <p>
2276 * createSelectionElement
2277 * </p>
2278 *
2279 * @param selectionType
2280 * a
2281 * {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.SelectionType}
2282 * object.
2283 * @param parentElement
2284 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
2285 * object.
2286 * @param labelString
2287 * a {@link java.lang.String} object.
2288 * @param selectionType
2289 * @param selection
2290 * a {@link eu.etaxonomy.cdm.model.common.IAnnotatableEntity}
2291 * object.
2292 * @param style
2293 * a int.
2294 * @param conversation
2295 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
2296 * object.
2297 * @return a
2298 * {@link eu.etaxonomy.taxeditor.ui.selection.AbstractSelectionElement}
2299 * object.
2300 */
2301 public AbstractSelectionElement createSelectionElement(
2302 SelectionType selectionType, ConversationHolder conversation,
2303 ICdmFormElement parentElement, String labelString,
2304 ICdmBase selection, int mode, int style) {
2305 AbstractSelectionElement element = null;
2306
2307 IAnnotatableEntity entity = (IAnnotatableEntity) HibernateProxyHelper
2308 .deproxy(selection);
2309
2310 switch (selectionType) {
2311 case AGENT:
2312 element = new AgentSelectionElement(this, conversation,
2313 parentElement, labelString, (TeamOrPersonBase) entity,
2314 mode, style);
2315 break;
2316 case PERSON:
2317 element = new PersonSelectionElement(this, conversation,
2318 parentElement, labelString, (Person) entity, mode, style);
2319 break;
2320 case TEAM:
2321 element = new TeamSelectionElement(this, conversation,
2322 parentElement, labelString, (Team) entity, mode, style);
2323 break;
2324 case AUTHOR_TEAM:
2325 element = new NomenclaturalAuthorTeamSelectionElement(this,
2326 conversation, parentElement, labelString, (Team) entity,
2327 mode, style);
2328 break;
2329 case INSTITUTION:
2330 element = new InstitutionSelectionElement(this, conversation,
2331 parentElement, labelString, (Institution) entity, mode,
2332 style);
2333 break;
2334 case NAME:
2335 element = new NameSelectionElement(this, conversation,
2336 parentElement, labelString, (TaxonNameBase) entity, mode,
2337 style);
2338 break;
2339 case REFERENCE:
2340 element = new ReferenceSelectionElement(this, conversation,
2341 parentElement, labelString, (Reference) entity, mode, style);
2342 break;
2343 case TAXON_BASE:
2344 element = new TaxonBaseSelectionElement(this, conversation,
2345 parentElement, labelString, (TaxonBase) entity, mode, style);
2346 break;
2347 case TAXON:
2348 element = new TaxonSelectionElement(this, conversation,
2349 parentElement, labelString, (Taxon) entity, mode, style);
2350 break;
2351 case SYNONYM:
2352 element = new SynonymSelectionElement(this, conversation,
2353 parentElement, labelString, (Synonym) entity, mode, style);
2354 break;
2355 case DERIVED_UNIT:
2356 element = new DerivedUnitBaseSelectionElement(this, conversation,
2357 parentElement, labelString, (DerivedUnitBase) entity, mode,
2358 style);
2359 break;
2360 case FIELD_OBSERVATION:
2361 element = new FieldObservationSelectionElement(this, conversation,
2362 parentElement, labelString, (FieldObservation) entity,
2363 mode, style);
2364 break;
2365 case FEATURE_TREE:
2366 element = new FeatureTreeSelectionElement(this, conversation,
2367 parentElement, labelString, (FeatureTree) entity, mode,
2368 style);
2369 break;
2370 case CLASSIFICATION:
2371 element = new ClassificationSelectionElement(this, conversation,
2372 parentElement, labelString, (Classification) entity, mode,
2373 style);
2374 break;
2375 case TAXON_NODE:
2376 element = new TaxonNodeSelectionElement(this, conversation,
2377 parentElement, labelString, (TaxonNode) entity, mode, style);
2378 break;
2379 case COLLECTION:
2380 element = new CollectionSelectionElement(this, conversation,
2381 parentElement, labelString, (Collection) entity, mode,
2382 style);
2383 break;
2384 case FEATURE:
2385 element = new FeatureSelectionElement(this, conversation,
2386 parentElement, labelString, (Feature) entity, mode, style);
2387 break;
2388 case POLYTOMOUS_KEY:
2389 element = new PolytomousKeySelectionElement(this, conversation,
2390 parentElement, labelString, (PolytomousKey) entity, mode,
2391 style);
2392 break;
2393 case POLYTOMOUS_KEY_NODE:
2394 element = new PolytomousKeyNodeSelectionElement(this, conversation,
2395 parentElement, labelString, (PolytomousKeyNode) entity,
2396 mode, style);
2397 break;
2398 case USER:
2399 element = new UserSelectionElement(this, conversation,
2400 parentElement, labelString, (User) entity, mode, style);
2401 break;
2402 case GROUP:
2403 element = new GroupSelectionElement(this, conversation,
2404 parentElement, labelString, (Group) entity, mode, style);
2405 break;
2406 default:
2407 new RuntimeException(
2408 "There is no selection composite for the desired selection type.");
2409 break;
2410 }
2411
2412 adapt(element);
2413 parentElement.addElement(element);
2414 return element;
2415 }
2416
2417 /**
2418 * <p>
2419 * createNamedAreaSelectionElement
2420 * </p>
2421 *
2422 * @param parentElement
2423 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
2424 * object.
2425 * @param conversation
2426 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
2427 * object.
2428 * @param labelString
2429 * a {@link java.lang.String} object.
2430 * @param selection
2431 * a {@link eu.etaxonomy.cdm.model.location.NamedArea} object.
2432 * @param style
2433 * a int.
2434 * @return a
2435 * {@link eu.etaxonomy.taxeditor.ui.selection.NamedAreaSelectionElement}
2436 * object.
2437 */
2438 public NamedAreaSelectionElement createNamedAreaSelectionElement(
2439 ICdmFormElement parentElement, ConversationHolder conversation,
2440 String labelString, NamedArea selection, int style) {
2441 NamedAreaSelectionElement element = new NamedAreaSelectionElement(this,
2442 conversation, parentElement, labelString, selection,
2443 AbstractSelectionElement.NOTHING, style);
2444 adapt(element);
2445 parentElement.addElement(element);
2446 return element;
2447 }
2448
2449 /** {@inheritDoc} */
2450 public LabelElement createLabel(ICdmFormElement parentElement, String text) {
2451 LabelElement labelElement = new LabelElement(this, parentElement, text);
2452 adapt(labelElement);
2453 parentElement.addElement(labelElement);
2454 return labelElement;
2455 }
2456
2457 /**
2458 * <p>
2459 * Getter for the field <code>selectionProvider</code>.
2460 * </p>
2461 *
2462 * @return a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
2463 */
2464 public ISelectionProvider getSelectionProvider() {
2465 return selectionProvider;
2466 }
2467
2468 /**
2469 * <p>
2470 * createDetailedDescriptionDetailElement
2471 * </p>
2472 *
2473 * @param parentElement
2474 * a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement}
2475 * object.
2476 * @param entity
2477 * a
2478 * {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase}
2479 * object.
2480 * @param style
2481 * a int.
2482 * @return a
2483 * {@link eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement}
2484 * object.
2485 */
2486 public AbstractDetailedDescriptionDetailElement createDetailedDescriptionDetailElement(
2487 ICdmFormElement parentElement, DescriptionElementBase entity,
2488 int style) {
2489 AbstractDetailedDescriptionDetailElement detailedDescriptionElement = null;
2490
2491 if (entity instanceof CategoricalData) {
2492 detailedDescriptionElement = new CategoricalDataDetailElement(this,
2493 parentElement, (CategoricalData) entity, style);
2494 } else if (entity instanceof CommonTaxonName) {
2495 detailedDescriptionElement = new CommonNameDetailElement(this,
2496 parentElement, (CommonTaxonName) entity, style);
2497 } else if (entity instanceof Distribution) {
2498 detailedDescriptionElement = new DistributionDetailElement(this,
2499 parentElement, (Distribution) entity, style);
2500 } else if (entity instanceof IndividualsAssociation) {
2501 detailedDescriptionElement = new IndividualsAssociationDetailElement(
2502 this, parentElement, (IndividualsAssociation) entity, style);
2503 } else if (entity instanceof QuantitativeData) {
2504 detailedDescriptionElement = new QuantitativeDataDetailElement(
2505 this, parentElement, (QuantitativeData) entity, style);
2506 } else if (entity instanceof TaxonInteraction) {
2507 detailedDescriptionElement = new TaxonInteractionDetailElement(
2508 this, parentElement, (TaxonInteraction) entity, style);
2509 } else if (entity instanceof TextData) {
2510 detailedDescriptionElement = new TextDataDetailElement(this,
2511 parentElement, (TextData) entity, style);
2512 } else {
2513 throw new IllegalStateException(
2514 "There is no interface for the given description element");
2515 }
2516 adapt(detailedDescriptionElement);
2517 parentElement.addElement(detailedDescriptionElement);
2518 return detailedDescriptionElement;
2519
2520 }
2521
2522 /**
2523 * Creates a styled text as a part of the form.
2524 *
2525 * @param parent
2526 * the text parent
2527 * @param value
2528 * the text initial value
2529 * @param style
2530 * the text style
2531 * @return the text widget
2532 */
2533 public StyledText createStyledText(Composite parent, String value, int style) {
2534 StyledText text = new StyledText(parent, getBorderStyle() | style
2535 | getOrientation());
2536 if (value != null)
2537 text.setText(value);
2538 text.setForeground(getColors().getForeground());
2539 text.setBackground(getColors().getBackground());
2540 // text.addFocusListener(visibilityHandler);
2541 return text;
2542 }
2543 }