2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.media
;
12 import org
.eclipse
.jface
.action
.GroupMarker
;
13 import org
.eclipse
.jface
.action
.MenuManager
;
14 import org
.eclipse
.jface
.viewers
.ISelection
;
15 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
16 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
17 import org
.eclipse
.jface
.viewers
.TreeNode
;
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
.IEditorPart
;
26 import org
.eclipse
.ui
.ISaveablePart
;
27 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
28 import org
.eclipse
.ui
.IWorkbenchPart
;
29 import org
.eclipse
.ui
.internal
.E4PartWrapper
;
31 import eu
.etaxonomy
.cdm
.ext
.occurrence
.gbif
.GbifResponse
;
32 import eu
.etaxonomy
.cdm
.model
.description
.IDescribable
;
33 import eu
.etaxonomy
.cdm
.model
.occurrence
.DerivedUnit
;
34 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
35 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
36 import eu
.etaxonomy
.taxeditor
.editor
.l10n
.Messages
;
37 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveViewPart
;
38 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
39 import eu
.etaxonomy
.taxeditor
.model
.IDirtyMarkable
;
40 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
41 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasMedia
;
42 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
43 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmEditorViewPart
;
44 import eu
.etaxonomy
.taxeditor
.view
.detail
.DetailsViewPart
;
45 import eu
.etaxonomy
.taxeditor
.view
.supplementaldata
.SupplementalDataViewPart
;
49 * @created Jun 15, 2010
52 public class MediaViewPart
extends AbstractCdmEditorViewPart
implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
54 public static final String ID
= "eu.etaxonomy.taxeditor.editor.view.media"; //$NON-NLS-1$
57 private TreeViewer viewer
;
61 public void createViewer(Composite parent
) {
63 viewer
= new TreeViewer(new Tree(parent
, SWT
.MULTI
| SWT
.H_SCROLL
64 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
66 viewer
.setContentProvider(new MediaContentProvider());
67 viewer
.setLabelProvider(new MediaLabelProvider());
68 viewer
.setAutoExpandLevel(2);
70 // Propagate selection from viewer
71 getSite().setSelectionProvider(viewer
);
73 // Add context menu to tree
74 MenuManager menuMgr
= new MenuManager();
75 menuMgr
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
76 getSite().registerContextMenu(menuMgr
, viewer
);
78 Control control
= viewer
.getControl();
79 Menu menu
= menuMgr
.createContextMenu(control
);
80 menuMgr
.setRemoveAllWhenShown(true);
81 control
.setMenu(menu
);
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
) {
101 // if(AbstractUtility.getActiveE4Editor() == null){
107 if (part
instanceof DetailsViewPart
|| part
instanceof SupplementalDataViewPart
108 || part
instanceof DescriptiveViewPart
) {
109 // do not show empty page as these views are also used to edit the
110 // description selected in this view
114 if(part
instanceof IPartContentHasMedia
&& ((IPartContentHasMedia
) part
).canAttachMedia() ){
115 if(selection
instanceof IStructuredSelection
){
116 Object firstElement
= ((IStructuredSelection
) selection
).getFirstElement();
117 if(firstElement
instanceof TreeNode
){
118 showViewer(part
, new StructuredSelection(((TreeNode
) firstElement
).getValue()));
121 else if(firstElement
!=null
122 && firstElement
instanceof IDescribable
<?
>){
123 showViewer(part
, (IStructuredSelection
) selection
);
128 if (selection
instanceof IStructuredSelection
){
129 IStructuredSelection structuredSelection
= (IStructuredSelection
) selection
;
130 if(structuredSelection
.getFirstElement() instanceof TreeNode
){
131 if (((TreeNode
)structuredSelection
.getFirstElement()).getValue() instanceof SpecimenOrObservationBase
){
132 structuredSelection
= new StructuredSelection(((TreeNode
)structuredSelection
.getFirstElement()).getValue());
133 showViewer(part
, structuredSelection
);
144 public void changed(Object object
) {
145 viewer
.expandToLevel(2);
148 StructuredSelection selection
= new StructuredSelection(object
);
149 viewer
.setSelection(selection
, true);
151 //TODO: should be replaced with the possibility to set views dirty
152 // when we move to Eclipse 4
153 // take a look at ISaveblePart
154 if(part
instanceof BulkEditor
&& !(object
instanceof SpecimenOrObservationBase
<?
>)){
155 ((BulkEditor
) part
).forceDirty();
156 IStructuredSelection selection
= (IStructuredSelection
) ((BulkEditor
) part
).getSelectionProvider().getSelection();
157 ((BulkEditor
) part
).changed(selection
.getFirstElement());
160 if (part
instanceof E4PartWrapper
){
161 part
= AbstractUtility
.getE4WrappedPart(part
);
162 if (part
instanceof IDirtyMarkable
){
163 StructuredSelection selection
= new StructuredSelection(object
);
164 ((IDirtyMarkable
)part
).changed(selection
.getFirstElement());
169 super.changed(object
);
174 public Viewer
getViewer() {
179 public boolean onComplete() {
184 protected String
getViewName() {
185 return Messages
.MediaViewPart_MEDIA
;