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
.util
.EventObject
;
14 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
15 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
16 import org
.eclipse
.swt
.widgets
.Control
;
17 import org
.eclipse
.ui
.forms
.SectionPart
;
19 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
20 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacadeNotSupportedException
;
21 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
22 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
25 import eu
.etaxonomy
.taxeditor
.model
.IElementHasDetails
;
26 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
27 import eu
.etaxonomy
.taxeditor
.model
.PolytomousKeyRelationship
;
28 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
29 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
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
.NameRelationshipDetailSection
;
37 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.NomenclaturalStatusSection
;
38 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.NonViralNameDetailSection
;
39 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.ProtologueSection
;
40 import eu
.etaxonomy
.taxeditor
.ui
.section
.name
.TypeDesignationSection
;
41 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.GeoScopeDetailSection
;
42 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.IDerivedUnitFacadeDetailSection
;
43 import eu
.etaxonomy
.taxeditor
.ui
.section
.reference
.NomenclaturalReferenceDetailSection
;
44 import eu
.etaxonomy
.taxeditor
.ui
.section
.taxon
.TaxonDetailSection
;
48 * CdmSectionPart class.
52 * @created Feb 8, 2010
55 public class CdmSectionPart
<T
> extends SectionPart
implements
56 IPropertyChangeListener
{
58 public static String EXPANDED
= "expanded";
59 public static String COLLAPSED
= "collapsed";
61 private final AbstractFormSection
<T
> formSection
;
66 private Object rootInput
;
70 * Constructor for CdmSectionPart.
74 * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
79 public CdmSectionPart(AbstractFormSection
<T
> section
) {
81 formSection
= section
;
86 public boolean setFormInput(Object input
) {
87 this.rootInput
= input
;
88 //FIXME (CM): Need to fix this part of the design.
89 //The design seems to be locked to the idea that only one
90 // entity (either from the navigator or the editor) drives
91 // the detail view. In the case of multiple inputs the only workaround
92 // is checking the type and extracting relevant objects.
93 if (input
instanceof IElementHasDetails
) {
94 input
= ((IElementHasDetails
) input
).getData();
96 if ((input
instanceof TaxonBase
)
97 && (formSection
instanceof ITaxonBaseDetailSection
)) {
98 ((ITaxonBaseDetailSection
) formSection
)
99 .setTaxonBase((TaxonBase
) input
);
102 else if (input
.getClass().equals(DerivedUnit
.class)
103 && (formSection
instanceof IDerivedUnitFacadeDetailSection
)) {
106 input
= DerivedUnitFacade
.NewInstance((DerivedUnit
) input
,
107 PreferencesUtil
.getDerivedUnitConfigurator());
108 } catch (DerivedUnitFacadeNotSupportedException e
) {
109 MessagingUtils
.error(getClass(), e
);
112 else if (input
instanceof PolytomousKeyRelationship
) {
113 input
= ((PolytomousKeyRelationship
) input
).getDestination();
116 else if ((input
instanceof PolytomousKeyNode
) &&
117 (formSection
instanceof PolytomousKeyDetailSection
||
118 formSection
instanceof GeoScopeDetailSection
||
119 formSection
instanceof ScopeRestrictionSection
||
120 formSection
instanceof TaxonomicScopeSection
)) {
121 input
= ((PolytomousKeyNode
)input
).getKey();
122 } else if ((input
instanceof TaxonRelationship
)
123 && (formSection
instanceof TaxonDetailSection
)) {
124 ((TaxonDetailSection
) formSection
)
125 .setTaxon( ((TaxonRelationship
)input
).getFromTaxon());
127 }else if ((input
instanceof TaxonRelationship
)
128 && (formSection
instanceof NonViralNameDetailSection
)) {
129 ((NonViralNameDetailSection
) formSection
)
130 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
132 }else if ((input
instanceof TaxonRelationship
)
133 && (formSection
instanceof NomenclaturalReferenceDetailSection
)) {
134 ((NomenclaturalReferenceDetailSection
) formSection
)
135 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
137 }else if ((input
instanceof TaxonRelationship
)
138 && (formSection
instanceof NomenclaturalStatusSection
)) {
139 ((NomenclaturalStatusSection
) formSection
)
140 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
142 }else if ((input
instanceof TaxonRelationship
)
143 && (formSection
instanceof ProtologueSection
)) {
144 ((ProtologueSection
) formSection
)
145 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
147 }else if ((input
instanceof TaxonRelationship
)
148 && (formSection
instanceof TypeDesignationSection
)) {
149 ((TypeDesignationSection
) formSection
)
150 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
152 }else if ((input
instanceof TaxonRelationship
)
153 && (formSection
instanceof NameRelationshipDetailSection
)) {
154 ((NameRelationshipDetailSection
) formSection
)
155 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
160 formSection
.setEntity((T
) input
);
169 * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
170 * .jface.util.PropertyChangeEvent)
174 public void propertyChange(PropertyChangeEvent event
) {
177 Object eventSource
= event
.getSource();
178 if (eventSource
instanceof EventObject
){
179 eventSource
= ((EventObject
)eventSource
).getSource();
181 Control
[] children
= formSection
.getLayoutComposite().getChildren();
182 boolean containsElement
= false;
183 for (Control control
: children
) {
184 if(eventSource
.equals(control
)){
185 containsElement
= true;
193 else if (formSection
.equals(eventSource
)){
196 else if(((eventSource
instanceof ICdmFormElement
)&& formSection
.containsFormElement((ICdmFormElement
) eventSource
))) {
203 protected void expansionStateChanged(boolean expanded
) {
204 super.expansionStateChanged(expanded
);
205 PreferencesUtil
.setStringValue(StoreUtil
.getPrefKey(formSection
.getClass(), rootInput
), expanded?EXPANDED
:COLLAPSED
);