3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.view
.detail
;
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
.taxeditor
.model
.IElementHasDetails
;
24 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
25 import eu
.etaxonomy
.taxeditor
.model
.PolytomousKeyRelationship
;
26 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.section
.ITaxonBaseDetailSection
;
30 import eu
.etaxonomy
.taxeditor
.ui
.section
.key
.GeographicalScopeDetailSection
;
31 import eu
.etaxonomy
.taxeditor
.ui
.section
.key
.PolytomousKeyDetailSection
;
32 import eu
.etaxonomy
.taxeditor
.ui
.section
.key
.ScopeRestrictionSection
;
33 import eu
.etaxonomy
.taxeditor
.ui
.section
.key
.TaxonomicScopeSection
;
34 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.IDerivedUnitFacadeDetailSection
;
38 * CdmSectionPart class.
42 * @created Feb 8, 2010
45 public class CdmSectionPart
<T
> extends SectionPart
implements
46 IPropertyChangeListener
{
48 private final AbstractFormSection
<T
> formSection
;
52 * Constructor for CdmSectionPart.
56 * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
61 public CdmSectionPart(AbstractFormSection
<T
> section
) {
63 formSection
= section
;
68 public boolean setFormInput(Object input
) {
69 //FIXME (CM): Need to fix this part of the design.
70 //The design seems to be locked to the idea that only one
71 // entity (either from the navigator or the editor) drives
72 // the detail view. In the case of multiple inputs the only workaround
73 // is checking the type and extracting relevant objects.
74 if (input
instanceof IElementHasDetails
) {
75 input
= ((IElementHasDetails
) input
).getData();
77 if ((input
instanceof TaxonBase
)
78 && (formSection
instanceof ITaxonBaseDetailSection
)) {
79 ((ITaxonBaseDetailSection
) formSection
)
80 .setTaxonBase((TaxonBase
) input
);
83 else if (input
.getClass().equals(DerivedUnit
.class)
84 && (formSection
instanceof IDerivedUnitFacadeDetailSection
)) {
87 input
= DerivedUnitFacade
.NewInstance((DerivedUnit
) input
,
88 PreferencesUtil
.getDerivedUnitConfigurator());
89 } catch (DerivedUnitFacadeNotSupportedException e
) {
90 MessagingUtils
.error(getClass(), e
);
93 else if (input
instanceof PolytomousKeyRelationship
) {
94 input
= ((PolytomousKeyRelationship
) input
).getDestination();
97 else if ((input
instanceof PolytomousKeyNode
) &&
98 (formSection
instanceof PolytomousKeyDetailSection
||
99 formSection
instanceof GeographicalScopeDetailSection
||
100 formSection
instanceof ScopeRestrictionSection
||
101 formSection
instanceof TaxonomicScopeSection
)) {
102 input
= ((PolytomousKeyNode
)input
).getKey();
106 formSection
.setEntity((T
) input
);
115 * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
116 * .jface.util.PropertyChangeEvent)
120 public void propertyChange(PropertyChangeEvent event
) {
123 Object eventSource
= event
.getSource();
124 Control
[] children
= formSection
.getLayoutComposite().getChildren();
125 boolean containsElement
= false;
126 for (Control control
: children
) {
127 if(eventSource
.equals(control
)){
128 containsElement
= true;
136 else if (formSection
.equals(eventSource
)){
139 else if(((eventSource
instanceof ICdmFormElement
)&& formSection
.containsFormElement((ICdmFormElement
) eventSource
))) {