1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.view.detail;
|
12
|
|
13
|
import org.eclipse.jface.util.IPropertyChangeListener;
|
14
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
15
|
import org.eclipse.ui.forms.SectionPart;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
18
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
|
19
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
20
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
21
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
22
|
import eu.etaxonomy.taxeditor.model.IElementHasDetails;
|
23
|
import eu.etaxonomy.taxeditor.model.PolytomousKeyRelationship;
|
24
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
25
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
26
|
import eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement;
|
27
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
28
|
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
|
29
|
import eu.etaxonomy.taxeditor.ui.section.key.GeographicalScopeDetailSection;
|
30
|
import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyDetailSection;
|
31
|
import eu.etaxonomy.taxeditor.ui.section.key.ScopeRestrictionSection;
|
32
|
import eu.etaxonomy.taxeditor.ui.section.key.TaxonomicScopeSection;
|
33
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.IDerivedUnitFacadeDetailSection;
|
34
|
|
35
|
/**
|
36
|
* <p>
|
37
|
* CdmSectionPart class.
|
38
|
* </p>
|
39
|
*
|
40
|
* @author n.hoffmann
|
41
|
* @created Feb 8, 2010
|
42
|
* @version 1.0
|
43
|
*/
|
44
|
public class CdmSectionPart<T> extends SectionPart implements
|
45
|
IPropertyChangeListener {
|
46
|
|
47
|
private final AbstractFormSection<T> formSection;
|
48
|
|
49
|
/**
|
50
|
* <p>
|
51
|
* Constructor for CdmSectionPart.
|
52
|
* </p>
|
53
|
*
|
54
|
* @param section
|
55
|
* a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
|
56
|
* object.
|
57
|
* @param <T>
|
58
|
* a T object.
|
59
|
*/
|
60
|
public CdmSectionPart(AbstractFormSection<T> section) {
|
61
|
super(section);
|
62
|
formSection = section;
|
63
|
}
|
64
|
|
65
|
/** {@inheritDoc} */
|
66
|
@Override
|
67
|
public boolean setFormInput(Object input) {
|
68
|
//FIXME (CM): Need to fix this part of the design.
|
69
|
//The design seems to be locked to the idea that only one
|
70
|
// entity (either from the navigator or the editor) drives
|
71
|
// the detail view. In the case of multiple inputs the only workaround
|
72
|
// is checking the type and extracting relevant objects.
|
73
|
if (input instanceof IElementHasDetails) {
|
74
|
input = ((IElementHasDetails) input).getData();
|
75
|
}
|
76
|
if ((input instanceof TaxonBase)
|
77
|
&& (formSection instanceof ITaxonBaseDetailSection)) {
|
78
|
((ITaxonBaseDetailSection) formSection)
|
79
|
.setTaxonBase((TaxonBase) input);
|
80
|
return true;
|
81
|
}
|
82
|
if ((input instanceof DerivedUnit)
|
83
|
&& (formSection instanceof IDerivedUnitFacadeDetailSection)) {
|
84
|
|
85
|
try {
|
86
|
input = DerivedUnitFacade.NewInstance((DerivedUnit) input,
|
87
|
PreferencesUtil.getDerivedUnitConfigurator());
|
88
|
} catch (DerivedUnitFacadeNotSupportedException e) {
|
89
|
StoreUtil.error(getClass(), e);
|
90
|
}
|
91
|
}
|
92
|
if (input instanceof PolytomousKeyRelationship) {
|
93
|
input = ((PolytomousKeyRelationship) input).getDestination();
|
94
|
}
|
95
|
|
96
|
if ((input instanceof PolytomousKeyNode) &&
|
97
|
(formSection instanceof PolytomousKeyDetailSection ||
|
98
|
formSection instanceof GeographicalScopeDetailSection ||
|
99
|
formSection instanceof ScopeRestrictionSection ||
|
100
|
formSection instanceof TaxonomicScopeSection)) {
|
101
|
input = ((PolytomousKeyNode)input).getKey();
|
102
|
}
|
103
|
|
104
|
|
105
|
formSection.setEntity((T) input);
|
106
|
|
107
|
return true;
|
108
|
}
|
109
|
|
110
|
/*
|
111
|
* (non-Javadoc)
|
112
|
*
|
113
|
* @see
|
114
|
* org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
|
115
|
* .jface.util.PropertyChangeEvent)
|
116
|
*/
|
117
|
/** {@inheritDoc} */
|
118
|
@Override
|
119
|
public void propertyChange(PropertyChangeEvent event) {
|
120
|
if (event != null) {
|
121
|
|
122
|
Object eventSource = event.getSource();
|
123
|
|
124
|
if (formSection.equals(eventSource)){
|
125
|
markDirty();
|
126
|
}
|
127
|
if((
|
128
|
(eventSource instanceof AbstractCdmFormElement)
|
129
|
&& formSection.containsFormElement((AbstractCdmFormElement) eventSource))
|
130
|
) {
|
131
|
markDirty();
|
132
|
}
|
133
|
}
|
134
|
}
|
135
|
|
136
|
}
|