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.
9 package eu
.etaxonomy
.taxeditor
.view
.detail
;
11 import java
.util
.EventObject
;
13 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
14 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
15 import org
.eclipse
.swt
.widgets
.Control
;
16 import org
.eclipse
.ui
.forms
.SectionPart
;
18 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
19 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacadeNotSupportedException
;
20 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
21 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
24 import eu
.etaxonomy
.taxeditor
.model
.IElementHasDetails
;
25 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
26 import eu
.etaxonomy
.taxeditor
.model
.PolytomousKeyRelationship
;
27 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
28 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.section
.ITaxonBaseDetailSection
;
32 import eu
.etaxonomy
.taxeditor
.ui
.section
.key
.PolytomousKeyDetailSection
;
33 import eu
.etaxonomy
.taxeditor
.ui
.section
.key
.ScopeRestrictionSection
;
34 import eu
.etaxonomy
.taxeditor
.ui
.section
.key
.TaxonomicScopeSection
;
35 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.NameRelationshipDetailSection
;
36 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.NomenclaturalStatusSection
;
37 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.NonViralNameDetailSection
;
38 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.TypeDesignationSection
;
39 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.GeoScopeDetailSection
;
40 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.IDerivedUnitFacadeDetailSection
;
41 import eu
.etaxonomy
.taxeditor
.ui
.section
.reference
.NomenclaturalReferenceDetailSection
;
42 import eu
.etaxonomy
.taxeditor
.ui
.section
.supplemental
.RightsSection
;
43 import eu
.etaxonomy
.taxeditor
.ui
.section
.taxon
.TaxonDetailSection
;
47 * CdmSectionPart class.
51 * @created Feb 8, 2010
53 public class CdmSectionPart
<T
> extends SectionPart
implements
54 IPropertyChangeListener
{
56 public static String EXPANDED
= "expanded";
57 public static String COLLAPSED
= "collapsed";
59 private final AbstractFormSection
<T
> formSection
;
64 private Object rootInput
;
68 * Constructor for CdmSectionPart.
72 * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
77 public CdmSectionPart(AbstractFormSection
<T
> section
) {
79 formSection
= section
;
83 public boolean setFormInput(Object input
) {
84 this.rootInput
= input
;
85 //FIXME (CM): Need to fix this part of the design.
86 //The design seems to be locked to the idea that only one
87 // entity (either from the navigator or the editor) drives
88 // the detail view. In the case of multiple inputs the only workaround
89 // is checking the type and extracting relevant objects.
90 if (input
instanceof IElementHasDetails
) {
91 input
= ((IElementHasDetails
) input
).getData();
93 if ((input
instanceof TaxonBase
)
94 && (formSection
instanceof ITaxonBaseDetailSection
)) {
95 ((ITaxonBaseDetailSection
) formSection
)
96 .setTaxonBase((TaxonBase
<?
>) input
);
99 else if (input
.getClass().equals(DerivedUnit
.class)
100 && (formSection
instanceof IDerivedUnitFacadeDetailSection
)) {
103 input
= DerivedUnitFacade
.NewInstance((DerivedUnit
) input
,
104 PreferencesUtil
.getDerivedUnitConfigurator());
105 } catch (DerivedUnitFacadeNotSupportedException e
) {
106 MessagingUtils
.error(getClass(), e
);
109 else if (input
instanceof PolytomousKeyRelationship
) {
110 input
= ((PolytomousKeyRelationship
) input
).getDestination();
111 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();
120 else if ((input
instanceof PolytomousKeyNode
) &&
121 (formSection
instanceof PolytomousKeyDetailSection
||
122 formSection
instanceof GeoScopeDetailSection
||
123 formSection
instanceof ScopeRestrictionSection
||
124 formSection
instanceof TaxonomicScopeSection
)) {
125 input
= ((PolytomousKeyNode
)input
).getKey();
126 } else if ((input
instanceof TaxonRelationship
)
127 && (formSection
instanceof TaxonDetailSection
)) {
128 ((TaxonDetailSection
) formSection
)
129 .setTaxon( ((TaxonRelationship
)input
).getFromTaxon());
131 }else if ((input
instanceof TaxonRelationship
)
132 && (formSection
instanceof NonViralNameDetailSection
)) {
133 ((NonViralNameDetailSection
) formSection
)
134 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
136 }else if ((input
instanceof TaxonRelationship
)
137 && (formSection
instanceof NomenclaturalReferenceDetailSection
)) {
138 ((NomenclaturalReferenceDetailSection
) formSection
)
139 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
141 }else if ((input
instanceof TaxonRelationship
)
142 && (formSection
instanceof NomenclaturalStatusSection
)) {
143 ((NomenclaturalStatusSection
) formSection
)
144 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
146 // }else if ((input instanceof TaxonRelationship)
147 // && (formSection instanceof ProtologueSection)) {
148 // ((ProtologueSection) formSection)
149 // .setTaxonBase( ((TaxonRelationship)input).getFromTaxon());
151 }else if ((input
instanceof TaxonRelationship
)
152 && (formSection
instanceof TypeDesignationSection
)) {
153 ((TypeDesignationSection
) formSection
)
154 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
155 // .setEntity( ((TaxonRelationship)input).getFromTaxon().getName());
157 }else if ((input
instanceof TaxonRelationship
)
158 && (formSection
instanceof NameRelationshipDetailSection
)) {
159 ((NameRelationshipDetailSection
) formSection
)
160 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
162 }else if ((input
instanceof DerivedUnitFacade
)
163 && (formSection
instanceof RightsSection
)){
164 ((RightsSection
)formSection
).setEntity(((DerivedUnitFacade
)input
).innerDerivedUnit());
167 //check whether this is needed
168 // }else if ((input instanceof TaxonBase)
169 // && (formSection instanceof TypeDesignationSection)){
170 // ((TypeDesignationSection)formSection).setEntity(((TaxonBase)input).getName());
174 formSection
.setEntity((T
) input
);
180 public void propertyChange(PropertyChangeEvent event
) {
183 Object eventSource
= event
.getSource();
184 if (eventSource
instanceof EventObject
){
185 eventSource
= ((EventObject
)eventSource
).getSource();
187 Control
[] children
= formSection
.getLayoutComposite().getChildren();
188 boolean containsElement
= false;
189 for (Control control
: children
) {
190 if(eventSource
.equals(control
)){
191 containsElement
= true;
199 else if (formSection
.equals(eventSource
)){
202 else if(((eventSource
instanceof ICdmFormElement
)&& formSection
.containsFormElement((ICdmFormElement
) eventSource
))) {
209 protected void expansionStateChanged(boolean expanded
) {
210 super.expansionStateChanged(expanded
);
211 PreferencesUtil
.setStringValue(StoreUtil
.getPrefKey(formSection
.getClass(), rootInput
.getClass().getCanonicalName()), expanded?EXPANDED
:COLLAPSED
);