1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.editor.view.media;
|
12
|
|
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;
|
30
|
|
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;
|
41
|
|
42
|
/**
|
43
|
* <p>MediaViewPart class.</p>
|
44
|
*
|
45
|
* @author n.hoffmann
|
46
|
* @created Jun 15, 2010
|
47
|
* @version 1.0
|
48
|
*/
|
49
|
public class MediaViewPart extends AbstractCdmEditorViewPart implements IPartContentHasDetails, IPartContentHasSupplementalData {
|
50
|
|
51
|
/** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.medi"{trunked}</code> */
|
52
|
public static final String ID = "eu.etaxonomy.taxeditor.editor.view.media";
|
53
|
|
54
|
|
55
|
private TreeViewer viewer;
|
56
|
|
57
|
/*
|
58
|
* (non-Javadoc)
|
59
|
* @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#createViewer(org.eclipse.swt.widgets.Composite)
|
60
|
*/
|
61
|
/** {@inheritDoc} */
|
62
|
@Override
|
63
|
public void createViewer(Composite parent) {
|
64
|
|
65
|
viewer = new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL
|
66
|
| SWT.V_SCROLL | SWT.FULL_SELECTION));
|
67
|
|
68
|
viewer.setContentProvider(new MediaContentProvider());
|
69
|
viewer.setLabelProvider(new MediaLabelProvider());
|
70
|
viewer.setAutoExpandLevel(2);
|
71
|
|
72
|
// Propagate selection from viewer
|
73
|
getSite().setSelectionProvider(viewer);
|
74
|
|
75
|
// Add context menu to tree
|
76
|
MenuManager menuMgr = new MenuManager();
|
77
|
menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
|
78
|
getSite().registerContextMenu(menuMgr, viewer);
|
79
|
|
80
|
Control control = viewer.getControl();
|
81
|
Menu menu = menuMgr.createContextMenu(control);
|
82
|
control.setMenu(menu);
|
83
|
|
84
|
}
|
85
|
|
86
|
/* (non-Javadoc)
|
87
|
* @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#getInitialSelection()
|
88
|
*/
|
89
|
/** {@inheritDoc} */
|
90
|
@Override
|
91
|
protected ISelection getInitialSelection() {
|
92
|
if(getEditor() != null){
|
93
|
return new StructuredSelection(getEditor().getEditorInput());
|
94
|
}
|
95
|
|
96
|
return super.getInitialSelection();
|
97
|
}
|
98
|
|
99
|
/** {@inheritDoc} */
|
100
|
@Override
|
101
|
protected void selectionChanged_internal(IWorkbenchPart part, ISelection selection) {
|
102
|
if(part==this){
|
103
|
return;
|
104
|
}
|
105
|
if(AbstractUtility.getActiveEditor() == null){
|
106
|
showEmptyPage();
|
107
|
return;
|
108
|
}
|
109
|
|
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
|
112
|
return;
|
113
|
}
|
114
|
|
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));
|
119
|
}
|
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()));
|
124
|
}
|
125
|
else{
|
126
|
showViewer(part, (IStructuredSelection) selection);
|
127
|
}
|
128
|
}else{
|
129
|
showEmptyPage();
|
130
|
}
|
131
|
}
|
132
|
else{
|
133
|
showEmptyPage();
|
134
|
}
|
135
|
}
|
136
|
|
137
|
/** {@inheritDoc} */
|
138
|
@Override
|
139
|
public void changed(Object object) {
|
140
|
viewer.expandToLevel(2);
|
141
|
viewer.refresh();
|
142
|
if(object != null){
|
143
|
StructuredSelection selection = new StructuredSelection(object);
|
144
|
viewer.setSelection(selection, true);
|
145
|
}
|
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();
|
151
|
}
|
152
|
super.changed(object);
|
153
|
}
|
154
|
|
155
|
/** {@inheritDoc} */
|
156
|
@Override
|
157
|
public Viewer getViewer() {
|
158
|
return viewer;
|
159
|
}
|
160
|
|
161
|
/**
|
162
|
* <p>onComplete</p>
|
163
|
*
|
164
|
* @return a boolean.
|
165
|
*/
|
166
|
@Override
|
167
|
public boolean onComplete() {
|
168
|
return true;
|
169
|
}
|
170
|
}
|