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.e4;
|
11
|
|
12
|
import javax.annotation.PostConstruct;
|
13
|
import javax.inject.Inject;
|
14
|
import javax.inject.Named;
|
15
|
|
16
|
import org.eclipse.e4.core.di.annotations.Optional;
|
17
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
18
|
import org.eclipse.e4.ui.services.EMenuService;
|
19
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
20
|
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
21
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
22
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
23
|
import org.eclipse.jface.viewers.StructuredSelection;
|
24
|
import org.eclipse.jface.viewers.TreeNode;
|
25
|
import org.eclipse.jface.viewers.TreeViewer;
|
26
|
import org.eclipse.jface.viewers.Viewer;
|
27
|
import org.eclipse.swt.SWT;
|
28
|
import org.eclipse.swt.widgets.Composite;
|
29
|
import org.eclipse.swt.widgets.Tree;
|
30
|
|
31
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
32
|
import eu.etaxonomy.cdm.model.description.IDescribable;
|
33
|
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
|
34
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
35
|
import eu.etaxonomy.taxeditor.editor.view.media.MediaContentProvider;
|
36
|
import eu.etaxonomy.taxeditor.editor.view.media.MediaLabelProvider;
|
37
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
38
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
39
|
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia;
|
40
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
41
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
42
|
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
|
43
|
|
44
|
/**
|
45
|
*
|
46
|
* @author pplitzner
|
47
|
* @since Aug 14, 2017
|
48
|
*
|
49
|
*/
|
50
|
public class MediaViewPartE4 extends AbstractCdmEditorPartE4
|
51
|
implements IPartContentHasDetails, IPartContentHasSupplementalData, IPostOperationEnabled {
|
52
|
|
53
|
private ISelectionChangedListener selectionChangedListener;
|
54
|
|
55
|
private TreeViewer viewer;
|
56
|
|
57
|
@Inject
|
58
|
private ESelectionService selService;
|
59
|
|
60
|
@PostConstruct
|
61
|
public void create(Composite parent, EMenuService menuService) {
|
62
|
|
63
|
viewer = new TreeViewer(new Tree(parent, SWT.MULTI | SWT.H_SCROLL
|
64
|
| SWT.V_SCROLL | SWT.FULL_SELECTION));
|
65
|
|
66
|
viewer.setContentProvider(new MediaContentProvider());
|
67
|
viewer.setLabelProvider(new MediaLabelProvider());
|
68
|
viewer.setAutoExpandLevel(2);
|
69
|
|
70
|
// Propagate selection from viewer
|
71
|
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
|
72
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
73
|
|
74
|
//create context menu
|
75
|
menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.mediaview");
|
76
|
}
|
77
|
|
78
|
@Inject
|
79
|
@Optional
|
80
|
public void selectionChanged(
|
81
|
@Named(IServiceConstants.ACTIVE_SELECTION)Object selection,
|
82
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart,
|
83
|
MPart thisPart){
|
84
|
if(activePart==thisPart){
|
85
|
return;
|
86
|
}
|
87
|
|
88
|
Object partObject = createPartObject(activePart);
|
89
|
|
90
|
if(partObject instanceof IPartContentHasMedia && ((IPartContentHasMedia) partObject).canAttachMedia()){
|
91
|
IStructuredSelection structuredSelection = createSelection(selection);
|
92
|
if(structuredSelection==null || structuredSelection.isEmpty()){
|
93
|
showEmptyPage();
|
94
|
return;
|
95
|
}
|
96
|
|
97
|
|
98
|
// if (partObject instanceof DetailsViewPart || partObject instanceof SupplementalDataViewPart
|
99
|
// || partObject instanceof DescriptiveViewPart) {
|
100
|
// // do not show empty page as these views are also used to edit the
|
101
|
// // description selected in this view
|
102
|
// return;
|
103
|
// }
|
104
|
|
105
|
Object firstElement = structuredSelection.getFirstElement();
|
106
|
if (partObject instanceof MultiPageTaxonEditor){
|
107
|
if (firstElement != ((MultiPageTaxonEditor)partObject).getTaxon()){
|
108
|
showEmptyPage();
|
109
|
return;
|
110
|
}
|
111
|
}
|
112
|
if(firstElement instanceof TreeNode){
|
113
|
showViewer(new StructuredSelection(((TreeNode) firstElement).getValue()), activePart, viewer);
|
114
|
return;
|
115
|
}
|
116
|
else if(firstElement!=null
|
117
|
&& firstElement instanceof IDescribable<?>){
|
118
|
showViewer((IStructuredSelection) selection, activePart, viewer);
|
119
|
return;
|
120
|
}
|
121
|
}
|
122
|
showEmptyPage();
|
123
|
return;
|
124
|
}
|
125
|
|
126
|
/** {@inheritDoc} */
|
127
|
@Override
|
128
|
public void changed(Object object) {
|
129
|
viewer.expandToLevel(2);
|
130
|
viewer.refresh();
|
131
|
if(object != null){
|
132
|
StructuredSelection selection = new StructuredSelection(object);
|
133
|
viewer.setSelection(selection, true);
|
134
|
}
|
135
|
// //TODO: should be replaced with the possibility to set views dirty
|
136
|
// // when we move to Eclipse 4
|
137
|
// // take a look at ISaveblePart
|
138
|
// if(part instanceof BulkEditor && !(object instanceof SpecimenOrObservationBase<?>)){
|
139
|
// ((BulkEditor) part).forceDirty();
|
140
|
// IStructuredSelection selection = (IStructuredSelection) ((BulkEditor) part).getSelectionProvider().getSelection();
|
141
|
// ((BulkEditor) part).changed(selection.getFirstElement());
|
142
|
//
|
143
|
// }
|
144
|
// if (part instanceof E4PartWrapper){
|
145
|
// part = WorkbenchUtility.getE4WrappedPart(part);
|
146
|
// if (part instanceof IDirtyMarkable){
|
147
|
// StructuredSelection selection = new StructuredSelection(object);
|
148
|
// ((IDirtyMarkable)part).changed(selection.getFirstElement());
|
149
|
// }
|
150
|
// }
|
151
|
|
152
|
super.changed(object);
|
153
|
}
|
154
|
|
155
|
@Override
|
156
|
protected String getViewName() {
|
157
|
return Messages.MediaViewPart_MEDIA;
|
158
|
}
|
159
|
|
160
|
public Viewer getViewer() {
|
161
|
return viewer;
|
162
|
}
|
163
|
|
164
|
/**
|
165
|
* {@inheritDoc}
|
166
|
*/
|
167
|
@Override
|
168
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
169
|
changed(objectAffectedByOperation);
|
170
|
return true;
|
171
|
}
|
172
|
|
173
|
/**
|
174
|
* {@inheritDoc}
|
175
|
*/
|
176
|
@Override
|
177
|
public boolean onComplete() {
|
178
|
viewer.refresh();
|
179
|
return true;
|
180
|
}
|
181
|
}
|