Project

General

Profile

Download (4.07 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.supplementaldata;
11

    
12
import org.eclipse.jface.viewers.ISelection;
13
import org.eclipse.jface.viewers.IStructuredSelection;
14
import org.eclipse.jface.viewers.StructuredSelection;
15
import org.eclipse.jface.viewers.TreeNode;
16
import org.eclipse.jface.viewers.Viewer;
17
import org.eclipse.swt.widgets.Composite;
18
import org.eclipse.ui.IWorkbenchPart;
19
import org.eclipse.ui.part.EditorPart;
20

    
21
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
22
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
23
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
24
import eu.etaxonomy.taxeditor.l10n.Messages;
25
import eu.etaxonomy.taxeditor.model.AbstractUtility;
26
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
27
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
28
import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
29
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
30

    
31

    
32
/**
33
 * <p>SupplementalDataViewPart class.</p>
34
 *
35
 * @author n.hoffmann
36
 * @created Jun 10, 2010
37
 * @version 1.0
38
 */
39
public class SupplementalDataViewPart extends AbstractCdmEditorViewPart {
40

    
41
	/** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.supp"{trunked}</code> */
42
	public static final String ID = "eu.etaxonomy.taxeditor.view.supplementalData"; //$NON-NLS-1$
43

    
44
	private SupplementalDataViewer viewer;
45

    
46
	/* (non-Javadoc)
47
	 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
48
	 */
49
	/** {@inheritDoc} */
50
	@Override
51
	public void createViewer(Composite parent) {
52
		viewer = new SupplementalDataViewer(parent, this);
53
	}
54

    
55

    
56
	/** {@inheritDoc} */
57
	@Override
58
	protected void selectionChanged_internal(IWorkbenchPart workbenchPart, ISelection selection) {
59
	    Object partObject = workbenchPart;
60
        Object wrappedPart = WorkbenchUtility.getE4WrappedPart(partObject);
61
        if(wrappedPart!=null){
62
            partObject = wrappedPart;
63
        }
64
		if(AbstractUtility.getActiveE4Editor() == null){
65
			showEmptyPage();
66
			return;
67
		}
68

    
69
        if(partObject == this){
70
            return;
71
        }
72

    
73
        if(!(selection instanceof IStructuredSelection)){
74
            return;
75
        }
76

    
77
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
78

    
79
		if((partObject instanceof EditorPart || partObject instanceof IPartContentHasSupplementalData)) {
80
			if(structuredSelection.size() != 1){
81
				showEmptyPage();
82
				return;
83
			}
84

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

    
108
	/** {@inheritDoc} */
109
	@Override
110
	public void dispose() {
111
		super.dispose();
112
		selectionService.removePostSelectionListener(this);
113
	}
114

    
115

    
116
	/** {@inheritDoc} */
117
	@Override
118
	public Viewer getViewer() {
119
		return viewer;
120
	}
121

    
122
	/**
123
	 * <p>onComplete</p>
124
	 *
125
	 * @return a boolean.
126
	 */
127
	@Override
128
    public boolean onComplete() {
129
		// TODO Auto-generated method stub
130
		return false;
131
	}
132

    
133

    
134
	@Override
135
	protected String getViewName() {
136
		return Messages.SupplementalDataViewPart_VIEWER_NAME;
137
	}
138
}
(1-1/2)