3 * Copyright (C) 2017 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.e4
;
12 import java
.util
.Arrays
;
13 import java
.util
.HashMap
;
14 import java
.util
.List
;
17 import javax
.annotation
.PostConstruct
;
18 import javax
.inject
.Inject
;
20 import org
.eclipse
.e4
.core
.contexts
.ContextInjectionFactory
;
21 import org
.eclipse
.e4
.core
.contexts
.IEclipseContext
;
22 import org
.eclipse
.e4
.core
.di
.annotations
.Optional
;
23 import org
.eclipse
.e4
.ui
.di
.UIEventTopic
;
24 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
25 import org
.eclipse
.e4
.ui
.services
.EMenuService
;
26 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
27 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
28 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
29 import org
.eclipse
.jface
.viewers
.TreeNode
;
30 import org
.eclipse
.jface
.viewers
.TreeViewer
;
31 import org
.eclipse
.jface
.viewers
.Viewer
;
32 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
;
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 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
43 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
44 import eu
.etaxonomy
.taxeditor
.bulkeditor
.e4
.BulkEditorE4
;
45 import eu
.etaxonomy
.taxeditor
.editor
.ITaxonEditor
;
46 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
47 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
48 import eu
.etaxonomy
.taxeditor
.editor
.view
.concept
.e4
.ConceptViewPartE4
;
49 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 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.NameDescriptionFilter
;
56 import eu
.etaxonomy
.taxeditor
.editor
.view
.media
.e4
.MediaViewPartE4
;
57 import eu
.etaxonomy
.taxeditor
.event
.WorkbenchEventConstants
;
58 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainerTree
;
59 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
60 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasFactualData
;
61 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
62 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySession
;
63 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
64 import eu
.etaxonomy
.taxeditor
.view
.e4
.AbstractCdmEditorPartE4
;
65 import eu
.etaxonomy
.taxeditor
.view
.e4
.details
.DetailsPartE4
;
66 import eu
.etaxonomy
.taxeditor
.view
.e4
.supplementaldata
.SupplementalDataPartE4
;
67 import eu
.etaxonomy
.taxeditor
.workbench
.part
.ICollapsableExpandable
;
73 public class FactualDataPartE4
extends AbstractCdmEditorPartE4
74 implements IPartContentHasDetails
, IPartContentHasSupplementalData
, ICdmEntitySessionEnabled
,
75 ICollapsableExpandable
{
78 * Maps {@link FeatureNodeContainerTree} to their corresponding {@link TaxonDescritpion}.<br>
79 * This serves as input for the {@link ITreeContentProvider} of the {@link TreeViewer}
81 protected Map
<DescriptionBase
<?
>, FeatureNodeContainerTree
> featureNodeContainerCache
= new HashMap
<DescriptionBase
<?
>, FeatureNodeContainerTree
>();
83 protected int dndOperations
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
85 private DescriptiveContentProvider provider
;
88 public void create(Composite parent
, EMenuService menuService
, MPart thisPart
,
89 IEclipseContext context
) {
90 TreeViewer treeViewer
= new TreeViewer(new Tree(parent
, SWT
.H_SCROLL
91 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
| SWT
.MULTI
));
93 this.thisPart
= thisPart
;
95 provider
= new DescriptiveContentProvider(featureNodeContainerCache
);
96 treeViewer
.setContentProvider(provider
);
97 treeViewer
.setLabelProvider(new DescriptiveLabelProvider());
98 treeViewer
.setSorter(new DescriptiveViewerSorter());
99 treeViewer
.setFilters(new NameDescriptionFilter());
100 treeViewer
.setAutoExpandLevel(2);
101 Transfer
[] transfers
= new Transfer
[] { DescriptionElementTransfer
.getInstance() };
102 treeViewer
.addDragSupport(dndOperations
, transfers
, new DescriptionElementDragListener(
108 // Propagate selection from viewer
109 selectionChangedListener
= (event
-> selService
.setSelection(event
.getSelection()));
110 viewer
.addSelectionChangedListener(selectionChangedListener
);
111 DescriptionElementDropAdapter dropListener
= new DescriptionElementDropAdapter(viewer
);
112 ContextInjectionFactory
.inject(dropListener
, context
);
114 treeViewer
.addDropSupport(dndOperations
, transfers
,
116 //create context menu
117 menuService
.registerContextMenu(viewer
.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.factualDataView");
122 public void selectionChanged_internal(Object selection
, MPart activePart
, MPart thisPart
) {
123 if(activePart
==thisPart
){
127 Object partObject
= createPartObject(activePart
);
131 if ((partObject
instanceof DetailsPartE4
&& !(selection
instanceof TaxonName
))|| partObject
instanceof SupplementalDataPartE4
132 || partObject
instanceof MediaViewPartE4
|| partObject
instanceof ConceptViewPartE4
|| ((partObject
instanceof AbstractCdmEditorPartE4
) &&(((AbstractCdmEditorPartE4
)partObject
).getViewer().getInput() instanceof DescriptionElementBase
))) {
133 // do not show empty page as these views are also used to edit the
134 // description selected in this view
139 if(partObject
instanceof IPartContentHasFactualData
){
141 if (!viewer
.getControl().isDisposed()){
142 viewer
.getControl().setEnabled(isEnabled());
146 IStructuredSelection structuredSelection
= createSelection(selection
);
147 if(structuredSelection
==null || structuredSelection
.isEmpty()){
152 Object firstElement
= structuredSelection
.getFirstElement();
153 if (partObject
instanceof TaxonNameEditorE4
){
154 if (firstElement
!= ((TaxonNameEditorE4
)partObject
).getTaxon()){
160 if(firstElement
instanceof TreeNode
){
161 firstElement
= ((TreeNode
) firstElement
).getValue();
163 if(firstElement
instanceof IDescribable
<?
>
164 && partObject
instanceof IPartContentHasFactualData
165 && !(firstElement
instanceof SpecimenOrObservationBase
&& partObject
instanceof BulkEditorE4
)){
166 // && !(firstElement instanceof TaxonName && partObject instanceof BulkEditorE4)){
167 if (firstElement
instanceof TaxonName
){
168 thisPart
.setLabel(Messages
.NameFactsDataView_Lable
);
170 thisPart
.setLabel(Messages
.FactualDataView_Lable
);
172 // featureNodeContainerCache.clear();
173 showViewer(structuredSelection
, activePart
, viewer
);
174 if ( viewer
.getControl() != null &&!this.viewer
.getControl().isDisposed()){
175 this.viewer
.getControl().setEnabled(isEnabled());
186 protected String
getViewName(){
187 return Messages
.DescriptiveViewPart_FACTUAL_DATA
;
191 public void changed(Object object
) {
192 Object
[] expandedObjects
= null;
193 if (!viewer
.getControl().isDisposed()){
194 expandedObjects
= ((TreeViewer
)viewer
).getExpandedElements();
196 for(FeatureNodeContainerTree containerTree
: featureNodeContainerCache
.values()){
197 containerTree
.buildTree();
199 if (featureNodeContainerCache
.isEmpty()){
202 // if(object instanceof DescriptionElementBase){
203 // DescriptionElementBase descriptionElement = (DescriptionElementBase) object;
204 // DescriptionBase description = descriptionElement.getInDescription();
205 //// FeatureNodeContainerTree containerTree = featureNodeContainerCache.get(description);
207 //// FeatureNodeContainer featureNodeContainer = containerTree.getFeatureNodeContainerForDescriptionElement(descriptionElement);
208 //// ((AbstractTreeViewer) viewer).expandToLevel(featureNodeContainer, 1);
214 ((TreeViewer
) viewer
).setExpandedElements(expandedObjects
);
217 StructuredSelection selection
= new StructuredSelection(object
);
218 viewer
.setSelection(selection
, true);
220 // selectionProvidingPart.setDirty(true);
221 super.changed(object
);
226 private void updateView(@UIEventTopic(WorkbenchEventConstants
.SAVE_TAXON
)boolean refresh
){
228 Object
[] expandedObjects
= ((TreeViewer
)viewer
).getExpandedElements();
230 ((TreeViewer
)viewer
).collapseAll();
231 if (expandedObjects
.length
>0){
232 ((TreeViewer
)viewer
).setExpandedElements(expandedObjects
);
239 private void updateView(@UIEventTopic(WorkbenchEventConstants
.CURRENT_ACTIVE_EDITOR
)ITaxonEditor editor
){
241 featureNodeContainerCache
.clear();
249 public void collapse() {
250 if(viewer
instanceof TreeViewer
) {
251 ((TreeViewer
) viewer
).collapseAll();
259 public void expand() {
260 if(viewer
instanceof TreeViewer
) {
261 ((TreeViewer
) viewer
).expandAll();
265 public void toggleShowOnlyIndividualAssociations(){
266 provider
.toggleShowOnlyIndividualAssociations();
271 public ICdmEntitySession
getCdmEntitySession() {
272 if(selectionProvidingPart
!= null && selectionProvidingPart
instanceof ICdmEntitySessionEnabled
) {
273 return ((ICdmEntitySessionEnabled
) selectionProvidingPart
).getCdmEntitySession();
279 public List
<?
extends CdmBase
> getRootEntities() {
280 return Arrays
.asList((CdmBase
)getViewer().getInput());
283 public Map
<Object
, List
<String
>> getPropertyPathsMap() {
288 protected void showViewer(IStructuredSelection selection
, MPart activePart
, Viewer viewer
){
289 Object
[] expandedObjects
= null;
290 if (!((TreeViewer
)this.getViewer()).getControl().isDisposed()){
291 expandedObjects
= ((TreeViewer
)this.getViewer()).getExpandedElements();
293 super.showViewer(selection
, activePart
, viewer
);
294 if (expandedObjects
== null || expandedObjects
.length
== 0){
295 ((TreeViewer
)this.viewer
).expandToLevel(2);
297 ((TreeViewer
)this.viewer
).setExpandedElements(expandedObjects
);