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.editor.view.descriptive.e4;
|
11
|
|
12
|
import java.util.Arrays;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.List;
|
15
|
import java.util.Map;
|
16
|
|
17
|
import javax.annotation.PostConstruct;
|
18
|
import javax.inject.Inject;
|
19
|
|
20
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
21
|
import org.eclipse.e4.ui.services.EMenuService;
|
22
|
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
23
|
import org.eclipse.jface.action.Action;
|
24
|
import org.eclipse.jface.action.IAction;
|
25
|
import org.eclipse.jface.resource.ImageDescriptor;
|
26
|
import org.eclipse.jface.viewers.AbstractTreeViewer;
|
27
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
28
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
29
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
30
|
import org.eclipse.jface.viewers.StructuredSelection;
|
31
|
import org.eclipse.jface.viewers.TreeNode;
|
32
|
import org.eclipse.jface.viewers.TreeViewer;
|
33
|
import org.eclipse.swt.SWT;
|
34
|
import org.eclipse.swt.dnd.DND;
|
35
|
import org.eclipse.swt.dnd.Transfer;
|
36
|
import org.eclipse.swt.graphics.ImageData;
|
37
|
import org.eclipse.swt.widgets.Composite;
|
38
|
import org.eclipse.swt.widgets.Tree;
|
39
|
|
40
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
41
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
42
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
43
|
import eu.etaxonomy.cdm.model.description.IDescribable;
|
44
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
45
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
46
|
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
|
47
|
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
|
48
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
49
|
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor;
|
50
|
import eu.etaxonomy.taxeditor.editor.view.concept.e4.ConceptViewPartE4;
|
51
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementDragListener;
|
52
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementDropAdapter;
|
53
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementTransfer;
|
54
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveContentProvider;
|
55
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveLabelProvider;
|
56
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewerSorter;
|
57
|
import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
|
58
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
59
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
60
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainerTree;
|
61
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
62
|
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
|
63
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
64
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
65
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
66
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
67
|
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
|
68
|
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
|
69
|
import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4;
|
70
|
|
71
|
/**
|
72
|
* @author pplitzner
|
73
|
* @date 15.08.2017
|
74
|
*
|
75
|
*/
|
76
|
public class FactualDataPartE4 extends AbstractCdmEditorPartE4
|
77
|
implements IPartContentHasDetails, IPartContentHasSupplementalData, ICdmEntitySessionEnabled {
|
78
|
|
79
|
/**
|
80
|
* Maps {@link FeatureNodeContainerTree} to their corresponding {@link TaxonDescritpion}.<br>
|
81
|
* This serves as input for the {@link ITreeContentProvider} of the {@link TreeViewer}
|
82
|
*/
|
83
|
protected Map<DescriptionBase<?>, FeatureNodeContainerTree> featureNodeContainerCache = new HashMap<DescriptionBase<?>, FeatureNodeContainerTree>();
|
84
|
|
85
|
protected ToggleDescriptionAction showAllElementsAction;
|
86
|
|
87
|
protected ToggleDescriptionAction hideAllElementsAction;
|
88
|
|
89
|
protected int dndOperations = DND.DROP_COPY | DND.DROP_MOVE;
|
90
|
|
91
|
private DescriptiveContentProvider provider;
|
92
|
|
93
|
private ISelectionChangedListener selectionChangedListener;
|
94
|
|
95
|
@Inject
|
96
|
private ESelectionService selService;
|
97
|
|
98
|
@PostConstruct
|
99
|
public void create(Composite parent, EMenuService menuService) {
|
100
|
TreeViewer treeViewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL
|
101
|
| SWT.V_SCROLL | SWT.FULL_SELECTION));
|
102
|
provider = new DescriptiveContentProvider(featureNodeContainerCache);
|
103
|
treeViewer.setContentProvider(provider);
|
104
|
treeViewer.setLabelProvider(new DescriptiveLabelProvider());
|
105
|
treeViewer.setSorter(new DescriptiveViewerSorter());
|
106
|
treeViewer.setAutoExpandLevel(2);
|
107
|
Transfer[] transfers = new Transfer[] { DescriptionElementTransfer.getInstance() };
|
108
|
treeViewer.addDragSupport(dndOperations, transfers, new DescriptionElementDragListener(
|
109
|
this));
|
110
|
treeViewer.addDropSupport(dndOperations, transfers,
|
111
|
new DescriptionElementDropAdapter(viewer));
|
112
|
|
113
|
viewer = treeViewer;
|
114
|
|
115
|
// Propagate selection from viewer
|
116
|
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
|
117
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
118
|
|
119
|
//create context menu
|
120
|
menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.factualDataView");
|
121
|
|
122
|
showAllElementsAction = new ToggleDescriptionAction(false);
|
123
|
hideAllElementsAction = new ToggleDescriptionAction(true);
|
124
|
|
125
|
//FIXME E4 implement toolbar
|
126
|
// createToolbar();
|
127
|
|
128
|
}
|
129
|
|
130
|
// protected void createToolbar() {
|
131
|
// IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
|
132
|
// toolBarManager.add(showAllElementsAction);
|
133
|
// toolBarManager.add(hideAllElementsAction);
|
134
|
// }
|
135
|
|
136
|
|
137
|
@Override
|
138
|
public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
|
139
|
if(activePart==thisPart){
|
140
|
return;
|
141
|
}
|
142
|
|
143
|
Object partObject = createPartObject(activePart);
|
144
|
|
145
|
if (partObject instanceof DetailsPartE4 || partObject instanceof SupplementalDataPartE4
|
146
|
|| partObject instanceof MediaViewPartE4 || partObject instanceof ConceptViewPartE4) {
|
147
|
// do not show empty page as these views are also used to edit the
|
148
|
// description selected in this view
|
149
|
return;
|
150
|
}
|
151
|
|
152
|
if(partObject instanceof IPartContentHasFactualData){
|
153
|
IStructuredSelection structuredSelection = createSelection(selection);
|
154
|
if(structuredSelection==null || structuredSelection.isEmpty()){
|
155
|
showEmptyPage();
|
156
|
return;
|
157
|
}
|
158
|
if(partObject instanceof ChecklistEditor){
|
159
|
if(structuredSelection.getFirstElement() instanceof Taxon){
|
160
|
Taxon taxon = (Taxon)structuredSelection.getFirstElement();
|
161
|
structuredSelection = new StructuredSelection(taxon);
|
162
|
}
|
163
|
}
|
164
|
Object firstElement = structuredSelection.getFirstElement();
|
165
|
if (partObject instanceof MultiPageTaxonEditor){
|
166
|
if (firstElement != ((MultiPageTaxonEditor)partObject).getTaxon()){
|
167
|
showEmptyPage();
|
168
|
return;
|
169
|
}
|
170
|
}
|
171
|
if(firstElement instanceof TreeNode){
|
172
|
firstElement = ((TreeNode) firstElement).getValue();
|
173
|
}
|
174
|
if(firstElement instanceof IDescribable<?>
|
175
|
&& partObject instanceof IPartContentHasFactualData
|
176
|
&& !(firstElement instanceof SpecimenOrObservationBase && partObject instanceof BulkEditor)){
|
177
|
|
178
|
featureNodeContainerCache.clear();
|
179
|
showViewer(structuredSelection, activePart, viewer);
|
180
|
return;
|
181
|
}
|
182
|
}
|
183
|
showEmptyPage();
|
184
|
return;
|
185
|
}
|
186
|
|
187
|
@Override
|
188
|
protected String getViewName(){
|
189
|
return Messages.DescriptiveViewPart_FACTUAL_DATA;
|
190
|
}
|
191
|
|
192
|
/**
|
193
|
*
|
194
|
* @author n.hoffmann
|
195
|
* @created May 28, 2010
|
196
|
* @version 1.0
|
197
|
*/
|
198
|
protected class ToggleDescriptionAction extends Action{
|
199
|
private final boolean expanded;
|
200
|
|
201
|
public ToggleDescriptionAction(boolean expand){
|
202
|
super(null, IAction.AS_PUSH_BUTTON);
|
203
|
expanded = expand;
|
204
|
setImageAndTooltip();
|
205
|
}
|
206
|
|
207
|
private void setImageAndTooltip(){
|
208
|
setImageDescriptor(new ImageDescriptor() {
|
209
|
@Override
|
210
|
public ImageData getImageData() {
|
211
|
setText(expanded ? Messages.DescriptiveViewPart_COLLAPSE_ALL : Messages.DescriptiveViewPart_EXPAND_ALL);
|
212
|
String resource = expanded ? ImageResources.COLLAPSE_ALL : ImageResources.EXPAND_ALL;
|
213
|
return ImageResources.getImage(resource).getImageData();
|
214
|
}
|
215
|
});
|
216
|
|
217
|
String toolTipText = expanded ? Messages.DescriptiveViewPart_COLLAPSE_ALL : Messages.DescriptiveViewPart_SHOW_ALL_DATA;
|
218
|
setToolTipText(toolTipText);
|
219
|
}
|
220
|
|
221
|
@Override
|
222
|
public void run() {
|
223
|
if(expanded){
|
224
|
((AbstractTreeViewer) viewer).collapseAll();
|
225
|
}else{
|
226
|
((AbstractTreeViewer) viewer).expandAll();
|
227
|
}
|
228
|
setImageAndTooltip();
|
229
|
}
|
230
|
}
|
231
|
|
232
|
/** {@inheritDoc} */
|
233
|
@Override
|
234
|
public void changed(Object object) {
|
235
|
for(FeatureNodeContainerTree containerTree : featureNodeContainerCache.values()){
|
236
|
containerTree.buildTree();
|
237
|
}
|
238
|
((AbstractTreeViewer) viewer).expandToLevel(2);
|
239
|
viewer.refresh();
|
240
|
|
241
|
if(object instanceof DescriptionElementBase){
|
242
|
DescriptionElementBase descriptionElement = (DescriptionElementBase) object;
|
243
|
DescriptionBase description = descriptionElement.getInDescription();
|
244
|
FeatureNodeContainerTree containerTree = featureNodeContainerCache.get(description);
|
245
|
|
246
|
FeatureNodeContainer featureNodeContainer = containerTree.getFeatureNodeContainerForDescriptionElement(descriptionElement);
|
247
|
((AbstractTreeViewer) viewer).expandToLevel(featureNodeContainer, 1);
|
248
|
|
249
|
}
|
250
|
|
251
|
if(object != null){
|
252
|
StructuredSelection selection = new StructuredSelection(object);
|
253
|
viewer.setSelection(selection, true);
|
254
|
}
|
255
|
// if(part instanceof BulkEditor && !(object instanceof SpecimenOrObservationBase<?>)){
|
256
|
// ((BulkEditor) part).forceDirty();
|
257
|
// IStructuredSelection selection = (IStructuredSelection) ((BulkEditor) part).getSelectionProvider().getSelection();
|
258
|
// ((BulkEditor) part).changed(selection.getFirstElement());
|
259
|
//
|
260
|
// }
|
261
|
//
|
262
|
// if (part instanceof E4PartWrapper){
|
263
|
// part = WorkbenchUtility.getE4WrappedPart(part);
|
264
|
// if (part instanceof IDirtyMarkable){
|
265
|
// StructuredSelection selection = new StructuredSelection(object);
|
266
|
// ((IDirtyMarkable)part).changed(selection.getFirstElement());
|
267
|
// }
|
268
|
// }
|
269
|
|
270
|
|
271
|
super.changed(object);
|
272
|
}
|
273
|
|
274
|
public void toggleShowOnlyIndividualAssociations(){
|
275
|
provider.toggleShowOnlyIndividualAssociations();
|
276
|
viewer.refresh();
|
277
|
}
|
278
|
|
279
|
@Override
|
280
|
public ICdmEntitySession getCdmEntitySession() {
|
281
|
if(selectionProvidingPart != null && selectionProvidingPart instanceof ICdmEntitySessionEnabled) {
|
282
|
return ((ICdmEntitySessionEnabled) selectionProvidingPart).getCdmEntitySession();
|
283
|
}
|
284
|
return null;
|
285
|
}
|
286
|
|
287
|
@Override
|
288
|
public List<? extends CdmBase> getRootEntities() {
|
289
|
return Arrays.asList((CdmBase)getViewer().getInput());
|
290
|
}
|
291
|
@Override
|
292
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
293
|
return null;
|
294
|
}
|
295
|
|
296
|
}
|