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.core.di.annotations.Optional;
|
20
|
import org.eclipse.e4.core.services.log.Logger;
|
21
|
import org.eclipse.e4.ui.di.UIEventTopic;
|
22
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
23
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
24
|
import org.eclipse.jface.viewers.StructuredSelection;
|
25
|
import org.eclipse.jface.viewers.TreeNode;
|
26
|
import org.eclipse.swt.SWTException;
|
27
|
import org.eclipse.swt.widgets.Composite;
|
28
|
|
29
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
30
|
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
|
31
|
import eu.etaxonomy.cdm.model.common.ICdmBase;
|
32
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
33
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
34
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
35
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
36
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
37
|
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
|
38
|
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
|
39
|
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
|
40
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
41
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
42
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
43
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
44
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
45
|
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
|
46
|
|
47
|
|
48
|
/**
|
49
|
*
|
50
|
* @author pplitzner
|
51
|
* @since Aug 10, 2017
|
52
|
*
|
53
|
*/
|
54
|
public class SupplementalDataPartE4 extends AbstractCdmEditorPartE4 {
|
55
|
@Inject
|
56
|
private Logger logger;
|
57
|
|
58
|
@Inject
|
59
|
public SupplementalDataPartE4() {
|
60
|
}
|
61
|
|
62
|
@PostConstruct
|
63
|
public void create(Composite parent, MPart thisPart, IEclipseContext context) {
|
64
|
|
65
|
this.thisPart = thisPart;
|
66
|
|
67
|
viewer = ContextInjectionFactory.make(SupplementalDataViewerE4.class, context);
|
68
|
((SupplementalDataViewerE4)viewer).init(parent, this);
|
69
|
}
|
70
|
|
71
|
@Override
|
72
|
public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
|
73
|
if(activePart==thisPart){
|
74
|
return;
|
75
|
}
|
76
|
|
77
|
Object partObject = createPartObject(activePart);
|
78
|
|
79
|
if(partObject instanceof IPartContentHasSupplementalData) {
|
80
|
|
81
|
IStructuredSelection structuredSelection = createSelection(selection);
|
82
|
if(structuredSelection==null || structuredSelection.isEmpty()){
|
83
|
showEmptyPage();
|
84
|
return;
|
85
|
}
|
86
|
if(structuredSelection.size() != 1){
|
87
|
showEmptyPage();
|
88
|
return;
|
89
|
}
|
90
|
if (partObject instanceof ITaxonEditor && structuredSelection.getFirstElement() instanceof Taxon ){
|
91
|
if (((ITaxonEditor)partObject).getTaxon() != structuredSelection.getFirstElement() && ((Taxon)structuredSelection.getFirstElement()).isMisapplication()){
|
92
|
Set<TaxonRelationship> rels =((Taxon)structuredSelection.getFirstElement()).getTaxonRelations(((ITaxonEditor)partObject).getTaxon());
|
93
|
if (rels != null && rels.size() == 1){
|
94
|
structuredSelection = new StructuredSelection(rels.iterator().next());
|
95
|
}else{
|
96
|
showEmptyPage();
|
97
|
return;
|
98
|
}
|
99
|
|
100
|
}
|
101
|
}
|
102
|
// do not show supplemental data for feature nodes
|
103
|
if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
|
104
|
showEmptyPage();
|
105
|
return;
|
106
|
}
|
107
|
|
108
|
else if(structuredSelection.getFirstElement() instanceof DerivedUnitFacade){
|
109
|
return;
|
110
|
}
|
111
|
else if(structuredSelection.getFirstElement() instanceof PolytomousKeyNode){
|
112
|
structuredSelection = new StructuredSelection(((PolytomousKeyNode)structuredSelection.getFirstElement()).getKey());
|
113
|
}
|
114
|
else if(structuredSelection.getFirstElement() instanceof TreeNode){
|
115
|
structuredSelection = new StructuredSelection(((TreeNode)structuredSelection.getFirstElement()).getValue());
|
116
|
}
|
117
|
else if(structuredSelection.getFirstElement() instanceof GbifResponse){
|
118
|
structuredSelection = new StructuredSelection(((GbifResponse)structuredSelection.getFirstElement()).getDerivedUnitFacade().innerDerivedUnit());
|
119
|
}
|
120
|
else if(structuredSelection.getFirstElement() instanceof DescriptionElementBase ){
|
121
|
structuredSelection = new StructuredSelection((structuredSelection.getFirstElement()));
|
122
|
}
|
123
|
else if(structuredSelection.getFirstElement() instanceof TermDto
|
124
|
|| structuredSelection.getFirstElement() instanceof TermVocabularyDto){
|
125
|
showViewer(structuredSelection, activePart, viewer);
|
126
|
return;
|
127
|
}
|
128
|
|
129
|
|
130
|
if(!(structuredSelection.getFirstElement() instanceof ICdmBase)){
|
131
|
showEmptyPage();
|
132
|
return;
|
133
|
}
|
134
|
showViewer(structuredSelection, activePart, viewer);
|
135
|
((SupplementalDataViewerE4)viewer).setEnabled(isEnabled());
|
136
|
|
137
|
return;
|
138
|
}
|
139
|
else{
|
140
|
showEmptyPage();
|
141
|
return;
|
142
|
}
|
143
|
}
|
144
|
|
145
|
@Override
|
146
|
protected void showEmptyPage() {
|
147
|
super.showEmptyPage();
|
148
|
if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed()){
|
149
|
try{
|
150
|
((SupplementalDataViewerE4)viewer).destroySections();
|
151
|
}catch (SWTException e){
|
152
|
if (PreferencesUtil.isShowUpWidgetIsDisposedMessages() && e.getMessage().equals("Widget is disposed")){
|
153
|
MessagingUtils.errorDialog("Widget is disposed",
|
154
|
null,
|
155
|
MessagingUtils.WIDGET_IS_DISPOSED_MESSAGE,
|
156
|
null,
|
157
|
e,
|
158
|
true);
|
159
|
|
160
|
}
|
161
|
}
|
162
|
}
|
163
|
}
|
164
|
|
165
|
@Override
|
166
|
protected String getViewName() {
|
167
|
return Messages.SupplementalDataViewPart_VIEWER_NAME;
|
168
|
}
|
169
|
|
170
|
@Inject
|
171
|
@Optional
|
172
|
private void updateView(@UIEventTopic(WorkbenchEventConstants.REFRESH_SUPPLEMENTAL)boolean refresh){
|
173
|
if(refresh){
|
174
|
viewer.refresh();
|
175
|
}
|
176
|
}
|
177
|
}
|