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
.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
.IEditorInput
;
26 import org
.eclipse
.ui
.IEditorPart
;
27 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
28 import org
.eclipse
.ui
.IWorkbenchPart
;
30 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
31 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
32 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
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
;
40 * <p>MediaViewPart class.</p>
43 * @created Jun 15, 2010
46 public class MediaViewPart
extends AbstractCdmEditorViewPart
implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
48 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.medi"{trunked}</code> */
49 public static final String ID
= "eu.etaxonomy.taxeditor.editor.view.media";
51 private TreeViewer viewer
;
55 * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#createViewer(org.eclipse.swt.widgets.Composite)
59 public void createViewer(Composite parent
) {
61 viewer
= new TreeViewer(new Tree(parent
, SWT
.MULTI
| SWT
.H_SCROLL
62 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
64 viewer
.setContentProvider(new MediaContentProvider());
65 viewer
.setLabelProvider(new MediaLabelProvider());
66 viewer
.setAutoExpandLevel(2);
68 // Propagate selection from viewer
69 getSite().setSelectionProvider(viewer
);
71 // Add context menu to tree
72 MenuManager menuMgr
= new MenuManager();
73 menuMgr
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
74 getSite().registerContextMenu(menuMgr
, viewer
);
76 Control control
= viewer
.getControl();
77 Menu menu
= menuMgr
.createContextMenu(control
);
78 control
.setMenu(menu
);
83 * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#getInitialSelection()
87 protected ISelection
getInitialSelection() {
88 if(getEditor() != null){
89 return new StructuredSelection(getEditor().getEditorInput());
92 return super.getInitialSelection();
97 protected void selectionChanged_internal(IWorkbenchPart part
, ISelection selection
) {
98 if(AbstractUtility
.getActiveEditor() == null){
103 if(part
instanceof MultiPageTaxonEditor
){
104 IEditorInput input
= ((IEditorPart
) part
).getEditorInput();
105 showViewer(part
, new StructuredSelection(input
));
108 else if(part
instanceof IPartContentHasMedia
&& selection
instanceof IStructuredSelection
){
109 showViewer(part
, (IStructuredSelection
) selection
);
115 public void changed(Object object
) {
117 //TODO: should be replaced with the possibility to set views dirty
118 // when we move to Eclipse 4
119 if(part
instanceof BulkEditor
&& !(object
instanceof SpecimenOrObservationBase
<?
>)){
120 ((BulkEditor
) part
).forceDirty();
122 super.changed(object
);
127 public Viewer
getViewer() {
137 public boolean onComplete() {