1
|
/**
|
2
|
* Copyright (C) 2017 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
|
package eu.etaxonomy.taxeditor.view.e4.details;
|
10
|
|
11
|
import javax.annotation.PostConstruct;
|
12
|
import javax.inject.Inject;
|
13
|
|
14
|
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
15
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
16
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
17
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
18
|
import org.eclipse.jface.viewers.StructuredSelection;
|
19
|
import org.eclipse.swt.SWTException;
|
20
|
import org.eclipse.swt.widgets.Composite;
|
21
|
|
22
|
import eu.etaxonomy.cdm.model.description.Feature;
|
23
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
24
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
25
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
26
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
27
|
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
|
28
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
29
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
30
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
31
|
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPart;
|
32
|
import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4;
|
33
|
|
34
|
/**
|
35
|
* @author pplitzner
|
36
|
* @date 18.07.2017
|
37
|
*/
|
38
|
public class DetailsPartE4 extends AbstractCdmEditorPart implements IPartContentHasSupplementalData, IPartContentHasFactualData {
|
39
|
|
40
|
@Inject
|
41
|
public DetailsPartE4() {
|
42
|
}
|
43
|
|
44
|
@PostConstruct
|
45
|
public void create(Composite parent, MPart thisPart, IEclipseContext context) {
|
46
|
|
47
|
this.thisPart = thisPart;
|
48
|
|
49
|
viewer = ContextInjectionFactory.make(DetailsViewerE4.class, context);
|
50
|
((DetailsViewerE4)viewer).init(parent, this);
|
51
|
|
52
|
// Propagate selection from viewer
|
53
|
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
|
54
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
|
59
|
if (activePart==thisPart){
|
60
|
return;
|
61
|
}
|
62
|
|
63
|
Object partObject = getPartObject(activePart);
|
64
|
if (partObject instanceof SupplementalDataPartE4 ) {
|
65
|
// do not show empty page
|
66
|
return;
|
67
|
}
|
68
|
|
69
|
if(partObject instanceof IPartContentHasDetails){
|
70
|
IStructuredSelection structuredSelection = createSelection(selection);
|
71
|
if(structuredSelection == null || structuredSelection.isEmpty()){
|
72
|
showEmptyPage();
|
73
|
return;
|
74
|
}
|
75
|
|
76
|
// do not show details for feature nodes TODO strange check to avoid having shown the distribution map for every FeatureNodeContainer
|
77
|
if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
|
78
|
// do show the map for distributions
|
79
|
Feature feature = ((FeatureNodeContainer) structuredSelection.getFirstElement()).getFeature();
|
80
|
if(!feature.equals(Feature.DISTRIBUTION())){
|
81
|
showEmptyPage();
|
82
|
return;
|
83
|
}
|
84
|
}
|
85
|
|
86
|
//FIXME this is a temporary workaround to fix selection handling for supplemental data view
|
87
|
// Now the supp data view gets double selection from details view and name editor (see #7126)
|
88
|
|
89
|
viewer.setSelection(structuredSelection, false);
|
90
|
|
91
|
showViewer(structuredSelection, activePart, viewer);
|
92
|
|
93
|
return;
|
94
|
}
|
95
|
else{
|
96
|
showEmptyPage();
|
97
|
return;
|
98
|
}
|
99
|
}
|
100
|
|
101
|
public void refreshSelection(){
|
102
|
selectionChanged_internal(new StructuredSelection(this.viewer.getInput()), selectionProvidingPart, thisPart);
|
103
|
}
|
104
|
|
105
|
@Override
|
106
|
protected void showEmptyPage() {
|
107
|
super.showEmptyPage();
|
108
|
if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed() ){
|
109
|
try{
|
110
|
((DetailsViewerE4)viewer).destroySections();
|
111
|
}catch(SWTException e){
|
112
|
if (PreferencesUtil.isShowUpWidgetIsDisposedMessages() && e.getMessage().equals("Widget is disposed")){
|
113
|
MessagingUtils.errorDialog("Widget is disposed",
|
114
|
null,
|
115
|
MessagingUtils.WIDGET_IS_DISPOSED_MESSAGE,
|
116
|
null,
|
117
|
e,
|
118
|
true);
|
119
|
|
120
|
}
|
121
|
}
|
122
|
}
|
123
|
}
|
124
|
|
125
|
@Override
|
126
|
protected String getViewName(){
|
127
|
return Messages.DetailsViewPart_VIEWER_NAME;
|
128
|
}
|
129
|
|
130
|
}
|