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
.ui
.model
.application
.ui
.basic
.MPart
;
20 import org
.eclipse
.e4
.ui
.services
.EMenuService
;
21 import org
.eclipse
.jface
.action
.Action
;
22 import org
.eclipse
.jface
.action
.IAction
;
23 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
24 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
25 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
26 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
27 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
28 import org
.eclipse
.jface
.viewers
.TreeNode
;
29 import org
.eclipse
.jface
.viewers
.TreeViewer
;
30 import org
.eclipse
.swt
.SWT
;
31 import org
.eclipse
.swt
.dnd
.DND
;
32 import org
.eclipse
.swt
.dnd
.Transfer
;
33 import org
.eclipse
.swt
.graphics
.ImageData
;
34 import org
.eclipse
.swt
.widgets
.Composite
;
35 import org
.eclipse
.swt
.widgets
.Tree
;
37 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
38 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
39 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
40 import eu
.etaxonomy
.cdm
.model
.description
.IDescribable
;
41 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
42 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
43 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
44 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
45 import eu
.etaxonomy
.taxeditor
.editor
.name
.e4
.TaxonNameEditorE4
;
46 import eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
.ChecklistEditor
;
47 import eu
.etaxonomy
.taxeditor
.editor
.view
.concept
.e4
.ConceptViewPartE4
;
48 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptionElementDragListener
;
49 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptionElementDropAdapter
;
50 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptionElementTransfer
;
51 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveContentProvider
;
52 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveLabelProvider
;
53 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveViewerSorter
;
54 import eu
.etaxonomy
.taxeditor
.editor
.view
.media
.e4
.MediaViewPartE4
;
55 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
56 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
57 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainerTree
;
58 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
59 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasFactualData
;
60 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
61 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
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
;
73 public class FactualDataPartE4
extends AbstractCdmEditorPartE4
74 implements IPartContentHasDetails
, IPartContentHasSupplementalData
, ICdmEntitySessionEnabled
{
77 * Maps {@link FeatureNodeContainerTree} to their corresponding {@link TaxonDescritpion}.<br>
78 * This serves as input for the {@link ITreeContentProvider} of the {@link TreeViewer}
80 protected Map
<DescriptionBase
<?
>, FeatureNodeContainerTree
> featureNodeContainerCache
= new HashMap
<DescriptionBase
<?
>, FeatureNodeContainerTree
>();
82 protected ToggleDescriptionAction showAllElementsAction
;
84 protected ToggleDescriptionAction hideAllElementsAction
;
86 protected int dndOperations
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
88 private DescriptiveContentProvider provider
;
91 public void create(Composite parent
, EMenuService menuService
, MPart thisPart
) {
92 TreeViewer treeViewer
= new TreeViewer(new Tree(parent
, SWT
.H_SCROLL
93 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
95 this.thisPart
= thisPart
;
97 provider
= new DescriptiveContentProvider(featureNodeContainerCache
);
98 treeViewer
.setContentProvider(provider
);
99 treeViewer
.setLabelProvider(new DescriptiveLabelProvider());
100 treeViewer
.setSorter(new DescriptiveViewerSorter());
101 treeViewer
.setAutoExpandLevel(2);
102 Transfer
[] transfers
= new Transfer
[] { DescriptionElementTransfer
.getInstance() };
103 treeViewer
.addDragSupport(dndOperations
, transfers
, new DescriptionElementDragListener(
105 treeViewer
.addDropSupport(dndOperations
, transfers
,
106 new DescriptionElementDropAdapter(viewer
));
110 // Propagate selection from viewer
111 selectionChangedListener
= (event
-> selService
.setSelection(AbstractUtility
.getElementsFromSelectionChangedEvent(event
)));
112 viewer
.addSelectionChangedListener(selectionChangedListener
);
114 //create context menu
115 menuService
.registerContextMenu(viewer
.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.factualDataView");
117 showAllElementsAction
= new ToggleDescriptionAction(false);
118 hideAllElementsAction
= new ToggleDescriptionAction(true);
120 //FIXME E4 implement toolbar
123 //FIXME E4 migrate drag and drop
126 // protected void createToolbar() {
127 // IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
128 // toolBarManager.add(showAllElementsAction);
129 // toolBarManager.add(hideAllElementsAction);
134 public void selectionChanged_internal(Object selection
, MPart activePart
, MPart thisPart
) {
135 if(activePart
==thisPart
){
139 Object partObject
= createPartObject(activePart
);
141 if (partObject
instanceof DetailsPartE4
|| partObject
instanceof SupplementalDataPartE4
142 || partObject
instanceof MediaViewPartE4
|| partObject
instanceof ConceptViewPartE4
) {
143 // do not show empty page as these views are also used to edit the
144 // description selected in this view
148 if(partObject
instanceof IPartContentHasFactualData
){
149 IStructuredSelection structuredSelection
= createSelection(selection
);
150 if(structuredSelection
==null || structuredSelection
.isEmpty()){
154 if(partObject
instanceof ChecklistEditor
){
155 if(structuredSelection
.getFirstElement() instanceof Taxon
){
156 Taxon taxon
= (Taxon
)structuredSelection
.getFirstElement();
157 structuredSelection
= new StructuredSelection(taxon
);
160 Object firstElement
= structuredSelection
.getFirstElement();
161 if (partObject
instanceof TaxonNameEditorE4
){
162 if (firstElement
!= ((TaxonNameEditorE4
)partObject
).getTaxon()){
167 if(firstElement
instanceof TreeNode
){
168 firstElement
= ((TreeNode
) firstElement
).getValue();
170 if(firstElement
instanceof IDescribable
<?
>
171 && partObject
instanceof IPartContentHasFactualData
172 && !(firstElement
instanceof SpecimenOrObservationBase
&& partObject
instanceof BulkEditor
)){
174 featureNodeContainerCache
.clear();
175 showViewer(structuredSelection
, activePart
, viewer
);
184 protected String
getViewName(){
185 return Messages
.DescriptiveViewPart_FACTUAL_DATA
;
191 * @created May 28, 2010
194 protected class ToggleDescriptionAction
extends Action
{
195 private final boolean expanded
;
197 public ToggleDescriptionAction(boolean expand
){
198 super(null, IAction
.AS_PUSH_BUTTON
);
200 setImageAndTooltip();
203 private void setImageAndTooltip(){
204 setImageDescriptor(new ImageDescriptor() {
206 public ImageData
getImageData() {
207 setText(expanded ? Messages
.DescriptiveViewPart_COLLAPSE_ALL
: Messages
.DescriptiveViewPart_EXPAND_ALL
);
208 String resource
= expanded ? ImageResources
.COLLAPSE_ALL
: ImageResources
.EXPAND_ALL
;
209 return ImageResources
.getImage(resource
).getImageData();
213 String toolTipText
= expanded ? Messages
.DescriptiveViewPart_COLLAPSE_ALL
: Messages
.DescriptiveViewPart_SHOW_ALL_DATA
;
214 setToolTipText(toolTipText
);
220 ((AbstractTreeViewer
) viewer
).collapseAll();
222 ((AbstractTreeViewer
) viewer
).expandAll();
224 setImageAndTooltip();
230 public void changed(Object object
) {
231 for(FeatureNodeContainerTree containerTree
: featureNodeContainerCache
.values()){
232 containerTree
.buildTree();
234 ((AbstractTreeViewer
) viewer
).expandToLevel(2);
237 if(object
instanceof DescriptionElementBase
){
238 DescriptionElementBase descriptionElement
= (DescriptionElementBase
) object
;
239 DescriptionBase description
= descriptionElement
.getInDescription();
240 FeatureNodeContainerTree containerTree
= featureNodeContainerCache
.get(description
);
242 FeatureNodeContainer featureNodeContainer
= containerTree
.getFeatureNodeContainerForDescriptionElement(descriptionElement
);
243 ((AbstractTreeViewer
) viewer
).expandToLevel(featureNodeContainer
, 1);
248 StructuredSelection selection
= new StructuredSelection(object
);
249 viewer
.setSelection(selection
, true);
251 // if(part instanceof BulkEditor && !(object instanceof SpecimenOrObservationBase<?>)){
252 // ((BulkEditor) part).forceDirty();
253 // IStructuredSelection selection = (IStructuredSelection) ((BulkEditor) part).getSelectionProvider().getSelection();
254 // ((BulkEditor) part).changed(selection.getFirstElement());
258 // if (part instanceof E4PartWrapper){
259 // part = WorkbenchUtility.getE4WrappedPart(part);
260 // if (part instanceof IDirtyMarkable){
261 // StructuredSelection selection = new StructuredSelection(object);
262 // ((IDirtyMarkable)part).changed(selection.getFirstElement());
267 super.changed(object
);
270 public void toggleShowOnlyIndividualAssociations(){
271 //FIXME E4 migrate toggle menu icon
272 provider
.toggleShowOnlyIndividualAssociations();
277 public ICdmEntitySession
getCdmEntitySession() {
278 if(selectionProvidingPart
!= null && selectionProvidingPart
instanceof ICdmEntitySessionEnabled
) {
279 return ((ICdmEntitySessionEnabled
) selectionProvidingPart
).getCdmEntitySession();
285 public List
<?
extends CdmBase
> getRootEntities() {
286 return Arrays
.asList((CdmBase
)getViewer().getInput());
289 public Map
<Object
, List
<String
>> getPropertyPathsMap() {