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
|
import javax.inject.Named;
|
15
|
|
16
|
import org.eclipse.e4.core.di.annotations.Optional;
|
17
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
18
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
19
|
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
20
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
21
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
22
|
import org.eclipse.swt.widgets.Composite;
|
23
|
|
24
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
25
|
import eu.etaxonomy.cdm.model.description.Feature;
|
26
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
27
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
28
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
29
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
30
|
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
|
31
|
import eu.etaxonomy.taxeditor.workbench.part.ISelectionElementEditingPart;
|
32
|
|
33
|
/**
|
34
|
* @author pplitzner
|
35
|
* @date 18.07.2017
|
36
|
*
|
37
|
*/
|
38
|
public class DetailsPartE4 extends AbstractCdmEditorPartE4{
|
39
|
|
40
|
private ISelectionChangedListener selectionChangedListener;
|
41
|
|
42
|
@Inject
|
43
|
private ESelectionService selService;
|
44
|
|
45
|
@Inject
|
46
|
public DetailsPartE4() {
|
47
|
}
|
48
|
|
49
|
@PostConstruct
|
50
|
public void create(Composite parent, MPart thisPart) {
|
51
|
|
52
|
this.thisPart = thisPart;
|
53
|
|
54
|
viewer = new DetailsViewerE4(parent, this);
|
55
|
|
56
|
// Propagate selection from viewer
|
57
|
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
|
58
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
59
|
}
|
60
|
|
61
|
@Inject
|
62
|
@Optional
|
63
|
public void selectionChanged(
|
64
|
@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
|
65
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
66
|
MPart thisPart){
|
67
|
if(activePart==thisPart){
|
68
|
return;
|
69
|
}
|
70
|
|
71
|
Object partObject = createPartObject(activePart);
|
72
|
|
73
|
if(partObject instanceof IPartContentHasDetails){
|
74
|
IStructuredSelection structuredSelection = createSelection(selection);
|
75
|
if(structuredSelection==null || structuredSelection.isEmpty()){
|
76
|
showEmptyPage();
|
77
|
return;
|
78
|
}
|
79
|
if(!(partObject instanceof ISelectionElementEditingPart) &&
|
80
|
partObject instanceof IConversationEnabled && ((IConversationEnabled) partObject).getConversationHolder()==null) {
|
81
|
//TODO show specific message (refactor EmptyElement to allow specific messages)
|
82
|
showEmptyPage();
|
83
|
return;
|
84
|
}
|
85
|
// do not show details for feature nodes TODO strange check to avoid having shown the distribution map for every FeatureNodeContainer
|
86
|
if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
|
87
|
// do show the map for distributions
|
88
|
Feature feature = ((FeatureNodeContainer) structuredSelection.getFirstElement()).getFeature();
|
89
|
if(!feature.equals(Feature.DISTRIBUTION())){
|
90
|
showEmptyPage();
|
91
|
return;
|
92
|
}
|
93
|
}
|
94
|
showViewer(structuredSelection, activePart, viewer);
|
95
|
return;
|
96
|
}
|
97
|
else if(selectionProvidingPart!=null && selectionProvidingPart.isVisible()){
|
98
|
return;
|
99
|
}
|
100
|
else{
|
101
|
showEmptyPage();
|
102
|
return;
|
103
|
}
|
104
|
}
|
105
|
|
106
|
// protected void showEmptyPage() {
|
107
|
// super.showEmptyPage();
|
108
|
// if(viewer!=null){
|
109
|
// viewer.showEmptyPage();
|
110
|
// }
|
111
|
// selectionProvidingPart = null;
|
112
|
// }
|
113
|
|
114
|
@Override
|
115
|
protected String getViewName(){
|
116
|
return Messages.DetailsViewPart_VIEWER_NAME;
|
117
|
}
|
118
|
|
119
|
}
|