2 * Copyright (C) 2007 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
.supplementaldata
;
13 import javax
.annotation
.PostConstruct
;
14 import javax
.inject
.Inject
;
16 import org
.eclipse
.e4
.core
.contexts
.ContextInjectionFactory
;
17 import org
.eclipse
.e4
.core
.contexts
.IEclipseContext
;
18 import org
.eclipse
.e4
.core
.di
.annotations
.Optional
;
19 import org
.eclipse
.e4
.ui
.di
.UIEventTopic
;
20 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
21 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
22 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
23 import org
.eclipse
.jface
.viewers
.TreeNode
;
24 import org
.eclipse
.swt
.SWTException
;
25 import org
.eclipse
.swt
.widgets
.Composite
;
27 import eu
.etaxonomy
.cdm
.ext
.occurrence
.gbif
.GbifResponse
;
28 import eu
.etaxonomy
.cdm
.facade
.DerivedUnitFacade
;
29 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
30 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
31 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
32 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
35 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermDto
;
36 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermNodeDto
;
37 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermVocabularyDto
;
38 import eu
.etaxonomy
.taxeditor
.editor
.ITaxonEditor
;
39 import eu
.etaxonomy
.taxeditor
.event
.WorkbenchEventConstants
;
40 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
41 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
42 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
43 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
44 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
45 import eu
.etaxonomy
.taxeditor
.view
.e4
.AbstractCdmEditorPart
;
51 public class SupplementalDataPartE4
extends AbstractCdmEditorPart
<SupplementalDataViewerE4
> {
54 public SupplementalDataPartE4() {}
57 public void create(Composite parent
, MPart thisPart
, IEclipseContext context
) {
59 this.thisPart
= thisPart
;
61 viewer
= ContextInjectionFactory
.make(SupplementalDataViewerE4
.class, context
);
62 viewer
.init(parent
, this);
66 public void selectionChanged_internal(Object selection
, MPart activePart
, MPart thisPart
) {
67 if(activePart
== thisPart
){
71 Object partObject
= getPartObject(activePart
);
73 if(partObject
instanceof IPartContentHasSupplementalData
) {
76 IStructuredSelection structuredSelection
= createSelection(selection
);
77 if(structuredSelection
== null || structuredSelection
.isEmpty()){
81 if(structuredSelection
.size() != 1){
85 if (partObject
instanceof ITaxonEditor
&& structuredSelection
.getFirstElement() instanceof Taxon
){
86 if (((ITaxonEditor
)partObject
).getTaxon() != structuredSelection
.getFirstElement() && ((Taxon
)structuredSelection
.getFirstElement()).isMisapplication()){
87 Set
<TaxonRelationship
> rels
=((Taxon
)structuredSelection
.getFirstElement()).getTaxonRelations(((ITaxonEditor
)partObject
).getTaxon());
88 if (rels
!= null && rels
.size() == 1){
89 structuredSelection
= new StructuredSelection(rels
.iterator().next());
96 // do not show supplemental data for feature nodes
97 if(structuredSelection
.getFirstElement() instanceof FeatureNodeContainer
){
102 else if(structuredSelection
.getFirstElement() instanceof DerivedUnitFacade
){
105 else if(structuredSelection
.getFirstElement() instanceof PolytomousKeyNode
){
106 structuredSelection
= new StructuredSelection(((PolytomousKeyNode
)structuredSelection
.getFirstElement()).getKey());
108 else if(structuredSelection
.getFirstElement() instanceof TreeNode
){
109 structuredSelection
= new StructuredSelection(((TreeNode
)structuredSelection
.getFirstElement()).getValue());
111 else if(structuredSelection
.getFirstElement() instanceof GbifResponse
){
112 structuredSelection
= new StructuredSelection(((GbifResponse
)structuredSelection
.getFirstElement()).getDerivedUnitFacade().innerDerivedUnit());
114 else if(structuredSelection
.getFirstElement() instanceof DescriptionElementBase
){
115 structuredSelection
= new StructuredSelection((structuredSelection
.getFirstElement()));
117 if (((DescriptionElementBase
)structuredSelection
.getFirstElement()).getInDescription() != null && (((DescriptionElementBase
)structuredSelection
.getFirstElement()).getInDescription().isComputed() || ((DescriptionElementBase
)structuredSelection
.getFirstElement()).getInDescription().isCloneForSource())){
118 if (PreferencesUtil
.isComputedDesciptionHandlingDisabled()){
125 else if(structuredSelection
.getFirstElement() instanceof DescriptionBase
){
127 if (((DescriptionBase
<?
>)structuredSelection
.getFirstElement()).isComputed() || ((DescriptionBase
<?
>)structuredSelection
.getFirstElement()).isCloneForSource()){
128 if (PreferencesUtil
.isComputedDesciptionHandlingDisabled()){
135 else if(structuredSelection
.getFirstElement() instanceof TermDto
136 || structuredSelection
.getFirstElement() instanceof TermVocabularyDto
137 || structuredSelection
.getFirstElement() instanceof TermNodeDto
){
138 showViewer(structuredSelection
, activePart
, viewer
);
142 if(!(structuredSelection
.getFirstElement() instanceof ICdmBase
)){
146 showViewer(structuredSelection
, activePart
, viewer
);
147 viewer
.setEnabled(isEnabled());
158 protected void showEmptyPage() {
159 super.showEmptyPage();
160 if(viewer
!= null && viewer
.getControl() !=null && !viewer
.getControl().isDisposed()){
162 viewer
.destroySections();
163 }catch (SWTException e
){
164 if (PreferencesUtil
.isShowUpWidgetIsDisposedMessages() && e
.getMessage().equals("Widget is disposed")){
165 MessagingUtils
.errorDialog("Widget is disposed",
167 MessagingUtils
.WIDGET_IS_DISPOSED_MESSAGE
,
177 protected String
getViewName() {
178 return Messages
.SupplementalDataViewPart_VIEWER_NAME
;
183 private void updateView(@UIEventTopic(WorkbenchEventConstants
.REFRESH_SUPPLEMENTAL
)boolean refresh
){