1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2017 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.view.e4.details;
|
11
|
|
12
|
import javax.annotation.PostConstruct;
|
13
|
import javax.inject.Inject;
|
14
|
|
15
|
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
16
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
17
|
import org.eclipse.e4.core.services.log.Logger;
|
18
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
19
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
20
|
import org.eclipse.swt.SWTException;
|
21
|
import org.eclipse.swt.widgets.Composite;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
24
|
import eu.etaxonomy.cdm.model.description.Feature;
|
25
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
26
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
27
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
28
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
29
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
30
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
31
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
32
|
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
|
33
|
import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4;
|
34
|
import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
|
35
|
|
36
|
/**
|
37
|
* @author pplitzner
|
38
|
* @date 18.07.2017
|
39
|
*
|
40
|
*/
|
41
|
public class DetailsPartE4 extends AbstractCdmEditorPartE4 implements IPartContentHasSupplementalData {
|
42
|
@Inject
|
43
|
private Logger logger;
|
44
|
|
45
|
@Inject
|
46
|
public DetailsPartE4() {
|
47
|
}
|
48
|
|
49
|
@PostConstruct
|
50
|
public void create(Composite parent, MPart thisPart, IEclipseContext context) {
|
51
|
|
52
|
this.thisPart = thisPart;
|
53
|
|
54
|
viewer = ContextInjectionFactory.make(DetailsViewerE4.class, context);
|
55
|
((DetailsViewerE4)viewer).init(parent, this);
|
56
|
|
57
|
// Propagate selection from viewer
|
58
|
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
|
59
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
60
|
}
|
61
|
|
62
|
@Override
|
63
|
public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
|
64
|
if (activePart==thisPart){
|
65
|
return;
|
66
|
}
|
67
|
|
68
|
Object partObject = createPartObject(activePart);
|
69
|
if (partObject instanceof SupplementalDataPartE4) {
|
70
|
// do not show empty page
|
71
|
return;
|
72
|
}
|
73
|
|
74
|
if(partObject instanceof IPartContentHasDetails){
|
75
|
IStructuredSelection structuredSelection = createSelection(selection);
|
76
|
if(structuredSelection==null || structuredSelection.isEmpty()){
|
77
|
showEmptyPage();
|
78
|
return;
|
79
|
}
|
80
|
if(!(partObject instanceof ISelectionElementEditingPart) &&
|
81
|
partObject instanceof IConversationEnabled && ((IConversationEnabled) partObject).getConversationHolder()==null) {
|
82
|
//TODO show specific message (refactor EmptyElement to allow specific messages)
|
83
|
showEmptyPage();
|
84
|
return;
|
85
|
}
|
86
|
// do not show details for feature nodes TODO strange check to avoid having shown the distribution map for every FeatureNodeContainer
|
87
|
if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
|
88
|
// do show the map for distributions
|
89
|
Feature feature = ((FeatureNodeContainer) structuredSelection.getFirstElement()).getFeature();
|
90
|
if(!feature.equals(Feature.DISTRIBUTION())){
|
91
|
showEmptyPage();
|
92
|
return;
|
93
|
}
|
94
|
}
|
95
|
// if (partObject instanceof IDistributionEditor){
|
96
|
//
|
97
|
// showViewer(structuredSelection, activePart, viewer);
|
98
|
// return;
|
99
|
//
|
100
|
// }
|
101
|
//FIXME this is a temporary workaround to fix selection handling for supplemental data view
|
102
|
// Now the supp data view gets double selection from details view and name editor (see #7126)
|
103
|
viewer.setSelection(structuredSelection, false);
|
104
|
showViewer(structuredSelection, activePart, viewer);
|
105
|
return;
|
106
|
}
|
107
|
else{
|
108
|
showEmptyPage();
|
109
|
return;
|
110
|
}
|
111
|
}
|
112
|
|
113
|
@Override
|
114
|
protected void showEmptyPage() {
|
115
|
super.showEmptyPage();
|
116
|
if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed() ){
|
117
|
try{
|
118
|
((DetailsViewerE4)viewer).destroySections();
|
119
|
}catch(SWTException e){
|
120
|
if (PreferencesUtil.isShowUpWidgetIsDisposedMessages() && e.getMessage().equals("Widget is disposed")){
|
121
|
MessagingUtils.errorDialog("Widget is disposed",
|
122
|
null,
|
123
|
MessagingUtils.WIDGET_IS_DISPOSED_MESSAGE,
|
124
|
null,
|
125
|
e,
|
126
|
true);
|
127
|
|
128
|
}
|
129
|
}
|
130
|
}
|
131
|
}
|
132
|
|
133
|
@Override
|
134
|
protected String getViewName(){
|
135
|
return Messages.DetailsViewPart_VIEWER_NAME;
|
136
|
}
|
137
|
|
138
|
}
|