1 |
2d9a13f7
|
n.hoffmann
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
20326c1c
|
Patric Plitzner
|
* European Distributed Institute of Taxonomy
|
4 |
2d9a13f7
|
n.hoffmann
|
* http://www.e-taxonomy.eu
|
5 |
20326c1c
|
Patric Plitzner
|
*
|
6 |
2d9a13f7
|
n.hoffmann
|
* 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 |
f211dd28
|
n.hoffmann
|
package eu.etaxonomy.taxeditor.view.detail;
|
11 |
2d9a13f7
|
n.hoffmann
|
|
12 |
f13a970a
|
Patrick Plitzner
|
import java.util.Collection;
|
13 |
|
|
|
14 |
2443669b
|
Patrick Plitzner
|
import org.eclipse.core.runtime.IProgressMonitor;
|
15 |
f13a970a
|
Patrick Plitzner
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
16 |
|
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
17 |
2d9a13f7
|
n.hoffmann
|
import org.eclipse.jface.viewers.ISelection;
|
18 |
|
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
19 |
d9a8f632
|
Patric Plitzner
|
import org.eclipse.jface.viewers.TreeNode;
|
20 |
2d9a13f7
|
n.hoffmann
|
import org.eclipse.jface.viewers.Viewer;
|
21 |
|
|
import org.eclipse.swt.widgets.Composite;
|
22 |
30140758
|
n.hoffmann
|
import org.eclipse.ui.IEditorPart;
|
23 |
2443669b
|
Patrick Plitzner
|
import org.eclipse.ui.IMemento;
|
24 |
2d9a13f7
|
n.hoffmann
|
import org.eclipse.ui.IWorkbenchPart;
|
25 |
|
|
|
26 |
af0c6587
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
27 |
9ab081a8
|
Patric Plitzner
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
28 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
29 |
2b2cc2b4
|
n.hoffmann
|
import eu.etaxonomy.cdm.model.description.Feature;
|
30 |
9ab081a8
|
Patric Plitzner
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
31 |
a86dbf9a
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
32 |
ee1ed5a9
|
Patric Plitzner
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
33 |
c10e4c27
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
|
34 |
2443669b
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.model.IContextListener;
|
35 |
ee1ed5a9
|
Patric Plitzner
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
36 |
2d9a13f7
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
37 |
f13a970a
|
Patrick Plitzner
|
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
38 |
f211dd28
|
n.hoffmann
|
import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
|
39 |
2d9a13f7
|
n.hoffmann
|
|
40 |
|
|
/**
|
41 |
3be6ef3e
|
n.hoffmann
|
* <p>DetailsViewPart class.</p>
|
42 |
|
|
*
|
43 |
2d9a13f7
|
n.hoffmann
|
* @author n.hoffmann
|
44 |
|
|
* @created Jun 10, 2010
|
45 |
|
|
* @version 1.0
|
46 |
|
|
*/
|
47 |
2443669b
|
Patrick Plitzner
|
public class DetailsViewPart extends AbstractCdmEditorViewPart implements IPartContentHasSupplementalData, IContextListener{
|
48 |
20326c1c
|
Patric Plitzner
|
|
49 |
3be6ef3e
|
n.hoffmann
|
/** Constant <code>ID="eu.etaxonomy.taxeditor.editor.forms.det"{trunked}</code> */
|
50 |
cc330739
|
Patrick Plitzner
|
public static String ID = "eu.etaxonomy.taxeditor.view.detail"; //$NON-NLS-1$
|
51 |
2d9a13f7
|
n.hoffmann
|
|
52 |
c10e4c27
|
n.hoffmann
|
private DetailsViewer viewer;
|
53 |
2d9a13f7
|
n.hoffmann
|
|
54 |
f13a970a
|
Patrick Plitzner
|
//FIXME E4: this can be removed when working with E4 event system
|
55 |
|
|
private Object selectionProvidingPart;
|
56 |
|
|
|
57 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
58 |
2d9a13f7
|
n.hoffmann
|
@Override
|
59 |
|
|
public void createViewer(Composite parent) {
|
60 |
20326c1c
|
Patric Plitzner
|
|
61 |
c10e4c27
|
n.hoffmann
|
viewer = new DetailsViewer(parent, this);
|
62 |
|
|
getSite().setSelectionProvider(viewer);
|
63 |
2d9a13f7
|
n.hoffmann
|
}
|
64 |
|
|
|
65 |
20326c1c
|
Patric Plitzner
|
@Override
|
66 |
f13a970a
|
Patrick Plitzner
|
protected void selectionChanged_internal(IWorkbenchPart workbenchPart, ISelection selection){
|
67 |
|
|
Object part = workbenchPart;
|
68 |
|
|
Object wrappedPart = AbstractUtility.getE4WrappedPart(part);
|
69 |
|
|
if(wrappedPart!=null){
|
70 |
|
|
part = wrappedPart;
|
71 |
|
|
}
|
72 |
|
|
if(AbstractUtility.getActiveE4Editor() == null && !(AbstractUtility.getActiveE4Part() instanceof IConversationEnabled)){
|
73 |
2832a925
|
Patric Plitzner
|
showEmptyPage();
|
74 |
|
|
return;
|
75 |
|
|
}
|
76 |
|
|
|
77 |
f13a970a
|
Patrick Plitzner
|
//special case where the details view still open with details about the closed object #5495
|
78 |
|
|
try{
|
79 |
|
|
boolean isSelectionProvidingPartStillActive = false;
|
80 |
|
|
if(selectionProvidingPart!=null){
|
81 |
|
|
EPartService partService = TaxeditorStorePlugin.getDefault().getWorkbench().getService(EPartService.class);
|
82 |
|
|
Collection<MPart> parts = partService.getParts();
|
83 |
|
|
for (MPart mPart : parts) {
|
84 |
|
|
if(selectionProvidingPart.equals(mPart.getObject())){
|
85 |
|
|
isSelectionProvidingPartStillActive = true;
|
86 |
|
|
break;
|
87 |
|
|
}
|
88 |
|
|
}
|
89 |
|
|
if(!isSelectionProvidingPartStillActive &&
|
90 |
|
|
selection instanceof IStructuredSelection && ((IStructuredSelection) selection).getFirstElement() !=null){
|
91 |
|
|
showEmptyPage();
|
92 |
|
|
return;
|
93 |
|
|
}
|
94 |
|
|
}
|
95 |
|
|
}catch(IllegalStateException e){
|
96 |
|
|
//nothing
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
if(part == this){
|
100 |
6de63659
|
Patrick Plitzner
|
return;
|
101 |
|
|
}
|
102 |
2832a925
|
Patric Plitzner
|
|
103 |
|
|
if(!(selection instanceof IStructuredSelection)){
|
104 |
|
|
return;
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
|
108 |
|
|
|
109 |
|
|
if((part instanceof IEditorPart) || (part instanceof IPartContentHasDetails)) {
|
110 |
|
|
if(structuredSelection.size() != 1){
|
111 |
|
|
showEmptyPage();
|
112 |
|
|
return;
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
// do not show details for feature nodes TODO really?
|
116 |
|
|
if(structuredSelection.getFirstElement() instanceof FeatureNodeContainer){
|
117 |
|
|
// do show the map for distributions
|
118 |
|
|
Feature feature = ((FeatureNodeContainer) ((IStructuredSelection) selection).getFirstElement()).getFeature();
|
119 |
|
|
if(!feature.equals(Feature.DISTRIBUTION())){
|
120 |
|
|
showEmptyPage();
|
121 |
|
|
return;
|
122 |
|
|
}
|
123 |
|
|
}
|
124 |
f13a970a
|
Patrick Plitzner
|
selectionProvidingPart = part;
|
125 |
2832a925
|
Patric Plitzner
|
showViewer(part, structuredSelection);
|
126 |
|
|
}else{
|
127 |
|
|
showEmptyPage();
|
128 |
|
|
}
|
129 |
|
|
}
|
130 |
|
|
|
131 |
18fd7dae
|
Patrick Plitzner
|
@Override
|
132 |
|
|
protected String getViewName(){
|
133 |
cc330739
|
Patrick Plitzner
|
return Messages.DetailsViewPart_VIEWER_NAME;
|
134 |
d9a8f632
|
Patric Plitzner
|
}
|
135 |
|
|
|
136 |
18fd7dae
|
Patrick Plitzner
|
@Override
|
137 |
|
|
protected String createPartTitle(Object selectedObject){
|
138 |
d9a8f632
|
Patric Plitzner
|
if(selectedObject!=null){
|
139 |
|
|
if(selectedObject instanceof TreeNode){
|
140 |
|
|
selectedObject = ((TreeNode) selectedObject).getValue();
|
141 |
|
|
}
|
142 |
9ab081a8
|
Patric Plitzner
|
if(selectedObject instanceof SpecimenOrObservationBase){
|
143 |
cc330739
|
Patrick Plitzner
|
return getViewName()+": "+HibernateProxyHelper.deproxy(selectedObject, SpecimenOrObservationBase.class).getRecordBasis(); //$NON-NLS-1$
|
144 |
9ab081a8
|
Patric Plitzner
|
}
|
145 |
a3182ec6
|
Patric Plitzner
|
if(selectedObject instanceof CdmBase){
|
146 |
cc330739
|
Patrick Plitzner
|
return getViewName()+": "+HibernateProxyHelper.deproxy(selectedObject, CdmBase.class).getClass().getSimpleName(); //$NON-NLS-1$
|
147 |
a3182ec6
|
Patric Plitzner
|
}
|
148 |
cc330739
|
Patrick Plitzner
|
return getViewName()+": "+selectedObject.getClass().getSimpleName(); //$NON-NLS-1$
|
149 |
d9a8f632
|
Patric Plitzner
|
}
|
150 |
|
|
return getViewName();
|
151 |
|
|
}
|
152 |
|
|
|
153 |
2832a925
|
Patric Plitzner
|
@Override
|
154 |
|
|
public void showEmptyPage() {
|
155 |
f13a970a
|
Patrick Plitzner
|
selectionProvidingPart = null;
|
156 |
2832a925
|
Patric Plitzner
|
viewer.setSelection(null);
|
157 |
|
|
super.showEmptyPage();
|
158 |
2d9a13f7
|
n.hoffmann
|
}
|
159 |
20326c1c
|
Patric Plitzner
|
|
160 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
161 |
2d9a13f7
|
n.hoffmann
|
@Override
|
162 |
|
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
163 |
20326c1c
|
Patric Plitzner
|
|
164 |
c10e4c27
|
n.hoffmann
|
viewer.setInput(objectAffectedByOperation);
|
165 |
20326c1c
|
Patric Plitzner
|
|
166 |
2d9a13f7
|
n.hoffmann
|
return super.postOperation(objectAffectedByOperation);
|
167 |
|
|
}
|
168 |
20326c1c
|
Patric Plitzner
|
|
169 |
|
|
|
170 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
171 |
2d9a13f7
|
n.hoffmann
|
@Override
|
172 |
|
|
public Viewer getViewer() {
|
173 |
c10e4c27
|
n.hoffmann
|
return viewer;
|
174 |
2d9a13f7
|
n.hoffmann
|
}
|
175 |
|
|
|
176 |
20326c1c
|
Patric Plitzner
|
|
177 |
3be6ef3e
|
n.hoffmann
|
/** {@inheritDoc} */
|
178 |
2d9a13f7
|
n.hoffmann
|
@Override
|
179 |
|
|
public void dispose() {
|
180 |
|
|
selectionService.removePostSelectionListener(this);
|
181 |
11329ecc
|
Katja Luther
|
super.dispose();
|
182 |
d9a8f632
|
Patric Plitzner
|
|
183 |
2d9a13f7
|
n.hoffmann
|
}
|
184 |
a2353579
|
n.hoffmann
|
|
185 |
20326c1c
|
Patric Plitzner
|
@Override
|
186 |
|
|
public boolean onComplete() {
|
187 |
f211dd28
|
n.hoffmann
|
return true;
|
188 |
a2353579
|
n.hoffmann
|
}
|
189 |
2443669b
|
Patrick Plitzner
|
|
190 |
|
|
/**
|
191 |
|
|
* {@inheritDoc}
|
192 |
|
|
*/
|
193 |
|
|
@Override
|
194 |
|
|
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
/**
|
198 |
|
|
* {@inheritDoc}
|
199 |
|
|
*/
|
200 |
|
|
@Override
|
201 |
|
|
public void contextStop(IMemento memento, IProgressMonitor monitor) {
|
202 |
|
|
showEmptyPage();
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
/**
|
206 |
|
|
* {@inheritDoc}
|
207 |
|
|
*/
|
208 |
|
|
@Override
|
209 |
|
|
public void contextStart(IMemento memento, IProgressMonitor monitor) {
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
/**
|
213 |
|
|
* {@inheritDoc}
|
214 |
|
|
*/
|
215 |
|
|
@Override
|
216 |
|
|
public void contextRefresh(IProgressMonitor monitor) {
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
/**
|
220 |
|
|
* {@inheritDoc}
|
221 |
|
|
*/
|
222 |
|
|
@Override
|
223 |
|
|
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
|
224 |
|
|
}
|
225 |
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
2d9a13f7
|
n.hoffmann
|
}
|