Project

General

Profile

Download (4.53 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

    
17
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.jface.viewers.StructuredSelection;
20
import org.eclipse.jface.viewers.TreeNode;
21
import org.eclipse.swt.widgets.Composite;
22

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

    
35

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

    
44
	@Inject
45
    public SupplementalDataPartE4() {
46
    }
47

    
48
	@PostConstruct
49
	public void create(Composite parent, MPart thisPart) {
50

    
51
	    this.thisPart = thisPart;
52

    
53
	    viewer = new SupplementalDataViewerE4(parent, this);
54
	}
55

    
56
    @Override
57
    public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
58
	    if(activePart==thisPart){
59
	        return;
60
	    }
61

    
62
        Object partObject = createPartObject(activePart);
63

    
64
	    if(partObject instanceof IPartContentHasSupplementalData) {
65

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

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

    
105
	        if(!(structuredSelection.getFirstElement() instanceof ICdmBase)){
106
	            showEmptyPage();
107
	            return;
108
	        }
109
	        showViewer(structuredSelection, activePart, viewer);
110
	        return;
111
	    }
112
        else{
113
	        showEmptyPage();
114
	        return;
115
	    }
116
	}
117

    
118
    /**
119
     * {@inheritDoc}
120
     */
121
    @Override
122
    protected void showEmptyPage() {
123
        super.showEmptyPage();
124
        if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed()){
125
            ((SupplementalDataViewerE4)viewer).destroySections();
126
        }
127
    }
128

    
129
	@Override
130
    protected String getViewName() {
131
		return Messages.SupplementalDataViewPart_VIEWER_NAME;
132
	}
133
}
(1-1/2)