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";
55 private TreeViewer viewer
;
59 * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#createViewer(org.eclipse.swt.widgets.Composite)
63 public void createViewer(Composite parent
) {
65 viewer
= new TreeViewer(new Tree(parent
, SWT
.MULTI
| SWT
.H_SCROLL
66 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
68 viewer
.setContentProvider(new MediaContentProvider());
69 viewer
.setLabelProvider(new MediaLabelProvider());
70 viewer
.setAutoExpandLevel(2);
72 // Propagate selection from viewer
73 getSite().setSelectionProvider(viewer
);
75 // Add context menu to tree
76 MenuManager menuMgr
= new MenuManager();
77 menuMgr
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
78 getSite().registerContextMenu(menuMgr
, viewer
);
80 Control control
= viewer
.getControl();
81 Menu menu
= menuMgr
.createContextMenu(control
);
82 control
.setMenu(menu
);
87 * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#getInitialSelection()
91 protected ISelection
getInitialSelection() {
92 if(getEditor() != null){
93 return new StructuredSelection(getEditor().getEditorInput());
96 return super.getInitialSelection();
101 protected void selectionChanged_internal(IWorkbenchPart part
, ISelection selection
) {
105 if(AbstractUtility
.getActiveEditor() == null){
110 if(part
instanceof DetailsViewPart
|| part
instanceof SupplementalDataViewPart
){
111 // do not show empty page as these views are also used to edit the description selected in this view
115 if(part
instanceof IPartContentHasMedia
&& ((IPartContentHasMedia
) part
).canAttachMedia()){
116 if(part
instanceof MultiPageTaxonEditor
){
117 IEditorInput input
= ((IEditorPart
) part
).getEditorInput();
118 showViewer(part
, new StructuredSelection(input
));
120 else if(selection
instanceof IStructuredSelection
){
121 Object firstElement
= ((IStructuredSelection
) selection
).getFirstElement();
122 if(firstElement
instanceof TreeNode
){
123 showViewer(part
, new StructuredSelection(((TreeNode
) firstElement
).getValue()));
126 showViewer(part
, (IStructuredSelection
) selection
);
139 public void changed(Object object
) {
140 viewer
.expandToLevel(2);
143 StructuredSelection selection
= new StructuredSelection(object
);
144 viewer
.setSelection(selection
, true);
146 //TODO: should be replaced with the possibility to set views dirty
147 // when we move to Eclipse 4
148 // take a look at ISaveblePart
149 if(part
instanceof BulkEditor
&& !(object
instanceof SpecimenOrObservationBase
<?
>)){
150 ((BulkEditor
) part
).forceDirty();
152 super.changed(object
);
157 public Viewer
getViewer() {
167 public boolean onComplete() {