1 |
860fc861
|
Patrick Plitzner
|
// $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.TreeViewer;
|
35 |
|
|
import org.eclipse.jface.viewers.Viewer;
|
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.MULTI | 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 |
|
|
|
178 |
|
|
if(firstElement instanceof IDescribable<?>
|
179 |
|
|
&& partObject instanceof IPartContentHasFactualData
|
180 |
|
|
&& !(firstElement instanceof SpecimenOrObservationBase && partObject instanceof BulkEditor)){
|
181 |
|
|
|
182 |
|
|
featureNodeContainerCache.clear();
|
183 |
|
|
showViewer(structuredSelection, activePart, viewer);
|
184 |
|
|
return;
|
185 |
|
|
}
|
186 |
|
|
}
|
187 |
|
|
showEmptyPage();
|
188 |
|
|
return;
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
@Override
|
192 |
|
|
protected String getViewName(){
|
193 |
|
|
return Messages.DescriptiveViewPart_FACTUAL_DATA;
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
/**
|
197 |
|
|
*
|
198 |
|
|
* @author n.hoffmann
|
199 |
|
|
* @created May 28, 2010
|
200 |
|
|
* @version 1.0
|
201 |
|
|
*/
|
202 |
|
|
protected class ToggleDescriptionAction extends Action{
|
203 |
|
|
private final boolean expanded;
|
204 |
|
|
|
205 |
|
|
public ToggleDescriptionAction(boolean expand){
|
206 |
|
|
super(null, IAction.AS_PUSH_BUTTON);
|
207 |
|
|
expanded = expand;
|
208 |
|
|
setImageAndTooltip();
|
209 |
|
|
}
|
210 |
|
|
|
211 |
|
|
private void setImageAndTooltip(){
|
212 |
|
|
setImageDescriptor(new ImageDescriptor() {
|
213 |
|
|
@Override
|
214 |
|
|
public ImageData getImageData() {
|
215 |
|
|
setText(expanded ? Messages.DescriptiveViewPart_COLLAPSE_ALL : Messages.DescriptiveViewPart_EXPAND_ALL);
|
216 |
|
|
String resource = expanded ? ImageResources.COLLAPSE_ALL : ImageResources.EXPAND_ALL;
|
217 |
|
|
return ImageResources.getImage(resource).getImageData();
|
218 |
|
|
}
|
219 |
|
|
});
|
220 |
|
|
|
221 |
|
|
String toolTipText = expanded ? Messages.DescriptiveViewPart_COLLAPSE_ALL : Messages.DescriptiveViewPart_SHOW_ALL_DATA;
|
222 |
|
|
setToolTipText(toolTipText);
|
223 |
|
|
}
|
224 |
|
|
|
225 |
|
|
@Override
|
226 |
|
|
public void run() {
|
227 |
|
|
if(expanded){
|
228 |
|
|
((AbstractTreeViewer) viewer).collapseAll();
|
229 |
|
|
}else{
|
230 |
|
|
((AbstractTreeViewer) viewer).expandAll();
|
231 |
|
|
}
|
232 |
|
|
setImageAndTooltip();
|
233 |
|
|
}
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
/** {@inheritDoc} */
|
237 |
|
|
@Override
|
238 |
|
|
public void changed(Object object) {
|
239 |
|
|
for(FeatureNodeContainerTree containerTree : featureNodeContainerCache.values()){
|
240 |
|
|
containerTree.buildTree();
|
241 |
|
|
}
|
242 |
|
|
((AbstractTreeViewer) viewer).expandToLevel(2);
|
243 |
|
|
viewer.refresh();
|
244 |
|
|
|
245 |
|
|
if(object instanceof DescriptionElementBase){
|
246 |
|
|
DescriptionElementBase descriptionElement = (DescriptionElementBase) object;
|
247 |
|
|
DescriptionBase description = descriptionElement.getInDescription();
|
248 |
|
|
FeatureNodeContainerTree containerTree = featureNodeContainerCache.get(description);
|
249 |
|
|
|
250 |
|
|
FeatureNodeContainer featureNodeContainer = containerTree.getFeatureNodeContainerForDescriptionElement(descriptionElement);
|
251 |
|
|
((AbstractTreeViewer) viewer).expandToLevel(featureNodeContainer, 1);
|
252 |
|
|
|
253 |
|
|
}
|
254 |
|
|
|
255 |
|
|
if(object != null){
|
256 |
|
|
StructuredSelection selection = new StructuredSelection(object);
|
257 |
|
|
viewer.setSelection(selection, true);
|
258 |
|
|
}
|
259 |
|
|
// if(part instanceof BulkEditor && !(object instanceof SpecimenOrObservationBase<?>)){
|
260 |
|
|
// ((BulkEditor) part).forceDirty();
|
261 |
|
|
// IStructuredSelection selection = (IStructuredSelection) ((BulkEditor) part).getSelectionProvider().getSelection();
|
262 |
|
|
// ((BulkEditor) part).changed(selection.getFirstElement());
|
263 |
|
|
//
|
264 |
|
|
// }
|
265 |
|
|
//
|
266 |
|
|
// if (part instanceof E4PartWrapper){
|
267 |
|
|
// part = WorkbenchUtility.getE4WrappedPart(part);
|
268 |
|
|
// if (part instanceof IDirtyMarkable){
|
269 |
|
|
// StructuredSelection selection = new StructuredSelection(object);
|
270 |
|
|
// ((IDirtyMarkable)part).changed(selection.getFirstElement());
|
271 |
|
|
// }
|
272 |
|
|
// }
|
273 |
|
|
|
274 |
|
|
|
275 |
|
|
super.changed(object);
|
276 |
|
|
}
|
277 |
|
|
|
278 |
|
|
public void toggleShowOnlyIndividualAssociations(){
|
279 |
|
|
provider.toggleShowOnlyIndividualAssociations();
|
280 |
|
|
viewer.refresh();
|
281 |
|
|
}
|
282 |
|
|
|
283 |
|
|
public Viewer getViewer() {
|
284 |
|
|
return viewer;
|
285 |
|
|
}
|
286 |
|
|
|
287 |
|
|
@Override
|
288 |
|
|
public ICdmEntitySession getCdmEntitySession() {
|
289 |
|
|
if(selectionProvidingPart != null && selectionProvidingPart instanceof ICdmEntitySessionEnabled) {
|
290 |
|
|
return ((ICdmEntitySessionEnabled) selectionProvidingPart).getCdmEntitySession();
|
291 |
|
|
}
|
292 |
|
|
return null;
|
293 |
|
|
}
|
294 |
|
|
|
295 |
|
|
@Override
|
296 |
|
|
public List<? extends CdmBase> getRootEntities() {
|
297 |
|
|
return Arrays.asList((CdmBase)getViewer().getInput());
|
298 |
|
|
}
|
299 |
|
|
@Override
|
300 |
|
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
301 |
|
|
return null;
|
302 |
|
|
}
|
303 |
|
|
|
304 |
|
|
}
|