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
.awt
.Event
;
13 import java
.util
.EventObject
;
15 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
16 import org
.eclipse
.jface
.util
.PropertyChangeEvent
;
17 import org
.eclipse
.swt
.widgets
.Control
;
18 import org
.eclipse
.ui
.forms
.SectionPart
;
20 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
21 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacadeNotSupportedException
;
22 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
23 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
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
.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
.occurrence
.GeoScopeDetailSection
;
36 import eu
.etaxonomy
.taxeditor
.ui
.section
.occurrence
.IDerivedUnitFacadeDetailSection
;
40 * CdmSectionPart class.
44 * @created Feb 8, 2010
47 public class CdmSectionPart
<T
> extends SectionPart
implements
48 IPropertyChangeListener
{
50 private final AbstractFormSection
<T
> formSection
;
54 * Constructor for CdmSectionPart.
58 * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
63 public CdmSectionPart(AbstractFormSection
<T
> section
) {
65 formSection
= section
;
70 public boolean setFormInput(Object input
) {
71 //FIXME (CM): Need to fix this part of the design.
72 //The design seems to be locked to the idea that only one
73 // entity (either from the navigator or the editor) drives
74 // the detail view. In the case of multiple inputs the only workaround
75 // is checking the type and extracting relevant objects.
76 if (input
instanceof IElementHasDetails
) {
77 input
= ((IElementHasDetails
) input
).getData();
79 if ((input
instanceof TaxonBase
)
80 && (formSection
instanceof ITaxonBaseDetailSection
)) {
81 ((ITaxonBaseDetailSection
) formSection
)
82 .setTaxonBase((TaxonBase
) input
);
85 else if (input
.getClass().equals(DerivedUnit
.class)
86 && (formSection
instanceof IDerivedUnitFacadeDetailSection
)) {
89 input
= DerivedUnitFacade
.NewInstance((DerivedUnit
) input
,
90 PreferencesUtil
.getDerivedUnitConfigurator());
91 } catch (DerivedUnitFacadeNotSupportedException e
) {
92 MessagingUtils
.error(getClass(), e
);
95 else if (input
instanceof PolytomousKeyRelationship
) {
96 input
= ((PolytomousKeyRelationship
) input
).getDestination();
99 else if ((input
instanceof PolytomousKeyNode
) &&
100 (formSection
instanceof PolytomousKeyDetailSection
||
101 formSection
instanceof GeoScopeDetailSection
||
102 formSection
instanceof ScopeRestrictionSection
||
103 formSection
instanceof TaxonomicScopeSection
)) {
104 input
= ((PolytomousKeyNode
)input
).getKey();
108 formSection
.setEntity((T
) input
);
117 * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
118 * .jface.util.PropertyChangeEvent)
122 public void propertyChange(PropertyChangeEvent event
) {
125 Object eventSource
= event
.getSource();
126 if (eventSource
instanceof EventObject
){
127 eventSource
= ((EventObject
)eventSource
).getSource();
129 Control
[] children
= formSection
.getLayoutComposite().getChildren();
130 boolean containsElement
= false;
131 for (Control control
: children
) {
132 if(eventSource
.equals(control
)){
133 containsElement
= true;
141 else if (formSection
.equals(eventSource
)){
144 else if(((eventSource
instanceof ICdmFormElement
)&& formSection
.containsFormElement((ICdmFormElement
) eventSource
))) {