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.Collection;
|
13
|
import java.util.Set;
|
14
|
|
15
|
import org.eclipse.core.runtime.IProgressMonitor;
|
16
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
17
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
18
|
import org.eclipse.jface.viewers.ISelection;
|
19
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
20
|
import org.eclipse.jface.viewers.TreeNode;
|
21
|
import org.eclipse.jface.viewers.Viewer;
|
22
|
import org.eclipse.swt.widgets.Composite;
|
23
|
import org.eclipse.ui.IEditorPart;
|
24
|
import org.eclipse.ui.IMemento;
|
25
|
import org.eclipse.ui.IWorkbenchPart;
|
26
|
import org.eclipse.ui.internal.e4.compatibility.CompatibilityPart;
|
27
|
|
28
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
29
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
30
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
31
|
import eu.etaxonomy.cdm.model.description.Feature;
|
32
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
33
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
34
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
35
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
36
|
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
|
37
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
38
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
39
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
40
|
import eu.etaxonomy.taxeditor.model.IContextListener;
|
41
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
42
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
43
|
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
44
|
import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
|
45
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
46
|
|
47
|
/**
|
48
|
* <p>DetailsViewPart class.</p>
|
49
|
*
|
50
|
* @author n.hoffmann
|
51
|
* @created Jun 10, 2010
|
52
|
* @version 1.0
|
53
|
*/
|
54
|
public class DetailsViewPart extends AbstractCdmEditorViewPart implements IPartContentHasSupplementalData, IContextListener{
|
55
|
|
56
|
/** Constant <code>ID="eu.etaxonomy.taxeditor.editor.forms.det"{trunked}</code> */
|
57
|
public static String ID = "eu.etaxonomy.taxeditor.view.detail"; //$NON-NLS-1$
|
58
|
|
59
|
private DetailsViewer viewer;
|
60
|
|
61
|
private CdmBase lastObject;
|
62
|
private Object lastPart;
|
63
|
|
64
|
/** {@inheritDoc} */
|
65
|
@Override
|
66
|
public void createViewer(Composite parent) {
|
67
|
|
68
|
viewer = new DetailsViewer(parent, this);
|
69
|
getSite().setSelectionProvider(viewer);
|
70
|
}
|
71
|
|
72
|
@Override
|
73
|
protected void selectionChanged_internal(IWorkbenchPart workbenchPart, ISelection selection){
|
74
|
Object partObject = workbenchPart;
|
75
|
Object wrappedPart = WorkbenchUtility.getE4WrappedPart(partObject);
|
76
|
if(wrappedPart!=null){
|
77
|
partObject = wrappedPart;
|
78
|
}
|
79
|
if(AbstractUtility.getActiveEditor() == null && !(AbstractUtility.getActivePart() instanceof IConversationEnabled)){
|
80
|
showEmptyPage();
|
81
|
return;
|
82
|
}
|
83
|
|
84
|
//special case where the details view still open with details about the closed object #5495
|
85
|
try{
|
86
|
boolean isSelectionProvidingPartStillActive = false;
|
87
|
if(selectionProvidingPart!=null){
|
88
|
EPartService partService = TaxeditorStorePlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getService(EPartService.class);
|
89
|
Collection<MPart> parts = partService.getParts();
|
90
|
for (MPart mPart : parts) {
|
91
|
Object object = mPart.getObject();
|
92
|
if(object instanceof CompatibilityPart){
|
93
|
object = ((CompatibilityPart) object).getPart();
|
94
|
}
|
95
|
if(selectionProvidingPart.equals(object)){
|
96
|
isSelectionProvidingPartStillActive = true;
|
97
|
break;
|
98
|
}
|
99
|
}
|
100
|
if(!isSelectionProvidingPartStillActive &&
|
101
|
selection instanceof IStructuredSelection && ((IStructuredSelection) selection).getFirstElement() !=null){
|
102
|
showEmptyPage();
|
103
|
return;
|
104
|
}
|
105
|
}
|
106
|
}catch(IllegalStateException e){
|
107
|
//nothing
|
108
|
}
|
109
|
|
110
|
if(partObject == this){
|
111
|
return;
|
112
|
}
|
113
|
|
114
|
if(!(selection instanceof IStructuredSelection)){
|
115
|
return;
|
116
|
}
|
117
|
|
118
|
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
|
119
|
|
120
|
if((partObject instanceof IEditorPart) || (partObject instanceof IPartContentHasDetails)) {
|
121
|
if(structuredSelection.size() != 1){
|
122
|
showEmptyPage();
|
123
|
return;
|
124
|
}
|
125
|
|
126
|
// do not show details for feature nodes TODO really?
|
127
|
if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
|
128
|
// do show the map for distributions
|
129
|
Feature feature = ((FeatureNodeContainer) ((IStructuredSelection) selection).getFirstElement()).getFeature();
|
130
|
if(!feature.equals(Feature.DISTRIBUTION())){
|
131
|
showEmptyPage();
|
132
|
return;
|
133
|
}
|
134
|
}
|
135
|
showViewer(partObject, structuredSelection);
|
136
|
}else{
|
137
|
showEmptyPage();
|
138
|
}
|
139
|
}
|
140
|
|
141
|
@Override
|
142
|
protected String getViewName(){
|
143
|
return Messages.DetailsViewPart_VIEWER_NAME;
|
144
|
}
|
145
|
|
146
|
@Override
|
147
|
protected String createPartTitle(Object selectedObject){
|
148
|
if(selectedObject!=null){
|
149
|
if(selectedObject instanceof TreeNode){
|
150
|
selectedObject = ((TreeNode) selectedObject).getValue();
|
151
|
}
|
152
|
if(selectedObject instanceof SpecimenOrObservationBase){
|
153
|
return getViewName()+": "+HibernateProxyHelper.deproxy(selectedObject, SpecimenOrObservationBase.class).getRecordBasis(); //$NON-NLS-1$
|
154
|
}
|
155
|
if(selectedObject instanceof CdmBase){
|
156
|
return getViewName()+": "+HibernateProxyHelper.deproxy(selectedObject, CdmBase.class).getClass().getSimpleName(); //$NON-NLS-1$
|
157
|
}
|
158
|
return getViewName()+": "+selectedObject.getClass().getSimpleName(); //$NON-NLS-1$
|
159
|
}
|
160
|
return getViewName();
|
161
|
}
|
162
|
|
163
|
@Override
|
164
|
public void showEmptyPage() {
|
165
|
viewer.setSelection(null);
|
166
|
|
167
|
super.showEmptyPage();
|
168
|
}
|
169
|
|
170
|
/** {@inheritDoc} */
|
171
|
@Override
|
172
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
173
|
|
174
|
viewer.setInput(objectAffectedByOperation);
|
175
|
|
176
|
return super.postOperation(objectAffectedByOperation);
|
177
|
}
|
178
|
|
179
|
|
180
|
/** {@inheritDoc} */
|
181
|
@Override
|
182
|
public Viewer getViewer() {
|
183
|
return viewer;
|
184
|
}
|
185
|
|
186
|
|
187
|
/** {@inheritDoc} */
|
188
|
@Override
|
189
|
public void dispose() {
|
190
|
selectionService.removePostSelectionListener(this);
|
191
|
super.dispose();
|
192
|
|
193
|
}
|
194
|
|
195
|
@Override
|
196
|
public boolean onComplete() {
|
197
|
return true;
|
198
|
}
|
199
|
|
200
|
/**
|
201
|
* {@inheritDoc}
|
202
|
*/
|
203
|
@Override
|
204
|
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
|
205
|
}
|
206
|
|
207
|
/**
|
208
|
* {@inheritDoc}
|
209
|
*/
|
210
|
@Override
|
211
|
public void contextStop(IMemento memento, IProgressMonitor monitor) {
|
212
|
showEmptyPage();
|
213
|
}
|
214
|
|
215
|
/**
|
216
|
* {@inheritDoc}
|
217
|
*/
|
218
|
@Override
|
219
|
public void contextStart(IMemento memento, IProgressMonitor monitor) {
|
220
|
}
|
221
|
|
222
|
/**
|
223
|
* {@inheritDoc}
|
224
|
*/
|
225
|
@Override
|
226
|
public void contextRefresh(IProgressMonitor monitor) {
|
227
|
}
|
228
|
|
229
|
/**
|
230
|
* {@inheritDoc}
|
231
|
*/
|
232
|
@Override
|
233
|
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
|
234
|
}
|
235
|
@Override
|
236
|
public void showViewer(Object part, IStructuredSelection selection){
|
237
|
|
238
|
|
239
|
|
240
|
this.part = part;
|
241
|
|
242
|
Object element = selection.getFirstElement();
|
243
|
|
244
|
// if (part == lastPart && element == lastObject ){
|
245
|
// getViewer().setInput(element);
|
246
|
// return;
|
247
|
// }else{
|
248
|
// lastPart = part;
|
249
|
// if (element instanceof CdmBase){
|
250
|
// lastObject = (CdmBase)element;
|
251
|
// }else{
|
252
|
// lastObject = null;
|
253
|
// }
|
254
|
// }
|
255
|
//avoid widget is disposed exceptions
|
256
|
if (getViewer().getControl()==null || getViewer().getControl().isDisposed() ){
|
257
|
return;
|
258
|
}
|
259
|
|
260
|
setPartName(createPartTitle(element));
|
261
|
if (element instanceof Taxon){
|
262
|
Taxon taxon = HibernateProxyHelper.deproxy(element, Taxon.class);
|
263
|
if (taxon.isMisapplication()){
|
264
|
|
265
|
if (part instanceof ITaxonEditor){
|
266
|
Taxon accepted= ((ITaxonEditor)part).getTaxon();
|
267
|
Set<TaxonRelationship> rels = taxon.getTaxonRelations(accepted);
|
268
|
|
269
|
if (rels.iterator().hasNext()){
|
270
|
TaxonRelationship rel = rels.iterator().next();
|
271
|
if (rel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
|
272
|
getViewer().setInput(rel);
|
273
|
showViewer();
|
274
|
return;
|
275
|
}
|
276
|
}
|
277
|
}
|
278
|
|
279
|
|
280
|
}
|
281
|
}
|
282
|
if (element instanceof Object[] && ((Object[])element).length == 0){
|
283
|
return;
|
284
|
}
|
285
|
getViewer().setInput(element);
|
286
|
super.showViewer(part, selection);
|
287
|
}
|
288
|
}
|
289
|
|
290
|
|