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