Started working on buckminster build process. Started implementing fully featured...
[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.Map;
8
9 import org.apache.log4j.Logger;
10 import org.eclipse.core.runtime.Assert;
11 import org.eclipse.core.runtime.ListenerList;
12 import org.eclipse.jface.util.IPropertyChangeListener;
13 import org.eclipse.jface.viewers.ISelection;
14 import org.eclipse.jface.viewers.ISelectionProvider;
15 import org.eclipse.jface.window.Window;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.events.FocusAdapter;
18 import org.eclipse.swt.events.FocusEvent;
19 import org.eclipse.swt.events.FocusListener;
20 import org.eclipse.swt.events.MouseAdapter;
21 import org.eclipse.swt.events.MouseEvent;
22 import org.eclipse.swt.events.MouseListener;
23 import org.eclipse.swt.events.SelectionEvent;
24 import org.eclipse.swt.events.SelectionListener;
25 import org.eclipse.swt.events.TypedEvent;
26 import org.eclipse.swt.graphics.Color;
27 import org.eclipse.swt.graphics.Font;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Control;
30 import org.eclipse.swt.widgets.Display;
31 import org.eclipse.swt.widgets.Event;
32 import org.eclipse.swt.widgets.Label;
33 import org.eclipse.ui.forms.IFormColors;
34 import org.eclipse.ui.forms.widgets.FormToolkit;
35 import org.eclipse.ui.forms.widgets.Section;
36 import org.eclipse.ui.forms.widgets.TableWrapData;
37 import org.eclipse.ui.forms.widgets.TableWrapLayout;
38 import org.eclipse.ui.internal.forms.widgets.FormFonts;
39 import org.joda.time.Partial;
40
41 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
42 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
43 import eu.etaxonomy.cdm.model.agent.Institution;
44 import eu.etaxonomy.cdm.model.agent.Person;
45 import eu.etaxonomy.cdm.model.agent.Team;
46 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
47 import eu.etaxonomy.cdm.model.common.Annotation;
48 import eu.etaxonomy.cdm.model.common.AnnotationType;
49 import eu.etaxonomy.cdm.model.common.Credit;
50 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
51 import eu.etaxonomy.cdm.model.common.DescriptionElementSource;
52 import eu.etaxonomy.cdm.model.common.Extension;
53 import eu.etaxonomy.cdm.model.common.ExtensionType;
54 import eu.etaxonomy.cdm.model.common.IVersionableEntity;
55 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
56 import eu.etaxonomy.cdm.model.common.IdentifiableSource;
57 import eu.etaxonomy.cdm.model.common.Language;
58 import eu.etaxonomy.cdm.model.common.LanguageString;
59 import eu.etaxonomy.cdm.model.common.Marker;
60 import eu.etaxonomy.cdm.model.common.MarkerType;
61 import eu.etaxonomy.cdm.model.common.TimePeriod;
62 import eu.etaxonomy.cdm.model.common.VersionableEntity;
63 import eu.etaxonomy.cdm.model.description.CategoricalData;
64 import eu.etaxonomy.cdm.model.description.CommonTaxonName;
65 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
66 import eu.etaxonomy.cdm.model.description.Distribution;
67 import eu.etaxonomy.cdm.model.description.Feature;
68 import eu.etaxonomy.cdm.model.description.FeatureTree;
69 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
70 import eu.etaxonomy.cdm.model.description.MeasurementUnit;
71 import eu.etaxonomy.cdm.model.description.Modifier;
72 import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
73 import eu.etaxonomy.cdm.model.description.QuantitativeData;
74 import eu.etaxonomy.cdm.model.description.Scope;
75 import eu.etaxonomy.cdm.model.description.Sex;
76 import eu.etaxonomy.cdm.model.description.Stage;
77 import eu.etaxonomy.cdm.model.description.State;
78 import eu.etaxonomy.cdm.model.description.StateData;
79 import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
80 import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
81 import eu.etaxonomy.cdm.model.description.TaxonInteraction;
82 import eu.etaxonomy.cdm.model.description.TextData;
83 import eu.etaxonomy.cdm.model.location.NamedArea;
84 import eu.etaxonomy.cdm.model.location.NamedAreaType;
85 import eu.etaxonomy.cdm.model.media.ImageFile;
86 import eu.etaxonomy.cdm.model.media.Media;
87 import eu.etaxonomy.cdm.model.media.MediaRepresentation;
88 import eu.etaxonomy.cdm.model.media.Rights;
89 import eu.etaxonomy.cdm.model.media.RightsTerm;
90 import eu.etaxonomy.cdm.model.name.NameRelationship;
91 import eu.etaxonomy.cdm.model.name.NameRelationshipType;
92 import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
93 import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
94 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
95 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
96 import eu.etaxonomy.cdm.model.name.Rank;
97 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
98 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
99 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
100 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
101 import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
102 import eu.etaxonomy.cdm.model.occurrence.FieldObservation;
103 import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
104 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
105 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
106 import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
107 import eu.etaxonomy.taxeditor.forms.selection.AbstractSelectionElement;
108 import eu.etaxonomy.taxeditor.forms.selection.AgentSelectionElement;
109 import eu.etaxonomy.taxeditor.forms.selection.DerivedUnitBaseSelectionElement;
110 import eu.etaxonomy.taxeditor.forms.selection.FeatureTreeSelectionElement;
111 import eu.etaxonomy.taxeditor.forms.selection.FieldObservationSelectionElement;
112 import eu.etaxonomy.taxeditor.forms.selection.InstitutionSelectionElement;
113 import eu.etaxonomy.taxeditor.forms.selection.NameSelectionElement;
114 import eu.etaxonomy.taxeditor.forms.selection.NamedAreaSelectionElement;
115 import eu.etaxonomy.taxeditor.forms.selection.NomenclaturalAuthorTeamSelectionElement;
116 import eu.etaxonomy.taxeditor.forms.selection.PersonSelectionElement;
117 import eu.etaxonomy.taxeditor.forms.selection.ReferenceSelectionElement;
118 import eu.etaxonomy.taxeditor.forms.selection.TaxonSelectionElement;
119 import eu.etaxonomy.taxeditor.forms.selection.TeamSelectionElement;
120 import eu.etaxonomy.taxeditor.forms.term.AbstractEnumComboElement;
121 import eu.etaxonomy.taxeditor.forms.term.AbstractTermComboElement;
122 import eu.etaxonomy.taxeditor.forms.term.AnnotationTypeComboElement;
123 import eu.etaxonomy.taxeditor.forms.term.ExtensionTypeComboElement;
124 import eu.etaxonomy.taxeditor.forms.term.LanguageComboElement;
125 import eu.etaxonomy.taxeditor.forms.term.MarkerTypeComboElement;
126 import eu.etaxonomy.taxeditor.forms.term.MeasurementUnitComboElement;
127 import eu.etaxonomy.taxeditor.forms.term.ModifierComboElement;
128 import eu.etaxonomy.taxeditor.forms.term.NameRelationshipTypeComboElement;
129 import eu.etaxonomy.taxeditor.forms.term.NameTypeDesignationStatusComboElement;
130 import eu.etaxonomy.taxeditor.forms.term.NamedAreaTypeComboElement;
131 import eu.etaxonomy.taxeditor.forms.term.NomenclaturalCodeComboElement;
132 import eu.etaxonomy.taxeditor.forms.term.NomenclaturalStatusTypeComboElement;
133 import eu.etaxonomy.taxeditor.forms.term.PresenceAbsenceTermComboElement;
134 import eu.etaxonomy.taxeditor.forms.term.PreservationMethodComboElement;
135 import eu.etaxonomy.taxeditor.forms.term.RankComboElement;
136 import eu.etaxonomy.taxeditor.forms.term.ReferenceTypeComboElement;
137 import eu.etaxonomy.taxeditor.forms.term.RightsTypeComboElement;
138 import eu.etaxonomy.taxeditor.forms.term.ScopeComboElement;
139 import eu.etaxonomy.taxeditor.forms.term.SexComboElement;
140 import eu.etaxonomy.taxeditor.forms.term.SpecimenTypeDesignationStatusComboElement;
141 import eu.etaxonomy.taxeditor.forms.term.StageComboElement;
142 import eu.etaxonomy.taxeditor.forms.term.StateComboElement;
143 import eu.etaxonomy.taxeditor.forms.term.StatisticalMeasureComboElement;
144 import eu.etaxonomy.taxeditor.section.AbstractCdmDetailElement;
145 import eu.etaxonomy.taxeditor.section.AbstractEntityCollectionElement;
146 import eu.etaxonomy.taxeditor.section.EmptyElement;
147 import eu.etaxonomy.taxeditor.section.agent.PersonDetailElement;
148 import eu.etaxonomy.taxeditor.section.agent.PersonDetailSection;
149 import eu.etaxonomy.taxeditor.section.agent.TeamDetailElement;
150 import eu.etaxonomy.taxeditor.section.agent.TeamDetailSection;
151 import eu.etaxonomy.taxeditor.section.agent.TeamMemberElement;
152 import eu.etaxonomy.taxeditor.section.agent.TeamMemberSection;
153 import eu.etaxonomy.taxeditor.section.agent.TeamOrPersonBaseDetailSection;
154 import eu.etaxonomy.taxeditor.section.description.DerivedUnitElement;
155 import eu.etaxonomy.taxeditor.section.description.DescribedSpecimenSection;
156 import eu.etaxonomy.taxeditor.section.description.DescriptionDetailElement;
157 import eu.etaxonomy.taxeditor.section.description.DescriptionDetailSection;
158 import eu.etaxonomy.taxeditor.section.description.DescriptionElementDetailElement;
159 import eu.etaxonomy.taxeditor.section.description.DescriptionElementDetailSection;
160 import eu.etaxonomy.taxeditor.section.description.DescriptionElementMediaSection;
161 import eu.etaxonomy.taxeditor.section.description.DescriptionElementSourceElement;
162 import eu.etaxonomy.taxeditor.section.description.DescriptionElementSourceSection;
163 import eu.etaxonomy.taxeditor.section.description.DescriptionSourceElement;
164 import eu.etaxonomy.taxeditor.section.description.DescriptionSourceSection;
165 import eu.etaxonomy.taxeditor.section.description.ModifierElement;
166 import eu.etaxonomy.taxeditor.section.description.ModifierSection;
167 import eu.etaxonomy.taxeditor.section.description.NaturalLanguageDetailElement;
168 import eu.etaxonomy.taxeditor.section.description.NaturalLanguageSection;
169 import eu.etaxonomy.taxeditor.section.description.ScopeElement;
170 import eu.etaxonomy.taxeditor.section.description.ScopeSection;
171 import eu.etaxonomy.taxeditor.section.description.StateDataElement;
172 import eu.etaxonomy.taxeditor.section.description.StateDataSection;
173 import eu.etaxonomy.taxeditor.section.description.StatisticalMeasurementValueElement;
174 import eu.etaxonomy.taxeditor.section.description.StatisticalMeasurementValueSection;
175 import eu.etaxonomy.taxeditor.section.description.detail.AbstractDetailedDescriptionDetailElement;
176 import eu.etaxonomy.taxeditor.section.description.detail.CategoricalDataDetailElement;
177 import eu.etaxonomy.taxeditor.section.description.detail.CommonNameDetailElement;
178 import eu.etaxonomy.taxeditor.section.description.detail.DistributionDetailElement;
179 import eu.etaxonomy.taxeditor.section.description.detail.IndividualsAssociationDetailElement;
180 import eu.etaxonomy.taxeditor.section.description.detail.QuantitativeDataDetailElement;
181 import eu.etaxonomy.taxeditor.section.description.detail.TaxonInteractionDetailElement;
182 import eu.etaxonomy.taxeditor.section.description.detail.TextDataDetailElement;
183 import eu.etaxonomy.taxeditor.section.name.AuthorshipDetailElement;
184 import eu.etaxonomy.taxeditor.section.name.AuthorshipDetailSection;
185 import eu.etaxonomy.taxeditor.section.name.NameDetailElement;
186 import eu.etaxonomy.taxeditor.section.name.NameDetailSection;
187 import eu.etaxonomy.taxeditor.section.name.NameRelationshipDetailElement;
188 import eu.etaxonomy.taxeditor.section.name.NameRelationshipDetailSection;
189 import eu.etaxonomy.taxeditor.section.name.NameTypeDesignationElement;
190 import eu.etaxonomy.taxeditor.section.name.NomenclaturalStatusElement;
191 import eu.etaxonomy.taxeditor.section.name.NomenclaturalStatusSection;
192 import eu.etaxonomy.taxeditor.section.name.NonViralNameDetailElement;
193 import eu.etaxonomy.taxeditor.section.name.NonViralNameDetailSection;
194 import eu.etaxonomy.taxeditor.section.name.ProtologueElement;
195 import eu.etaxonomy.taxeditor.section.name.ProtologueSection;
196 import eu.etaxonomy.taxeditor.section.name.SpecimenTypeDesignationElement;
197 import eu.etaxonomy.taxeditor.section.name.TypeDesignationSection;
198 import eu.etaxonomy.taxeditor.section.occurrence.DerivedUnitBaseDetailElement;
199 import eu.etaxonomy.taxeditor.section.occurrence.DerivedUnitBaseDetailSection;
200 import eu.etaxonomy.taxeditor.section.occurrence.DerivedUnitFacadeDetailElement;
201 import eu.etaxonomy.taxeditor.section.occurrence.DerivedUnitFacadeDetailSection;
202 import eu.etaxonomy.taxeditor.section.occurrence.FieldObservationDetailElement;
203 import eu.etaxonomy.taxeditor.section.occurrence.FieldObservationDetailSection;
204 import eu.etaxonomy.taxeditor.section.occurrence.GatheringEventDetailElement;
205 import eu.etaxonomy.taxeditor.section.occurrence.GatheringEventDetailSection;
206 import eu.etaxonomy.taxeditor.section.reference.NomenclaturalReferenceDetailElement;
207 import eu.etaxonomy.taxeditor.section.reference.NomenclaturalReferenceDetailSection;
208 import eu.etaxonomy.taxeditor.section.reference.ReferenceBaseDetailElement;
209 import eu.etaxonomy.taxeditor.section.reference.ReferenceBaseDetailSection;
210 import eu.etaxonomy.taxeditor.section.supplemental.AnnotationElement;
211 import eu.etaxonomy.taxeditor.section.supplemental.AnnotationSection;
212 import eu.etaxonomy.taxeditor.section.supplemental.CreditElement;
213 import eu.etaxonomy.taxeditor.section.supplemental.CreditSection;
214 import eu.etaxonomy.taxeditor.section.supplemental.ExtensionElement;
215 import eu.etaxonomy.taxeditor.section.supplemental.ExtensionSection;
216 import eu.etaxonomy.taxeditor.section.supplemental.HeadlineSection;
217 import eu.etaxonomy.taxeditor.section.supplemental.IdentifiableSourceElement;
218 import eu.etaxonomy.taxeditor.section.supplemental.ImageFileElement;
219 import eu.etaxonomy.taxeditor.section.supplemental.MarkerElement;
220 import eu.etaxonomy.taxeditor.section.supplemental.MarkerSection;
221 import eu.etaxonomy.taxeditor.section.supplemental.MediaElement;
222 import eu.etaxonomy.taxeditor.section.supplemental.MediaRepresentationElement;
223 import eu.etaxonomy.taxeditor.section.supplemental.MediaRepresentationPartSection;
224 import eu.etaxonomy.taxeditor.section.supplemental.MediaRepresentationSection;
225 import eu.etaxonomy.taxeditor.section.supplemental.MediaSection;
226 import eu.etaxonomy.taxeditor.section.supplemental.RightsElement;
227 import eu.etaxonomy.taxeditor.section.supplemental.RightsSection;
228 import eu.etaxonomy.taxeditor.section.supplemental.SourceSection;
229 import eu.etaxonomy.taxeditor.section.supplemental.VersionElement;
230 import eu.etaxonomy.taxeditor.section.supplemental.VersionSection;
231 import eu.etaxonomy.taxeditor.section.taxon.ParsingMessageElement;
232 import eu.etaxonomy.taxeditor.section.taxon.ParsingMessagesSection;
233 import eu.etaxonomy.taxeditor.section.taxon.TaxonBaseDetailElement;
234 import eu.etaxonomy.taxeditor.section.taxon.TaxonBaseDetailSection;
235
236 /**
237 *
238 * @author n.hoffmann
239 * @created Feb 24, 2010
240 * @version 1.0
241 */
242 public class CdmFormFactory extends FormToolkit{
243
244 private static final Logger logger = Logger
245 .getLogger(CdmFormFactory.class);
246
247 private BoldFontHolder2 boldFontHolder2;
248 private MouseListener selectionMouseHandler;
249 private FocusListener selectionFocusHandler;
250
251 private ListenerList selectionListenerList = new ListenerList();
252
253 private ListenerList propertyChangeListeners = new ListenerList();
254
255 private int orientation = Window.getDefaultOrientation();
256 private ISelectionProvider selectionProvider;
257
258 /**
259 *
260 * @return
261 */
262 public static final TableWrapLayout LAYOUT(){
263 return LAYOUT(1, false);
264 }
265
266 /**
267 *
268 * @param columns
269 * @param equalWidth
270 * @return
271 */
272 public static final TableWrapLayout LAYOUT(int columns, boolean equalWidth){
273 TableWrapLayout layout = new TableWrapLayout();
274 layout.topMargin = 0;
275 layout.rightMargin = 0;
276 layout.bottomMargin = 0;
277 layout.leftMargin = 0;
278 layout.numColumns = columns;
279 layout.makeColumnsEqualWidth = equalWidth;
280 layout.verticalSpacing = 0;
281 layout.horizontalSpacing = 0;
282 return layout;
283 }
284
285 /**
286 *
287 * @return
288 */
289 public static final TableWrapData FILL(){
290 TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL_GRAB);
291 // layoutData.grabHorizontal = true;
292 // layoutData.grabVertical = true;
293 return layoutData;
294 }
295
296 public static final TableWrapData LEFT(){
297 return new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP);
298 }
299
300 public static final TableWrapData RIGHT(){
301 return new TableWrapData(TableWrapData.RIGHT, TableWrapData.TOP);
302 }
303
304 /**
305 *
306 * @return
307 */
308 public static final TableWrapData FILL_HORIZONTALLY(){
309 return FILL_HORIZONTALLY(1, 1);
310 }
311
312 /**
313 *
314 * @param horizontalSpan
315 * @param verticalSpan
316 * @return
317 */
318 public static final TableWrapData FILL_HORIZONTALLY(int horizontalSpan, int verticalSpan){
319 TableWrapData layoutData = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP);
320 layoutData.colspan = horizontalSpan;
321 layoutData.rowspan = verticalSpan;
322 return layoutData;
323 }
324
325 public static ISelection EMPTY_SELECTION = new ISelection() {
326 public boolean isEmpty() {
327 return true;
328 }
329 };
330
331 private class SelectionMouseHandler extends MouseAdapter{
332 @Override
333 public void mouseDown(MouseEvent e) {
334 notifySelectionListeners(e);
335 }
336 }
337
338 private class SelectionFocusHandler extends FocusAdapter{
339 @Override
340 public void focusGained(FocusEvent e) {
341 notifySelectionListeners(e);
342 }
343 }
344
345 private void notifySelectionListeners(TypedEvent e){
346 Event event = new Event();
347 event.widget = e.widget;
348 SelectionEvent selectionEvent = new SelectionEvent(event);
349
350 for(Object listener : selectionListenerList.getListeners()){
351 ((SelectionListener) listener).widgetSelected(selectionEvent);
352 }
353 }
354
355 /**
356 *
357 * @param display
358 * @param selectionProvider
359 */
360 public CdmFormFactory(Display display, ISelectionProvider selectionProvider) {
361 super(display);
362 this.selectionProvider = selectionProvider;
363 init();
364 }
365
366 /**
367 *
368 * @param display
369 */
370 public CdmFormFactory(Display display){
371 super(display);
372 init();
373 }
374
375 /**
376 *
377 */
378 private void init() {
379 boldFontHolder2 = new BoldFontHolder2();
380 selectionMouseHandler = new SelectionMouseHandler();
381 selectionFocusHandler = new SelectionFocusHandler();
382 }
383
384 /**
385 * Creates an instance initialized with the correct selectionProvider
386 *
387 * Make sure to remove the instance when the entityComposite disposes via
388 * destroySelectionArbitrator(..)
389 * @return
390 */
391 public SelectionArbitrator createSelectionArbitrator(IEntityElement entityElement){
392 SelectionArbitrator selectionArbitrator = new SelectionArbitrator(entityElement);
393 selectionArbitrator.addSelectionProvider(selectionProvider);
394 selectionProvider.addSelectionChangedListener(selectionArbitrator);
395 addSelectionListener(selectionArbitrator);
396 return selectionArbitrator;
397 }
398
399 public void destroySelectionArbitrator(SelectionArbitrator selectionArbitrator){
400 removeSelectionListener(selectionArbitrator);
401 selectionProvider.removeSelectionChangedListener(selectionArbitrator);
402 }
403
404 @Override
405 public void adapt(Composite composite) {
406 composite.addMouseListener(selectionMouseHandler);
407 super.adapt(composite);
408 }
409
410 public void adapt(AbstractCdmFormElement formElement){
411 formElement.setPropertyChangeListeners(propertyChangeListeners);
412 }
413
414 @Override
415 public void adapt(Control control, boolean trackFocus, boolean trackKeyboard) {
416 if(trackFocus){
417 control.addFocusListener(selectionFocusHandler);
418 }
419 super.adapt(control, trackFocus, trackKeyboard);
420 }
421
422 public void destroyElement(ICdmFormElement formElement){
423 // return if element was not initialized
424 if(formElement == null){
425 return;
426 }
427 // destroy selection arbitrator, if any
428 if(formElement instanceof ISelectableElement){
429 destroySelectionArbitrator(((ISelectableElement) formElement).getSelectionArbitrator());
430 }
431 // remove this element form its parents list of elements
432 // ICdmFormElement parentElement = formElement.getParentElement();
433 // if(parentElement != null){
434 // parentElement.removeElement(formElement);
435 // }
436 // call destroy on child elements recursively
437 for(ICdmFormElement childElement : formElement.getElements()){
438 destroyElement(childElement);
439 }
440 // dispose of the controls
441 for(Control control : formElement.getControls()){
442 // we added the layoutComposite of the parental element as the layout composite to this formElement
443 // but we do not want to destroy it.
444 if(control.equals(formElement.getLayoutComposite())){
445 continue;
446 }else{
447 control.dispose();
448 control = null;
449 }
450 }
451 }
452
453
454 public Label createEmptyCell(Composite parent){
455 return this.createLabel(parent, null);
456 }
457
458 /**
459 *
460 * @param parent
461 * @param labelString
462 * @param textHeight
463 * @param style
464 * @return
465 */
466 public TextWithLabelElement createMultilineTextWithLabel(ICdmFormElement parentElement, String labelString, int textHeight, int style){
467 TextWithLabelElement element = new TextWithLabelElement(this, parentElement, labelString, "", textHeight, style);
468 adapt(element);
469 parentElement.addElement(element);
470 return element;
471 }
472
473
474 /**
475 *
476 * @param parent
477 * @param labelString
478 * @param initialText
479 * @param style
480 * @return
481 */
482 public TextWithLabelElement createTextWithLabelElement(ICdmFormElement parentElement, String labelString, String initialText, int style){
483 TextWithLabelElement element = new TextWithLabelElement(this, parentElement, labelString, initialText, null, style);
484 adapt(element);
485 parentElement.addElement(element);
486 return element;
487 }
488
489 public NumberWithLabelElement createIntegerTextWithLabelElement(ICdmFormElement parentElement, String labelString, Integer initialInteger, int style){
490 NumberWithLabelElement element = new NumberWithLabelElement(this, parentElement, labelString, initialInteger, style);
491 adapt(element);
492 parentElement.addElement(element);
493 return element;
494 }
495
496
497 public NumberWithLabelElement createFloatTextWithLabelElement(
498 ICdmFormElement parentElement, String labelString, float initialFloat,
499 int style) {
500 NumberWithLabelElement element = new NumberWithLabelElement(this, parentElement, labelString, initialFloat, style);
501 adapt(element);
502 parentElement.addElement(element);
503 return element;
504 }
505
506 public LanguageStringWithLabelElement createLanguageStringWithLabelElement(ICdmFormElement parentElement, String labelString, LanguageString languageString, int style){
507 LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(this, parentElement, labelString, languageString, style);
508 adapt(element);
509 parentElement.addElement(element);
510 return element;
511 }
512
513 public LanguageStringWithLabelElement createLanguageStringWithLabelElement(ICdmFormElement parentElement, String labelString, LanguageString languageString, int height, int style){
514 LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(this, parentElement, labelString, languageString, height, style);
515 adapt(element);
516 parentElement.addElement(element);
517 return element;
518 }
519
520 /**
521 *
522 * @param parentElement
523 * @param labelString
524 * @param initialText
525 * @param style
526 * @return
527 */
528 public TextWithLabelElement createTextElement(ICdmFormElement parentElement, String initialText, int style){
529 TextWithLabelElement element = new TextWithLabelElement(this, parentElement, null, initialText, null, style);
530 adapt(element);
531 parentElement.addElement(element);
532 return element;
533 }
534
535 public KeyValueViewerElement createKeyValueViewerElement(ICdmFormElement parentElement, String keyHeading, String valueHeading, Map<Object, Object> map){
536 KeyValueViewerElement element = new KeyValueViewerElement(this, parentElement, keyHeading, valueHeading, map);
537 adapt(element);
538 parentElement.addElement(element);
539 return element;
540 }
541
542
543 public static enum TermComboType{
544 EXTENSIONTYPE,
545 LANGUAGE,
546 MARKERTYPE,
547 NOMENCLATURALSTATUSTYPE,
548 RANK,
549 RIGHTSTYPE,
550 NAMERELATIONSHIP,
551 NAMEDAREATYPE,
552 PRESENCEABSENCESTATUS,
553 ANNOTATIONTYPE,
554 NAMETYPEDESIGNATIONSTATUS,
555 SPECIMENTYPEDESIGNATIONSTATUS,
556 SEX,
557 STAGE,
558 PRESERVATION_METHOD,
559 MEASUREMENT_UNIT,
560 STATE,
561 MODIFIER,
562 STATISTICAL_MEASURE,
563 SCOPE
564 }
565
566 public AbstractTermComboElement createTermComboElement(TermComboType termComboType, ICdmFormElement parentElement, DefinedTermBase selection, int style){
567 AbstractTermComboElement element = null;
568
569 switch(termComboType){
570 case EXTENSIONTYPE:
571 element = new ExtensionTypeComboElement(this, parentElement, null, (ExtensionType) selection, style);
572 break;
573 case LANGUAGE:
574 element = new LanguageComboElement(this, parentElement, "Language", (Language) selection, style);
575 break;
576 case MARKERTYPE:
577 element = new MarkerTypeComboElement(this, parentElement, null, (MarkerType) selection, style);
578 break;
579 case NOMENCLATURALSTATUSTYPE:
580 element = new NomenclaturalStatusTypeComboElement(this, parentElement, "Nomenclatural Status Type", (NomenclaturalStatusType) selection, style);
581 break;
582 case RANK:
583 element = new RankComboElement(this, parentElement, "Rank", (Rank) selection, style);
584 break;
585 case RIGHTSTYPE:
586 element = new RightsTypeComboElement(this, parentElement, "Rights Type", (RightsTerm) selection, style);
587 break;
588 case NAMERELATIONSHIP:
589 element = new NameRelationshipTypeComboElement(this, parentElement, "Name Relationship Type", (NameRelationshipType) selection, style);
590 break;
591 case NAMEDAREATYPE:
592 element = new NamedAreaTypeComboElement(this, parentElement, "Named Area Type", (NamedAreaType) selection, style);
593 break;
594 case ANNOTATIONTYPE:
595 element = new AnnotationTypeComboElement(this, parentElement, "Annotation Type", (AnnotationType) selection, style);
596 break;
597 case PRESENCEABSENCESTATUS:
598 element = new PresenceAbsenceTermComboElement(this, parentElement, "Distribution Status", (PresenceAbsenceTermBase) selection, style);
599 break;
600 case NAMETYPEDESIGNATIONSTATUS:
601 element = new NameTypeDesignationStatusComboElement(this, parentElement, "Designation Status", (NameTypeDesignationStatus) selection, style);
602 break;
603 case SPECIMENTYPEDESIGNATIONSTATUS:
604 element = new SpecimenTypeDesignationStatusComboElement(this, parentElement, "Designation Status", (SpecimenTypeDesignationStatus) selection, style);
605 break;
606 case SEX:
607 element = new SexComboElement(this, parentElement, "Sex", (Sex) selection, style);
608 break;
609 case STAGE:
610 element = new StageComboElement(this, parentElement, "Life Stage", (Stage) selection, style);
611 break;
612 case PRESERVATION_METHOD:
613 element = new PreservationMethodComboElement(this, parentElement, "Preservation Method", (PreservationMethod) selection, style);
614 case MEASUREMENT_UNIT:
615 element = new MeasurementUnitComboElement(this, parentElement, "Measurement Unit", (MeasurementUnit) selection, style);
616 break;
617 case STATE:
618 element = new StateComboElement(this, parentElement, "State", (State) selection, style);
619 break;
620 case SCOPE:
621 element = new ScopeComboElement(this, parentElement, "Scope", (Scope) selection, style);
622 break;
623 case MODIFIER:
624 element = new ModifierComboElement(this, parentElement, "Modifier", (Modifier) selection, style);
625 break;
626 case STATISTICAL_MEASURE:
627 element = new StatisticalMeasureComboElement(this, parentElement, "Statistical Measure", (StatisticalMeasure) selection, style);
628 break;
629 }
630
631 adapt(element);
632 parentElement.addElement(element);
633 return element;
634 }
635
636 public static enum EnumComboType{
637 REFERENCETYPE,
638 NOMENCLATURALCODE
639 }
640
641 public AbstractEnumComboElement createEnumComboElement(EnumComboType enumComboType, ICdmFormElement parentElement, int style){
642 AbstractEnumComboElement element = null;
643
644 switch(enumComboType){
645 case REFERENCETYPE:
646 element = new ReferenceTypeComboElement(this, parentElement, "Reference Type", null, style);
647 break;
648 case NOMENCLATURALCODE:
649 element = new NomenclaturalCodeComboElement(this, parentElement, "Nomenclatural Code", null, style);
650 break;
651 }
652 adapt(element);
653 parentElement.addElement(element);
654 return element;
655 }
656
657 /**
658 *
659 * @param parent
660 * @param imageUri
661 * @param style
662 * @return
663 */
664 public ImageElement createImageElement(ICdmFormElement parentElement, URI imageUri, int style){
665 ImageElement element = new ImageElement(this, parentElement, imageUri, style);
666 adapt(element);
667 parentElement.addElement(element);
668 return element;
669 }
670
671 /**
672 *
673 * @param parent
674 * @param labelString
675 * @param initialText
676 * @param style
677 * @return
678 */
679 public TextActionElement createTextActionElement(ICdmFormElement parentElement, String labelString, String buttonLabel, String initialText, int style){
680 TextActionElement element = new TextActionElement(this, parentElement, labelString, buttonLabel, initialText, style);
681 adapt(element);
682 parentElement.addElement(element);
683 return element;
684 }
685
686 /**
687 *
688 * @author n.hoffmann
689 * @created Mar 5, 2010
690 * @version 1.0
691 */
692 public static enum SelectionType{
693 AGENT,
694 INSTITUTION,
695 NAME,
696 REFERENCE,
697 TAXON,
698 TEAM,
699 AUTHOR_TEAM,
700 PERSON,
701 DERIVED_UNIT,
702 FIELD_OBSERVATION,
703 FEATURE_TREE
704 }
705
706 /**
707 * @param parent
708 * @param string
709 * @param b
710 * @param taxonBasePropertySection
711 * @return
712 */
713 public CheckboxElement createCheckbox(ICdmFormElement parentElement, String label, boolean initialState, int style) {
714 CheckboxElement element = new CheckboxElement(this, parentElement, label, initialState, style | orientation);
715 adapt(element);
716 parentElement.addElement(element);
717 return element;
718 }
719
720
721
722 /**
723 * Creates a section as a part of the form.
724 *
725 * @param parent
726 * the section parent
727 * @param sectionStyle
728 * the section style
729 * @return the section widget
730 */
731 public Section adapt(AbstractFormSection section) {
732 section.setMenu(section.getLayoutComposite().getMenu());
733 adapt(section, true, true);
734
735 // handle focus and property change events for cdm use
736 section.addFocusListener(selectionFocusHandler);
737 section.setPropertyChangeListeners(propertyChangeListeners);
738
739 if (section.getToggle() != null) {
740 section.getToggle().setHoverDecorationColor(getColors()
741 .getColor(IFormColors.TB_TOGGLE_HOVER));
742 section.getToggle().setDecorationColor(getColors()
743 .getColor(IFormColors.TB_TOGGLE));
744 }
745
746 section.setFont(boldFontHolder2.getBoldFont(section.getLayoutComposite().getFont()));
747
748 if ((section.getStyle() & Section.TITLE_BAR) != 0
749 || (section.getStyle() & Section.SHORT_TITLE_BAR) != 0) {
750 getColors().initializeSectionToolBarColors();
751 section.setTitleBarBackground(getColors().getColor(IFormColors.TB_BG));
752 section.setTitleBarBorderColor(getColors()
753 .getColor(IFormColors.TB_BORDER));
754 }
755 // call setTitleBarForeground regardless as it also sets the label color
756 section.setTitleBarForeground(getColors()
757 .getColor(IFormColors.TB_TOGGLE));
758 return section;
759 }
760
761 private class BoldFontHolder2 {
762 private Font normalFont;
763
764 private Font boldFont;
765
766 public BoldFontHolder2() {
767 }
768
769 public Font getBoldFont(Font font) {
770 createBoldFont(font);
771 return boldFont;
772 }
773
774 private void createBoldFont(Font font) {
775 if (normalFont == null || !normalFont.equals(font)) {
776 normalFont = font;
777 dispose();
778 }
779 if (boldFont == null) {
780 boldFont = FormFonts.getInstance().getBoldFont(getColors().getDisplay(),
781 normalFont);
782 }
783 }
784
785 public void dispose() {
786 if (boldFont != null) {
787 FormFonts.getInstance().markFinished(boldFont, getColors().getDisplay());
788 boldFont = null;
789 }
790 }
791 }
792
793 public ToggleableTextElement createToggleableTextField(ICdmFormElement parentElement,
794 String labelString, String initialText, boolean initialState, int style) {
795 ToggleableTextElement element = new ToggleableTextElement(this, parentElement,
796 labelString, initialText, initialState, style | orientation);
797 adapt(element);
798 parentElement.addElement(element);
799 return element;
800 }
801
802 public TimePeriodElement createTimePeriodElement(
803 ICdmFormElement parentElement, String labelString, TimePeriod timePeriod, int style) {
804 TimePeriodElement element = new TimePeriodElement(this, parentElement, labelString, timePeriod, style);
805 adapt(element);
806 parentElement.addElement(element);
807 return element;
808 }
809
810 public DateDetailSection createDateDetailSection(ICdmFormElement parentElement, int style){
811 DateDetailSection section = new DateDetailSection(this, parentElement, style);
812 parentElement.addElement(section);
813 adapt(section);
814 return section;
815 }
816
817 public PartialElement createPartialElement(ICdmFormElement parentElement, String labelString, Partial partial, int style){
818 PartialElement element = new PartialElement(this, parentElement, labelString, style);
819 adapt(element);
820 parentElement.addElement(element);
821 return element;
822 }
823
824 public void addSelectionListener(SelectionListener listener){
825 selectionListenerList.add(listener);
826 }
827
828 public void removeSelectionListener(SelectionListener listener){
829 if(listener == null){
830 logger.error("Tried to remove a selection listener from this factories listeners but was null");
831 }else{
832 selectionListenerList.remove(listener);
833 }
834 }
835
836 public void addPropertyChangeListener(IPropertyChangeListener listener) {
837 propertyChangeListeners.add(listener);
838 }
839
840 public void removePropertyChangeListener(IPropertyChangeListener listener){
841 propertyChangeListeners.remove(listener);
842 }
843
844
845
846 public Label createHorizontalSeparator(ICdmFormElement parentElement, int style) {
847 Label separator = this.createSeparator(parentElement.getLayoutComposite(), SWT.HORIZONTAL | style);
848 separator.setLayoutData(FILL_HORIZONTALLY());
849 return separator;
850 }
851
852 public VersionElement createVersionElement(ICdmFormElement parentElement, VersionableEntity entity,
853 int style) {
854 VersionElement element = new VersionElement(this, parentElement, entity, style);
855 adapt(element);
856 parentElement.addElement(element);
857 return element;
858 }
859
860 public VersionSection createVersionSection(ICdmFormElement parentElement, int style) {
861 VersionSection section = new VersionSection(this, parentElement, style);
862 parentElement.addElement(section);
863 adapt(section);
864 return section;
865 }
866
867 public EmptyElement createEmptyElement(ICdmFormElement parentElement) {
868 EmptyElement element = new EmptyElement(this, parentElement, null, SWT.NULL);
869 adapt(element);
870 parentElement.addElement(element);
871 return element;
872 }
873
874 public HeadlineSection createHeadlineSection(ICdmFormElement parentElement) {
875 HeadlineSection section = new HeadlineSection(this, parentElement, SWT.NULL);
876 parentElement.addElement(section);
877 adapt(section);
878 return section;
879 }
880
881
882 public ParsingMessageElement createParsingMessageElement(
883 ICdmFormElement parentElement, ParserProblem parserProblem, int style) {
884 ParsingMessageElement element = new ParsingMessageElement(this, parentElement, parserProblem, style);
885 adapt(element);
886 parentElement.addElement(element);
887 return element;
888 }
889
890
891 // SIMPLIFY
892
893 /**
894 *
895 */
896 public static enum DetailType{
897 NONVIRALNAME,
898 SCIENTIFICNAME,
899 REFERENCEBASE,
900 NOMENCLATURALREFERENCE,
901 TAXONBASE,
902 AUTHORSHIP,
903 TEAM,
904 PERSON,
905 DESCRIPTION,
906 DESCRIPTIONELEMENT,
907 PARSINGMESSAGE,
908 NAMERELATIONSHIP,
909 TEAMORPERSONBASE,
910 MEDIA,
911 FIELD_OBSERVATION,
912 DERIVED_UNIT_FACADE,
913 GATHERING_EVENT,
914 DERIVED_UNIT, NATURAL_LANGUAGE
915 }
916
917 /**
918 *
919 * @param detailType
920 * @param parentElement
921 * @param selectionProvider
922 * @param style
923 * @return
924 */
925 public AbstractFormSection createCdmDetailSection(DetailType detailType, ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
926 AbstractFormSection section = null;
927
928 switch(detailType){
929 case SCIENTIFICNAME:
930 section = new NameDetailSection(this, conversation, parentElement, selectionProvider, style);
931 break;
932 case REFERENCEBASE:
933 section = new ReferenceBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
934 break;
935 case NOMENCLATURALREFERENCE:
936 section = new NomenclaturalReferenceDetailSection(this, conversation, parentElement, selectionProvider, style);
937 break;
938 case TAXONBASE:
939 section = new TaxonBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
940 break;
941 case AUTHORSHIP:
942 section = new AuthorshipDetailSection(this, conversation, parentElement, selectionProvider, style);
943 break;
944 case TEAMORPERSONBASE:
945 section = new TeamOrPersonBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
946 break;
947 case TEAM:
948 section = new TeamDetailSection(this, conversation, parentElement, null, style);
949 break;
950 case PERSON:
951 section = new PersonDetailSection(this, conversation, parentElement, null, style);
952 break;
953 case DESCRIPTION:
954 section = new DescriptionDetailSection(this, conversation, parentElement, selectionProvider, style);
955 break;
956 case DESCRIPTIONELEMENT:
957 section = new DescriptionElementDetailSection(this, conversation, parentElement, selectionProvider, style);
958 break;
959 case PARSINGMESSAGE:
960 section = new ParsingMessagesSection(this, conversation, parentElement, selectionProvider, style);
961 break;
962 case NONVIRALNAME:
963 section = new NonViralNameDetailSection(this, conversation, parentElement, selectionProvider, style);
964 break;
965 case MEDIA:
966 section = new eu.etaxonomy.taxeditor.section.description.MediaDetailsSection(this, conversation, parentElement, selectionProvider, style);
967 break;
968 case DERIVED_UNIT_FACADE:
969 section = new DerivedUnitFacadeDetailSection(this, conversation, parentElement, selectionProvider, style);
970 break;
971 case FIELD_OBSERVATION:
972 section = new FieldObservationDetailSection(this, conversation, parentElement, selectionProvider, style);
973 break;
974 case GATHERING_EVENT:
975 section = new GatheringEventDetailSection(this, conversation, parentElement, selectionProvider, style);
976 break;
977 case DERIVED_UNIT:
978 section = new DerivedUnitBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
979 break;
980 case NATURAL_LANGUAGE:
981 section = new NaturalLanguageSection(this, conversation, parentElement, selectionProvider, style);
982 break;
983 }
984 parentElement.addElement(section);
985 adapt(section);
986 return section;
987 }
988
989 /**
990 *
991 * @param detailType
992 * @param parent
993 * @param style
994 * @return
995 */
996 public AbstractCdmDetailElement createCdmDetailElement(DetailType detailType, ICdmFormElement parentElement, int style){
997 AbstractCdmDetailElement element = null;
998
999 switch(detailType){
1000 case SCIENTIFICNAME:
1001 element = new NameDetailElement(this, parentElement, style);
1002 break;
1003 case REFERENCEBASE:
1004 element = new ReferenceBaseDetailElement(this, parentElement, style);
1005 break;
1006 case NOMENCLATURALREFERENCE:
1007 element = new NomenclaturalReferenceDetailElement(this, parentElement, style);
1008 break;
1009 case TAXONBASE:
1010 element = new TaxonBaseDetailElement(this, parentElement, style);
1011 break;
1012 case AUTHORSHIP:
1013 element = new AuthorshipDetailElement(this, parentElement, style);
1014 break;
1015 case TEAM:
1016 element = new TeamDetailElement(this, parentElement, style);
1017 break;
1018 case PERSON:
1019 element = new PersonDetailElement(this, parentElement, style);
1020 break;
1021 case DESCRIPTION:
1022 element = new DescriptionDetailElement(this, parentElement, style);
1023 break;
1024 case DESCRIPTIONELEMENT:
1025 element = new DescriptionElementDetailElement(this, parentElement, style);
1026 break;
1027 case NONVIRALNAME:
1028 element = new NonViralNameDetailElement(this, parentElement);
1029 break;
1030 case DERIVED_UNIT_FACADE:
1031 element = new DerivedUnitFacadeDetailElement(this, parentElement);
1032 break;
1033 case FIELD_OBSERVATION:
1034 element = new FieldObservationDetailElement(this, parentElement);
1035 break;
1036 case GATHERING_EVENT:
1037 element = new GatheringEventDetailElement(this, parentElement);
1038 break;
1039 case DERIVED_UNIT:
1040 element = new DerivedUnitBaseDetailElement(this, parentElement);
1041 break;
1042 case NATURAL_LANGUAGE:
1043 element = new NaturalLanguageDetailElement(this, parentElement);
1044 break;
1045 }
1046
1047 adapt(element);
1048 parentElement.addElement(element);
1049 return element;
1050 }
1051
1052 /**
1053 *
1054 * @author n.hoffmann
1055 * @created Mar 5, 2010
1056 * @version 1.0
1057 */
1058 public static enum EntityDetailType{
1059 TEAM,
1060 TEAMMEMBER,
1061 ANNOTATION,
1062 CREDIT,
1063 DESCRIPTIONELEMENTSOURCE,
1064 EXTENSION,
1065 MARKER,
1066 MEDIA,
1067 DESCRIPTIONELEMENTMEDIA,
1068 MEDIAREPRESENTATION,
1069 MEDIAREPRESENTATIONPART,
1070 MODIFIER,
1071 NOMENCLATURALSTATUS,
1072 NAME_RELATIONSHIP,
1073 PROTOLOG,
1074 RIGHTS,
1075 SOURCE,
1076 SCOPE,
1077 DESCRIPTIONSOURCE,
1078 TYPEDESIGNATION,
1079 STATE_DATA,
1080 STATISTICAL_MEASUREMENT_VALUE,
1081 DESCRIBED_SPECIMEN,
1082 }
1083
1084 /**
1085 *
1086 * @param entityDetailType
1087 * @param parent
1088 * @param style
1089 * @return
1090 */
1091 public AbstractFormSection createEntityDetailSection(EntityDetailType entityDetailType, ConversationHolder conversation, ICdmFormElement parentElement, int style){
1092 AbstractFormSection section = null;
1093
1094 switch(entityDetailType){
1095 case TEAM:
1096 section = new TeamDetailSection(this, conversation, parentElement, null, style);
1097 break;
1098 case TEAMMEMBER:
1099 section = new TeamMemberSection(this, conversation, parentElement, style);
1100 break;
1101 case ANNOTATION:
1102 section = new AnnotationSection(this, conversation, parentElement, style);
1103 break;
1104 case CREDIT:
1105 section = new CreditSection(this, conversation, parentElement, style);
1106 break;
1107 case DESCRIPTIONELEMENTSOURCE:
1108 section = new DescriptionElementSourceSection(this, conversation, parentElement, style);
1109 break;
1110 case EXTENSION:
1111 section = new ExtensionSection(this, conversation, parentElement, style);
1112 break;
1113 case MARKER:
1114 section = new MarkerSection(this, conversation, parentElement, style);
1115 break;
1116 case MEDIA:
1117 section = new MediaSection(this, conversation, parentElement, style);
1118 break;
1119 case DESCRIPTIONELEMENTMEDIA:
1120 section = new DescriptionElementMediaSection(this, conversation, parentElement, style);
1121 break;
1122 case MEDIAREPRESENTATION:
1123 section = new MediaRepresentationSection(this, conversation, parentElement, style);
1124 break;
1125 case MEDIAREPRESENTATIONPART:
1126 section = new MediaRepresentationPartSection(this, conversation, parentElement, style);
1127 break;
1128 case MODIFIER:
1129 section = new ModifierSection(this, conversation, parentElement, style);
1130 break;
1131 case NOMENCLATURALSTATUS:
1132 section = new NomenclaturalStatusSection(this, conversation, parentElement, style);
1133 break;
1134 case NAME_RELATIONSHIP:
1135 section = new NameRelationshipDetailSection(this, conversation, parentElement, style);
1136 break;
1137 case PROTOLOG:
1138 section = new ProtologueSection(this, conversation, parentElement, style);
1139 break;
1140 case RIGHTS:
1141 section = new RightsSection(this, conversation, parentElement, style);
1142 break;
1143 case SOURCE:
1144 section = new SourceSection(this, conversation, parentElement, style);
1145 break;
1146 case SCOPE:
1147 section = new ScopeSection(this, conversation, parentElement, style);
1148 break;
1149 case DESCRIPTIONSOURCE:
1150 section = new DescriptionSourceSection(this, conversation, parentElement, style);
1151 break;
1152 case TYPEDESIGNATION:
1153 section = new TypeDesignationSection(this, conversation, parentElement, style);
1154 break;
1155 case STATE_DATA:
1156 section = new StateDataSection(this, conversation, parentElement, style);
1157 break;
1158 case STATISTICAL_MEASUREMENT_VALUE:
1159 section = new StatisticalMeasurementValueSection(this, conversation, parentElement, style);
1160 break;
1161 case DESCRIBED_SPECIMEN:
1162 section = new DescribedSpecimenSection(this, conversation, parentElement, style);
1163 break;
1164 }
1165 parentElement.addElement(section);
1166 adapt(section);
1167 return section;
1168 }
1169
1170 /**
1171 *
1172 * @param parent
1173 * @param entity
1174 * @param removeListener
1175 * @param style
1176 * @return
1177 */
1178 public AbstractEntityCollectionElement createEntityCollectionElement(AbstractFormSection parentElement, IVersionableEntity versionableEntity, SelectionListener removeListener, Color backgroundColor, int style){
1179 AbstractEntityCollectionElement element = null;
1180
1181 VersionableEntity entity = (VersionableEntity) HibernateProxyHelper.deproxy(versionableEntity);
1182
1183 if(entity instanceof Annotation){
1184 element = new AnnotationElement(this, parentElement, (Annotation) entity, removeListener, style);
1185 }
1186 else if(entity instanceof Person){
1187 element = new TeamMemberElement(this, parentElement, (Person) entity, removeListener, style);
1188 }
1189 else if(entity instanceof Credit){
1190 element = new CreditElement(this, parentElement, (Credit) entity, removeListener, style);
1191 }
1192 else if(entity instanceof Extension){
1193 element = new ExtensionElement(this, parentElement, (Extension) entity, removeListener, style);
1194 }
1195 else if(entity instanceof Marker){
1196 element = new MarkerElement(this, parentElement, (Marker) entity, removeListener, style);
1197 }
1198 else if(entity instanceof Media){
1199 element = new MediaElement(this, parentElement, (Media) entity, removeListener, style);
1200 }
1201 else if(entity instanceof MediaRepresentation){
1202 element = new MediaRepresentationElement(this, parentElement, (MediaRepresentation) entity, removeListener, style);
1203 }
1204 else if(entity instanceof ImageFile){
1205 element = new ImageFileElement(this, parentElement, (ImageFile) entity, removeListener, style);
1206 }
1207 else if(entity instanceof NomenclaturalStatus){
1208 element = new NomenclaturalStatusElement(this, parentElement, (NomenclaturalStatus) entity, removeListener, style);
1209 }
1210 else if(entity instanceof Rights){
1211 element = new RightsElement(this, parentElement, (Rights) entity, removeListener, style);
1212 }
1213 else if(entity instanceof DescriptionElementSource){
1214 element = new DescriptionElementSourceElement(this, parentElement, (DescriptionElementSource) entity, removeListener, style);
1215 }
1216 else if(entity instanceof IdentifiableSource){
1217 element = new IdentifiableSourceElement(this, parentElement, (IdentifiableSource) entity, removeListener, style);
1218 }
1219 else if(entity instanceof Scope){
1220 element = new ScopeElement(this, parentElement, (Scope) entity, removeListener, style);
1221 }
1222 else if(entity instanceof Modifier){
1223 element = new ModifierElement(this, parentElement, (Modifier) entity, removeListener, style);
1224 }
1225 else if(entity instanceof ReferenceBase){
1226 element = new DescriptionSourceElement(this, parentElement, (ReferenceBase) entity, removeListener, style);
1227 }
1228 else if(entity instanceof NameTypeDesignation){
1229 element = new NameTypeDesignationElement(this, parentElement, (NameTypeDesignation) entity, removeListener, style);
1230 }
1231 else if(entity instanceof NameRelationship){
1232 element = new NameRelationshipDetailElement(this, parentElement, (NameRelationship) entity, removeListener, style);
1233 }
1234 else if(entity instanceof SpecimenTypeDesignation){
1235 element = new SpecimenTypeDesignationElement(this, parentElement, (SpecimenTypeDesignation) entity, removeListener, style);
1236 }
1237 else if(entity instanceof StateData){
1238 element = new StateDataElement(this, parentElement, (StateData) entity, removeListener, style);
1239 }
1240 else if(entity instanceof StatisticalMeasurementValue){
1241 element = new StatisticalMeasurementValueElement(this, parentElement, (StatisticalMeasurementValue) entity, removeListener, style);
1242 }
1243 else if(entity instanceof DerivedUnit){
1244 element = new DerivedUnitElement(this, parentElement, (DerivedUnit) entity, removeListener, style);
1245 }
1246
1247 else if(entity instanceof DescriptionElementBase){
1248 // this is the special case for protologs, maybe we can do this differently when API improves
1249 DescriptionElementBase descriptionElement = (DescriptionElementBase) entity;
1250 if(descriptionElement.getFeature().equals(Feature.PROTOLOGUE())){
1251 element = new ProtologueElement(this, parentElement, descriptionElement, removeListener, style);
1252 }
1253 }
1254
1255 Assert.isNotNull(element, "Could not generate composite for entity. Looks like the case is not handled already. Check implementation. Entity: " + entity);
1256
1257 if(backgroundColor != null && !backgroundColor.isDisposed()){
1258 element.setBackgroundColor(backgroundColor);
1259 }
1260
1261 adapt(element);
1262 parentElement.addElement(element);
1263 return element;
1264 }
1265
1266 /**
1267 *
1268 * @param selectionType
1269 * @param parentElement
1270 * @param labelString
1271 * @param selection
1272 * @param style
1273 * @return
1274 */
1275 public AbstractSelectionElement createSelectionElement(SelectionType selectionType, ConversationHolder conversation, ICdmFormElement parentElement, String labelString, IdentifiableEntity selection, int style){
1276 AbstractSelectionElement element = null;
1277
1278 IdentifiableEntity entity = (IdentifiableEntity) HibernateProxyHelper.deproxy(selection);
1279
1280 switch (selectionType) {
1281 case AGENT:
1282 element = new AgentSelectionElement(this, conversation, parentElement, labelString, (TeamOrPersonBase) entity, style);
1283 break;
1284 case PERSON:
1285 element = new PersonSelectionElement(this, conversation, parentElement, labelString, (Person) entity, style);
1286 break;
1287 case TEAM:
1288 element = new TeamSelectionElement(this, conversation, parentElement, labelString, (Team) entity, style);
1289 break;
1290 case AUTHOR_TEAM:
1291 element = new NomenclaturalAuthorTeamSelectionElement(this, conversation, parentElement, labelString, (Team) entity, style);
1292 break;
1293 case INSTITUTION:
1294 element = new InstitutionSelectionElement(this, conversation, parentElement, labelString, (Institution) entity, style);
1295 break;
1296 case NAME:
1297 element = new NameSelectionElement(this, conversation, parentElement, labelString, (TaxonNameBase) entity, style);
1298 break;
1299 case REFERENCE:
1300 element = new ReferenceSelectionElement(this, conversation, parentElement, labelString, (ReferenceBase) entity, style);
1301 break;
1302 case TAXON:
1303 element = new TaxonSelectionElement(this, conversation, parentElement, labelString, (TaxonBase) entity, style);
1304 break;
1305 case DERIVED_UNIT:
1306 element = new DerivedUnitBaseSelectionElement(this, conversation, parentElement, labelString, (DerivedUnitBase) entity, style);
1307 break;
1308 case FIELD_OBSERVATION:
1309 element = new FieldObservationSelectionElement(this, conversation, parentElement, labelString, (FieldObservation) entity, style);
1310 break;
1311 case FEATURE_TREE:
1312 element = new FeatureTreeSelectionElement(this, conversation, parentElement, labelString, (FeatureTree) entity, style);
1313 break;
1314 default:
1315 new RuntimeException("There is no selection composite for the desired selection type.");
1316 break;
1317 }
1318
1319 adapt(element);
1320 parentElement.addElement(element);
1321 return element;
1322 }
1323
1324 public NamedAreaSelectionElement createNamedAreaSelectionElement(ICdmFormElement parentElement, ConversationHolder conversation, String labelString, NamedArea selection, int style){
1325 NamedAreaSelectionElement element = new NamedAreaSelectionElement(this, conversation, parentElement, labelString, selection, style);
1326 adapt(element);
1327 parentElement.addElement(element);
1328 return element;
1329 }
1330
1331 public LabelElement createLabel(ICdmFormElement parentElement, String text) {
1332 LabelElement labelElement = new LabelElement(this, parentElement, text);
1333 adapt(labelElement);
1334 parentElement.addElement(labelElement);
1335 return labelElement;
1336 }
1337
1338 public ISelectionProvider getSelectionProvider() {
1339 return selectionProvider;
1340 }
1341
1342 public AbstractDetailedDescriptionDetailElement createDetailedDescriptionDetailElement(
1343 ICdmFormElement parentElement, DescriptionElementBase entity, int style) {
1344 AbstractDetailedDescriptionDetailElement detailedDescriptionElement = null;
1345
1346
1347 if(entity instanceof CategoricalData){
1348 detailedDescriptionElement = new CategoricalDataDetailElement(this, parentElement, (CategoricalData) entity, style);
1349 }
1350 else if(entity instanceof CommonTaxonName){
1351 detailedDescriptionElement = new CommonNameDetailElement(this, parentElement, (CommonTaxonName) entity, style);
1352 }
1353 else if(entity instanceof Distribution){
1354 detailedDescriptionElement = new DistributionDetailElement(this, parentElement, (Distribution) entity, style);
1355 }
1356 else if(entity instanceof IndividualsAssociation){
1357 detailedDescriptionElement = new IndividualsAssociationDetailElement(this, parentElement, (IndividualsAssociation) entity, style);
1358 }
1359 else if(entity instanceof QuantitativeData){
1360 detailedDescriptionElement = new QuantitativeDataDetailElement(this, parentElement, (QuantitativeData) entity, style);
1361 }
1362 else if(entity instanceof TaxonInteraction){
1363 detailedDescriptionElement = new TaxonInteractionDetailElement(this, parentElement, (TaxonInteraction) entity, style);
1364 }
1365 else if(entity instanceof TextData){
1366 detailedDescriptionElement = new TextDataDetailElement(this, parentElement, (TextData) entity, style);
1367 }
1368 else{
1369 throw new IllegalStateException("There is no interface for the given description element");
1370 }
1371 adapt(detailedDescriptionElement);
1372 parentElement.addElement(detailedDescriptionElement);
1373 return detailedDescriptionElement;
1374
1375 }
1376 }