2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.view
.detail
;
12 import java
.awt
.Event
;
13 import java
.util
.EventObject
;
15 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
16 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
17 import org
.eclipse
.swt
.widgets
.Control
;
18 import org
.eclipse
.ui
.forms
.SectionPart
;
20 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
21 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacadeNotSupportedException
;
22 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
23 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
26 import eu
.etaxonomy
.taxeditor
.model
.IElementHasDetails
;
27 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
28 import eu
.etaxonomy
.taxeditor
.model
.PolytomousKeyRelationship
;
29 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.section
.ITaxonBaseDetailSection
;
33 import eu
.etaxonomy
.taxeditor
.ui
.section
.key
.PolytomousKeyDetailSection
;
34 import eu
.etaxonomy
.taxeditor
.ui
.section
.key
.ScopeRestrictionSection
;
35 import eu
.etaxonomy
.taxeditor
.ui
.section
.key
.TaxonomicScopeSection
;
36 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.NameDetailSection
;
37 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.NameRelationshipDetailSection
;
38 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.NomenclaturalStatusSection
;
39 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.NonViralNameDetailSection
;
40 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.ProtologueSection
;
41 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.TypeDesignationSection
;
42 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.GeoScopeDetailSection
;
43 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.IDerivedUnitFacadeDetailSection
;
44 import eu
.etaxonomy
.taxeditor
.ui
.section
.reference
.NomenclaturalReferenceDetailSection
;
45 import eu
.etaxonomy
.taxeditor
.ui
.section
.taxon
.TaxonRelationshipDetailSection
;
49 * CdmSectionPart class.
53 * @created Feb 8, 2010
56 public class CdmSectionPart
<T
> extends SectionPart
implements
57 IPropertyChangeListener
{
59 private final AbstractFormSection
<T
> formSection
;
63 * Constructor for CdmSectionPart.
67 * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
72 public CdmSectionPart(AbstractFormSection
<T
> section
) {
74 formSection
= section
;
79 public boolean setFormInput(Object input
) {
80 //FIXME (CM): Need to fix this part of the design.
81 //The design seems to be locked to the idea that only one
82 // entity (either from the navigator or the editor) drives
83 // the detail view. In the case of multiple inputs the only workaround
84 // is checking the type and extracting relevant objects.
85 if (input
instanceof IElementHasDetails
) {
86 input
= ((IElementHasDetails
) input
).getData();
88 if ((input
instanceof TaxonBase
)
89 && (formSection
instanceof ITaxonBaseDetailSection
)) {
90 ((ITaxonBaseDetailSection
) formSection
)
91 .setTaxonBase((TaxonBase
) input
);
94 else if (input
.getClass().equals(DerivedUnit
.class)
95 && (formSection
instanceof IDerivedUnitFacadeDetailSection
)) {
98 input
= DerivedUnitFacade
.NewInstance((DerivedUnit
) input
,
99 PreferencesUtil
.getDerivedUnitConfigurator());
100 } catch (DerivedUnitFacadeNotSupportedException e
) {
101 MessagingUtils
.error(getClass(), e
);
104 else if (input
instanceof PolytomousKeyRelationship
) {
105 input
= ((PolytomousKeyRelationship
) input
).getDestination();
108 else if ((input
instanceof PolytomousKeyNode
) &&
109 (formSection
instanceof PolytomousKeyDetailSection
||
110 formSection
instanceof GeoScopeDetailSection
||
111 formSection
instanceof ScopeRestrictionSection
||
112 formSection
instanceof TaxonomicScopeSection
)) {
113 input
= ((PolytomousKeyNode
)input
).getKey();
114 } else if ((input
instanceof TaxonRelationship
)
115 && (formSection
instanceof NonViralNameDetailSection
)) {
116 ((NonViralNameDetailSection
) formSection
)
117 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
119 }else if ((input
instanceof TaxonRelationship
)
120 && (formSection
instanceof NomenclaturalReferenceDetailSection
)) {
121 ((NomenclaturalReferenceDetailSection
) formSection
)
122 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
124 }else if ((input
instanceof TaxonRelationship
)
125 && (formSection
instanceof NomenclaturalStatusSection
)) {
126 ((NomenclaturalStatusSection
) formSection
)
127 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
129 }else if ((input
instanceof TaxonRelationship
)
130 && (formSection
instanceof ProtologueSection
)) {
131 ((ProtologueSection
) formSection
)
132 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
134 }else if ((input
instanceof TaxonRelationship
)
135 && (formSection
instanceof TypeDesignationSection
)) {
136 ((TypeDesignationSection
) formSection
)
137 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
139 }else if ((input
instanceof TaxonRelationship
)
140 && (formSection
instanceof NameRelationshipDetailSection
)) {
141 ((NameRelationshipDetailSection
) formSection
)
142 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
147 formSection
.setEntity((T
) input
);
156 * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
157 * .jface.util.PropertyChangeEvent)
161 public void propertyChange(PropertyChangeEvent event
) {
164 Object eventSource
= event
.getSource();
165 if (eventSource
instanceof EventObject
){
166 eventSource
= ((EventObject
)eventSource
).getSource();
168 Control
[] children
= formSection
.getLayoutComposite().getChildren();
169 boolean containsElement
= false;
170 for (Control control
: children
) {
171 if(eventSource
.equals(control
)){
172 containsElement
= true;
180 else if (formSection
.equals(eventSource
)){
183 else if(((eventSource
instanceof ICdmFormElement
)&& formSection
.containsFormElement((ICdmFormElement
) eventSource
))) {