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
.IEditorPart
;
24 import org
.eclipse
.ui
.IMemento
;
25 import org
.eclipse
.ui
.IWorkbenchPart
;
26 import org
.eclipse
.ui
.internal
.e4
.compatibility
.CompatibilityPart
;
28 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
29 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
30 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
31 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
32 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
36 import eu
.etaxonomy
.taxeditor
.editor
.ITaxonEditor
;
37 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
38 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
39 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
40 import eu
.etaxonomy
.taxeditor
.model
.IContextListener
;
41 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
42 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
43 import eu
.etaxonomy
.taxeditor
.store
.internal
.TaxeditorStorePlugin
;
44 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmEditorViewPart
;
45 import eu
.etaxonomy
.taxeditor
.workbench
.WorkbenchUtility
;
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
;
63 public void createViewer(Composite parent
) {
65 viewer
= new DetailsViewer(parent
, this);
66 getSite().setSelectionProvider(viewer
);
70 protected void selectionChanged_internal(IWorkbenchPart workbenchPart
, ISelection selection
){
71 Object part
= workbenchPart
;
72 Object wrappedPart
= WorkbenchUtility
.getE4WrappedPart(part
);
73 if(wrappedPart
!=null){
76 if(AbstractUtility
.getActiveE4Editor() == null && !(AbstractUtility
.getActiveE4Part() instanceof IConversationEnabled
)){
81 //special case where the details view still open with details about the closed object #5495
83 boolean isSelectionProvidingPartStillActive
= false;
84 if(selectionProvidingPart
!=null){
85 EPartService partService
= TaxeditorStorePlugin
.getDefault().getWorkbench().getService(EPartService
.class);
86 Collection
<MPart
> parts
= partService
.getParts();
87 for (MPart mPart
: parts
) {
88 Object object
= mPart
.getObject();
89 if(object
instanceof CompatibilityPart
){
90 object
= ((CompatibilityPart
) object
).getPart();
92 if(selectionProvidingPart
.equals(object
)){
93 isSelectionProvidingPartStillActive
= true;
97 if(!isSelectionProvidingPartStillActive
&&
98 selection
instanceof IStructuredSelection
&& ((IStructuredSelection
) selection
).getFirstElement() !=null){
103 }catch(IllegalStateException e
){
111 if(!(selection
instanceof IStructuredSelection
)){
115 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
117 if((part
instanceof IEditorPart
) || (part
instanceof IPartContentHasDetails
)) {
118 if(structuredSelection
.size() != 1){
123 // do not show details for feature nodes TODO really?
124 if(structuredSelection
.getFirstElement() instanceof FeatureNodeContainer
){
125 // do show the map for distributions
126 Feature feature
= ((FeatureNodeContainer
) ((IStructuredSelection
) selection
).getFirstElement()).getFeature();
127 if(!feature
.equals(Feature
.DISTRIBUTION())){
132 showViewer(part
, structuredSelection
);
139 protected String
getViewName(){
140 return Messages
.DetailsViewPart_VIEWER_NAME
;
144 protected String
createPartTitle(Object selectedObject
){
145 if(selectedObject
!=null){
146 if(selectedObject
instanceof TreeNode
){
147 selectedObject
= ((TreeNode
) selectedObject
).getValue();
149 if(selectedObject
instanceof SpecimenOrObservationBase
){
150 return getViewName()+": "+HibernateProxyHelper
.deproxy(selectedObject
, SpecimenOrObservationBase
.class).getRecordBasis(); //$NON-NLS-1$
152 if(selectedObject
instanceof CdmBase
){
153 return getViewName()+": "+HibernateProxyHelper
.deproxy(selectedObject
, CdmBase
.class).getClass().getSimpleName(); //$NON-NLS-1$
155 return getViewName()+": "+selectedObject
.getClass().getSimpleName(); //$NON-NLS-1$
157 return getViewName();
161 public void showEmptyPage() {
162 viewer
.setSelection(null);
163 super.showEmptyPage();
168 public boolean postOperation(CdmBase objectAffectedByOperation
) {
170 viewer
.setInput(objectAffectedByOperation
);
172 return super.postOperation(objectAffectedByOperation
);
178 public Viewer
getViewer() {
185 public void dispose() {
186 selectionService
.removePostSelectionListener(this);
192 public boolean onComplete() {
200 public void contextAboutToStop(IMemento memento
, IProgressMonitor monitor
) {
207 public void contextStop(IMemento memento
, IProgressMonitor monitor
) {
215 public void contextStart(IMemento memento
, IProgressMonitor monitor
) {
222 public void contextRefresh(IProgressMonitor monitor
) {
229 public void workbenchShutdown(IMemento memento
, IProgressMonitor monitor
) {
232 public void showViewer(Object part
, IStructuredSelection selection
){
235 Object element
= selection
.getFirstElement();
236 //avoid widget is disposed exceptions
237 if (getViewer().getControl()==null || getViewer().getControl().isDisposed()){
241 setPartName(createPartTitle(element
));
242 if (element
instanceof Taxon
){
243 Taxon taxon
= HibernateProxyHelper
.deproxy(element
, Taxon
.class);
244 if (taxon
.isMisapplication()){
246 if (part
instanceof ITaxonEditor
){
247 Taxon accepted
= ((ITaxonEditor
)part
).getTaxon();
248 Set
<TaxonRelationship
> rels
= taxon
.getTaxonRelations(accepted
);
250 if (rels
.iterator().hasNext()){
251 TaxonRelationship rel
= rels
.iterator().next();
252 if (rel
.getType().equals(TaxonRelationshipType
.MISAPPLIED_NAME_FOR())){
253 getViewer().setInput(rel
);
255 // super.showViewer(part, selection);
264 getViewer().setInput(element
);
266 // super.showViewer(part, selection);