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
;
14 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
15 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
16 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EPartService
;
17 import org
.eclipse
.jface
.viewers
.ISelection
;
18 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
19 import org
.eclipse
.jface
.viewers
.TreeNode
;
20 import org
.eclipse
.jface
.viewers
.Viewer
;
21 import org
.eclipse
.swt
.widgets
.Composite
;
22 import org
.eclipse
.ui
.IEditorPart
;
23 import org
.eclipse
.ui
.IMemento
;
24 import org
.eclipse
.ui
.IWorkbenchPart
;
25 import org
.eclipse
.ui
.internal
.e4
.compatibility
.CompatibilityPart
;
27 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
28 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
29 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
30 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
31 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
32 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
33 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
34 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
35 import eu
.etaxonomy
.taxeditor
.model
.IContextListener
;
36 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
37 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
38 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
39 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmEditorViewPart
;
42 * <p>DetailsViewPart class.</p>
45 * @created Jun 10, 2010
48 public class DetailsViewPart
extends AbstractCdmEditorViewPart
implements IPartContentHasSupplementalData
, IContextListener
{
50 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.forms.det"{trunked}</code> */
51 public static String ID
= "eu.etaxonomy.taxeditor.view.detail"; //$NON-NLS-1$
53 private DetailsViewer viewer
;
55 //FIXME E4: this can be removed when working with E4 event system
56 private Object selectionProvidingPart
;
60 public void createViewer(Composite parent
) {
62 viewer
= new DetailsViewer(parent
, this);
63 getSite().setSelectionProvider(viewer
);
67 protected void selectionChanged_internal(IWorkbenchPart workbenchPart
, ISelection selection
){
68 Object part
= workbenchPart
;
69 Object wrappedPart
= AbstractUtility
.getE4WrappedPart(part
);
70 if(wrappedPart
!=null){
73 if(AbstractUtility
.getActiveE4Editor() == null && !(AbstractUtility
.getActiveE4Part() instanceof IConversationEnabled
)){
78 //special case where the details view still open with details about the closed object #5495
80 boolean isSelectionProvidingPartStillActive
= false;
81 if(selectionProvidingPart
!=null){
82 EPartService partService
= TaxeditorStorePlugin
.getDefault().getWorkbench().getService(EPartService
.class);
83 Collection
<MPart
> parts
= partService
.getParts();
84 for (MPart mPart
: parts
) {
85 Object object
= mPart
.getObject();
86 if(object
instanceof CompatibilityPart
){
87 object
= ((CompatibilityPart
) object
).getPart();
89 if(selectionProvidingPart
.equals(object
)){
90 isSelectionProvidingPartStillActive
= true;
94 if(!isSelectionProvidingPartStillActive
&&
95 selection
instanceof IStructuredSelection
&& ((IStructuredSelection
) selection
).getFirstElement() !=null){
100 }catch(IllegalStateException e
){
108 if(!(selection
instanceof IStructuredSelection
)){
112 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
114 if((part
instanceof IEditorPart
) || (part
instanceof IPartContentHasDetails
)) {
115 if(structuredSelection
.size() != 1){
120 // do not show details for feature nodes TODO really?
121 if(structuredSelection
.getFirstElement() instanceof FeatureNodeContainer
){
122 // do show the map for distributions
123 Feature feature
= ((FeatureNodeContainer
) ((IStructuredSelection
) selection
).getFirstElement()).getFeature();
124 if(!feature
.equals(Feature
.DISTRIBUTION())){
129 selectionProvidingPart
= part
;
130 showViewer(part
, structuredSelection
);
137 protected String
getViewName(){
138 return Messages
.DetailsViewPart_VIEWER_NAME
;
142 protected String
createPartTitle(Object selectedObject
){
143 if(selectedObject
!=null){
144 if(selectedObject
instanceof TreeNode
){
145 selectedObject
= ((TreeNode
) selectedObject
).getValue();
147 if(selectedObject
instanceof SpecimenOrObservationBase
){
148 return getViewName()+": "+HibernateProxyHelper
.deproxy(selectedObject
, SpecimenOrObservationBase
.class).getRecordBasis(); //$NON-NLS-1$
150 if(selectedObject
instanceof CdmBase
){
151 return getViewName()+": "+HibernateProxyHelper
.deproxy(selectedObject
, CdmBase
.class).getClass().getSimpleName(); //$NON-NLS-1$
153 return getViewName()+": "+selectedObject
.getClass().getSimpleName(); //$NON-NLS-1$
155 return getViewName();
159 public void showEmptyPage() {
160 selectionProvidingPart
= null;
161 viewer
.setSelection(null);
162 super.showEmptyPage();
167 public boolean postOperation(CdmBase objectAffectedByOperation
) {
169 viewer
.setInput(objectAffectedByOperation
);
171 return super.postOperation(objectAffectedByOperation
);
177 public Viewer
getViewer() {
184 public void dispose() {
185 selectionService
.removePostSelectionListener(this);
191 public boolean onComplete() {
199 public void contextAboutToStop(IMemento memento
, IProgressMonitor monitor
) {
206 public void contextStop(IMemento memento
, IProgressMonitor monitor
) {
214 public void contextStart(IMemento memento
, IProgressMonitor monitor
) {
221 public void contextRefresh(IProgressMonitor monitor
) {
228 public void workbenchShutdown(IMemento memento
, IProgressMonitor monitor
) {