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.concept.e4;
|
11
|
|
12
|
import java.util.Map.Entry;
|
13
|
|
14
|
import javax.annotation.PostConstruct;
|
15
|
|
16
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
17
|
import org.eclipse.e4.ui.services.EMenuService;
|
18
|
import org.eclipse.jface.viewers.ISelection;
|
19
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
20
|
import org.eclipse.jface.viewers.ListViewer;
|
21
|
import org.eclipse.jface.viewers.StructuredSelection;
|
22
|
import org.eclipse.jface.viewers.ViewerSorter;
|
23
|
import org.eclipse.swt.widgets.Composite;
|
24
|
|
25
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
26
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
|
27
|
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
|
28
|
import eu.etaxonomy.taxeditor.editor.key.AbstractGraphKeyEditor;
|
29
|
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
|
30
|
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
|
31
|
import eu.etaxonomy.taxeditor.editor.view.concept.ConceptContentProvider;
|
32
|
import eu.etaxonomy.taxeditor.editor.view.concept.ConceptLabelProvider;
|
33
|
import eu.etaxonomy.taxeditor.editor.view.descriptive.e4.FactualDataPartE4;
|
34
|
import eu.etaxonomy.taxeditor.editor.view.media.e4.MediaViewPartE4;
|
35
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
36
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
37
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
38
|
import eu.etaxonomy.taxeditor.model.LineSelection;
|
39
|
import eu.etaxonomy.taxeditor.view.e4.AbstractCdmEditorPartE4;
|
40
|
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
|
41
|
import eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4;
|
42
|
|
43
|
/**
|
44
|
*
|
45
|
* @author pplitzner
|
46
|
* @date 21.08.2017
|
47
|
*
|
48
|
*/
|
49
|
public class ConceptViewPartE4 extends AbstractCdmEditorPartE4
|
50
|
implements IPartContentHasDetails, IPartContentHasSupplementalData{
|
51
|
|
52
|
@Override
|
53
|
public void selectionChanged_internal(Object selection, MPart activePart, MPart thisPart) {
|
54
|
if(activePart==thisPart){
|
55
|
return;
|
56
|
}
|
57
|
viewer.getControl().setEnabled(true);
|
58
|
Object partObject = createPartObject(activePart);
|
59
|
|
60
|
if (partObject instanceof DetailsPartE4 || partObject instanceof SupplementalDataPartE4
|
61
|
|| partObject instanceof FactualDataPartE4|| partObject instanceof MediaViewPartE4) {
|
62
|
// do not show empty page as these views are also used to edit the
|
63
|
// description selected in this view
|
64
|
return;
|
65
|
}
|
66
|
else if(partObject instanceof BulkEditor && selection instanceof LineSelection){
|
67
|
if(((LineSelection) selection).getFirstElement() instanceof Taxon){
|
68
|
showViewer((LineSelection) selection, activePart, viewer);
|
69
|
}
|
70
|
else{
|
71
|
showEmptyPage();
|
72
|
}
|
73
|
return;
|
74
|
}
|
75
|
else if(partObject instanceof AbstractGraphKeyEditor){
|
76
|
showEmptyPage();
|
77
|
}
|
78
|
else if(partObject instanceof TaxonNameEditorE4){
|
79
|
Taxon taxon = ((TaxonNameEditorE4) partObject).getTaxon();
|
80
|
if(taxon!=null){
|
81
|
showViewer(new StructuredSelection(taxon), activePart, viewer);
|
82
|
}
|
83
|
}
|
84
|
else {
|
85
|
showEmptyPage();
|
86
|
}
|
87
|
|
88
|
}
|
89
|
|
90
|
@PostConstruct
|
91
|
public void create(Composite parent, EMenuService menuService, MPart thisPart) {
|
92
|
|
93
|
this.thisPart = thisPart;
|
94
|
|
95
|
ConceptRelationViewer conceptViewer = new ConceptRelationViewer(parent);
|
96
|
|
97
|
conceptViewer.setContentProvider(new ConceptContentProvider());
|
98
|
conceptViewer.setLabelProvider(new ConceptLabelProvider());
|
99
|
|
100
|
|
101
|
conceptViewer.setSorter(new ViewerSorter());
|
102
|
|
103
|
viewer = conceptViewer;
|
104
|
|
105
|
// Propagate selection from viewer
|
106
|
selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
|
107
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
108
|
|
109
|
//create context menu
|
110
|
menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.conceptview");
|
111
|
|
112
|
}
|
113
|
|
114
|
@Override
|
115
|
public void changed(Object object) {
|
116
|
getViewer().refresh();
|
117
|
super.changed(object);
|
118
|
}
|
119
|
|
120
|
private class ConceptRelationViewer extends ListViewer {
|
121
|
|
122
|
public ConceptRelationViewer(Composite parent) {
|
123
|
super(parent);
|
124
|
}
|
125
|
|
126
|
@Override
|
127
|
public ISelection getSelection() {
|
128
|
ISelection selection = super.getSelection();
|
129
|
if(selection instanceof IStructuredSelection && !selection.isEmpty()){
|
130
|
Object firstElement = ((IStructuredSelection) selection).getFirstElement();
|
131
|
TaxonRelationship taxonRelationship = ((Entry<TaxonRelationship, Taxon>)firstElement).getKey();
|
132
|
return new StructuredSelection(taxonRelationship);
|
133
|
|
134
|
}
|
135
|
return selection;
|
136
|
}
|
137
|
|
138
|
@Override
|
139
|
public void setSelection(ISelection selection) {
|
140
|
super.setSelection(selection);
|
141
|
}
|
142
|
|
143
|
}
|
144
|
|
145
|
@Override
|
146
|
protected String getViewName() {
|
147
|
return Messages.ConceptViewPart_VIEWER_NAME;
|
148
|
}
|
149
|
|
150
|
}
|