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
.IEditorInput
;
27 import org
.eclipse
.ui
.IEditorPart
;
28 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
29 import org
.eclipse
.ui
.IWorkbenchPart
;
31 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
32 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
33 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
34 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveViewPart
;
35 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
36 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
37 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasMedia
;
38 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
39 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmEditorViewPart
;
40 import eu
.etaxonomy
.taxeditor
.view
.detail
.DetailsViewPart
;
41 import eu
.etaxonomy
.taxeditor
.view
.supplementaldata
.SupplementalDataViewPart
;
45 * @created Jun 15, 2010
48 public class MediaViewPart
extends AbstractCdmEditorViewPart
implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
50 public static final String ID
= "eu.etaxonomy.taxeditor.editor.view.media";
53 private TreeViewer viewer
;
57 public void createViewer(Composite parent
) {
59 viewer
= new TreeViewer(new Tree(parent
, SWT
.MULTI
| SWT
.H_SCROLL
60 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
62 viewer
.setContentProvider(new MediaContentProvider());
63 viewer
.setLabelProvider(new MediaLabelProvider());
64 viewer
.setAutoExpandLevel(2);
66 // Propagate selection from viewer
67 getSite().setSelectionProvider(viewer
);
69 // Add context menu to tree
70 MenuManager menuMgr
= new MenuManager();
71 menuMgr
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
72 getSite().registerContextMenu(menuMgr
, viewer
);
74 Control control
= viewer
.getControl();
75 Menu menu
= menuMgr
.createContextMenu(control
);
76 control
.setMenu(menu
);
82 protected ISelection
getInitialSelection() {
83 if(getEditor() != null){
84 return new StructuredSelection(getEditor().getEditorInput());
87 return super.getInitialSelection();
92 protected void selectionChanged_internal(IWorkbenchPart part
, ISelection selection
) {
96 if(AbstractUtility
.getActiveEditor() == null){
101 if (part
instanceof DetailsViewPart
|| part
instanceof SupplementalDataViewPart
102 || part
instanceof DescriptiveViewPart
) {
103 // do not show empty page as these views are also used to edit the
104 // description selected in this view
108 if(part
instanceof IPartContentHasMedia
&& ((IPartContentHasMedia
) part
).canAttachMedia()){
109 if(part
instanceof MultiPageTaxonEditor
){
110 IEditorInput input
= ((IEditorPart
) part
).getEditorInput();
111 showViewer(part
, new StructuredSelection(input
));
114 else if(selection
instanceof IStructuredSelection
){
115 Object firstElement
= ((IStructuredSelection
) selection
).getFirstElement();
116 if(firstElement
instanceof TreeNode
){
117 showViewer(part
, new StructuredSelection(((TreeNode
) firstElement
).getValue()));
120 else if(firstElement
!=null){
121 showViewer(part
, (IStructuredSelection
) selection
);
131 public void changed(Object object
) {
132 viewer
.expandToLevel(2);
135 StructuredSelection selection
= new StructuredSelection(object
);
136 viewer
.setSelection(selection
, true);
138 //TODO: should be replaced with the possibility to set views dirty
139 // when we move to Eclipse 4
140 // take a look at ISaveblePart
141 if(part
instanceof BulkEditor
&& !(object
instanceof SpecimenOrObservationBase
<?
>)){
142 ((BulkEditor
) part
).forceDirty();
144 super.changed(object
);
149 public Viewer
getViewer() {
154 public boolean onComplete() {