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
.editor
.view
.media
.e4
;
12 import javax
.annotation
.PostConstruct
;
13 import javax
.inject
.Inject
;
14 import javax
.inject
.Named
;
16 import org
.eclipse
.e4
.core
.di
.annotations
.Optional
;
17 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
18 import org
.eclipse
.e4
.ui
.services
.EMenuService
;
19 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
20 import org
.eclipse
.e4
.ui
.workbench
.modeling
.ESelectionService
;
21 import org
.eclipse
.jface
.viewers
.AbstractTreeViewer
;
22 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
23 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
24 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
25 import org
.eclipse
.jface
.viewers
.TreeNode
;
26 import org
.eclipse
.jface
.viewers
.TreeViewer
;
27 import org
.eclipse
.swt
.SWT
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.Tree
;
31 import eu
.etaxonomy
.cdm
.model
.description
.IDescribable
;
32 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
33 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
34 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveViewPart
;
35 import eu
.etaxonomy
.taxeditor
.editor
.view
.media
.MediaContentProvider
;
36 import eu
.etaxonomy
.taxeditor
.editor
.view
.media
.MediaLabelProvider
;
37 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
38 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
39 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasMedia
;
40 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
41 import eu
.etaxonomy
.taxeditor
.view
.e4
.AbstractCdmEditorPartE4
;
42 import eu
.etaxonomy
.taxeditor
.view
.e4
.details
.DetailsPartE4
;
43 import eu
.etaxonomy
.taxeditor
.view
.e4
.supplementaldata
.SupplementalDataPartE4
;
51 public class MediaViewPartE4
extends AbstractCdmEditorPartE4
52 implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
54 private ISelectionChangedListener selectionChangedListener
;
57 private ESelectionService selService
;
60 public void create(Composite parent
, EMenuService menuService
) {
62 TreeViewer treeViewer
= new TreeViewer(new Tree(parent
, SWT
.H_SCROLL
63 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
65 treeViewer
.setContentProvider(new MediaContentProvider());
66 treeViewer
.setLabelProvider(new MediaLabelProvider());
67 treeViewer
.setAutoExpandLevel(2);
70 // Propagate selection from viewer
71 selectionChangedListener
= (event
-> selService
.setSelection(AbstractUtility
.getElementsFromSelectionChangedEvent(event
)));
72 viewer
.addSelectionChangedListener(selectionChangedListener
);
75 menuService
.registerContextMenu(viewer
.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.mediaview");
81 public void selectionChanged(
82 @Named(IServiceConstants
.ACTIVE_SELECTION
)Object selection
,
83 @Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
,
85 if(activePart
==thisPart
){
89 Object partObject
= createPartObject(activePart
);
91 if (partObject
instanceof DetailsPartE4
|| partObject
instanceof SupplementalDataPartE4
92 || partObject
instanceof DescriptiveViewPart
) {
93 // do not show empty page as these views are also used to edit the
94 // description selected in this view
98 if(partObject
instanceof IPartContentHasMedia
&& ((IPartContentHasMedia
) partObject
).canAttachMedia()){
99 IStructuredSelection structuredSelection
= createSelection(selection
);
100 if(structuredSelection
==null || structuredSelection
.isEmpty()){
105 Object firstElement
= structuredSelection
.getFirstElement();
106 if (partObject
instanceof MultiPageTaxonEditor
){
107 if (firstElement
!= ((MultiPageTaxonEditor
)partObject
).getTaxon()){
112 if(firstElement
instanceof TreeNode
){
113 showViewer(new StructuredSelection(((TreeNode
) firstElement
).getValue()), activePart
, viewer
);
116 else if(firstElement
!=null
117 && firstElement
instanceof IDescribable
<?
>){
118 showViewer(structuredSelection
, activePart
, viewer
);
128 public void changed(Object object
) {
129 ((AbstractTreeViewer
) viewer
).expandToLevel(2);
132 StructuredSelection selection
= new StructuredSelection(object
);
133 viewer
.setSelection(selection
, true);
135 super.changed(object
);
139 protected String
getViewName() {
140 return Messages
.MediaViewPart_MEDIA
;