Project

General

Profile

Download (4.23 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.view.e4.supplementaldata;
11

    
12
import java.util.Set;
13

    
14
import javax.inject.Inject;
15
import javax.inject.Named;
16

    
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

    
25
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
26
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
27
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
28
import eu.etaxonomy.cdm.model.taxon.Taxon;
29
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
30
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
31
import eu.etaxonomy.taxeditor.l10n.Messages;
32
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
33
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
34
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmDataViewerE4;
35
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
36

    
37

    
38
/**
39
 *
40
 * @author pplitzner
41
 * @since Aug 10, 2017
42
 *
43
 */
44
public class SupplementalDataPartE4 extends AbstractCdmEditorPartE4 {
45

    
46
	@Inject
47
    public SupplementalDataPartE4() {
48
    }
49

    
50
	@Override
51
	public AbstractCdmDataViewerE4 createViewer(Composite parent) {
52
		return new SupplementalDataViewerE4(parent, this);
53
	}
54

    
55
	@Inject
56
	@Optional
57
	protected void selectionChanged_internal(
58
	        @Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
59
	        @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
60
	        MPart thisPart) {
61
	    if(activePart==thisPart){
62
	        return;
63
	    }
64

    
65
	    IStructuredSelection structuredSelection = createSelection(selection);
66
	    if(structuredSelection.isEmpty()){
67
	        showEmptyPage();
68
	        return;
69
	    }
70

    
71
        Object partObject = createPartObject(activePart);
72

    
73
	    if(partObject instanceof IPartContentHasSupplementalData) {
74
	        if(structuredSelection.size() != 1){
75
	            showEmptyPage();
76
	            return;
77
	        }
78
	        if (partObject instanceof ITaxonEditor && structuredSelection.getFirstElement() instanceof Taxon ){
79
	            if (((ITaxonEditor)partObject).getTaxon() != structuredSelection.getFirstElement() && ((Taxon)structuredSelection.getFirstElement()).isMisapplication()){
80
	                Set<TaxonRelationship> rels =((Taxon)structuredSelection.getFirstElement()).getTaxonRelations(((ITaxonEditor)partObject).getTaxon());
81
	                if (rels.size() == 1){
82
	                    structuredSelection = new StructuredSelection(rels.iterator().next());
83
	                }else{
84
	                    showEmptyPage();
85
	                    return;
86
	                }
87

    
88
	            }
89
	        }
90
	        // do not show supplemental data for feature nodes
91
	        if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
92
	            showEmptyPage();
93
	            return;
94
	        }
95
	        else if(structuredSelection.getFirstElement() instanceof DerivedUnitFacade){
96
	            return;
97
	        }
98
	        else if(structuredSelection.getFirstElement() instanceof PolytomousKeyNode){
99
	            structuredSelection = new StructuredSelection(((PolytomousKeyNode)structuredSelection.getFirstElement()).getKey());
100
	        }
101
	        else if(structuredSelection.getFirstElement() instanceof TreeNode){
102
	            structuredSelection = new StructuredSelection(((TreeNode)structuredSelection.getFirstElement()).getValue());
103
	        }
104
	        else if(structuredSelection.getFirstElement() instanceof GbifResponse){
105
	            structuredSelection = new StructuredSelection(((GbifResponse)structuredSelection.getFirstElement()).getDerivedUnitFacade().innerDerivedUnit());
106
	        }
107

    
108
	        showViewer(structuredSelection, activePart);
109
	        return;
110
	    }else{
111
	        showEmptyPage();
112
	        return;
113
	    }
114
	}
115

    
116
	@Override
117
    protected String getViewName() {
118
		return Messages.SupplementalDataViewPart_VIEWER_NAME;
119
	}
120
}
(1-1/2)