1 |
860fc861
|
Patrick Plitzner
|
/**
|
2 |
|
|
* Copyright (C) 2017 EDIT
|
3 |
|
|
* European Distributed Institute of Taxonomy
|
4 |
|
|
* http://www.e-taxonomy.eu
|
5 |
|
|
*
|
6 |
|
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7 |
|
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8 |
|
|
*/
|
9 |
|
|
package eu.etaxonomy.taxeditor.editor.view.descriptive.e4;
|
10 |
|
|
|
11 |
|
|
import java.util.Arrays;
|
12 |
|
|
import java.util.HashMap;
|
13 |
|
|
import java.util.List;
|
14 |
|
|
import java.util.Map;
|
15 |
|
|
|
16 |
|
|
import javax.annotation.PostConstruct;
|
17 |
84f9c7fd
|
Patrick Plitzner
|
import javax.inject.Inject;
|
18 |
860fc861
|
Patrick Plitzner
|
|
19 |
b5b429af
|
Patrick Plitzner
|
import org.eclipse.e4.core.contexts.ContextInjectionFactory;
|
20 |
|
|
import org.eclipse.e4.core.contexts.IEclipseContext;
|
21 |
84f9c7fd
|
Patrick Plitzner
|
import org.eclipse.e4.core.di.annotations.Optional;
|
22 |
|
|
import org.eclipse.e4.ui.di.UIEventTopic;
|
23 |
860fc861
|
Patrick Plitzner
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
24 |
|
|
import org.eclipse.e4.ui.services.EMenuService;
|
25 |
b3860b27
|
Katja Luther
|
import org.eclipse.jface.viewers.AbstractTreeViewer;
|
26 |
860fc861
|
Patrick Plitzner
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
27 |
|
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
28 |
|
|
import org.eclipse.jface.viewers.StructuredSelection;
|
29 |
2965ad0f
|
Patrick Plitzner
|
import org.eclipse.jface.viewers.TreeNode;
|
30 |
860fc861
|
Patrick Plitzner
|
import org.eclipse.jface.viewers.TreeViewer;
|
31 |
39fb1444
|
Katja Luther
|
import org.eclipse.jface.viewers.Viewer;
|
32 |
860fc861
|
Patrick Plitzner
|
import org.eclipse.swt.SWT;
|
33 |
|
|
import org.eclipse.swt.dnd.DND;
|
34 |
|
|
import org.eclipse.swt.dnd.Transfer;
|
35 |
|
|
import org.eclipse.swt.widgets.Composite;
|
36 |
|
|
import org.eclipse.swt.widgets.Tree;
|
37 |
|
|
|
38 |
|
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
39 |
|
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
40 |
|
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
41 |
|
|
import eu.etaxonomy.cdm.model.description.IDescribable;
|
42 |
b6f51ff3
|
Katja Luther
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
43 |
860fc861
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
44 |
843eefc4
|
Katja Luther
|
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
|
45 |
be22ce7d
|
Katja Luther
|
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
|
46 |
860fc861
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
47 |
eaff1338
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
48 |
da0bf48a
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.editor.view.concept.e4.ConceptViewPartE4;
|
49 |
860fc861
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementDragListener;
|
50 |
|
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementDropAdapter;
|
51 |
|
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementTransfer;
|
52 |
|
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveContentProvider;
|
53 |
|
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveLabelProvider;
|
54 |
|
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewerSorter;
|
55 |
68d759c3
|
Katja Luther
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.NameDescriptionFilter;
|
56 |
860fc861
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
|
57 |
84f9c7fd
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
|
58 |
b3860b27
|
Katja Luther
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
59 |
860fc861
|
Patrick Plitzner
|
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.session.ICdmEntitySession;
|
64 |
|
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
65 |
|
|
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
|
66 |
|
|
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
|
67 |
|
|
import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4;
|
68 |
cc30ce42
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.workbench.part.ICollapsableExpandable;
|
69 |
860fc861
|
Patrick Plitzner
|
|
70 |
|
|
/**
|
71 |
|
|
* @author pplitzner
|
72 |
|
|
* @date 15.08.2017
|
73 |
|
|
*/
|
74 |
|
|
public class FactualDataPartE4 extends AbstractCdmEditorPartE4
|
75 |
c4de8fcb
|
Andreas Müller
|
implements IPartContentHasDetails, IPartContentHasSupplementalData,
|
76 |
ad7201d3
|
Andreas Müller
|
ICdmEntitySessionEnabled<CdmBase>, ICollapsableExpandable {
|
77 |
860fc861
|
Patrick Plitzner
|
|
78 |
|
|
/**
|
79 |
|
|
* Maps {@link FeatureNodeContainerTree} to their corresponding {@link TaxonDescritpion}.<br>
|
80 |
|
|
* This serves as input for the {@link ITreeContentProvider} of the {@link TreeViewer}
|
81 |
|
|
*/
|
82 |
ad7201d3
|
Andreas Müller
|
protected Map<DescriptionBase<?>, FeatureNodeContainerTree> featureNodeContainerCache = new HashMap<>();
|
83 |
860fc861
|
Patrick Plitzner
|
|
84 |
|
|
protected int dndOperations = DND.DROP_COPY | DND.DROP_MOVE;
|
85 |
|
|
|
86 |
|
|
private DescriptiveContentProvider provider;
|
87 |
|
|
|
88 |
|
|
@PostConstruct
|
89 |
b5b429af
|
Patrick Plitzner
|
public void create(Composite parent, EMenuService menuService, MPart thisPart,
|
90 |
|
|
IEclipseContext context) {
|
91 |
b99a3ada
|
Patrick Plitzner
|
TreeViewer treeViewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL
|
92 |
4c124358
|
Patrick Plitzner
|
| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI));
|
93 |
b9a45989
|
Patrick Plitzner
|
|
94 |
|
|
this.thisPart = thisPart;
|
95 |
|
|
|
96 |
860fc861
|
Patrick Plitzner
|
provider = new DescriptiveContentProvider(featureNodeContainerCache);
|
97 |
|
|
treeViewer.setContentProvider(provider);
|
98 |
|
|
treeViewer.setLabelProvider(new DescriptiveLabelProvider());
|
99 |
|
|
treeViewer.setSorter(new DescriptiveViewerSorter());
|
100 |
68d759c3
|
Katja Luther
|
treeViewer.setFilters(new NameDescriptionFilter());
|
101 |
860fc861
|
Patrick Plitzner
|
treeViewer.setAutoExpandLevel(2);
|
102 |
|
|
Transfer[] transfers = new Transfer[] { DescriptionElementTransfer.getInstance() };
|
103 |
|
|
treeViewer.addDragSupport(dndOperations, transfers, new DescriptionElementDragListener(
|
104 |
|
|
this));
|
105 |
28b6d887
|
Katja Luther
|
|
106 |
860fc861
|
Patrick Plitzner
|
|
107 |
|
|
viewer = treeViewer;
|
108 |
|
|
|
109 |
|
|
// Propagate selection from viewer
|
110 |
b0a5a69c
|
Patrick Plitzner
|
selectionChangedListener = (event -> selService.setSelection(event.getSelection()));
|
111 |
860fc861
|
Patrick Plitzner
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
112 |
28b6d887
|
Katja Luther
|
DescriptionElementDropAdapter dropListener = new DescriptionElementDropAdapter(viewer);
|
113 |
|
|
ContextInjectionFactory.inject(dropListener, context);
|
114 |
68d759c3
|
Katja Luther
|
|
115 |
28b6d887
|
Katja Luther
|
treeViewer.addDropSupport(dndOperations, transfers,
|
116 |
|
|
dropListener);
|
117 |
860fc861
|
Patrick Plitzner
|
//create context menu
|
118 |
|
|
menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.factualDataView");
|
119 |
|
|
|
120 |
|
|
}
|
121 |
|
|
|
122 |
20fa89e3
|
Patrick Plitzner
|
@Override
|
123 |
|
|
public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
|
124 |
860fc861
|
Patrick Plitzner
|
if(activePart==thisPart){
|
125 |
|
|
return;
|
126 |
|
|
}
|
127 |
|
|
|
128 |
|
|
Object partObject = createPartObject(activePart);
|
129 |
b6f51ff3
|
Katja Luther
|
|
130 |
|
|
if ((partObject instanceof DetailsPartE4 && !(selection instanceof TaxonName))|| partObject instanceof SupplementalDataPartE4
|
131 |
9b4eaf57
|
Katja Luther
|
|| partObject instanceof MediaViewPartE4 || partObject instanceof ConceptViewPartE4 || ((partObject instanceof AbstractCdmEditorPartE4) &&(((AbstractCdmEditorPartE4)partObject).getViewer().getInput() instanceof DescriptionElementBase))) {
|
132 |
860fc861
|
Patrick Plitzner
|
// do not show empty page as these views are also used to edit the
|
133 |
|
|
// description selected in this view
|
134 |
|
|
return;
|
135 |
|
|
}
|
136 |
|
|
|
137 |
b6f51ff3
|
Katja Luther
|
if(partObject instanceof IPartContentHasFactualData ){
|
138 |
2a62fead
|
Katja Luther
|
if (!viewer.getControl().isDisposed()){
|
139 |
a8284340
|
Katja Luther
|
viewer.getControl().setEnabled(isEnabled());
|
140 |
2a62fead
|
Katja Luther
|
}
|
141 |
39fb1444
|
Katja Luther
|
|
142 |
860fc861
|
Patrick Plitzner
|
IStructuredSelection structuredSelection = createSelection(selection);
|
143 |
|
|
if(structuredSelection==null || structuredSelection.isEmpty()){
|
144 |
|
|
showEmptyPage();
|
145 |
|
|
return;
|
146 |
|
|
}
|
147 |
69be3e73
|
Katja Luther
|
|
148 |
860fc861
|
Patrick Plitzner
|
Object firstElement = structuredSelection.getFirstElement();
|
149 |
eaff1338
|
Patrick Plitzner
|
if (partObject instanceof TaxonNameEditorE4){
|
150 |
|
|
if (firstElement != ((TaxonNameEditorE4)partObject).getTaxon()){
|
151 |
860fc861
|
Patrick Plitzner
|
showEmptyPage();
|
152 |
|
|
return;
|
153 |
|
|
}
|
154 |
|
|
}
|
155 |
a160d195
|
Katja Luther
|
|
156 |
2965ad0f
|
Patrick Plitzner
|
if(firstElement instanceof TreeNode){
|
157 |
|
|
firstElement = ((TreeNode) firstElement).getValue();
|
158 |
|
|
}
|
159 |
860fc861
|
Patrick Plitzner
|
if(firstElement instanceof IDescribable<?>
|
160 |
|
|
&& partObject instanceof IPartContentHasFactualData
|
161 |
843eefc4
|
Katja Luther
|
&& !(firstElement instanceof SpecimenOrObservationBase && partObject instanceof BulkEditor)){
|
162 |
|
|
// && !(firstElement instanceof TaxonName && partObject instanceof BulkEditor)){
|
163 |
9b4eaf57
|
Katja Luther
|
if (firstElement instanceof TaxonName ){
|
164 |
5fcf8d0f
|
Katja Luther
|
thisPart.setLabel(Messages.NameFactsDataView_Lable);
|
165 |
|
|
}else{
|
166 |
|
|
thisPart.setLabel(Messages.FactualDataView_Lable);
|
167 |
|
|
}
|
168 |
39fb1444
|
Katja Luther
|
// featureNodeContainerCache.clear();
|
169 |
860fc861
|
Patrick Plitzner
|
showViewer(structuredSelection, activePart, viewer);
|
170 |
7953b892
|
Katja Luther
|
if ( viewer.getControl() != null &&!this.viewer.getControl().isDisposed()){
|
171 |
|
|
this.viewer.getControl().setEnabled(isEnabled());
|
172 |
|
|
}
|
173 |
39fb1444
|
Katja Luther
|
|
174 |
860fc861
|
Patrick Plitzner
|
return;
|
175 |
|
|
}
|
176 |
|
|
}
|
177 |
|
|
showEmptyPage();
|
178 |
|
|
return;
|
179 |
|
|
}
|
180 |
|
|
|
181 |
|
|
@Override
|
182 |
|
|
protected String getViewName(){
|
183 |
|
|
return Messages.DescriptiveViewPart_FACTUAL_DATA;
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
@Override
|
187 |
|
|
public void changed(Object object) {
|
188 |
39fb1444
|
Katja Luther
|
Object[] expandedObjects = null;
|
189 |
|
|
if (!viewer.getControl().isDisposed()){
|
190 |
|
|
expandedObjects = ((TreeViewer)viewer).getExpandedElements();
|
191 |
ffb73e56
|
Katja Luther
|
}else{
|
192 |
|
|
return;
|
193 |
39fb1444
|
Katja Luther
|
}
|
194 |
860fc861
|
Patrick Plitzner
|
for(FeatureNodeContainerTree containerTree : featureNodeContainerCache.values()){
|
195 |
|
|
containerTree.buildTree();
|
196 |
|
|
}
|
197 |
ffb73e56
|
Katja Luther
|
|
198 |
39fb1444
|
Katja Luther
|
viewer.refresh();
|
199 |
b3860b27
|
Katja Luther
|
super.changed(object);
|
200 |
39fb1444
|
Katja Luther
|
((TreeViewer) viewer).setExpandedElements(expandedObjects);
|
201 |
b3860b27
|
Katja Luther
|
if(object instanceof DescriptionElementBase){
|
202 |
|
|
DescriptionElementBase descriptionElement = (DescriptionElementBase) object;
|
203 |
fdc6d8ed
|
Andreas Müller
|
DescriptionBase<?> description = descriptionElement.getInDescription();
|
204 |
b3860b27
|
Katja Luther
|
FeatureNodeContainerTree containerTree = featureNodeContainerCache.get(description);
|
205 |
|
|
FeatureNodeContainer featureNodeContainer = containerTree.getFeatureNodeContainerForDescriptionElement(descriptionElement);
|
206 |
1546bd75
|
Katja Luther
|
if (featureNodeContainer == null){
|
207 |
|
|
containerTree = new FeatureNodeContainerTree(description, provider.getFeatureTree(description));
|
208 |
|
|
featureNodeContainerCache.put(description, containerTree);
|
209 |
|
|
featureNodeContainer = containerTree.getFeatureNodeContainerForDescriptionElement(descriptionElement);
|
210 |
|
|
}
|
211 |
b3860b27
|
Katja Luther
|
((AbstractTreeViewer) viewer).expandToLevel(featureNodeContainer, 2);
|
212 |
860fc861
|
Patrick Plitzner
|
StructuredSelection selection = new StructuredSelection(object);
|
213 |
|
|
viewer.setSelection(selection, true);
|
214 |
|
|
}
|
215 |
b3860b27
|
Katja Luther
|
|
216 |
|
|
|
217 |
|
|
|
218 |
860fc861
|
Patrick Plitzner
|
}
|
219 |
|
|
|
220 |
84f9c7fd
|
Patrick Plitzner
|
@Inject
|
221 |
|
|
@Optional
|
222 |
|
|
private void updateView(@UIEventTopic(WorkbenchEventConstants.SAVE_TAXON)boolean refresh){
|
223 |
|
|
if(refresh){
|
224 |
39fb1444
|
Katja Luther
|
Object[] expandedObjects = ((TreeViewer)viewer).getExpandedElements();
|
225 |
84f9c7fd
|
Patrick Plitzner
|
viewer.refresh();
|
226 |
39fb1444
|
Katja Luther
|
((TreeViewer)viewer).collapseAll();
|
227 |
|
|
if (expandedObjects.length>0){
|
228 |
|
|
((TreeViewer)viewer).setExpandedElements(expandedObjects);
|
229 |
|
|
}
|
230 |
84f9c7fd
|
Patrick Plitzner
|
}
|
231 |
|
|
}
|
232 |
|
|
|
233 |
b3860b27
|
Katja Luther
|
|
234 |
be22ce7d
|
Katja Luther
|
@Inject
|
235 |
|
|
@Optional
|
236 |
|
|
private void updateView(@UIEventTopic(WorkbenchEventConstants.CURRENT_ACTIVE_EDITOR)ITaxonEditor editor){
|
237 |
|
|
if(editor == null){
|
238 |
|
|
featureNodeContainerCache.clear();
|
239 |
|
|
}
|
240 |
|
|
}
|
241 |
|
|
|
242 |
cc975ee6
|
Patrick Plitzner
|
/**
|
243 |
|
|
* {@inheritDoc}
|
244 |
|
|
*/
|
245 |
|
|
@Override
|
246 |
|
|
public void collapse() {
|
247 |
|
|
if(viewer instanceof TreeViewer) {
|
248 |
|
|
((TreeViewer) viewer).collapseAll();
|
249 |
|
|
}
|
250 |
|
|
}
|
251 |
|
|
|
252 |
cc30ce42
|
Patrick Plitzner
|
/**
|
253 |
|
|
* {@inheritDoc}
|
254 |
|
|
*/
|
255 |
|
|
@Override
|
256 |
|
|
public void expand() {
|
257 |
|
|
if(viewer instanceof TreeViewer) {
|
258 |
|
|
((TreeViewer) viewer).expandAll();
|
259 |
|
|
}
|
260 |
|
|
}
|
261 |
|
|
|
262 |
860fc861
|
Patrick Plitzner
|
public void toggleShowOnlyIndividualAssociations(){
|
263 |
|
|
provider.toggleShowOnlyIndividualAssociations();
|
264 |
|
|
viewer.refresh();
|
265 |
|
|
}
|
266 |
|
|
|
267 |
|
|
@Override
|
268 |
|
|
public ICdmEntitySession getCdmEntitySession() {
|
269 |
|
|
if(selectionProvidingPart != null && selectionProvidingPart instanceof ICdmEntitySessionEnabled) {
|
270 |
ad7201d3
|
Andreas Müller
|
return ((ICdmEntitySessionEnabled<?>) selectionProvidingPart).getCdmEntitySession();
|
271 |
860fc861
|
Patrick Plitzner
|
}
|
272 |
|
|
return null;
|
273 |
|
|
}
|
274 |
|
|
|
275 |
|
|
@Override
|
276 |
ad7201d3
|
Andreas Müller
|
public List<CdmBase> getRootEntities() {
|
277 |
860fc861
|
Patrick Plitzner
|
return Arrays.asList((CdmBase)getViewer().getInput());
|
278 |
|
|
}
|
279 |
|
|
@Override
|
280 |
|
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
281 |
|
|
return null;
|
282 |
|
|
}
|
283 |
|
|
|
284 |
39fb1444
|
Katja Luther
|
@Override
|
285 |
|
|
protected void showViewer(IStructuredSelection selection, MPart activePart, Viewer viewer){
|
286 |
|
|
Object[] expandedObjects = null;
|
287 |
|
|
if (!((TreeViewer)this.getViewer()).getControl().isDisposed()){
|
288 |
|
|
expandedObjects = ((TreeViewer)this.getViewer()).getExpandedElements();
|
289 |
|
|
}
|
290 |
|
|
super.showViewer(selection, activePart, viewer);
|
291 |
|
|
if (expandedObjects == null || expandedObjects.length == 0){
|
292 |
|
|
((TreeViewer)this.viewer).expandToLevel(2);
|
293 |
|
|
}else{
|
294 |
|
|
((TreeViewer)this.viewer).setExpandedElements(expandedObjects);
|
295 |
|
|
}
|
296 |
|
|
}
|
297 |
860fc861
|
Patrick Plitzner
|
}
|