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