37ae4fd92cc94c8f0fb775c1b8f8d8f0e1c18a3d
[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.model.description.PolytomousKeyNode;
24 import eu.etaxonomy.taxeditor.model.AbstractUtility;
25 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
26 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
27 import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
28
29
30 /**
31 * <p>SupplementalDataViewPart class.</p>
32 *
33 * @author n.hoffmann
34 * @created Jun 10, 2010
35 * @version 1.0
36 */
37 public class SupplementalDataViewPart extends AbstractCdmEditorViewPart {
38
39 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.supp"{trunked}</code> */
40 public static final String ID = "eu.etaxonomy.taxeditor.view.supplementalData";
41
42 private SupplementalDataViewer viewer;
43
44 /* (non-Javadoc)
45 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
46 */
47 /** {@inheritDoc} */
48 @Override
49 public void createViewer(Composite parent) {
50 viewer = new SupplementalDataViewer(parent, this);
51 }
52
53
54 /** {@inheritDoc} */
55 @Override
56 public void selectionChanged(IWorkbenchPart part, ISelection selection) {
57 if(AbstractUtility.getActiveEditor() == null){
58 showEmptyPage();
59 return;
60 }
61
62 if(part == this){
63 return;
64 }
65
66 if(!(selection instanceof IStructuredSelection)){
67 return;
68 }
69
70 IStructuredSelection structuredSelection = (IStructuredSelection) selection;
71
72 if((part instanceof EditorPart || part instanceof IPartContentHasSupplementalData)) {
73 if(structuredSelection.size() != 1){
74 showEmptyPage();
75 return;
76 }
77
78 // do not show supplemental data for feature nodes
79 if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
80 showEmptyPage();
81 return;
82 }
83 else if(structuredSelection.getFirstElement() instanceof DerivedUnitFacade){
84 return;
85 }
86 else if(structuredSelection.getFirstElement() instanceof PolytomousKeyNode){
87 structuredSelection = new StructuredSelection(((PolytomousKeyNode)structuredSelection.getFirstElement()).getKey());
88 }
89 else if(structuredSelection.getFirstElement() instanceof TreeNode){
90 structuredSelection = new StructuredSelection(((TreeNode)structuredSelection.getFirstElement()).getValue());
91 }
92 showViewer(part, structuredSelection);
93 }else{
94 showEmptyPage();
95 }
96 }
97
98 /** {@inheritDoc} */
99 @Override
100 public void dispose() {
101 super.dispose();
102 selectionService.removePostSelectionListener(this);
103 }
104
105
106 /** {@inheritDoc} */
107 @Override
108 public Viewer getViewer() {
109 return viewer;
110 }
111
112 /**
113 * <p>onComplete</p>
114 *
115 * @return a boolean.
116 */
117 @Override
118 public boolean onComplete() {
119 // TODO Auto-generated method stub
120 return false;
121 }
122
123
124 }