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.viewers.AbstractTreeViewer;
|
24
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
25
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
26
|
import org.eclipse.jface.viewers.StructuredSelection;
|
27
|
import org.eclipse.jface.viewers.TreeNode;
|
28
|
import org.eclipse.jface.viewers.TreeViewer;
|
29
|
import org.eclipse.swt.SWT;
|
30
|
import org.eclipse.swt.dnd.DND;
|
31
|
import org.eclipse.swt.dnd.Transfer;
|
32
|
import org.eclipse.swt.widgets.Composite;
|
33
|
import org.eclipse.swt.widgets.Tree;
|
34
|
|
35
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
36
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
37
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
38
|
import eu.etaxonomy.cdm.model.description.IDescribable;
|
39
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
40
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
41
|
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
|
42
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
43
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
44
|
import eu.etaxonomy.taxeditor.editor.view.checklist.ChecklistEditor;
|
45
|
import eu.etaxonomy.taxeditor.editor.view.concept.e4.ConceptViewPartE4;
|
46
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementDragListener;
|
47
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementDropAdapter;
|
48
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementTransfer;
|
49
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveContentProvider;
|
50
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveLabelProvider;
|
51
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewerSorter;
|
52
|
import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
|
53
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
54
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
55
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainerTree;
|
56
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
57
|
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
|
58
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
59
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
60
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
61
|
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
|
62
|
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
|
63
|
import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4;
|
64
|
import eu.etaxonomy.taxeditor.workbench.part.ICollapsableExpandable;
|
65
|
|
66
|
/**
|
67
|
* @author pplitzner
|
68
|
* @date 15.08.2017
|
69
|
*
|
70
|
*/
|
71
|
public class FactualDataPartE4 extends AbstractCdmEditorPartE4
|
72
|
implements IPartContentHasDetails, IPartContentHasSupplementalData, ICdmEntitySessionEnabled,
|
73
|
ICollapsableExpandable {
|
74
|
|
75
|
/**
|
76
|
* Maps {@link FeatureNodeContainerTree} to their corresponding {@link TaxonDescritpion}.<br>
|
77
|
* This serves as input for the {@link ITreeContentProvider} of the {@link TreeViewer}
|
78
|
*/
|
79
|
protected Map<DescriptionBase<?>, FeatureNodeContainerTree> featureNodeContainerCache = new HashMap<DescriptionBase<?>, FeatureNodeContainerTree>();
|
80
|
|
81
|
protected int dndOperations = DND.DROP_COPY | DND.DROP_MOVE;
|
82
|
|
83
|
private DescriptiveContentProvider provider;
|
84
|
|
85
|
@PostConstruct
|
86
|
public void create(Composite parent, EMenuService menuService, MPart thisPart,
|
87
|
IEclipseContext context) {
|
88
|
TreeViewer treeViewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL
|
89
|
| SWT.V_SCROLL | SWT.FULL_SELECTION));
|
90
|
|
91
|
this.thisPart = thisPart;
|
92
|
|
93
|
provider = new DescriptiveContentProvider(featureNodeContainerCache);
|
94
|
treeViewer.setContentProvider(provider);
|
95
|
treeViewer.setLabelProvider(new DescriptiveLabelProvider());
|
96
|
treeViewer.setSorter(new DescriptiveViewerSorter());
|
97
|
treeViewer.setAutoExpandLevel(2);
|
98
|
Transfer[] transfers = new Transfer[] { DescriptionElementTransfer.getInstance() };
|
99
|
treeViewer.addDragSupport(dndOperations, transfers, new DescriptionElementDragListener(
|
100
|
this));
|
101
|
DescriptionElementDropAdapter dropListener = new DescriptionElementDropAdapter(viewer);
|
102
|
ContextInjectionFactory.inject(dropListener, context);
|
103
|
treeViewer.addDropSupport(dndOperations, transfers,
|
104
|
dropListener);
|
105
|
|
106
|
viewer = treeViewer;
|
107
|
|
108
|
// Propagate selection from viewer
|
109
|
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
|
110
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
111
|
|
112
|
//create context menu
|
113
|
menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.factualDataView");
|
114
|
|
115
|
}
|
116
|
|
117
|
@Override
|
118
|
public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
|
119
|
if(activePart==thisPart){
|
120
|
return;
|
121
|
}
|
122
|
|
123
|
Object partObject = createPartObject(activePart);
|
124
|
|
125
|
if (partObject instanceof DetailsPartE4 || partObject instanceof SupplementalDataPartE4
|
126
|
|| partObject instanceof MediaViewPartE4 || partObject instanceof ConceptViewPartE4) {
|
127
|
// do not show empty page as these views are also used to edit the
|
128
|
// description selected in this view
|
129
|
return;
|
130
|
}
|
131
|
|
132
|
if(partObject instanceof IPartContentHasFactualData){
|
133
|
IStructuredSelection structuredSelection = createSelection(selection);
|
134
|
if(structuredSelection==null || structuredSelection.isEmpty()){
|
135
|
showEmptyPage();
|
136
|
return;
|
137
|
}
|
138
|
if(partObject instanceof ChecklistEditor){
|
139
|
if(structuredSelection.getFirstElement() instanceof Taxon){
|
140
|
Taxon taxon = (Taxon)structuredSelection.getFirstElement();
|
141
|
structuredSelection = new StructuredSelection(taxon);
|
142
|
}
|
143
|
}
|
144
|
Object firstElement = structuredSelection.getFirstElement();
|
145
|
if (partObject instanceof TaxonNameEditorE4){
|
146
|
if (firstElement != ((TaxonNameEditorE4)partObject).getTaxon()){
|
147
|
showEmptyPage();
|
148
|
return;
|
149
|
}
|
150
|
}
|
151
|
if(firstElement instanceof TreeNode){
|
152
|
firstElement = ((TreeNode) firstElement).getValue();
|
153
|
}
|
154
|
if(firstElement instanceof IDescribable<?>
|
155
|
&& partObject instanceof IPartContentHasFactualData
|
156
|
&& !(firstElement instanceof SpecimenOrObservationBase && partObject instanceof BulkEditor)){
|
157
|
|
158
|
featureNodeContainerCache.clear();
|
159
|
showViewer(structuredSelection, activePart, viewer);
|
160
|
return;
|
161
|
}
|
162
|
}
|
163
|
showEmptyPage();
|
164
|
return;
|
165
|
}
|
166
|
|
167
|
@Override
|
168
|
protected String getViewName(){
|
169
|
return Messages.DescriptiveViewPart_FACTUAL_DATA;
|
170
|
}
|
171
|
|
172
|
/** {@inheritDoc} */
|
173
|
@Override
|
174
|
public void changed(Object object) {
|
175
|
for(FeatureNodeContainerTree containerTree : featureNodeContainerCache.values()){
|
176
|
containerTree.buildTree();
|
177
|
}
|
178
|
((AbstractTreeViewer) viewer).expandToLevel(2);
|
179
|
viewer.refresh();
|
180
|
|
181
|
if(object instanceof DescriptionElementBase){
|
182
|
DescriptionElementBase descriptionElement = (DescriptionElementBase) object;
|
183
|
DescriptionBase description = descriptionElement.getInDescription();
|
184
|
FeatureNodeContainerTree containerTree = featureNodeContainerCache.get(description);
|
185
|
|
186
|
FeatureNodeContainer featureNodeContainer = containerTree.getFeatureNodeContainerForDescriptionElement(descriptionElement);
|
187
|
((AbstractTreeViewer) viewer).expandToLevel(featureNodeContainer, 1);
|
188
|
|
189
|
}
|
190
|
|
191
|
if(object != null){
|
192
|
StructuredSelection selection = new StructuredSelection(object);
|
193
|
viewer.setSelection(selection, true);
|
194
|
}
|
195
|
// if(part instanceof BulkEditor && !(object instanceof SpecimenOrObservationBase<?>)){
|
196
|
// ((BulkEditor) part).forceDirty();
|
197
|
// IStructuredSelection selection = (IStructuredSelection) ((BulkEditor) part).getSelectionProvider().getSelection();
|
198
|
// ((BulkEditor) part).changed(selection.getFirstElement());
|
199
|
//
|
200
|
// }
|
201
|
//
|
202
|
// if (part instanceof E4PartWrapper){
|
203
|
// part = WorkbenchUtility.getE4WrappedPart(part);
|
204
|
// if (part instanceof IDirtyMarkable){
|
205
|
// StructuredSelection selection = new StructuredSelection(object);
|
206
|
// ((IDirtyMarkable)part).changed(selection.getFirstElement());
|
207
|
// }
|
208
|
// }
|
209
|
|
210
|
|
211
|
super.changed(object);
|
212
|
}
|
213
|
|
214
|
/**
|
215
|
* {@inheritDoc}
|
216
|
*/
|
217
|
@Override
|
218
|
public void collapse() {
|
219
|
if(viewer instanceof TreeViewer) {
|
220
|
((TreeViewer) viewer).collapseAll();
|
221
|
}
|
222
|
}
|
223
|
|
224
|
/**
|
225
|
* {@inheritDoc}
|
226
|
*/
|
227
|
@Override
|
228
|
public void expand() {
|
229
|
if(viewer instanceof TreeViewer) {
|
230
|
((TreeViewer) viewer).expandAll();
|
231
|
}
|
232
|
}
|
233
|
|
234
|
public void toggleShowOnlyIndividualAssociations(){
|
235
|
provider.toggleShowOnlyIndividualAssociations();
|
236
|
viewer.refresh();
|
237
|
}
|
238
|
|
239
|
@Override
|
240
|
public ICdmEntitySession getCdmEntitySession() {
|
241
|
if(selectionProvidingPart != null && selectionProvidingPart instanceof ICdmEntitySessionEnabled) {
|
242
|
return ((ICdmEntitySessionEnabled) selectionProvidingPart).getCdmEntitySession();
|
243
|
}
|
244
|
return null;
|
245
|
}
|
246
|
|
247
|
@Override
|
248
|
public List<? extends CdmBase> getRootEntities() {
|
249
|
return Arrays.asList((CdmBase)getViewer().getInput());
|
250
|
}
|
251
|
@Override
|
252
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
253
|
return null;
|
254
|
}
|
255
|
|
256
|
}
|