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