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
|
import java.util.Set;
|
17
|
|
18
|
import javax.annotation.PostConstruct;
|
19
|
import javax.inject.Inject;
|
20
|
|
21
|
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
22
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
23
|
import org.eclipse.e4.core.di.annotations.Optional;
|
24
|
import org.eclipse.e4.ui.di.UIEventTopic;
|
25
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
26
|
import org.eclipse.e4.ui.services.EMenuService;
|
27
|
import org.eclipse.jface.viewers.AbstractTreeViewer;
|
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.widgets.Composite;
|
37
|
import org.eclipse.swt.widgets.Tree;
|
38
|
|
39
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
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.description.TaxonDescription;
|
45
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
46
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
47
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
48
|
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditorE4;
|
49
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
50
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
51
|
import eu.etaxonomy.taxeditor.editor.view.concept.e4.ConceptViewPartE4;
|
52
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementDragListener;
|
53
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementDropAdapter;
|
54
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementTransfer;
|
55
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveContentProvider;
|
56
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveLabelProvider;
|
57
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewerSorter;
|
58
|
import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
|
59
|
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
|
60
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
61
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainerTree;
|
62
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
63
|
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
|
64
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
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
|
import eu.etaxonomy.taxeditor.workbench.part.ICollapsableExpandable;
|
71
|
|
72
|
/**
|
73
|
* @author pplitzner
|
74
|
* @date 15.08.2017
|
75
|
*
|
76
|
*/
|
77
|
public class FactualDataPartE4 extends AbstractCdmEditorPartE4
|
78
|
implements IPartContentHasDetails, IPartContentHasSupplementalData, ICdmEntitySessionEnabled,
|
79
|
ICollapsableExpandable {
|
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 int dndOperations = DND.DROP_COPY | DND.DROP_MOVE;
|
88
|
|
89
|
private DescriptiveContentProvider provider;
|
90
|
|
91
|
@PostConstruct
|
92
|
public void create(Composite parent, EMenuService menuService, MPart thisPart,
|
93
|
IEclipseContext context) {
|
94
|
TreeViewer treeViewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL
|
95
|
| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI));
|
96
|
|
97
|
this.thisPart = thisPart;
|
98
|
|
99
|
provider = new DescriptiveContentProvider(featureNodeContainerCache);
|
100
|
treeViewer.setContentProvider(provider);
|
101
|
treeViewer.setLabelProvider(new DescriptiveLabelProvider());
|
102
|
treeViewer.setSorter(new DescriptiveViewerSorter());
|
103
|
treeViewer.setAutoExpandLevel(2);
|
104
|
Transfer[] transfers = new Transfer[] { DescriptionElementTransfer.getInstance() };
|
105
|
treeViewer.addDragSupport(dndOperations, transfers, new DescriptionElementDragListener(
|
106
|
this));
|
107
|
|
108
|
|
109
|
viewer = treeViewer;
|
110
|
|
111
|
// Propagate selection from viewer
|
112
|
selectionChangedListener = (event -> selService.setSelection(event.getSelection()));
|
113
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
114
|
DescriptionElementDropAdapter dropListener = new DescriptionElementDropAdapter(viewer);
|
115
|
ContextInjectionFactory.inject(dropListener, context);
|
116
|
treeViewer.addDropSupport(dndOperations, transfers,
|
117
|
dropListener);
|
118
|
//create context menu
|
119
|
menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.factualDataView");
|
120
|
|
121
|
}
|
122
|
|
123
|
@Override
|
124
|
public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
|
125
|
if(activePart==thisPart){
|
126
|
return;
|
127
|
}
|
128
|
|
129
|
Object partObject = createPartObject(activePart);
|
130
|
|
131
|
if (partObject instanceof DetailsPartE4 || partObject instanceof SupplementalDataPartE4
|
132
|
|| partObject instanceof MediaViewPartE4 || partObject instanceof ConceptViewPartE4) {
|
133
|
// do not show empty page as these views are also used to edit the
|
134
|
// description selected in this view
|
135
|
return;
|
136
|
}
|
137
|
// if(partObject instanceof ChecklistEditorE4){
|
138
|
// IWorkbenchPage page = PlatformUI.getWorkbench()
|
139
|
// .getActiveWorkbenchWindow().getActivePage();
|
140
|
// page.hideView(page.findView("eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4"));
|
141
|
// }
|
142
|
|
143
|
if(partObject instanceof IPartContentHasFactualData){
|
144
|
if (!viewer.getControl().isDisposed()){
|
145
|
viewer.getControl().setEnabled(true);
|
146
|
}
|
147
|
IStructuredSelection structuredSelection = createSelection(selection);
|
148
|
if(structuredSelection==null || structuredSelection.isEmpty()){
|
149
|
showEmptyPage();
|
150
|
return;
|
151
|
}
|
152
|
|
153
|
Object firstElement = structuredSelection.getFirstElement();
|
154
|
if (partObject instanceof TaxonNameEditorE4){
|
155
|
if (firstElement != ((TaxonNameEditorE4)partObject).getTaxon()){
|
156
|
showEmptyPage();
|
157
|
return;
|
158
|
}
|
159
|
}
|
160
|
|
161
|
if(firstElement instanceof TreeNode){
|
162
|
firstElement = ((TreeNode) firstElement).getValue();
|
163
|
}
|
164
|
if(firstElement instanceof IDescribable<?>
|
165
|
&& partObject instanceof IPartContentHasFactualData
|
166
|
&& !(firstElement instanceof SpecimenOrObservationBase && partObject instanceof BulkEditorE4)
|
167
|
&& !(firstElement instanceof TaxonName && partObject instanceof BulkEditorE4)){
|
168
|
|
169
|
featureNodeContainerCache.clear();
|
170
|
showViewer(structuredSelection, activePart, viewer);
|
171
|
return;
|
172
|
}
|
173
|
}
|
174
|
showEmptyPage();
|
175
|
return;
|
176
|
}
|
177
|
|
178
|
@Override
|
179
|
protected String getViewName(){
|
180
|
return Messages.DescriptiveViewPart_FACTUAL_DATA;
|
181
|
}
|
182
|
|
183
|
/** {@inheritDoc} */
|
184
|
@Override
|
185
|
public void changed(Object object) {
|
186
|
for(FeatureNodeContainerTree containerTree : featureNodeContainerCache.values()){
|
187
|
containerTree.buildTree();
|
188
|
}
|
189
|
|
190
|
if(object instanceof DescriptionElementBase){
|
191
|
DescriptionElementBase descriptionElement = (DescriptionElementBase) object;
|
192
|
DescriptionBase description = descriptionElement.getInDescription();
|
193
|
FeatureNodeContainerTree containerTree = featureNodeContainerCache.get(description);
|
194
|
|
195
|
FeatureNodeContainer featureNodeContainer = containerTree.getFeatureNodeContainerForDescriptionElement(descriptionElement);
|
196
|
((AbstractTreeViewer) viewer).expandToLevel(featureNodeContainer, 1);
|
197
|
|
198
|
}
|
199
|
((AbstractTreeViewer) viewer).expandToLevel(2);
|
200
|
viewer.refresh();
|
201
|
|
202
|
|
203
|
if(object != null){
|
204
|
StructuredSelection selection = new StructuredSelection(object);
|
205
|
viewer.setSelection(selection, true);
|
206
|
}
|
207
|
super.changed(object);
|
208
|
}
|
209
|
|
210
|
@Inject
|
211
|
@Optional
|
212
|
private void updateView(@UIEventTopic(WorkbenchEventConstants.SAVE_TAXON)boolean refresh){
|
213
|
if(refresh){
|
214
|
List<? extends CdmBase> rootEntities = getRootEntities();
|
215
|
for (CdmBase cdmBase : rootEntities) {
|
216
|
if(cdmBase.isInstanceOf(Taxon.class)){
|
217
|
Taxon taxon = HibernateProxyHelper.deproxy(cdmBase, Taxon.class);
|
218
|
Set<TaxonDescription> descriptions = taxon.getDescriptions();
|
219
|
for (TaxonDescription taxonDescription : descriptions) {
|
220
|
taxonDescription.setTitleCache(null, false);
|
221
|
}
|
222
|
}
|
223
|
}
|
224
|
viewer.refresh();
|
225
|
}
|
226
|
}
|
227
|
|
228
|
/**
|
229
|
* {@inheritDoc}
|
230
|
*/
|
231
|
@Override
|
232
|
public void collapse() {
|
233
|
if(viewer instanceof TreeViewer) {
|
234
|
((TreeViewer) viewer).collapseAll();
|
235
|
}
|
236
|
}
|
237
|
|
238
|
/**
|
239
|
* {@inheritDoc}
|
240
|
*/
|
241
|
@Override
|
242
|
public void expand() {
|
243
|
if(viewer instanceof TreeViewer) {
|
244
|
((TreeViewer) viewer).expandAll();
|
245
|
}
|
246
|
}
|
247
|
|
248
|
public void toggleShowOnlyIndividualAssociations(){
|
249
|
provider.toggleShowOnlyIndividualAssociations();
|
250
|
viewer.refresh();
|
251
|
}
|
252
|
|
253
|
@Override
|
254
|
public ICdmEntitySession getCdmEntitySession() {
|
255
|
if(selectionProvidingPart != null && selectionProvidingPart instanceof ICdmEntitySessionEnabled) {
|
256
|
return ((ICdmEntitySessionEnabled) selectionProvidingPart).getCdmEntitySession();
|
257
|
}
|
258
|
return null;
|
259
|
}
|
260
|
|
261
|
@Override
|
262
|
public List<? extends CdmBase> getRootEntities() {
|
263
|
return Arrays.asList((CdmBase)getViewer().getInput());
|
264
|
}
|
265
|
@Override
|
266
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
267
|
return null;
|
268
|
}
|
269
|
|
270
|
}
|