Project

General

Profile

Download (5.8 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.annotation.PreDestroy;
16
import javax.inject.Inject;
17
import javax.inject.Named;
18

    
19
import org.eclipse.e4.core.di.annotations.Optional;
20
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
21
import org.eclipse.e4.ui.services.IServiceConstants;
22
import org.eclipse.jface.viewers.IStructuredSelection;
23
import org.eclipse.jface.viewers.StructuredSelection;
24
import org.eclipse.jface.viewers.TreeNode;
25
import org.eclipse.jface.viewers.Viewer;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.ui.part.EditorPart;
28

    
29
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
30
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
31
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
32
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
33
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
34
import eu.etaxonomy.cdm.model.taxon.Taxon;
35
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
36
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
37
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
38
import eu.etaxonomy.taxeditor.l10n.Messages;
39
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
40
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
41
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
42
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
43

    
44

    
45
/**
46
 *
47
 * @author pplitzner
48
 * @since Aug 10, 2017
49
 *
50
 */
51
public class SupplementalDataPartE4 implements IConversationEnabled, IDirtyMarkable{
52

    
53
	private SupplementalDataViewerE4 viewer;
54

    
55
	@Inject
56
    public SupplementalDataPartE4() {
57
    }
58

    
59
	@PostConstruct
60
	public void create(Composite parent) {
61
		viewer = new SupplementalDataViewerE4(parent, this);
62
	}
63

    
64

    
65
    @Inject
66
    @Optional
67
	protected void selectionChanged_internal(
68
            @Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
69
            @Named(IServiceConstants.ACTIVE_PART)MPart activePart,
70
            MPart thisPart) {
71
        if(activePart==thisPart){
72
            return;
73
        }
74
        if(selection==null){
75
            showEmptyPage();
76
            return;
77
        }
78

    
79
	    Object partObject = activePart;
80
        Object wrappedPart = WorkbenchUtility.getE4WrappedPart(partObject);
81
        if(wrappedPart!=null){
82
            partObject = wrappedPart;
83
        }
84

    
85
        IStructuredSelection structuredSelection;
86
        if(!(selection instanceof IStructuredSelection)){
87
            structuredSelection = new StructuredSelection(selection);
88
        }
89
        else{
90
            structuredSelection = (IStructuredSelection) selection;
91
        }
92
        if(structuredSelection.isEmpty()){
93
            showEmptyPage();
94
            return;
95
        }
96

    
97
		if((partObject instanceof EditorPart || partObject instanceof IPartContentHasSupplementalData)) {
98
			if(structuredSelection.size() != 1){
99
				showEmptyPage();
100
				return;
101
			}
102
		if (partObject instanceof ITaxonEditor && structuredSelection.getFirstElement() instanceof Taxon ){
103
			if (((ITaxonEditor)partObject).getTaxon() != structuredSelection.getFirstElement() && ((Taxon)structuredSelection.getFirstElement()).isMisapplication()){
104
				Set<TaxonRelationship> rels =((Taxon)structuredSelection.getFirstElement()).getTaxonRelations(((ITaxonEditor)partObject).getTaxon());
105
				if (rels.size() == 1){
106
					 structuredSelection = new StructuredSelection(rels.iterator().next());
107
				}else{
108
					showEmptyPage();
109
					return;
110
				}
111

    
112
			}
113
		}
114
			// do not show supplemental data for feature nodes
115
			if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
116
				showEmptyPage();
117
				return;
118
			}
119
			else if(structuredSelection.getFirstElement() instanceof DerivedUnitFacade){
120
				return;
121
			}
122
			else if(structuredSelection.getFirstElement() instanceof PolytomousKeyNode){
123
			    structuredSelection = new StructuredSelection(((PolytomousKeyNode)structuredSelection.getFirstElement()).getKey());
124
            }
125
			else if(structuredSelection.getFirstElement() instanceof TreeNode){
126
				structuredSelection = new StructuredSelection(((TreeNode)structuredSelection.getFirstElement()).getValue());
127
			}
128
			else if(structuredSelection.getFirstElement() instanceof GbifResponse){
129
			    structuredSelection = new StructuredSelection(((GbifResponse)structuredSelection.getFirstElement()).getDerivedUnitFacade().innerDerivedUnit());
130
			}
131

    
132
			showViewer(structuredSelection);
133
			return;
134
		}else{
135
			showEmptyPage();
136
			return;
137
		}
138
	}
139

    
140
    public void showViewer(IStructuredSelection selection){
141
        if(getViewer()!=null){
142
            Object element = selection.getFirstElement();
143
            if(selection.getFirstElement()!=null){
144
                getViewer().setInput(element);
145
            }
146
        }
147
    }
148

    
149
    public void showEmptyPage() {
150
        if(viewer!=null){
151
            viewer.showEmptyPage();
152
        }
153
    }
154

    
155
	@PreDestroy
156
	public void dispose() {
157
	}
158

    
159
	public Viewer getViewer() {
160
		return viewer;
161
	}
162

    
163
	protected String getViewName() {
164
		return Messages.SupplementalDataViewPart_VIEWER_NAME;
165
	}
166

    
167
	/**
168
	 * {@inheritDoc}
169
	 */
170
	@Override
171
	public void forceDirty() {
172
	    // TODO Auto-generated method stub
173

    
174
	}
175

    
176
    /**
177
     * {@inheritDoc}
178
     */
179
    @Override
180
    public void update(CdmDataChangeMap arg0) {
181
        // TODO Auto-generated method stub
182

    
183
    }
184

    
185
    /**
186
     * {@inheritDoc}
187
     */
188
    @Override
189
    public void changed(Object element) {
190
        // TODO Auto-generated method stub
191

    
192
    }
193

    
194
    /**
195
     * {@inheritDoc}
196
     */
197
    @Override
198
    public ConversationHolder getConversationHolder() {
199
        // TODO Auto-generated method stub
200
        return null;
201
    }
202
}
(1-1/2)