1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.view.detail;
|
11
|
|
12
|
import java.awt.Event;
|
13
|
import java.util.EventObject;
|
14
|
|
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;
|
19
|
|
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;
|
37
|
|
38
|
/**
|
39
|
* <p>
|
40
|
* CdmSectionPart class.
|
41
|
* </p>
|
42
|
*
|
43
|
* @author n.hoffmann
|
44
|
* @created Feb 8, 2010
|
45
|
* @version 1.0
|
46
|
*/
|
47
|
public class CdmSectionPart<T> extends SectionPart implements
|
48
|
IPropertyChangeListener {
|
49
|
|
50
|
private final AbstractFormSection<T> formSection;
|
51
|
|
52
|
/**
|
53
|
* <p>
|
54
|
* Constructor for CdmSectionPart.
|
55
|
* </p>
|
56
|
*
|
57
|
* @param section
|
58
|
* a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
|
59
|
* object.
|
60
|
* @param <T>
|
61
|
* a T object.
|
62
|
*/
|
63
|
public CdmSectionPart(AbstractFormSection<T> section) {
|
64
|
super(section);
|
65
|
formSection = section;
|
66
|
}
|
67
|
|
68
|
/** {@inheritDoc} */
|
69
|
@Override
|
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();
|
78
|
}
|
79
|
if ((input instanceof TaxonBase)
|
80
|
&& (formSection instanceof ITaxonBaseDetailSection)) {
|
81
|
((ITaxonBaseDetailSection) formSection)
|
82
|
.setTaxonBase((TaxonBase) input);
|
83
|
return true;
|
84
|
}
|
85
|
else if (input.getClass().equals(DerivedUnit.class)
|
86
|
&& (formSection instanceof IDerivedUnitFacadeDetailSection)) {
|
87
|
|
88
|
try {
|
89
|
input = DerivedUnitFacade.NewInstance((DerivedUnit) input,
|
90
|
PreferencesUtil.getDerivedUnitConfigurator());
|
91
|
} catch (DerivedUnitFacadeNotSupportedException e) {
|
92
|
MessagingUtils.error(getClass(), e);
|
93
|
}
|
94
|
}
|
95
|
else if (input instanceof PolytomousKeyRelationship) {
|
96
|
input = ((PolytomousKeyRelationship) input).getDestination();
|
97
|
}
|
98
|
|
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();
|
105
|
}
|
106
|
|
107
|
|
108
|
formSection.setEntity((T) input);
|
109
|
|
110
|
return true;
|
111
|
}
|
112
|
|
113
|
/*
|
114
|
* (non-Javadoc)
|
115
|
*
|
116
|
* @see
|
117
|
* org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
|
118
|
* .jface.util.PropertyChangeEvent)
|
119
|
*/
|
120
|
/** {@inheritDoc} */
|
121
|
@Override
|
122
|
public void propertyChange(PropertyChangeEvent event) {
|
123
|
if (event != null) {
|
124
|
|
125
|
Object eventSource = event.getSource();
|
126
|
if (eventSource instanceof EventObject){
|
127
|
eventSource = ((EventObject)eventSource).getSource();
|
128
|
}
|
129
|
Control[] children = formSection.getLayoutComposite().getChildren();
|
130
|
boolean containsElement = false;
|
131
|
for (Control control : children) {
|
132
|
if(eventSource.equals(control)){
|
133
|
containsElement = true;
|
134
|
break;
|
135
|
}
|
136
|
}
|
137
|
if(containsElement){
|
138
|
markDirty();
|
139
|
}
|
140
|
|
141
|
else if (formSection.equals(eventSource)){
|
142
|
markDirty();
|
143
|
}
|
144
|
else if(((eventSource instanceof ICdmFormElement)&& formSection.containsFormElement((ICdmFormElement) eventSource))) {
|
145
|
markDirty();
|
146
|
}
|
147
|
}
|
148
|
}
|
149
|
|
150
|
}
|