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
.occurrence
.SpecimenOrObservationBase
;
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
.TypeDesignationSection
;
40 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.DeterminationDetailSection
;
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
.occurrence
.dna
.SampleDesignationDetailSection
;
44 import eu
.etaxonomy
.taxeditor
.ui
.section
.reference
.NomenclaturalSourceDetailSection
;
45 import eu
.etaxonomy
.taxeditor
.ui
.section
.supplemental
.RightsSection
;
46 import eu
.etaxonomy
.taxeditor
.ui
.section
.taxon
.TaxonDetailSection
;
50 * CdmSectionPart class.
54 * @created Feb 8, 2010
56 public class CdmSectionPart
<T
> extends SectionPart
57 implements IPropertyChangeListener
{
59 public static String EXPANDED
= "expanded";
60 public static String COLLAPSED
= "collapsed";
62 private final AbstractFormSection
<T
> formSection
;
67 private Object rootInput
;
69 public CdmSectionPart(AbstractFormSection
<T
> section
) {
71 formSection
= section
;
75 public boolean setFormInput(Object input
) {
76 if (formSection
.isDisposed()){
80 this.rootInput
= input
;
81 //FIXME (CM): Need to fix this part of the design.
82 //The design seems to be locked to the idea that only one
83 // entity (either from the navigator or the editor) drives
84 // the detail view. In the case of multiple inputs the only workaround
85 // is checking the type and extracting relevant objects.
86 if (input
instanceof IElementHasDetails
) {
87 input
= ((IElementHasDetails
) input
).getData();
90 if ((input
instanceof TaxonBase
)
91 && (formSection
instanceof ITaxonBaseDetailSection
)) {
92 ((ITaxonBaseDetailSection
) formSection
)
93 .setTaxonBase((TaxonBase
<?
>) input
);
96 else if (input
.getClass().equals(DerivedUnit
.class)
97 && (formSection
instanceof IDerivedUnitFacadeDetailSection
)) {
100 input
= DerivedUnitFacade
.NewInstance((DerivedUnit
) input
,
101 PreferencesUtil
.getDerivedUnitConfigurator());
102 } catch (DerivedUnitFacadeNotSupportedException e
) {
103 MessagingUtils
.error(getClass(), e
);
106 else if (input
instanceof PolytomousKeyRelationship
) {
107 input
= ((PolytomousKeyRelationship
) input
).getDestination();
108 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();
117 else if ((input
instanceof PolytomousKeyNode
) &&
118 (formSection
instanceof PolytomousKeyDetailSection
||
119 formSection
instanceof GeoScopeDetailSection
||
120 formSection
instanceof ScopeRestrictionSection
||
121 formSection
instanceof TaxonomicScopeSection
)) {
122 input
= ((PolytomousKeyNode
)input
).getKey();
123 } else if ((input
instanceof TaxonRelationship
)
124 && (formSection
instanceof TaxonDetailSection
)) {
125 ((TaxonDetailSection
) formSection
)
126 .setTaxon( ((TaxonRelationship
)input
).getFromTaxon());
128 }else if ((input
instanceof TaxonRelationship
)
129 && (formSection
instanceof NonViralNameDetailSection
)) {
130 ((NonViralNameDetailSection
) formSection
)
131 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
133 }else if ((input
instanceof TaxonRelationship
)
134 && (formSection
instanceof NomenclaturalSourceDetailSection
)) {
135 ((NomenclaturalSourceDetailSection
) formSection
)
136 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
138 }else if ((input
instanceof TaxonRelationship
)
139 && (formSection
instanceof NomenclaturalStatusSection
)) {
140 ((NomenclaturalStatusSection
) formSection
)
141 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
143 }else if ((input
instanceof TaxonRelationship
)
144 && (formSection
instanceof TypeDesignationSection
)) {
145 ((TypeDesignationSection
) formSection
)
146 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
147 // .setEntity( ((TaxonRelationship)input).getFromTaxon().getName());
149 }else if ((input
instanceof TaxonRelationship
)
150 && (formSection
instanceof NameRelationshipDetailSection
)) {
151 ((NameRelationshipDetailSection
) formSection
)
152 .setTaxonBase( ((TaxonRelationship
)input
).getFromTaxon());
154 }else if ((input
instanceof DerivedUnitFacade
)
155 && (formSection
instanceof RightsSection
)){
156 ((RightsSection
)formSection
).setEntity(((DerivedUnitFacade
)input
).innerDerivedUnit());
158 }else if ((input
instanceof DerivedUnitFacade
)
159 && (formSection
instanceof DeterminationDetailSection
)){
160 DerivedUnitFacade facade
= ((DerivedUnitFacade
)input
);
161 SpecimenOrObservationBase
<?
> sob
= facade
.innerDerivedUnit() != null? facade
.innerDerivedUnit(): facade
.innerFieldUnit();
162 ((DeterminationDetailSection
)formSection
).setEntity(sob
);
164 }else if ((input
instanceof DerivedUnitFacade
)
165 && (formSection
instanceof SampleDesignationDetailSection
)){
166 ((SampleDesignationDetailSection
)formSection
).setEntity(((DerivedUnitFacade
)input
).innerDerivedUnit());
169 //check whether this is needed
170 // }else if ((input instanceof TaxonBase)
171 // && (formSection instanceof TypeDesignationSection)){
172 // ((TypeDesignationSection)formSection).setEntity(((TaxonBase)input).getName());
176 formSection
.setEntity((T
) input
);
182 public boolean setFormInputWithoutUpdate(Object input
) {
183 if (formSection
.isDisposed()){
187 this.rootInput
= input
;
188 //FIXME (CM): Need to fix this part of the design.
189 //The design seems to be locked to the idea that only one
190 // entity (either from the navigator or the editor) drives
191 // the detail view. In the case of multiple inputs the only workaround
192 // is checking the type and extracting relevant objects.
193 if (input
instanceof IElementHasDetails
) {
194 input
= ((IElementHasDetails
) input
).getData();
197 if ((input
instanceof TaxonBase
)
198 && (formSection
instanceof ITaxonBaseDetailSection
)) {
200 //if (!((TaxonBase<?>) input).getTitleCache().equals(((ITaxonBaseDetailSection) formSection).getTaxonBase().getTitleCache())) {
201 ((ITaxonBaseDetailSection
) formSection
)
202 .setTaxonBaseWithoutUpdate((TaxonBase
<?
>) input
);
208 //actually only for Taxon Details...
209 return this.setFormInput( input
);
213 public void propertyChange(PropertyChangeEvent event
) {
216 Object eventSource
= event
.getSource();
217 if (eventSource
instanceof EventObject
){
218 eventSource
= ((EventObject
)eventSource
).getSource();
220 Control
[] children
= formSection
.getLayoutComposite().getChildren();
221 boolean containsElement
= false;
222 for (Control control
: children
) {
223 if(eventSource
.equals(control
)){
224 containsElement
= true;
232 else if (formSection
.equals(eventSource
)){
235 else if(((eventSource
instanceof ICdmFormElement
)&& formSection
.containsFormElement((ICdmFormElement
) eventSource
))) {
242 protected void expansionStateChanged(boolean expanded
) {
243 super.expansionStateChanged(expanded
);
244 PreferencesUtil
.setStringValue(StoreUtil
.getPrefKey(formSection
.getClass(), rootInput
.getClass().getCanonicalName()), expanded?EXPANDED
:COLLAPSED
);