Project

General

Profile

Download (4.35 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) {
52
		viewer = 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
        Object partObject = createPartObject(activePart);
66

    
67
	    if(partObject instanceof IPartContentHasSupplementalData) {
68

    
69
	        IStructuredSelection structuredSelection = createSelection(selection);
70
	        if(structuredSelection==null || structuredSelection.isEmpty()){
71
	            showEmptyPage();
72
	            return;
73
	        }
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
	    }
111
        else if(selectionProvidingPart!=null && selectionProvidingPart.isVisible()){
112
            return;
113
        }
114
        else{
115
	        showEmptyPage();
116
	        return;
117
	    }
118
	}
119

    
120
	@Override
121
    protected String getViewName() {
122
		return Messages.SupplementalDataViewPart_VIEWER_NAME;
123
	}
124
}
(1-1/2)