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