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.annotation.PreDestroy;
|
14
|
import javax.inject.Inject;
|
15
|
import javax.inject.Named;
|
16
|
|
17
|
import org.eclipse.e4.core.di.annotations.Optional;
|
18
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
19
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
20
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
21
|
import org.eclipse.jface.viewers.StructuredSelection;
|
22
|
import org.eclipse.jface.viewers.Viewer;
|
23
|
import org.eclipse.swt.widgets.Composite;
|
24
|
import org.eclipse.ui.IEditorPart;
|
25
|
|
26
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
27
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
28
|
import eu.etaxonomy.cdm.model.description.Feature;
|
29
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
30
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
31
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
32
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
33
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
34
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
35
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
36
|
|
37
|
/**
|
38
|
* @author pplitzner
|
39
|
* @date 18.07.2017
|
40
|
*
|
41
|
*/
|
42
|
public class DetailsPartE4 implements IConversationEnabled, IDirtyMarkable{
|
43
|
|
44
|
private DetailsViewerE4 viewer;
|
45
|
|
46
|
private MPart selectionProvidingPart;
|
47
|
|
48
|
@Inject
|
49
|
public DetailsPartE4() {
|
50
|
}
|
51
|
|
52
|
@PostConstruct
|
53
|
public void create(Composite parent) {
|
54
|
viewer = new DetailsViewerE4(parent, this);
|
55
|
}
|
56
|
|
57
|
@Inject
|
58
|
@Optional
|
59
|
public void selectionChanged(
|
60
|
@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
|
61
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
62
|
MPart thisPart){
|
63
|
if(activePart==thisPart){
|
64
|
return;
|
65
|
}
|
66
|
if(selection==null){
|
67
|
showEmptyPage();
|
68
|
return;
|
69
|
}
|
70
|
|
71
|
Object partObject = activePart;
|
72
|
Object wrappedPart = WorkbenchUtility.getE4WrappedPart(activePart);
|
73
|
if(wrappedPart!=null){
|
74
|
partObject = wrappedPart;
|
75
|
}
|
76
|
|
77
|
IStructuredSelection structuredSelection;
|
78
|
if(!(selection instanceof IStructuredSelection)){
|
79
|
structuredSelection = new StructuredSelection(selection);
|
80
|
}
|
81
|
else{
|
82
|
structuredSelection = (IStructuredSelection) selection;
|
83
|
}
|
84
|
if(structuredSelection.isEmpty()){
|
85
|
showEmptyPage();
|
86
|
return;
|
87
|
}
|
88
|
if((partObject instanceof IEditorPart) || (partObject instanceof IPartContentHasDetails)
|
89
|
&& partObject instanceof IConversationEnabled) {
|
90
|
// do not show details for feature nodes TODO strange check to avoid having shown the distribution map for every FeatureNodeContainer
|
91
|
if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
|
92
|
// do show the map for distributions
|
93
|
Feature feature = ((FeatureNodeContainer) ((IStructuredSelection) selection).getFirstElement()).getFeature();
|
94
|
if(!feature.equals(Feature.DISTRIBUTION())){
|
95
|
showEmptyPage();
|
96
|
return;
|
97
|
}
|
98
|
}
|
99
|
showViewer(structuredSelection);
|
100
|
selectionProvidingPart = activePart;
|
101
|
}
|
102
|
else{
|
103
|
showEmptyPage();
|
104
|
return;
|
105
|
}
|
106
|
}
|
107
|
|
108
|
public void showEmptyPage() {
|
109
|
if(viewer!=null){
|
110
|
viewer.showEmptyPage();
|
111
|
}
|
112
|
selectionProvidingPart = null;
|
113
|
}
|
114
|
|
115
|
protected String getViewName(){
|
116
|
return Messages.DetailsViewPart_VIEWER_NAME;
|
117
|
}
|
118
|
|
119
|
public Viewer getViewer() {
|
120
|
return viewer;
|
121
|
}
|
122
|
|
123
|
|
124
|
@PreDestroy
|
125
|
public void dispose() {
|
126
|
}
|
127
|
|
128
|
public void showViewer(IStructuredSelection selection){
|
129
|
if(getViewer()!=null){
|
130
|
Object element = selection.getFirstElement();
|
131
|
if(selection.getFirstElement()!=null){
|
132
|
getViewer().setInput(element);
|
133
|
}
|
134
|
}
|
135
|
}
|
136
|
|
137
|
/**
|
138
|
* {@inheritDoc}
|
139
|
*/
|
140
|
@Override
|
141
|
public void update(CdmDataChangeMap arg0) {
|
142
|
// TODO Auto-generated method stub
|
143
|
|
144
|
}
|
145
|
|
146
|
/**
|
147
|
* {@inheritDoc}
|
148
|
*/
|
149
|
@Override
|
150
|
public ConversationHolder getConversationHolder() {
|
151
|
if(selectionProvidingPart != null && selectionProvidingPart instanceof IConversationEnabled) {
|
152
|
return ((IConversationEnabled) selectionProvidingPart).getConversationHolder();
|
153
|
}
|
154
|
return null;
|
155
|
}
|
156
|
|
157
|
/** {@inheritDoc} */
|
158
|
@Override
|
159
|
public void changed(Object object) {
|
160
|
Object part = selectionProvidingPart.getObject();
|
161
|
if(part instanceof IDirtyMarkable){
|
162
|
((IDirtyMarkable) part).changed(object);
|
163
|
}
|
164
|
else {
|
165
|
IEditorPart editor = AbstractUtility.getActiveEditor();
|
166
|
if (editor != null && editor instanceof IDirtyMarkable) {
|
167
|
((IDirtyMarkable) editor).changed(object);
|
168
|
}
|
169
|
}
|
170
|
}
|
171
|
|
172
|
/**
|
173
|
* {@inheritDoc}
|
174
|
*/
|
175
|
@Override
|
176
|
public void forceDirty() {
|
177
|
// TODO Auto-generated method stub
|
178
|
|
179
|
}
|
180
|
}
|