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.occurrence.DerivedUnitBase;
|
20
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
21
|
import eu.etaxonomy.taxeditor.model.IElementHasDetails;
|
22
|
import eu.etaxonomy.taxeditor.model.PolytomousKeyRelationship;
|
23
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
24
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
25
|
import eu.etaxonomy.taxeditor.ui.forms.AbstractCdmFormElement;
|
26
|
import eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection;
|
27
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
28
|
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
|
29
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.IDerivedUnitFacadeDetailSection;
|
30
|
|
31
|
/**
|
32
|
* <p>
|
33
|
* CdmSectionPart class.
|
34
|
* </p>
|
35
|
*
|
36
|
* @author n.hoffmann
|
37
|
* @created Feb 8, 2010
|
38
|
* @version 1.0
|
39
|
*/
|
40
|
public class CdmSectionPart<T> extends SectionPart implements
|
41
|
IPropertyChangeListener {
|
42
|
|
43
|
private final AbstractFormSection<T> formSection;
|
44
|
|
45
|
/**
|
46
|
* <p>
|
47
|
* Constructor for CdmSectionPart.
|
48
|
* </p>
|
49
|
*
|
50
|
* @param section
|
51
|
* a {@link eu.etaxonomy.taxeditor.ui.forms.AbstractFormSection}
|
52
|
* object.
|
53
|
* @param <T>
|
54
|
* a T object.
|
55
|
*/
|
56
|
public CdmSectionPart(AbstractFormSection<T> section) {
|
57
|
super(section);
|
58
|
formSection = section;
|
59
|
}
|
60
|
|
61
|
/** {@inheritDoc} */
|
62
|
@Override
|
63
|
public boolean setFormInput(Object input) {
|
64
|
if (input instanceof IElementHasDetails) {
|
65
|
input = ((IElementHasDetails) input).getData();
|
66
|
}
|
67
|
if ((input instanceof TaxonBase)
|
68
|
&& (formSection instanceof ITaxonBaseDetailSection)) {
|
69
|
((ITaxonBaseDetailSection) formSection)
|
70
|
.setTaxonBase((TaxonBase) input);
|
71
|
return true;
|
72
|
}
|
73
|
if ((input instanceof DerivedUnitBase)
|
74
|
&& (formSection instanceof IDerivedUnitFacadeDetailSection)) {
|
75
|
|
76
|
try {
|
77
|
input = DerivedUnitFacade.NewInstance((DerivedUnitBase) input,
|
78
|
PreferencesUtil.getDerivedUnitConfigurator());
|
79
|
} catch (DerivedUnitFacadeNotSupportedException e) {
|
80
|
StoreUtil.error(getClass(), e);
|
81
|
}
|
82
|
}
|
83
|
if (input instanceof PolytomousKeyRelationship) {
|
84
|
input = ((PolytomousKeyRelationship) input).getDestination();
|
85
|
}
|
86
|
|
87
|
formSection.setEntity((T) input);
|
88
|
|
89
|
return true;
|
90
|
}
|
91
|
|
92
|
/*
|
93
|
* (non-Javadoc)
|
94
|
*
|
95
|
* @see
|
96
|
* org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
|
97
|
* .jface.util.PropertyChangeEvent)
|
98
|
*/
|
99
|
/** {@inheritDoc} */
|
100
|
@Override
|
101
|
public void propertyChange(PropertyChangeEvent event) {
|
102
|
if (event != null) {
|
103
|
|
104
|
Object eventSource = event.getSource();
|
105
|
|
106
|
if (formSection.equals(eventSource)){
|
107
|
markDirty();
|
108
|
}
|
109
|
if((
|
110
|
(eventSource instanceof AbstractCdmFormElement)
|
111
|
&& formSection.containsFormElement((AbstractCdmFormElement) eventSource))
|
112
|
) {
|
113
|
markDirty();
|
114
|
}
|
115
|
}
|
116
|
}
|
117
|
|
118
|
}
|