2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * 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.
10 package eu
.etaxonomy
.taxeditor
.view
.detail
;
12 import java
.util
.Collection
;
15 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
16 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
17 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EPartService
;
18 import org
.eclipse
.jface
.viewers
.ISelection
;
19 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
20 import org
.eclipse
.jface
.viewers
.TreeNode
;
21 import org
.eclipse
.jface
.viewers
.Viewer
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
23 import org
.eclipse
.ui
.IEditorInput
;
24 import org
.eclipse
.ui
.IEditorPart
;
25 import org
.eclipse
.ui
.IMemento
;
26 import org
.eclipse
.ui
.IWorkbenchPart
;
27 import org
.eclipse
.ui
.internal
.e4
.compatibility
.CompatibilityPart
;
29 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
30 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
31 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
32 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
33 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
37 import eu
.etaxonomy
.taxeditor
.editor
.ITaxonEditor
;
38 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
39 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
40 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
41 import eu
.etaxonomy
.taxeditor
.model
.IContextListener
;
42 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
43 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
44 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
45 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmEditorViewPart
;
48 * <p>DetailsViewPart class.</p>
51 * @created Jun 10, 2010
54 public class DetailsViewPart
extends AbstractCdmEditorViewPart
implements IPartContentHasSupplementalData
, IContextListener
{
56 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.forms.det"{trunked}</code> */
57 public static String ID
= "eu.etaxonomy.taxeditor.view.detail"; //$NON-NLS-1$
59 private DetailsViewer viewer
;
61 //FIXME E4: this can be removed when working with E4 event system
62 private Object selectionProvidingPart
;
66 public void createViewer(Composite parent
) {
68 viewer
= new DetailsViewer(parent
, this);
69 getSite().setSelectionProvider(viewer
);
73 protected void selectionChanged_internal(IWorkbenchPart workbenchPart
, ISelection selection
){
74 Object part
= workbenchPart
;
75 Object wrappedPart
= AbstractUtility
.getE4WrappedPart(part
);
76 if(wrappedPart
!=null){
79 if(AbstractUtility
.getActiveE4Editor() == null && !(AbstractUtility
.getActiveE4Part() instanceof IConversationEnabled
)){
84 //special case where the details view still open with details about the closed object #5495
86 boolean isSelectionProvidingPartStillActive
= false;
87 if(selectionProvidingPart
!=null){
88 EPartService partService
= TaxeditorStorePlugin
.getDefault().getWorkbench().getService(EPartService
.class);
89 Collection
<MPart
> parts
= partService
.getParts();
90 for (MPart mPart
: parts
) {
91 Object object
= mPart
.getObject();
92 if(object
instanceof CompatibilityPart
){
93 object
= ((CompatibilityPart
) object
).getPart();
95 if(selectionProvidingPart
.equals(object
)){
96 isSelectionProvidingPartStillActive
= true;
100 if(!isSelectionProvidingPartStillActive
&&
101 selection
instanceof IStructuredSelection
&& ((IStructuredSelection
) selection
).getFirstElement() !=null){
106 }catch(IllegalStateException e
){
114 if(!(selection
instanceof IStructuredSelection
)){
118 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
120 if((part
instanceof IEditorPart
) || (part
instanceof IPartContentHasDetails
)) {
121 if(structuredSelection
.size() != 1){
126 // do not show details for feature nodes TODO really?
127 if(structuredSelection
.getFirstElement() instanceof FeatureNodeContainer
){
128 // do show the map for distributions
129 Feature feature
= ((FeatureNodeContainer
) ((IStructuredSelection
) selection
).getFirstElement()).getFeature();
130 if(!feature
.equals(Feature
.DISTRIBUTION())){
135 selectionProvidingPart
= part
;
136 showViewer(part
, structuredSelection
);
143 protected String
getViewName(){
144 return Messages
.DetailsViewPart_VIEWER_NAME
;
148 protected String
createPartTitle(Object selectedObject
){
149 if(selectedObject
!=null){
150 if(selectedObject
instanceof TreeNode
){
151 selectedObject
= ((TreeNode
) selectedObject
).getValue();
153 if(selectedObject
instanceof SpecimenOrObservationBase
){
154 return getViewName()+": "+HibernateProxyHelper
.deproxy(selectedObject
, SpecimenOrObservationBase
.class).getRecordBasis(); //$NON-NLS-1$
156 if(selectedObject
instanceof CdmBase
){
157 return getViewName()+": "+HibernateProxyHelper
.deproxy(selectedObject
, CdmBase
.class).getClass().getSimpleName(); //$NON-NLS-1$
159 return getViewName()+": "+selectedObject
.getClass().getSimpleName(); //$NON-NLS-1$
161 return getViewName();
165 public void showEmptyPage() {
166 selectionProvidingPart
= null;
167 viewer
.setSelection(null);
168 super.showEmptyPage();
173 public boolean postOperation(CdmBase objectAffectedByOperation
) {
175 viewer
.setInput(objectAffectedByOperation
);
177 return super.postOperation(objectAffectedByOperation
);
183 public Viewer
getViewer() {
190 public void dispose() {
191 selectionService
.removePostSelectionListener(this);
197 public boolean onComplete() {
205 public void contextAboutToStop(IMemento memento
, IProgressMonitor monitor
) {
212 public void contextStop(IMemento memento
, IProgressMonitor monitor
) {
220 public void contextStart(IMemento memento
, IProgressMonitor monitor
) {
227 public void contextRefresh(IProgressMonitor monitor
) {
234 public void workbenchShutdown(IMemento memento
, IProgressMonitor monitor
) {
237 public void showViewer(Object part
, IStructuredSelection selection
){
240 Object element
= selection
.getFirstElement();
241 //avoid widget is disposed exceptions
242 if (getViewer().getControl()==null || getViewer().getControl().isDisposed()){
246 setPartName(createPartTitle(element
));
247 if (element
instanceof Taxon
){
248 Taxon taxon
= HibernateProxyHelper
.deproxy(element
, Taxon
.class);
249 if (taxon
.isMisapplication()){
251 if (part
instanceof ITaxonEditor
){
252 Taxon accepted
= ((ITaxonEditor
)part
).getTaxon();
253 Set
<TaxonRelationship
> rels
= taxon
.getTaxonRelations(accepted
);
255 if (rels
.iterator().hasNext()){
256 TaxonRelationship rel
= rels
.iterator().next();
257 if (rel
.getType().equals(TaxonRelationshipType
.MISAPPLIED_NAME_FOR())){
258 getViewer().setInput(rel
);
268 getViewer().setInput(element
);