3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.editor
.view
.media
;
13 import org
.eclipse
.jface
.action
.GroupMarker
;
14 import org
.eclipse
.jface
.action
.MenuManager
;
15 import org
.eclipse
.jface
.viewers
.ISelection
;
16 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
17 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
18 import org
.eclipse
.jface
.viewers
.TreeNode
;
19 import org
.eclipse
.jface
.viewers
.TreeViewer
;
20 import org
.eclipse
.jface
.viewers
.Viewer
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
23 import org
.eclipse
.swt
.widgets
.Control
;
24 import org
.eclipse
.swt
.widgets
.Menu
;
25 import org
.eclipse
.swt
.widgets
.Tree
;
26 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
27 import org
.eclipse
.ui
.IWorkbenchPart
;
29 import eu
.etaxonomy
.cdm
.model
.description
.IDescribable
;
30 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
31 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
32 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveViewPart
;
33 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
34 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
35 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasMedia
;
36 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
37 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmEditorViewPart
;
38 import eu
.etaxonomy
.taxeditor
.view
.detail
.DetailsViewPart
;
39 import eu
.etaxonomy
.taxeditor
.view
.supplementaldata
.SupplementalDataViewPart
;
43 * @created Jun 15, 2010
46 public class MediaViewPart
extends AbstractCdmEditorViewPart
implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
48 public static final String ID
= "eu.etaxonomy.taxeditor.editor.view.media";
51 private TreeViewer viewer
;
55 public void createViewer(Composite parent
) {
57 viewer
= new TreeViewer(new Tree(parent
, SWT
.MULTI
| SWT
.H_SCROLL
58 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
60 viewer
.setContentProvider(new MediaContentProvider());
61 viewer
.setLabelProvider(new MediaLabelProvider());
62 viewer
.setAutoExpandLevel(2);
64 // Propagate selection from viewer
65 getSite().setSelectionProvider(viewer
);
67 // Add context menu to tree
68 MenuManager menuMgr
= new MenuManager();
69 menuMgr
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
70 getSite().registerContextMenu(menuMgr
, viewer
);
72 Control control
= viewer
.getControl();
73 Menu menu
= menuMgr
.createContextMenu(control
);
74 control
.setMenu(menu
);
80 protected ISelection
getInitialSelection() {
81 if(getEditor() != null){
82 return new StructuredSelection(getEditor().getEditorInput());
85 return super.getInitialSelection();
90 protected void selectionChanged_internal(IWorkbenchPart part
, ISelection selection
) {
94 if(AbstractUtility
.getActiveEditor() == null){
99 if (part
instanceof DetailsViewPart
|| part
instanceof SupplementalDataViewPart
100 || part
instanceof DescriptiveViewPart
) {
101 // do not show empty page as these views are also used to edit the
102 // description selected in this view
106 if(part
instanceof IPartContentHasMedia
&& ((IPartContentHasMedia
) part
).canAttachMedia()){
107 if(selection
instanceof IStructuredSelection
){
108 Object firstElement
= ((IStructuredSelection
) selection
).getFirstElement();
109 if(firstElement
instanceof TreeNode
){
110 showViewer(part
, new StructuredSelection(((TreeNode
) firstElement
).getValue()));
113 else if(firstElement
!=null
114 && firstElement
instanceof IDescribable
<?
>){
115 showViewer(part
, (IStructuredSelection
) selection
);
125 public void changed(Object object
) {
126 viewer
.expandToLevel(2);
129 StructuredSelection selection
= new StructuredSelection(object
);
130 viewer
.setSelection(selection
, true);
132 //TODO: should be replaced with the possibility to set views dirty
133 // when we move to Eclipse 4
134 // take a look at ISaveblePart
135 if(part
instanceof BulkEditor
&& !(object
instanceof SpecimenOrObservationBase
<?
>)){
136 ((BulkEditor
) part
).forceDirty();
137 IStructuredSelection selection
= (IStructuredSelection
) ((BulkEditor
) part
).getSelectionProvider().getSelection();
138 ((BulkEditor
) part
).changed(selection
.getFirstElement());
141 super.changed(object
);
146 public Viewer
getViewer() {
151 public boolean onComplete() {
156 protected String
getViewName() {