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.
10 package eu
.etaxonomy
.taxeditor
.view
.e4
.supplementaldata
;
14 import javax
.inject
.Inject
;
15 import javax
.inject
.Named
;
17 import org
.eclipse
.e4
.core
.di
.annotations
.Optional
;
18 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
19 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
20 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
21 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
22 import org
.eclipse
.jface
.viewers
.TreeNode
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.ui
.part
.EditorPart
;
26 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
27 import eu
.etaxonomy
.cdm
.ext
.occurrence
.gbif
.GbifResponse
;
28 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
31 import eu
.etaxonomy
.taxeditor
.editor
.ITaxonEditor
;
32 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
33 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
34 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
35 import eu
.etaxonomy
.taxeditor
.view
.e4
.AbstractCdmDataViewerE4
;
36 import eu
.etaxonomy
.taxeditor
.view
.e4
.AbstractCdmEditorPartE4
;
37 import eu
.etaxonomy
.taxeditor
.workbench
.WorkbenchUtility
;
46 public class SupplementalDataPartE4
extends AbstractCdmEditorPartE4
{
49 public SupplementalDataPartE4() {
53 public AbstractCdmDataViewerE4
createViewer(Composite parent
) {
54 return new SupplementalDataViewerE4(parent
, this);
59 protected void selectionChanged_internal(
60 @Named(IServiceConstants
.ACTIVE_SELECTION
)Object selection
,
61 @Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
63 if(activePart
==thisPart
){
71 Object partObject
= activePart
;
72 Object wrappedPart
= WorkbenchUtility
.getE4WrappedPart(partObject
);
73 if(wrappedPart
!=null){
74 partObject
= wrappedPart
;
77 IStructuredSelection structuredSelection
;
78 if(!(selection
instanceof IStructuredSelection
)){
79 structuredSelection
= new StructuredSelection(selection
);
82 structuredSelection
= (IStructuredSelection
) selection
;
84 if(structuredSelection
.isEmpty()){
89 if((partObject
instanceof EditorPart
|| partObject
instanceof IPartContentHasSupplementalData
)) {
90 if(structuredSelection
.size() != 1){
94 if (partObject
instanceof ITaxonEditor
&& structuredSelection
.getFirstElement() instanceof Taxon
){
95 if (((ITaxonEditor
)partObject
).getTaxon() != structuredSelection
.getFirstElement() && ((Taxon
)structuredSelection
.getFirstElement()).isMisapplication()){
96 Set
<TaxonRelationship
> rels
=((Taxon
)structuredSelection
.getFirstElement()).getTaxonRelations(((ITaxonEditor
)partObject
).getTaxon());
97 if (rels
.size() == 1){
98 structuredSelection
= new StructuredSelection(rels
.iterator().next());
106 // do not show supplemental data for feature nodes
107 if(structuredSelection
.getFirstElement() instanceof FeatureNodeContainer
){
111 else if(structuredSelection
.getFirstElement() instanceof DerivedUnitFacade
){
114 else if(structuredSelection
.getFirstElement() instanceof PolytomousKeyNode
){
115 structuredSelection
= new StructuredSelection(((PolytomousKeyNode
)structuredSelection
.getFirstElement()).getKey());
117 else if(structuredSelection
.getFirstElement() instanceof TreeNode
){
118 structuredSelection
= new StructuredSelection(((TreeNode
)structuredSelection
.getFirstElement()).getValue());
120 else if(structuredSelection
.getFirstElement() instanceof GbifResponse
){
121 structuredSelection
= new StructuredSelection(((GbifResponse
)structuredSelection
.getFirstElement()).getDerivedUnitFacade().innerDerivedUnit());
124 showViewer(structuredSelection
, activePart
);
133 protected String
getViewName() {
134 return Messages
.SupplementalDataViewPart_VIEWER_NAME
;