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