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
;
12 import org
.eclipse
.jface
.action
.GroupMarker
;
13 import org
.eclipse
.jface
.action
.MenuManager
;
14 import org
.eclipse
.jface
.viewers
.ISelection
;
15 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
16 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
17 import org
.eclipse
.jface
.viewers
.TreeNode
;
18 import org
.eclipse
.jface
.viewers
.TreeViewer
;
19 import org
.eclipse
.jface
.viewers
.Viewer
;
20 import org
.eclipse
.swt
.SWT
;
21 import org
.eclipse
.swt
.widgets
.Composite
;
22 import org
.eclipse
.swt
.widgets
.Control
;
23 import org
.eclipse
.swt
.widgets
.Menu
;
24 import org
.eclipse
.swt
.widgets
.Tree
;
25 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
26 import org
.eclipse
.ui
.IWorkbenchPart
;
28 import eu
.etaxonomy
.cdm
.model
.description
.IDescribable
;
29 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
30 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
31 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveViewPart
;
32 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
33 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
34 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasMedia
;
35 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
36 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmEditorViewPart
;
37 import eu
.etaxonomy
.taxeditor
.view
.detail
.DetailsViewPart
;
38 import eu
.etaxonomy
.taxeditor
.view
.supplementaldata
.SupplementalDataViewPart
;
42 * @created Jun 15, 2010
45 public class MediaViewPart
extends AbstractCdmEditorViewPart
implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
47 public static final String ID
= "eu.etaxonomy.taxeditor.editor.view.media";
50 private TreeViewer viewer
;
54 public void createViewer(Composite parent
) {
56 viewer
= new TreeViewer(new Tree(parent
, SWT
.MULTI
| SWT
.H_SCROLL
57 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
59 viewer
.setContentProvider(new MediaContentProvider());
60 viewer
.setLabelProvider(new MediaLabelProvider());
61 viewer
.setAutoExpandLevel(2);
63 // Propagate selection from viewer
64 getSite().setSelectionProvider(viewer
);
66 // Add context menu to tree
67 MenuManager menuMgr
= new MenuManager();
68 menuMgr
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
69 getSite().registerContextMenu(menuMgr
, viewer
);
71 Control control
= viewer
.getControl();
72 Menu menu
= menuMgr
.createContextMenu(control
);
73 control
.setMenu(menu
);
79 protected ISelection
getInitialSelection() {
80 if(getEditor() != null){
81 return new StructuredSelection(getEditor().getEditorInput());
84 return super.getInitialSelection();
89 protected void selectionChanged_internal(IWorkbenchPart part
, ISelection selection
) {
93 if(AbstractUtility
.getActiveEditor() == null){
98 if (part
instanceof DetailsViewPart
|| part
instanceof SupplementalDataViewPart
99 || part
instanceof DescriptiveViewPart
) {
100 // do not show empty page as these views are also used to edit the
101 // description selected in this view
105 if(part
instanceof IPartContentHasMedia
&& ((IPartContentHasMedia
) part
).canAttachMedia()){
106 if(selection
instanceof IStructuredSelection
){
107 Object firstElement
= ((IStructuredSelection
) selection
).getFirstElement();
108 if(firstElement
instanceof TreeNode
){
109 showViewer(part
, new StructuredSelection(((TreeNode
) firstElement
).getValue()));
112 else if(firstElement
!=null
113 && firstElement
instanceof IDescribable
<?
>){
114 showViewer(part
, (IStructuredSelection
) selection
);
124 public void changed(Object object
) {
125 viewer
.expandToLevel(2);
128 StructuredSelection selection
= new StructuredSelection(object
);
129 viewer
.setSelection(selection
, true);
131 //TODO: should be replaced with the possibility to set views dirty
132 // when we move to Eclipse 4
133 // take a look at ISaveblePart
134 if(part
instanceof BulkEditor
&& !(object
instanceof SpecimenOrObservationBase
<?
>)){
135 ((BulkEditor
) part
).forceDirty();
136 IStructuredSelection selection
= (IStructuredSelection
) ((BulkEditor
) part
).getSelectionProvider().getSelection();
137 ((BulkEditor
) part
).changed(selection
.getFirstElement());
140 super.changed(object
);
145 public Viewer
getViewer() {
150 public boolean onComplete() {
155 protected String
getViewName() {