Project

General

Profile

Download (5.42 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.core.contexts.ContextInjectionFactory;
18
import org.eclipse.e4.core.contexts.IEclipseContext;
19
import org.eclipse.e4.core.services.log.Logger;
20
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
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.SWTException;
25
import org.eclipse.swt.widgets.Composite;
26

    
27
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
28
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
29
import eu.etaxonomy.cdm.model.common.ICdmBase;
30
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
31
import eu.etaxonomy.cdm.model.taxon.Taxon;
32
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
33
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
34
import eu.etaxonomy.taxeditor.l10n.Messages;
35
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
36
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
37
import eu.etaxonomy.taxeditor.model.MessagingUtils;
38
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
39
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
40

    
41

    
42
/**
43
 *
44
 * @author pplitzner
45
 * @since Aug 10, 2017
46
 *
47
 */
48
public class SupplementalDataPartE4 extends AbstractCdmEditorPartE4 {
49
	@Inject
50
	private Logger logger;
51
	
52
	@Inject
53
    public SupplementalDataPartE4() {
54
    }
55

    
56
	@PostConstruct
57
	public void create(Composite parent, MPart thisPart, IEclipseContext context) {
58

    
59
	    this.thisPart = thisPart;
60

    
61
	    viewer = ContextInjectionFactory.make(SupplementalDataViewerE4.class, context);
62
	    ((SupplementalDataViewerE4)viewer).init(parent, this);
63
	}
64

    
65
    @Override
66
    public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
67
	    if(activePart==thisPart){
68
	        return;
69
	    }
70

    
71
        Object partObject = createPartObject(activePart);
72

    
73
	    if(partObject instanceof IPartContentHasSupplementalData) {
74

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

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

    
114
	        if(!(structuredSelection.getFirstElement() instanceof ICdmBase)){
115
	            showEmptyPage();
116
	            return;
117
	        }
118
	        showViewer(structuredSelection, activePart, viewer);
119
	        return;
120
	    }
121
        else{
122
	        showEmptyPage();
123
	        return;
124
	    }
125
	}
126

    
127
    /**
128
     * {@inheritDoc}
129
     */
130
    @Override
131
    protected void showEmptyPage() {
132
        super.showEmptyPage();
133
        if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed()){
134
        	try{
135
        		((SupplementalDataViewerE4)viewer).destroySections();
136
        	}catch (SWTException e){
137
        		if (PreferencesUtil.isShowUpWidgetIsDisposedMessages() && e.getMessage().equals("Widget is disposed")){
138
                    MessagingUtils.errorDialog("Widget is disposed",
139
                            null,
140
                            MessagingUtils.WIDGET_IS_DISPOSED_MESSAGE,
141
                            null,
142
                            e,
143
                            true);
144

    
145
                }
146
        	}
147
        }
148
    }
149

    
150
	@Override
151
    protected String getViewName() {
152
		return Messages.SupplementalDataViewPart_VIEWER_NAME;
153
	}
154
}
(1-1/2)