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 java
.awt
.Event
;
14 import java
.util
.EventObject
;
16 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
17 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
18 import org
.eclipse
.swt
.widgets
.Control
;
19 import org
.eclipse
.ui
.forms
.SectionPart
;
21 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
22 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacadeNotSupportedException
;
23 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
24 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
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
.occurrence
.GeoScopeDetailSection
;
37 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.IDerivedUnitFacadeDetailSection
;
41 * CdmSectionPart class.
45 * @created Feb 8, 2010
48 public class CdmSectionPart
<T
> extends SectionPart
implements
49 IPropertyChangeListener
{
51 private final AbstractFormSection
<T
> formSection
;
55 * Constructor for CdmSectionPart.
59 * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
64 public CdmSectionPart(AbstractFormSection
<T
> section
) {
66 formSection
= section
;
71 public boolean setFormInput(Object input
) {
72 //FIXME (CM): Need to fix this part of the design.
73 //The design seems to be locked to the idea that only one
74 // entity (either from the navigator or the editor) drives
75 // the detail view. In the case of multiple inputs the only workaround
76 // is checking the type and extracting relevant objects.
77 if (input
instanceof IElementHasDetails
) {
78 input
= ((IElementHasDetails
) input
).getData();
80 if ((input
instanceof TaxonBase
)
81 && (formSection
instanceof ITaxonBaseDetailSection
)) {
82 ((ITaxonBaseDetailSection
) formSection
)
83 .setTaxonBase((TaxonBase
) input
);
86 else if (input
.getClass().equals(DerivedUnit
.class)
87 && (formSection
instanceof IDerivedUnitFacadeDetailSection
)) {
90 input
= DerivedUnitFacade
.NewInstance((DerivedUnit
) input
,
91 PreferencesUtil
.getDerivedUnitConfigurator());
92 } catch (DerivedUnitFacadeNotSupportedException e
) {
93 MessagingUtils
.error(getClass(), e
);
96 else if (input
instanceof PolytomousKeyRelationship
) {
97 input
= ((PolytomousKeyRelationship
) input
).getDestination();
100 else if ((input
instanceof PolytomousKeyNode
) &&
101 (formSection
instanceof PolytomousKeyDetailSection
||
102 formSection
instanceof GeoScopeDetailSection
||
103 formSection
instanceof ScopeRestrictionSection
||
104 formSection
instanceof TaxonomicScopeSection
)) {
105 input
= ((PolytomousKeyNode
)input
).getKey();
109 formSection
.setEntity((T
) input
);
118 * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
119 * .jface.util.PropertyChangeEvent)
123 public void propertyChange(PropertyChangeEvent event
) {
126 Object eventSource
= event
.getSource();
127 if (eventSource
instanceof EventObject
){
128 eventSource
= ((EventObject
)eventSource
).getSource();
130 Control
[] children
= formSection
.getLayoutComposite().getChildren();
131 boolean containsElement
= false;
132 for (Control control
: children
) {
133 if(eventSource
.equals(control
)){
134 containsElement
= true;
142 else if (formSection
.equals(eventSource
)){
145 else if(((eventSource
instanceof ICdmFormElement
)&& formSection
.containsFormElement((ICdmFormElement
) eventSource
))) {