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.util.EventObject;
|
13
|
|
14
|
import org.eclipse.jface.util.IPropertyChangeListener;
|
15
|
import org.eclipse.jface.util.PropertyChangeEvent;
|
16
|
import org.eclipse.swt.widgets.Control;
|
17
|
import org.eclipse.ui.forms.SectionPart;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
20
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;
|
21
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
22
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
23
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
24
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
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.store.StoreUtil;
|
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.name.NameRelationshipDetailSection;
|
37
|
import eu.etaxonomy.taxeditor.ui.section.name.NomenclaturalStatusSection;
|
38
|
import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameDetailSection;
|
39
|
import eu.etaxonomy.taxeditor.ui.section.name.ProtologueSection;
|
40
|
import eu.etaxonomy.taxeditor.ui.section.name.TypeDesignationSection;
|
41
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.GeoScopeDetailSection;
|
42
|
import eu.etaxonomy.taxeditor.ui.section.occurrence.IDerivedUnitFacadeDetailSection;
|
43
|
import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailSection;
|
44
|
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonDetailSection;
|
45
|
|
46
|
/**
|
47
|
* <p>
|
48
|
* CdmSectionPart class.
|
49
|
* </p>
|
50
|
*
|
51
|
* @author n.hoffmann
|
52
|
* @created Feb 8, 2010
|
53
|
* @version 1.0
|
54
|
*/
|
55
|
public class CdmSectionPart<T> extends SectionPart implements
|
56
|
IPropertyChangeListener {
|
57
|
|
58
|
public static String EXPANDED = "expanded";
|
59
|
public static String COLLAPSED = "collapsed";
|
60
|
|
61
|
private final AbstractFormSection<T> formSection;
|
62
|
|
63
|
/**
|
64
|
* Initial input
|
65
|
*/
|
66
|
private Object rootInput;
|
67
|
|
68
|
/**
|
69
|
* <p>
|
70
|
* Constructor for CdmSectionPart.
|
71
|
* </p>
|
72
|
*
|
73
|
* @param section
|
74
|
* a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
|
75
|
* object.
|
76
|
* @param <T>
|
77
|
* a T object.
|
78
|
*/
|
79
|
public CdmSectionPart(AbstractFormSection<T> section) {
|
80
|
super(section);
|
81
|
formSection = section;
|
82
|
}
|
83
|
|
84
|
/** {@inheritDoc} */
|
85
|
@Override
|
86
|
public boolean setFormInput(Object input) {
|
87
|
this.rootInput = input;
|
88
|
//FIXME (CM): Need to fix this part of the design.
|
89
|
//The design seems to be locked to the idea that only one
|
90
|
// entity (either from the navigator or the editor) drives
|
91
|
// the detail view. In the case of multiple inputs the only workaround
|
92
|
// is checking the type and extracting relevant objects.
|
93
|
if (input instanceof IElementHasDetails) {
|
94
|
input = ((IElementHasDetails) input).getData();
|
95
|
}
|
96
|
if ((input instanceof TaxonBase)
|
97
|
&& (formSection instanceof ITaxonBaseDetailSection)) {
|
98
|
((ITaxonBaseDetailSection) formSection)
|
99
|
.setTaxonBase((TaxonBase) input);
|
100
|
return true;
|
101
|
}
|
102
|
else if (input.getClass().equals(DerivedUnit.class)
|
103
|
&& (formSection instanceof IDerivedUnitFacadeDetailSection)) {
|
104
|
|
105
|
try {
|
106
|
input = DerivedUnitFacade.NewInstance((DerivedUnit) input,
|
107
|
PreferencesUtil.getDerivedUnitConfigurator());
|
108
|
} catch (DerivedUnitFacadeNotSupportedException e) {
|
109
|
MessagingUtils.error(getClass(), e);
|
110
|
}
|
111
|
}
|
112
|
else if (input instanceof PolytomousKeyRelationship) {
|
113
|
input = ((PolytomousKeyRelationship) input).getDestination();
|
114
|
}
|
115
|
|
116
|
else if ((input instanceof PolytomousKeyNode) &&
|
117
|
(formSection instanceof PolytomousKeyDetailSection ||
|
118
|
formSection instanceof GeoScopeDetailSection ||
|
119
|
formSection instanceof ScopeRestrictionSection ||
|
120
|
formSection instanceof TaxonomicScopeSection)) {
|
121
|
input = ((PolytomousKeyNode)input).getKey();
|
122
|
} else if ((input instanceof TaxonRelationship)
|
123
|
&& (formSection instanceof TaxonDetailSection)) {
|
124
|
((TaxonDetailSection) formSection)
|
125
|
.setTaxon( ((TaxonRelationship)input).getFromTaxon());
|
126
|
return true;
|
127
|
}else if ((input instanceof TaxonRelationship)
|
128
|
&& (formSection instanceof NonViralNameDetailSection)) {
|
129
|
((NonViralNameDetailSection) formSection)
|
130
|
.setTaxonBase( ((TaxonRelationship)input).getFromTaxon());
|
131
|
return true;
|
132
|
}else if ((input instanceof TaxonRelationship)
|
133
|
&& (formSection instanceof NomenclaturalReferenceDetailSection)) {
|
134
|
((NomenclaturalReferenceDetailSection) formSection)
|
135
|
.setTaxonBase( ((TaxonRelationship)input).getFromTaxon());
|
136
|
return true;
|
137
|
}else if ((input instanceof TaxonRelationship)
|
138
|
&& (formSection instanceof NomenclaturalStatusSection)) {
|
139
|
((NomenclaturalStatusSection) formSection)
|
140
|
.setTaxonBase( ((TaxonRelationship)input).getFromTaxon());
|
141
|
return true;
|
142
|
}else if ((input instanceof TaxonRelationship)
|
143
|
&& (formSection instanceof ProtologueSection)) {
|
144
|
((ProtologueSection) formSection)
|
145
|
.setTaxonBase( ((TaxonRelationship)input).getFromTaxon());
|
146
|
return true;
|
147
|
}else if ((input instanceof TaxonRelationship)
|
148
|
&& (formSection instanceof TypeDesignationSection)) {
|
149
|
((TypeDesignationSection) formSection)
|
150
|
.setTaxonBase( ((TaxonRelationship)input).getFromTaxon());
|
151
|
return true;
|
152
|
}else if ((input instanceof TaxonRelationship)
|
153
|
&& (formSection instanceof NameRelationshipDetailSection)) {
|
154
|
((NameRelationshipDetailSection) formSection)
|
155
|
.setTaxonBase( ((TaxonRelationship)input).getFromTaxon());
|
156
|
return true;
|
157
|
}
|
158
|
|
159
|
|
160
|
formSection.setEntity((T) input);
|
161
|
|
162
|
return true;
|
163
|
}
|
164
|
|
165
|
/*
|
166
|
* (non-Javadoc)
|
167
|
*
|
168
|
* @see
|
169
|
* org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
|
170
|
* .jface.util.PropertyChangeEvent)
|
171
|
*/
|
172
|
/** {@inheritDoc} */
|
173
|
@Override
|
174
|
public void propertyChange(PropertyChangeEvent event) {
|
175
|
if (event != null) {
|
176
|
|
177
|
Object eventSource = event.getSource();
|
178
|
if (eventSource instanceof EventObject){
|
179
|
eventSource = ((EventObject)eventSource).getSource();
|
180
|
}
|
181
|
Control[] children = formSection.getLayoutComposite().getChildren();
|
182
|
boolean containsElement = false;
|
183
|
for (Control control : children) {
|
184
|
if(eventSource.equals(control)){
|
185
|
containsElement = true;
|
186
|
break;
|
187
|
}
|
188
|
}
|
189
|
if(containsElement){
|
190
|
markDirty();
|
191
|
}
|
192
|
|
193
|
else if (formSection.equals(eventSource)){
|
194
|
markDirty();
|
195
|
}
|
196
|
else if(((eventSource instanceof ICdmFormElement)&& formSection.containsFormElement((ICdmFormElement) eventSource))) {
|
197
|
markDirty();
|
198
|
}
|
199
|
}
|
200
|
}
|
201
|
|
202
|
@Override
|
203
|
protected void expansionStateChanged(boolean expanded) {
|
204
|
super.expansionStateChanged(expanded);
|
205
|
PreferencesUtil.setStringValue(StoreUtil.getPrefKey(formSection.getClass(), rootInput), expanded?EXPANDED:COLLAPSED);
|
206
|
}
|
207
|
|
208
|
}
|