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.e4.supplementaldata;
|
11
|
|
12
|
import java.util.Set;
|
13
|
|
14
|
import javax.annotation.PostConstruct;
|
15
|
import javax.inject.Inject;
|
16
|
|
17
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
18
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
19
|
import org.eclipse.jface.viewers.StructuredSelection;
|
20
|
import org.eclipse.jface.viewers.TreeNode;
|
21
|
import org.eclipse.swt.widgets.Composite;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
24
|
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
|
25
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
26
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
27
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
28
|
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
|
29
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
30
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
31
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
32
|
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
|
33
|
|
34
|
|
35
|
/**
|
36
|
*
|
37
|
* @author pplitzner
|
38
|
* @since Aug 10, 2017
|
39
|
*
|
40
|
*/
|
41
|
public class SupplementalDataPartE4 extends AbstractCdmEditorPartE4 {
|
42
|
|
43
|
@Inject
|
44
|
public SupplementalDataPartE4() {
|
45
|
}
|
46
|
|
47
|
@PostConstruct
|
48
|
public void create(Composite parent) {
|
49
|
viewer = new SupplementalDataViewerE4(parent, this);
|
50
|
}
|
51
|
|
52
|
@Override
|
53
|
public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
|
54
|
if(activePart==thisPart){
|
55
|
return;
|
56
|
}
|
57
|
|
58
|
Object partObject = createPartObject(activePart);
|
59
|
|
60
|
if(partObject instanceof IPartContentHasSupplementalData) {
|
61
|
|
62
|
IStructuredSelection structuredSelection = createSelection(selection);
|
63
|
if(structuredSelection==null || structuredSelection.isEmpty()){
|
64
|
showEmptyPage();
|
65
|
return;
|
66
|
}
|
67
|
if(structuredSelection.size() != 1){
|
68
|
showEmptyPage();
|
69
|
return;
|
70
|
}
|
71
|
if (partObject instanceof ITaxonEditor && structuredSelection.getFirstElement() instanceof Taxon ){
|
72
|
if (((ITaxonEditor)partObject).getTaxon() != structuredSelection.getFirstElement() && ((Taxon)structuredSelection.getFirstElement()).isMisapplication()){
|
73
|
Set<TaxonRelationship> rels =((Taxon)structuredSelection.getFirstElement()).getTaxonRelations(((ITaxonEditor)partObject).getTaxon());
|
74
|
if (rels.size() == 1){
|
75
|
structuredSelection = new StructuredSelection(rels.iterator().next());
|
76
|
}else{
|
77
|
showEmptyPage();
|
78
|
return;
|
79
|
}
|
80
|
|
81
|
}
|
82
|
}
|
83
|
// do not show supplemental data for feature nodes
|
84
|
if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
|
85
|
showEmptyPage();
|
86
|
return;
|
87
|
}
|
88
|
else if(structuredSelection.getFirstElement() instanceof DerivedUnitFacade){
|
89
|
return;
|
90
|
}
|
91
|
else if(structuredSelection.getFirstElement() instanceof PolytomousKeyNode){
|
92
|
structuredSelection = new StructuredSelection(((PolytomousKeyNode)structuredSelection.getFirstElement()).getKey());
|
93
|
}
|
94
|
else if(structuredSelection.getFirstElement() instanceof TreeNode){
|
95
|
structuredSelection = new StructuredSelection(((TreeNode)structuredSelection.getFirstElement()).getValue());
|
96
|
}
|
97
|
else if(structuredSelection.getFirstElement() instanceof GbifResponse){
|
98
|
structuredSelection = new StructuredSelection(((GbifResponse)structuredSelection.getFirstElement()).getDerivedUnitFacade().innerDerivedUnit());
|
99
|
}
|
100
|
|
101
|
showViewer(structuredSelection, activePart, viewer);
|
102
|
return;
|
103
|
}
|
104
|
else if(selectionProvidingPart!=null && selectionProvidingPart.isVisible()){
|
105
|
return;
|
106
|
}
|
107
|
else{
|
108
|
showEmptyPage();
|
109
|
return;
|
110
|
}
|
111
|
}
|
112
|
|
113
|
@Override
|
114
|
protected String getViewName() {
|
115
|
return Messages.SupplementalDataViewPart_VIEWER_NAME;
|
116
|
}
|
117
|
}
|