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
.TaxonBaseDetailSection
;
46 import eu
.etaxonomy
.taxeditor
.ui
.section
.taxon
.TaxonDetailElement
;
47 import eu
.etaxonomy
.taxeditor
.ui
.section
.taxon
.TaxonDetailSection
;
48 import eu
.etaxonomy
.taxeditor
.ui
.section
.taxon
.TaxonRelationshipDetailSection
;
52 * CdmSectionPart class.
56 * @created Feb 8, 2010
59 public class CdmSectionPart
<T
> extends SectionPart
implements
60 IPropertyChangeListener
{
62 private final AbstractFormSection
<T
> formSection
;
66 * Constructor for CdmSectionPart.
70 * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
75 public CdmSectionPart(AbstractFormSection
<T
> section
) {
77 formSection
= section
;
82 public boolean setFormInput(Object input
) {
83 //FIXME (CM): Need to fix this part of the design.
84 //The design seems to be locked to the idea that only one
85 // entity (either from the navigator or the editor) drives
86 // the detail view. In the case of multiple inputs the only workaround
87 // is checking the type and extracting relevant objects.
88 if (input
instanceof IElementHasDetails
) {
89 input
= ((IElementHasDetails
) input
).getData();
91 if ((input
instanceof TaxonBase
)
92 && (formSection
instanceof ITaxonBaseDetailSection
)) {
93 ((ITaxonBaseDetailSection
) formSection
)
94 .setTaxonBase((TaxonBase
) input
);
97 else if (input
.getClass().equals(DerivedUnit
.class)
98 && (formSection
instanceof IDerivedUnitFacadeDetailSection
)) {
101 input
= DerivedUnitFacade
.NewInstance((DerivedUnit
) input
,
102 PreferencesUtil
.getDerivedUnitConfigurator());
103 } catch (DerivedUnitFacadeNotSupportedException e
) {
104 MessagingUtils
.error(getClass(), e
);
107 else if (input
instanceof PolytomousKeyRelationship
) {
108 input
= ((PolytomousKeyRelationship
) input
).getDestination();
111 else if ((input
instanceof PolytomousKeyNode
) &&
112 (formSection
instanceof PolytomousKeyDetailSection
||
113 formSection
instanceof GeoScopeDetailSection
||
114 formSection
instanceof ScopeRestrictionSection
||
115 formSection
instanceof TaxonomicScopeSection
)) {
116 input
= ((PolytomousKeyNode
)input
).getKey();
117 } else if ((input
instanceof TaxonRelationship
)
118 && (formSection
instanceof TaxonDetailSection
)) {
119 ((TaxonDetailSection
) formSection
)
120 .setTaxon( ((TaxonRelationship
)input
).getFromTaxon());
122 }else if ((input
instanceof TaxonRelationship
)
123 && (formSection
instanceof NonViralNameDetailSection
)) {
124 ((NonViralNameDetailSection
) formSection
)
125 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
127 }else if ((input
instanceof TaxonRelationship
)
128 && (formSection
instanceof NomenclaturalReferenceDetailSection
)) {
129 ((NomenclaturalReferenceDetailSection
) formSection
)
130 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
132 }else if ((input
instanceof TaxonRelationship
)
133 && (formSection
instanceof NomenclaturalStatusSection
)) {
134 ((NomenclaturalStatusSection
) formSection
)
135 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
137 }else if ((input
instanceof TaxonRelationship
)
138 && (formSection
instanceof ProtologueSection
)) {
139 ((ProtologueSection
) formSection
)
140 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
142 }else if ((input
instanceof TaxonRelationship
)
143 && (formSection
instanceof TypeDesignationSection
)) {
144 ((TypeDesignationSection
) formSection
)
145 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
147 }else if ((input
instanceof TaxonRelationship
)
148 && (formSection
instanceof NameRelationshipDetailSection
)) {
149 ((NameRelationshipDetailSection
) formSection
)
150 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
155 formSection
.setEntity((T
) input
);
164 * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
165 * .jface.util.PropertyChangeEvent)
169 public void propertyChange(PropertyChangeEvent event
) {
172 Object eventSource
= event
.getSource();
173 if (eventSource
instanceof EventObject
){
174 eventSource
= ((EventObject
)eventSource
).getSource();
176 Control
[] children
= formSection
.getLayoutComposite().getChildren();
177 boolean containsElement
= false;
178 for (Control control
: children
) {
179 if(eventSource
.equals(control
)){
180 containsElement
= true;
188 else if (formSection
.equals(eventSource
)){
191 else if(((eventSource
instanceof ICdmFormElement
)&& formSection
.containsFormElement((ICdmFormElement
) eventSource
))) {