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