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
.store
.CdmStore
;
38 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmEditorViewPart
;
39 import eu
.etaxonomy
.taxeditor
.view
.detail
.DetailsViewPart
;
40 import eu
.etaxonomy
.taxeditor
.view
.supplementaldata
.SupplementalDataViewPart
;
44 * @created Jun 15, 2010
47 public class MediaViewPart
extends AbstractCdmEditorViewPart
implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
49 public static final String ID
= "eu.etaxonomy.taxeditor.editor.view.media";
52 private TreeViewer viewer
;
56 public void createViewer(Composite parent
) {
58 viewer
= new TreeViewer(new Tree(parent
, SWT
.MULTI
| SWT
.H_SCROLL
59 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
61 viewer
.setContentProvider(new MediaContentProvider());
62 viewer
.setLabelProvider(new MediaLabelProvider());
63 viewer
.setAutoExpandLevel(2);
65 // Propagate selection from viewer
66 getSite().setSelectionProvider(viewer
);
68 // Add context menu to tree
69 MenuManager menuMgr
= new MenuManager();
70 menuMgr
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
71 getSite().registerContextMenu(menuMgr
, viewer
);
73 Control control
= viewer
.getControl();
74 Menu menu
= menuMgr
.createContextMenu(control
);
75 control
.setMenu(menu
);
81 protected ISelection
getInitialSelection() {
82 if(getEditor() != null){
83 return new StructuredSelection(getEditor().getEditorInput());
86 return super.getInitialSelection();
91 protected void selectionChanged_internal(IWorkbenchPart part
, ISelection selection
) {
95 if(AbstractUtility
.getActiveEditor() == null){
100 if (part
instanceof DetailsViewPart
|| part
instanceof SupplementalDataViewPart
101 || part
instanceof DescriptiveViewPart
) {
102 // do not show empty page as these views are also used to edit the
103 // description selected in this view
107 if(part
instanceof IPartContentHasMedia
&& ((IPartContentHasMedia
) part
).canAttachMedia()){
108 if(selection
instanceof IStructuredSelection
){
109 Object firstElement
= ((IStructuredSelection
) selection
).getFirstElement();
110 if(firstElement
instanceof TreeNode
){
111 showViewer(part
, new StructuredSelection(((TreeNode
) firstElement
).getValue()));
114 else if(firstElement
!=null
115 && firstElement
instanceof IDescribable
<?
>){
116 showViewer(part
, (IStructuredSelection
) selection
);
126 public void changed(Object object
) {
127 viewer
.expandToLevel(2);
130 StructuredSelection selection
= new StructuredSelection(object
);
131 viewer
.setSelection(selection
, true);
133 //TODO: should be replaced with the possibility to set views dirty
134 // when we move to Eclipse 4
135 // take a look at ISaveblePart
136 if(part
instanceof BulkEditor
&& !(object
instanceof SpecimenOrObservationBase
<?
>)){
137 ((BulkEditor
) part
).forceDirty();
138 if(CdmStore
.getCurrentSessionManager().isRemoting()) {
139 IStructuredSelection selection
= (IStructuredSelection
) ((BulkEditor
) part
).getSelectionProvider().getSelection();
140 ((BulkEditor
) part
).changed(selection
.getFirstElement());
143 super.changed(object
);
148 public Viewer
getViewer() {
153 public boolean onComplete() {