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