Refactoring of selection elements. Additional minor refactoring. Fixed a bug with...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / detail / CdmSectionPart.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.view.detail;
12
13 import org.eclipse.jface.util.IPropertyChangeListener;
14 import org.eclipse.jface.util.PropertyChangeEvent;
15 import org.eclipse.ui.forms.SectionPart;
16
17 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
18 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
19 import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
20 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
21 import eu.etaxonomy.taxeditor.model.IElementHasDetails;
22 import eu.etaxonomy.taxeditor.model.PolytomousKeyRelationship;
23 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
24 import eu.etaxonomy.taxeditor.store.StoreUtil;
25 import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
26 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
27 import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
28 import eu.etaxonomy.taxeditor.ui.section.occurrence.IDerivedUnitFacadeDetailSection;
29
30 /**
31 * <p>
32 * CdmSectionPart class.
33 * </p>
34 *
35 * @author n.hoffmann
36 * @created Feb 8, 2010
37 * @version 1.0
38 */
39 public class CdmSectionPart<T> extends SectionPart implements
40 IPropertyChangeListener {
41
42 private final AbstractFormSection<T> formSection;
43
44 /**
45 * <p>
46 * Constructor for CdmSectionPart.
47 * </p>
48 *
49 * @param section
50 * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
51 * object.
52 * @param <T>
53 * a T object.
54 */
55 public CdmSectionPart(AbstractFormSection<T> section) {
56 super(section);
57 formSection = section;
58 }
59
60 /** {@inheritDoc} */
61 @Override
62 public boolean setFormInput(Object input) {
63 if (input instanceof IElementHasDetails) {
64 input = ((IElementHasDetails) input).getData();
65 }
66 if ((input instanceof TaxonBase)
67 && (formSection instanceof ITaxonBaseDetailSection)) {
68 ((ITaxonBaseDetailSection) formSection)
69 .setTaxonBase((TaxonBase) input);
70 return true;
71 }
72 if ((input instanceof DerivedUnitBase)
73 && (formSection instanceof IDerivedUnitFacadeDetailSection)) {
74
75 try {
76 input = DerivedUnitFacade.NewInstance((DerivedUnitBase) input,
77 PreferencesUtil.getDerivedUnitConfigurator());
78 } catch (DerivedUnitFacadeNotSupportedException e) {
79 StoreUtil.error(getClass(), e);
80 }
81 }
82 if (input instanceof PolytomousKeyRelationship) {
83 input = ((PolytomousKeyRelationship) input).getDestination();
84 }
85
86 formSection.setEntity((T) input);
87
88 return true;
89 }
90
91 /*
92 * (non-Javadoc)
93 *
94 * @see
95 * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
96 * .jface.util.PropertyChangeEvent)
97 */
98 /** {@inheritDoc} */
99 @Override
100 public void propertyChange(PropertyChangeEvent event) {
101 if (event != null) {
102
103 Object eventSource = event.getSource();
104
105 if (formSection.equals(eventSource)){
106 markDirty();
107 }
108 if((
109 (eventSource instanceof AbstractCdmFormElement)
110 && formSection.containsFormElement((AbstractCdmFormElement) eventSource))
111 ) {
112 markDirty();
113 }
114 }
115 }
116
117 }