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