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
|
import org.eclipse.ui.internal.E4PartWrapper;
|
28
|
|
29
|
import eu.etaxonomy.cdm.model.description.IDescribable;
|
30
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
31
|
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
|
32
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
33
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewPart;
|
34
|
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
|
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;
|
41
|
import eu.etaxonomy.taxeditor.workbench.WorkbenchUtility;
|
42
|
|
43
|
/**
|
44
|
* @author n.hoffmann
|
45
|
* @created Jun 15, 2010
|
46
|
* @version 1.0
|
47
|
*/
|
48
|
public class MediaViewPart extends AbstractCdmEditorViewPart implements IPartContentHasDetails, IPartContentHasSupplementalData {
|
49
|
|
50
|
public static final String ID = "eu.etaxonomy.taxeditor.editor.view.media"; //$NON-NLS-1$
|
51
|
|
52
|
|
53
|
private TreeViewer viewer;
|
54
|
|
55
|
/** {@inheritDoc} */
|
56
|
@Override
|
57
|
public void createViewer(Composite parent) {
|
58
|
|
59
|
viewer = new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL
|
60
|
| SWT.V_SCROLL | SWT.FULL_SELECTION));
|
61
|
|
62
|
viewer.setContentProvider(new MediaContentProvider());
|
63
|
viewer.setLabelProvider(new MediaLabelProvider());
|
64
|
viewer.setAutoExpandLevel(2);
|
65
|
|
66
|
// Propagate selection from viewer
|
67
|
getSite().setSelectionProvider(viewer);
|
68
|
|
69
|
// Add context menu to tree
|
70
|
MenuManager menuMgr = new MenuManager();
|
71
|
menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
|
72
|
getSite().registerContextMenu(menuMgr, viewer);
|
73
|
|
74
|
Control control = viewer.getControl();
|
75
|
Menu menu = menuMgr.createContextMenu(control);
|
76
|
menuMgr.setRemoveAllWhenShown(true);
|
77
|
control.setMenu(menu);
|
78
|
|
79
|
}
|
80
|
|
81
|
/** {@inheritDoc} */
|
82
|
@Override
|
83
|
protected ISelection getInitialSelection() {
|
84
|
if(getEditor() != null){
|
85
|
return new StructuredSelection(getEditor().getEditorInput());
|
86
|
}
|
87
|
|
88
|
return super.getInitialSelection();
|
89
|
}
|
90
|
|
91
|
/** {@inheritDoc} */
|
92
|
@Override
|
93
|
protected void selectionChanged_internal(IWorkbenchPart workbenchPart, ISelection selection) {
|
94
|
Object part = workbenchPart;
|
95
|
|
96
|
if(part==this){
|
97
|
return;
|
98
|
}
|
99
|
|
100
|
Object wrappedPart = WorkbenchUtility.getE4WrappedPart(part);
|
101
|
if(wrappedPart!=null){
|
102
|
part = wrappedPart;
|
103
|
}
|
104
|
// if(AbstractUtility.getActiveE4Editor() == null){
|
105
|
// showEmptyPage();
|
106
|
// return;
|
107
|
// }
|
108
|
|
109
|
|
110
|
if (part instanceof DetailsViewPart || part instanceof SupplementalDataViewPart
|
111
|
|| part instanceof DescriptiveViewPart) {
|
112
|
// do not show empty page as these views are also used to edit the
|
113
|
// description selected in this view
|
114
|
return;
|
115
|
}
|
116
|
|
117
|
if(part instanceof IPartContentHasMedia && ((IPartContentHasMedia) part).canAttachMedia() ){
|
118
|
if(selection instanceof IStructuredSelection){
|
119
|
Object firstElement = ((IStructuredSelection) selection).getFirstElement();
|
120
|
if(firstElement instanceof TreeNode){
|
121
|
showViewer(part, new StructuredSelection(((TreeNode) firstElement).getValue()));
|
122
|
return;
|
123
|
}
|
124
|
else if(firstElement!=null
|
125
|
&& firstElement instanceof IDescribable<?>){
|
126
|
showViewer(part, (IStructuredSelection) selection);
|
127
|
return;
|
128
|
}
|
129
|
}
|
130
|
}
|
131
|
if (selection instanceof IStructuredSelection){
|
132
|
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
|
133
|
if(structuredSelection.getFirstElement() instanceof TreeNode){
|
134
|
if (((TreeNode)structuredSelection.getFirstElement()).getValue() instanceof SpecimenOrObservationBase){
|
135
|
structuredSelection = new StructuredSelection(((TreeNode)structuredSelection.getFirstElement()).getValue());
|
136
|
showViewer(part, structuredSelection);
|
137
|
return;
|
138
|
}
|
139
|
}
|
140
|
}
|
141
|
|
142
|
showEmptyPage();
|
143
|
}
|
144
|
|
145
|
/** {@inheritDoc} */
|
146
|
@Override
|
147
|
public void changed(Object object) {
|
148
|
viewer.expandToLevel(2);
|
149
|
viewer.refresh();
|
150
|
if(object != null){
|
151
|
StructuredSelection selection = new StructuredSelection(object);
|
152
|
viewer.setSelection(selection, true);
|
153
|
}
|
154
|
//TODO: should be replaced with the possibility to set views dirty
|
155
|
// when we move to Eclipse 4
|
156
|
// take a look at ISaveblePart
|
157
|
if(part instanceof BulkEditor && !(object instanceof SpecimenOrObservationBase<?>)){
|
158
|
((BulkEditor) part).forceDirty();
|
159
|
IStructuredSelection selection = (IStructuredSelection) ((BulkEditor) part).getSelectionProvider().getSelection();
|
160
|
((BulkEditor) part).changed(selection.getFirstElement());
|
161
|
|
162
|
}
|
163
|
if (part instanceof E4PartWrapper){
|
164
|
part = WorkbenchUtility.getE4WrappedPart(part);
|
165
|
if (part instanceof IDirtyMarkable){
|
166
|
StructuredSelection selection = new StructuredSelection(object);
|
167
|
((IDirtyMarkable)part).changed(selection.getFirstElement());
|
168
|
}
|
169
|
}
|
170
|
|
171
|
|
172
|
super.changed(object);
|
173
|
}
|
174
|
|
175
|
/** {@inheritDoc} */
|
176
|
@Override
|
177
|
public Viewer getViewer() {
|
178
|
return viewer;
|
179
|
}
|
180
|
|
181
|
@Override
|
182
|
public boolean onComplete() {
|
183
|
return true;
|
184
|
}
|
185
|
|
186
|
@Override
|
187
|
protected String getViewName() {
|
188
|
return Messages.MediaViewPart_MEDIA;
|
189
|
}
|
190
|
}
|