Project

General

Profile

Download (4.41 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.annotation.PostConstruct;
15
import javax.inject.Inject;
16
import javax.inject.Named;
17

    
18
import org.eclipse.e4.core.di.annotations.Optional;
19
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
20
import org.eclipse.e4.ui.services.IServiceConstants;
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.widgets.Composite;
25

    
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.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
	@PostConstruct
51
	public void create(Composite parent, MPart thisPart) {
52

    
53
	    this.thisPart = thisPart;
54

    
55
	    viewer = new SupplementalDataViewerE4(parent, this);
56
	}
57

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

    
68
        Object partObject = createPartObject(activePart);
69

    
70
	    if(partObject instanceof IPartContentHasSupplementalData) {
71

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

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

    
111
	        showViewer(structuredSelection, activePart, viewer);
112
	        return;
113
	    }
114
        else if(selectionProvidingPart!=null && selectionProvidingPart.isVisible()){
115
            return;
116
        }
117
        else{
118
	        showEmptyPage();
119
	        return;
120
	    }
121
	}
122

    
123
	@Override
124
    protected String getViewName() {
125
		return Messages.SupplementalDataViewPart_VIEWER_NAME;
126
	}
127
}
(1-1/2)