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
;
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
;
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
;
70 public class FactualDataPartE4
extends AbstractCdmEditorPartE4
71 implements IPartContentHasDetails
, IPartContentHasSupplementalData
, ICdmEntitySessionEnabled
,
72 ICollapsableExpandable
{
75 * Maps {@link FeatureNodeContainerTree} to their corresponding {@link TaxonDescritpion}.<br>
76 * This serves as input for the {@link ITreeContentProvider} of the {@link TreeViewer}
78 protected Map
<DescriptionBase
<?
>, FeatureNodeContainerTree
> featureNodeContainerCache
= new HashMap
<DescriptionBase
<?
>, FeatureNodeContainerTree
>();
80 protected int dndOperations
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
82 private DescriptiveContentProvider provider
;
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
));
90 this.thisPart
= thisPart
;
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(
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
,
111 //create context menu
112 menuService
.registerContextMenu(viewer
.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.factualDataView");
117 public void selectionChanged_internal(Object selection
, MPart activePart
, MPart thisPart
) {
118 if(activePart
==thisPart
){
122 Object partObject
= createPartObject(activePart
);
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
131 if(partObject
instanceof IPartContentHasFactualData
){
132 if (!viewer
.getControl().isDisposed()){
133 viewer
.getControl().setEnabled(true);
135 IStructuredSelection structuredSelection
= createSelection(selection
);
136 if(structuredSelection
==null || structuredSelection
.isEmpty()){
140 if(partObject
instanceof ChecklistEditorE4
){
141 if(structuredSelection
.getFirstElement() instanceof Taxon
){
142 Taxon taxon
= (Taxon
)structuredSelection
.getFirstElement();
143 structuredSelection
= new StructuredSelection(taxon
);
146 Object firstElement
= structuredSelection
.getFirstElement();
147 if (partObject
instanceof TaxonNameEditorE4
){
148 if (firstElement
!= ((TaxonNameEditorE4
)partObject
).getTaxon()){
153 if(firstElement
instanceof TreeNode
){
154 firstElement
= ((TreeNode
) firstElement
).getValue();
156 if(firstElement
instanceof IDescribable
<?
>
157 && partObject
instanceof IPartContentHasFactualData
158 && !(firstElement
instanceof SpecimenOrObservationBase
&& partObject
instanceof BulkEditorE4
)){
160 featureNodeContainerCache
.clear();
161 showViewer(structuredSelection
, activePart
, viewer
);
170 protected String
getViewName(){
171 return Messages
.DescriptiveViewPart_FACTUAL_DATA
;
176 public void changed(Object object
) {
177 for(FeatureNodeContainerTree containerTree
: featureNodeContainerCache
.values()){
178 containerTree
.buildTree();
180 ((AbstractTreeViewer
) viewer
).expandToLevel(2);
183 if(object
instanceof DescriptionElementBase
){
184 DescriptionElementBase descriptionElement
= (DescriptionElementBase
) object
;
185 DescriptionBase description
= descriptionElement
.getInDescription();
186 FeatureNodeContainerTree containerTree
= featureNodeContainerCache
.get(description
);
188 FeatureNodeContainer featureNodeContainer
= containerTree
.getFeatureNodeContainerForDescriptionElement(descriptionElement
);
189 ((AbstractTreeViewer
) viewer
).expandToLevel(featureNodeContainer
, 1);
194 StructuredSelection selection
= new StructuredSelection(object
);
195 viewer
.setSelection(selection
, true);
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());
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());
213 super.changed(object
);
220 public void collapse() {
221 if(viewer
instanceof TreeViewer
) {
222 ((TreeViewer
) viewer
).collapseAll();
230 public void expand() {
231 if(viewer
instanceof TreeViewer
) {
232 ((TreeViewer
) viewer
).expandAll();
236 public void toggleShowOnlyIndividualAssociations(){
237 provider
.toggleShowOnlyIndividualAssociations();
242 public ICdmEntitySession
getCdmEntitySession() {
243 if(selectionProvidingPart
!= null && selectionProvidingPart
instanceof ICdmEntitySessionEnabled
) {
244 return ((ICdmEntitySessionEnabled
) selectionProvidingPart
).getCdmEntitySession();
250 public List
<?
extends CdmBase
> getRootEntities() {
251 return Arrays
.asList((CdmBase
)getViewer().getInput());
254 public Map
<Object
, List
<String
>> getPropertyPathsMap() {