9444596f5a7d8a3a45abbaedf5397335f56300fa
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / detail / DetailsViewPart.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.detail;
12
13 import org.eclipse.jface.viewers.ISelection;
14 import org.eclipse.jface.viewers.IStructuredSelection;
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.IEditorPart;
19 import org.eclipse.ui.IWorkbenchPart;
20
21 import eu.etaxonomy.cdm.model.common.CdmBase;
22 import eu.etaxonomy.cdm.model.description.Feature;
23 import eu.etaxonomy.taxeditor.model.AbstractUtility;
24 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
25 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
26 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
27 import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
28
29 /**
30 * <p>DetailsViewPart class.</p>
31 *
32 * @author n.hoffmann
33 * @created Jun 10, 2010
34 * @version 1.0
35 */
36 public class DetailsViewPart extends AbstractCdmEditorViewPart implements IPartContentHasSupplementalData{
37
38 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.forms.det"{trunked}</code> */
39 public static String ID = "eu.etaxonomy.taxeditor.view.detail";
40
41 private DetailsViewer viewer;
42
43 /** {@inheritDoc} */
44 @Override
45 public void createViewer(Composite parent) {
46
47 viewer = new DetailsViewer(parent, this);
48 getSite().setSelectionProvider(viewer);
49 }
50
51 @Override
52 protected void selectionChanged_internal(IWorkbenchPart part, ISelection selection){
53 if(AbstractUtility.getActiveEditor() == null){
54 showEmptyPage();
55 return;
56 }
57
58 if(part == this){
59 return;
60 }
61
62 if(!(selection instanceof IStructuredSelection)){
63 return;
64 }
65
66 IStructuredSelection structuredSelection = (IStructuredSelection) selection;
67
68 if((part instanceof IEditorPart) || (part instanceof IPartContentHasDetails)) {
69 if(structuredSelection.size() != 1){
70 setPartName(createPartTitle(null));
71 showEmptyPage();
72 return;
73 }
74
75 // do not show details for feature nodes TODO really?
76 if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
77 // do show the map for distributions
78 Feature feature = ((FeatureNodeContainer) ((IStructuredSelection) selection).getFirstElement()).getFeature();
79 if(!feature.equals(Feature.DISTRIBUTION())){
80 setPartName(createPartTitle(null));
81 showEmptyPage();
82 return;
83 }
84 }
85
86
87 setPartName(createPartTitle(((IStructuredSelection) selection).getFirstElement()));
88 showViewer(part, structuredSelection);
89 }else{
90 setPartName(createPartTitle(null));
91 showEmptyPage();
92 }
93 }
94
95 private String getViewName(){
96 return "Details";
97 }
98
99 private String createPartTitle(Object selectedObject){
100 if(selectedObject!=null){
101 if(selectedObject instanceof TreeNode){
102 selectedObject = ((TreeNode) selectedObject).getValue();
103 }
104 return getViewName()+": "+selectedObject;
105 }
106 return getViewName();
107 }
108
109 @Override
110 public void showEmptyPage() {
111 viewer.setSelection(null);
112 super.showEmptyPage();
113 }
114
115 /** {@inheritDoc} */
116 @Override
117 public boolean postOperation(CdmBase objectAffectedByOperation) {
118
119 viewer.setInput(objectAffectedByOperation);
120
121 return super.postOperation(objectAffectedByOperation);
122 }
123
124
125 /** {@inheritDoc} */
126 @Override
127 public Viewer getViewer() {
128 return viewer;
129 }
130
131
132 /** {@inheritDoc} */
133 @Override
134 public void dispose() {
135 selectionService.removePostSelectionListener(this);
136 super.dispose();
137
138 }
139
140 @Override
141 public boolean onComplete() {
142 return true;
143 }
144 }