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
.model
.AbstractUtility
;
35 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
36 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasMedia
;
37 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
38 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmEditorViewPart
;
39 import eu
.etaxonomy
.taxeditor
.view
.detail
.DetailsViewPart
;
40 import eu
.etaxonomy
.taxeditor
.view
.supplementaldata
.SupplementalDataViewPart
;
43 * <p>MediaViewPart class.</p>
46 * @created Jun 15, 2010
49 public class MediaViewPart
extends AbstractCdmEditorViewPart
implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
51 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.medi"{trunked}</code> */
52 public static final String ID
= "eu.etaxonomy.taxeditor.editor.view.media";
54 private TreeViewer viewer
;
58 * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#createViewer(org.eclipse.swt.widgets.Composite)
62 public void createViewer(Composite parent
) {
64 viewer
= new TreeViewer(new Tree(parent
, SWT
.MULTI
| SWT
.H_SCROLL
65 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
67 viewer
.setContentProvider(new MediaContentProvider());
68 viewer
.setLabelProvider(new MediaLabelProvider());
69 viewer
.setAutoExpandLevel(2);
71 // Propagate selection from viewer
72 getSite().setSelectionProvider(viewer
);
74 // Add context menu to tree
75 MenuManager menuMgr
= new MenuManager();
76 menuMgr
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
77 getSite().registerContextMenu(menuMgr
, viewer
);
79 Control control
= viewer
.getControl();
80 Menu menu
= menuMgr
.createContextMenu(control
);
81 control
.setMenu(menu
);
86 * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#getInitialSelection()
90 protected ISelection
getInitialSelection() {
91 if(getEditor() != null){
92 return new StructuredSelection(getEditor().getEditorInput());
95 return super.getInitialSelection();
100 protected void selectionChanged_internal(IWorkbenchPart part
, ISelection selection
) {
101 if(AbstractUtility
.getActiveEditor() == null){
106 if(part
instanceof DetailsViewPart
|| part
instanceof SupplementalDataViewPart
){
107 // do not show empty page as these views are also used to edit the description selected in this view
111 if(part
instanceof IPartContentHasMedia
){
112 if(part
instanceof MultiPageTaxonEditor
){
113 IEditorInput input
= ((IEditorPart
) part
).getEditorInput();
114 showViewer(part
, new StructuredSelection(input
));
116 else if(selection
instanceof IStructuredSelection
){
117 Object firstElement
= ((IStructuredSelection
) selection
).getFirstElement();
118 if(firstElement
instanceof TreeNode
){
119 showViewer(part
, new StructuredSelection(((TreeNode
) firstElement
).getValue()));
122 showViewer(part
, (IStructuredSelection
) selection
);
133 public void changed(Object object
) {
135 //TODO: should be replaced with the possibility to set views dirty
136 // when we move to Eclipse 4
137 if(part
instanceof BulkEditor
&& !(object
instanceof SpecimenOrObservationBase
<?
>)){
138 ((BulkEditor
) part
).forceDirty();
140 super.changed(object
);
145 public Viewer
getViewer() {
155 public boolean onComplete() {