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.l10n.Messages;
|
27
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
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.MediaViewLabelProvider;
|
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, MPart thisPart) {
|
51
|
|
52
|
this.thisPart = thisPart;
|
53
|
TreeViewer treeViewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL
|
54
|
| SWT.V_SCROLL | SWT.FULL_SELECTION));
|
55
|
|
56
|
treeViewer.setContentProvider(new MediaContentProvider());
|
57
|
treeViewer.setLabelProvider(new MediaViewLabelProvider());
|
58
|
|
59
|
// TreeViewerColumn imagePreview = new TreeViewerColumn(treeViewer, SWT.NONE);
|
60
|
// imagePreview.setLabelProvider(new DelegatingStyledCellLabelProvider(
|
61
|
// new MediaViewLabelProvider(createImageDescriptor())));
|
62
|
|
63
|
treeViewer.setAutoExpandLevel(2);
|
64
|
viewer = treeViewer;
|
65
|
|
66
|
// Propagate selection from viewer
|
67
|
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
|
68
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
69
|
|
70
|
//create context menu
|
71
|
menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.mediaview");
|
72
|
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
|
77
|
if(activePart==thisPart){
|
78
|
return;
|
79
|
}
|
80
|
|
81
|
Object partObject = createPartObject(activePart);
|
82
|
|
83
|
if (partObject instanceof DetailsPartE4 || partObject instanceof SupplementalDataPartE4
|
84
|
|| partObject instanceof FactualDataPartE4 || partObject instanceof ConceptViewPartE4) {
|
85
|
// do not show empty page as these views are also used to edit the
|
86
|
// description selected in this view
|
87
|
return;
|
88
|
}
|
89
|
|
90
|
if(partObject instanceof IPartContentHasMedia && ((IPartContentHasMedia) partObject).canAttachMedia()){
|
91
|
if (viewer.getControl() != null && !viewer.getControl().isDisposed()) {
|
92
|
viewer.getControl().setEnabled(true);
|
93
|
}
|
94
|
IStructuredSelection structuredSelection = createSelection(selection);
|
95
|
if(structuredSelection==null || structuredSelection.isEmpty()){
|
96
|
showEmptyPage();
|
97
|
return;
|
98
|
}
|
99
|
|
100
|
Object firstElement = structuredSelection.getFirstElement();
|
101
|
if (partObject instanceof TaxonNameEditorE4){
|
102
|
if (firstElement != ((TaxonNameEditorE4)partObject).getTaxon()){
|
103
|
showEmptyPage();
|
104
|
return;
|
105
|
}
|
106
|
}
|
107
|
if(firstElement instanceof TreeNode){
|
108
|
showViewer(new StructuredSelection(((TreeNode) firstElement).getValue()), activePart, viewer);
|
109
|
return;
|
110
|
}
|
111
|
else if(firstElement!=null
|
112
|
&& firstElement instanceof IDescribable<?>){
|
113
|
showViewer(structuredSelection, activePart, viewer);
|
114
|
return;
|
115
|
}
|
116
|
}
|
117
|
showEmptyPage();
|
118
|
return;
|
119
|
}
|
120
|
|
121
|
/** {@inheritDoc} */
|
122
|
@Override
|
123
|
public void changed(Object object) {
|
124
|
((AbstractTreeViewer) viewer).expandToLevel(2);
|
125
|
viewer.refresh();
|
126
|
if(object != null){
|
127
|
StructuredSelection selection = new StructuredSelection(object);
|
128
|
viewer.setSelection(selection, true);
|
129
|
}
|
130
|
super.changed(object);
|
131
|
}
|
132
|
|
133
|
@Override
|
134
|
protected String getViewName() {
|
135
|
return Messages.MediaViewPart_MEDIA;
|
136
|
}
|
137
|
|
138
|
|
139
|
|
140
|
}
|