Project

General

Profile

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

    
30

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

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

    
43
	private SupplementalDataViewer viewer;
44

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

    
54

    
55
	/** {@inheritDoc} */
56
	@Override
57
	protected void selectionChanged_internal(IWorkbenchPart part, ISelection selection) {
58
		if(AbstractUtility.getActiveE4Editor() == null){
59
			showEmptyPage();
60
			return;
61
		}
62

    
63
        if(part == this){
64
            return;
65
        }
66

    
67
        if(!(selection instanceof IStructuredSelection)){
68
            return;
69
        }
70

    
71
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
72

    
73
		if((part instanceof EditorPart || part instanceof IPartContentHasSupplementalData)) {
74
			if(structuredSelection.size() != 1){
75
				showEmptyPage();
76
				return;
77
			}
78

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

    
102
	/** {@inheritDoc} */
103
	@Override
104
	public void dispose() {
105
		super.dispose();
106
		selectionService.removePostSelectionListener(this);
107
	}
108

    
109

    
110
	/** {@inheritDoc} */
111
	@Override
112
	public Viewer getViewer() {
113
		return viewer;
114
	}
115

    
116
	/**
117
	 * <p>onComplete</p>
118
	 *
119
	 * @return a boolean.
120
	 */
121
	@Override
122
    public boolean onComplete() {
123
		// TODO Auto-generated method stub
124
		return false;
125
	}
126

    
127

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