reintegrated campanula branch: removed enum DetailType and all its uses
[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.Viewer;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.ui.IEditorPart;
18 import org.eclipse.ui.IWorkbenchPart;
19
20 import eu.etaxonomy.cdm.model.common.CdmBase;
21 import eu.etaxonomy.cdm.model.description.Feature;
22 import eu.etaxonomy.taxeditor.model.AbstractUtility;
23 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
24 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
25 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
26 import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
27
28 /**
29 * <p>DetailsViewPart class.</p>
30 *
31 * @author n.hoffmann
32 * @created Jun 10, 2010
33 * @version 1.0
34 */
35 public class DetailsViewPart extends AbstractCdmEditorViewPart implements IPartContentHasSupplementalData{
36
37 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.forms.det"{trunked}</code> */
38 public static String ID = "eu.etaxonomy.taxeditor.view.detail";
39
40 private DetailsViewer viewer;
41
42 /** {@inheritDoc} */
43 @Override
44 public void createViewer(Composite parent) {
45 //selectionService.addPostSelectionListener(this);
46
47 viewer = new DetailsViewer(parent, this);
48 getSite().setSelectionProvider(viewer);
49 }
50
51 /** {@inheritDoc} */
52 @Override
53 public void selectionChanged(IWorkbenchPart part, ISelection selection) {
54 if(AbstractUtility.getActiveEditor() == null){
55 showEmptyPage();
56 return;
57 }
58
59 if(part == this){
60 return;
61 }
62
63 if(!(selection instanceof IStructuredSelection)){
64 return;
65 }
66
67 IStructuredSelection structuredSelection = (IStructuredSelection) selection;
68
69 if((part instanceof IEditorPart) || (part instanceof IPartContentHasDetails)) {
70 if(structuredSelection.size() != 1){
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 showEmptyPage();
81 return;
82 }
83 }
84
85 showViewer(part, structuredSelection);
86 }else{
87 showEmptyPage();
88 }
89 }
90
91 /** {@inheritDoc} */
92 @Override
93 public boolean postOperation(CdmBase objectAffectedByOperation) {
94
95 viewer.setInput(objectAffectedByOperation);
96
97 return super.postOperation(objectAffectedByOperation);
98 }
99
100
101 /** {@inheritDoc} */
102 @Override
103 public Viewer getViewer() {
104 return viewer;
105 }
106
107
108 /** {@inheritDoc} */
109 @Override
110 public void dispose() {
111 super.dispose();
112 selectionService.removePostSelectionListener(this);
113 }
114
115 /**
116 * <p>onComplete</p>
117 *
118 * @return a boolean.
119 */
120 @Override
121 public boolean onComplete() {
122 return true;
123 }
124 }