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
|
package eu.etaxonomy.taxeditor.editor.view.media.e4;
|
10
|
|
11
|
import javax.annotation.PostConstruct;
|
12
|
|
13
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
14
|
import org.eclipse.e4.ui.services.EMenuService;
|
15
|
import org.eclipse.jface.viewers.AbstractTreeViewer;
|
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.swt.SWT;
|
21
|
import org.eclipse.swt.widgets.Composite;
|
22
|
import org.eclipse.swt.widgets.Tree;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.description.IDescribable;
|
25
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
26
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
27
|
import eu.etaxonomy.taxeditor.bulkeditor.e4.BulkEditor;
|
28
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
29
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonEditor;
|
30
|
import eu.etaxonomy.taxeditor.editor.view.concept.e4.ConceptViewPartE4;
|
31
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
|
32
|
import eu.etaxonomy.taxeditor.editor.view.media.MediaContentProvider;
|
33
|
import eu.etaxonomy.taxeditor.editor.view.media.MediaViewLabelProvider;
|
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.e4.AbstractCdmEditorPart;
|
38
|
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
|
39
|
import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4;
|
40
|
|
41
|
/**
|
42
|
* @author pplitzner
|
43
|
* @since Aug 14, 2017
|
44
|
*/
|
45
|
public class MediaViewPartE4 extends AbstractCdmEditorPart<TreeViewer>
|
46
|
implements IPartContentHasDetails, IPartContentHasSupplementalData {
|
47
|
|
48
|
@PostConstruct
|
49
|
public void create(Composite parent, EMenuService menuService, MPart thisPart) {
|
50
|
|
51
|
this.thisPart = thisPart;
|
52
|
TreeViewer treeViewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL
|
53
|
| SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI));
|
54
|
|
55
|
treeViewer.setContentProvider(new MediaContentProvider());
|
56
|
treeViewer.setLabelProvider(new MediaViewLabelProvider());
|
57
|
|
58
|
// TreeViewerColumn imagePreview = new TreeViewerColumn(treeViewer, SWT.NONE);
|
59
|
// imagePreview.setLabelProvider(new DelegatingStyledCellLabelProvider(
|
60
|
// new MediaViewLabelProvider(createImageDescriptor())));
|
61
|
|
62
|
treeViewer.setAutoExpandLevel(2);
|
63
|
viewer = treeViewer;
|
64
|
|
65
|
// Propagate selection from viewer
|
66
|
selectionChangedListener = (event -> selService.setSelection(event.getSelection()));
|
67
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
68
|
|
69
|
//create context menu
|
70
|
menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.mediaview");
|
71
|
}
|
72
|
|
73
|
@Override
|
74
|
public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
|
75
|
if(activePart == thisPart){
|
76
|
return;
|
77
|
}
|
78
|
|
79
|
Object partObject = getPartObject(activePart);
|
80
|
|
81
|
if (partObject instanceof DetailsPartE4 || partObject instanceof SupplementalDataPartE4
|
82
|
|| partObject instanceof FactualDataPartE4 || partObject instanceof ConceptViewPartE4) {
|
83
|
// do not show empty page as these views are also used to edit the
|
84
|
// description selected in this view
|
85
|
return;
|
86
|
}
|
87
|
|
88
|
if(partObject instanceof IPartContentHasMedia && ((IPartContentHasMedia) partObject).canAttachMedia()){
|
89
|
if (viewer.getControl() != null && !viewer.getControl().isDisposed()) {
|
90
|
viewer.getControl().setEnabled(true);
|
91
|
}
|
92
|
IStructuredSelection structuredSelection = createSelection(selection);
|
93
|
if(structuredSelection==null || structuredSelection.isEmpty()){
|
94
|
showEmptyPage();
|
95
|
return;
|
96
|
}
|
97
|
|
98
|
Object firstElement = structuredSelection.getFirstElement();
|
99
|
if (partObject instanceof TaxonEditor){
|
100
|
if (firstElement != ((TaxonEditor)partObject).getTaxon()){
|
101
|
showEmptyPage();
|
102
|
return;
|
103
|
}
|
104
|
}
|
105
|
if(firstElement instanceof TreeNode){
|
106
|
showViewer(new StructuredSelection(((TreeNode) firstElement).getValue()), activePart, viewer);
|
107
|
return;
|
108
|
}
|
109
|
else if(firstElement!=null
|
110
|
&& firstElement instanceof IDescribable<?> && !(firstElement instanceof TaxonName) && !(firstElement instanceof SpecimenOrObservationBase && partObject instanceof BulkEditor )){
|
111
|
showViewer(structuredSelection, activePart, viewer);
|
112
|
return;
|
113
|
}
|
114
|
}
|
115
|
showEmptyPage();
|
116
|
return;
|
117
|
}
|
118
|
|
119
|
@Override
|
120
|
public void changed(Object object) {
|
121
|
((AbstractTreeViewer) viewer).expandToLevel(2);
|
122
|
viewer.refresh();
|
123
|
if(object != null){
|
124
|
StructuredSelection selection = new StructuredSelection(object);
|
125
|
viewer.setSelection(selection, true);
|
126
|
}
|
127
|
super.changed(object);
|
128
|
}
|
129
|
|
130
|
@Override
|
131
|
protected String getViewName() {
|
132
|
return Messages.MediaViewPart_MEDIA;
|
133
|
}
|
134
|
}
|