1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.editor.view.media;
|
11
|
|
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.IWorkbenchActionConstants;
|
26
|
import org.eclipse.ui.IWorkbenchPart;
|
27
|
|
28
|
import eu.etaxonomy.cdm.model.description.IDescribable;
|
29
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
30
|
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
|
31
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
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.view.AbstractCdmEditorViewPart;
|
38
|
import eu.etaxonomy.taxeditor.view.detail.DetailsViewPart;
|
39
|
import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
|
40
|
|
41
|
/**
|
42
|
* @author n.hoffmann
|
43
|
* @created Jun 15, 2010
|
44
|
* @version 1.0
|
45
|
*/
|
46
|
public class MediaViewPart extends AbstractCdmEditorViewPart implements IPartContentHasDetails, IPartContentHasSupplementalData {
|
47
|
|
48
|
public static final String ID = "eu.etaxonomy.taxeditor.editor.view.media"; //$NON-NLS-1$
|
49
|
|
50
|
|
51
|
private TreeViewer viewer;
|
52
|
|
53
|
/** {@inheritDoc} */
|
54
|
@Override
|
55
|
public void createViewer(Composite parent) {
|
56
|
|
57
|
viewer = new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL
|
58
|
| SWT.V_SCROLL | SWT.FULL_SELECTION));
|
59
|
|
60
|
viewer.setContentProvider(new MediaContentProvider());
|
61
|
viewer.setLabelProvider(new MediaLabelProvider());
|
62
|
viewer.setAutoExpandLevel(2);
|
63
|
|
64
|
// Propagate selection from viewer
|
65
|
getSite().setSelectionProvider(viewer);
|
66
|
|
67
|
// Add context menu to tree
|
68
|
MenuManager menuMgr = new MenuManager();
|
69
|
menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
|
70
|
getSite().registerContextMenu(menuMgr, viewer);
|
71
|
|
72
|
Control control = viewer.getControl();
|
73
|
Menu menu = menuMgr.createContextMenu(control);
|
74
|
menuMgr.setRemoveAllWhenShown(true);
|
75
|
control.setMenu(menu);
|
76
|
|
77
|
}
|
78
|
|
79
|
/** {@inheritDoc} */
|
80
|
@Override
|
81
|
protected ISelection getInitialSelection() {
|
82
|
if(getEditor() != null){
|
83
|
return new StructuredSelection(getEditor().getEditorInput());
|
84
|
}
|
85
|
|
86
|
return super.getInitialSelection();
|
87
|
}
|
88
|
|
89
|
/** {@inheritDoc} */
|
90
|
@Override
|
91
|
protected void selectionChanged_internal(IWorkbenchPart part, ISelection selection) {
|
92
|
if(part==this){
|
93
|
return;
|
94
|
}
|
95
|
if(AbstractUtility.getActiveEditor() == null){
|
96
|
showEmptyPage();
|
97
|
return;
|
98
|
}
|
99
|
|
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
|
104
|
return;
|
105
|
}
|
106
|
|
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()));
|
112
|
return;
|
113
|
}
|
114
|
else if(firstElement!=null
|
115
|
&& firstElement instanceof IDescribable<?>){
|
116
|
showViewer(part, (IStructuredSelection) selection);
|
117
|
return;
|
118
|
}
|
119
|
}
|
120
|
}
|
121
|
showEmptyPage();
|
122
|
}
|
123
|
|
124
|
/** {@inheritDoc} */
|
125
|
@Override
|
126
|
public void changed(Object object) {
|
127
|
viewer.expandToLevel(2);
|
128
|
viewer.refresh();
|
129
|
if(object != null){
|
130
|
StructuredSelection selection = new StructuredSelection(object);
|
131
|
viewer.setSelection(selection, true);
|
132
|
}
|
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
|
IStructuredSelection selection = (IStructuredSelection) ((BulkEditor) part).getSelectionProvider().getSelection();
|
139
|
((BulkEditor) part).changed(selection.getFirstElement());
|
140
|
|
141
|
}
|
142
|
super.changed(object);
|
143
|
}
|
144
|
|
145
|
/** {@inheritDoc} */
|
146
|
@Override
|
147
|
public Viewer getViewer() {
|
148
|
return viewer;
|
149
|
}
|
150
|
|
151
|
@Override
|
152
|
public boolean onComplete() {
|
153
|
return true;
|
154
|
}
|
155
|
|
156
|
@Override
|
157
|
protected String getViewName() {
|
158
|
return Messages.MediaViewPart_MEDIA;
|
159
|
}
|
160
|
}
|