Merge branch 'develop' into remoting-4.0
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / supplementaldata / SupplementalDataViewPart.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.view.supplementaldata;
12
13 import org.eclipse.jface.viewers.ISelection;
14 import org.eclipse.jface.viewers.IStructuredSelection;
15 import org.eclipse.jface.viewers.StructuredSelection;
16 import org.eclipse.jface.viewers.TreeNode;
17 import org.eclipse.jface.viewers.Viewer;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.ui.IWorkbenchPart;
20 import org.eclipse.ui.part.EditorPart;
21
22 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
23 import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
24 import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
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";
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.getActiveEditor() == 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 }