2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.view
.e4
.details
;
11 import javax
.annotation
.PostConstruct
;
12 import javax
.inject
.Inject
;
14 import org
.eclipse
.e4
.core
.contexts
.ContextInjectionFactory
;
15 import org
.eclipse
.e4
.core
.contexts
.IEclipseContext
;
16 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
17 import org
.eclipse
.jface
.viewers
.ISelection
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
20 import org
.eclipse
.jface
.viewers
.TreeSelection
;
21 import org
.eclipse
.jface
.viewers
.TreeViewer
;
22 import org
.eclipse
.swt
.SWTException
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
25 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
26 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
27 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
28 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
29 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
30 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasFactualData
;
31 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
32 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
33 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
34 import eu
.etaxonomy
.taxeditor
.view
.detail
.CdmSectionPart
;
35 import eu
.etaxonomy
.taxeditor
.view
.e4
.AbstractCdmEditorPart
;
36 import eu
.etaxonomy
.taxeditor
.view
.e4
.supplementaldata
.SupplementalDataPartE4
;
42 public class DetailsPartE4
extends AbstractCdmEditorPart
<DetailsViewerE4
> implements IPartContentHasSupplementalData
, IPartContentHasFactualData
{
45 public DetailsPartE4() {
49 public void create(Composite parent
, MPart thisPart
, IEclipseContext context
) {
51 this.thisPart
= thisPart
;
53 viewer
= ContextInjectionFactory
.make(DetailsViewerE4
.class, context
);
54 viewer
.init(parent
, this);
56 // Propagate selection from viewer
57 selectionChangedListener
= (event
-> selService
.setSelection(AbstractUtility
.getElementsFromSelectionChangedEvent(event
)));
58 viewer
.addSelectionChangedListener(selectionChangedListener
);
62 public void selectionChanged_internal(Object selection
, MPart activePart
, MPart thisPart
) {
63 if (activePart
== null) {
67 if (activePart
== thisPart
){
68 if (this.getViewer().isNeedsRefresh()) {
70 viewer
.setNeedsRefresh(false);
79 Object partObject
= getPartObject(activePart
);
80 if (partObject
instanceof SupplementalDataPartE4
) {
81 // do not show empty page
85 if (partObject
instanceof AbstractCdmEditorPart
&& ((AbstractCdmEditorPart
)partObject
).getViewer() instanceof TreeViewer
) {
86 //active part is factual data view or media view
87 IStructuredSelection structuredSelection
= createSelection(selection
);
88 if (structuredSelection
!= null && !structuredSelection
.isEmpty()) {
89 //if the active part is empty the selection is still the previous selection
90 if (!(structuredSelection
instanceof TreeSelection
)) {
97 if(partObject
instanceof IPartContentHasDetails
){
98 IStructuredSelection structuredSelection
= createSelection(selection
);
99 if(structuredSelection
== null || structuredSelection
.isEmpty()){
104 // do not show details for feature nodes TODO strange check to avoid having shown the distribution map for every FeatureNodeContainer
105 if(structuredSelection
.getFirstElement() instanceof FeatureNodeContainer
){
106 // do show the map for distributions
107 Feature feature
= ((FeatureNodeContainer
) structuredSelection
.getFirstElement()).getFeature();
108 if(!feature
.equals(Feature
.DISTRIBUTION())){
114 //FIXME this is a temporary workaround to fix selection handling for supplemental data view
115 // Now the supp data view gets double selection from details view and name editor (see #7126)
117 viewer
.setSelection(structuredSelection
, false);
119 showViewer(structuredSelection
, activePart
, viewer
);
120 viewer
.setNeedsRefresh(false);
129 public void refreshSelection(){
130 this.viewer
.refresh_withoutnew_build();
134 protected void showEmptyPage() {
135 super.showEmptyPage();
136 if(viewer
!= null && viewer
.getControl() != null && !viewer
.getControl().isDisposed() ){
138 viewer
.destroySections();
139 }catch(SWTException e
){
140 if (PreferencesUtil
.isShowUpWidgetIsDisposedMessages() && e
.getMessage().equals("Widget is disposed")){
141 MessagingUtils
.errorDialog("Widget is disposed",
143 MessagingUtils
.WIDGET_IS_DISPOSED_MESSAGE
,
153 protected String
getViewName(){
154 return Messages
.DetailsViewPart_VIEWER_NAME
;