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