1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2017 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet;
|
11
|
|
12
|
import java.util.Collection;
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
|
16
|
import javax.annotation.PostConstruct;
|
17
|
import javax.annotation.PreDestroy;
|
18
|
import javax.inject.Inject;
|
19
|
|
20
|
import org.eclipse.core.runtime.IProgressMonitor;
|
21
|
import org.eclipse.e4.core.di.annotations.Optional;
|
22
|
import org.eclipse.e4.ui.di.Focus;
|
23
|
import org.eclipse.e4.ui.di.UIEventTopic;
|
24
|
import org.eclipse.e4.ui.model.application.MApplication;
|
25
|
import org.eclipse.e4.ui.services.EMenuService;
|
26
|
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
27
|
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
28
|
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
29
|
import org.eclipse.jface.viewers.ArrayContentProvider;
|
30
|
import org.eclipse.jface.viewers.DoubleClickEvent;
|
31
|
import org.eclipse.jface.viewers.IDoubleClickListener;
|
32
|
import org.eclipse.jface.viewers.ISelection;
|
33
|
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
34
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
35
|
import org.eclipse.jface.viewers.LabelProvider;
|
36
|
import org.eclipse.jface.viewers.ListViewer;
|
37
|
import org.eclipse.jface.viewers.ViewerComparator;
|
38
|
import org.eclipse.swt.widgets.Composite;
|
39
|
import org.eclipse.ui.IMemento;
|
40
|
|
41
|
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService;
|
42
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
43
|
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
|
44
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
45
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
46
|
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
|
47
|
import eu.etaxonomy.taxeditor.model.IContextListener;
|
48
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
49
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
50
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
51
|
|
52
|
/**
|
53
|
* @author pplitzner
|
54
|
* @date 12.12.2017
|
55
|
*
|
56
|
*/
|
57
|
public class DescriptiveDataSetNavigator
|
58
|
implements ICdmEntitySessionEnabled<DescriptiveDataSet>, IContextListener{
|
59
|
|
60
|
private ListViewer viewer;
|
61
|
|
62
|
@Inject
|
63
|
private ESelectionService selService;
|
64
|
|
65
|
private ISelectionChangedListener selectionChangedListener;
|
66
|
|
67
|
private ICdmEntitySession cdmEntitySession;
|
68
|
|
69
|
private List<DescriptiveDataSet> descriptiveDataSets;
|
70
|
|
71
|
public DescriptiveDataSetNavigator() {
|
72
|
CdmStore.getContextManager().addContextListener(this);
|
73
|
}
|
74
|
|
75
|
@PostConstruct
|
76
|
public void create(Composite parent, EPartService partService, EModelService modelService, MApplication application,
|
77
|
EMenuService menuService){
|
78
|
viewer = new ListViewer(parent);
|
79
|
viewer.setContentProvider(new ArrayContentProvider());
|
80
|
viewer.setLabelProvider(new LabelProvider(){
|
81
|
/**
|
82
|
* {@inheritDoc}
|
83
|
*/
|
84
|
@Override
|
85
|
public String getText(Object element) {
|
86
|
if(element instanceof DescriptiveDataSet){
|
87
|
return ((DescriptiveDataSet) element).getLabel();
|
88
|
}
|
89
|
return super.getText(element);
|
90
|
}
|
91
|
});
|
92
|
viewer.setComparator(new ViewerComparator());
|
93
|
|
94
|
viewer.addDoubleClickListener(new IDoubleClickListener() {
|
95
|
|
96
|
@Override
|
97
|
public void doubleClick(DoubleClickEvent event) {
|
98
|
ISelection selection = event.getSelection();
|
99
|
if(selection instanceof IStructuredSelection){
|
100
|
DescriptiveDataSet descriptiveDataSetUuid = (DescriptiveDataSet) ((IStructuredSelection) selection).getFirstElement();
|
101
|
if(descriptiveDataSetUuid!=null){
|
102
|
EditorUtil.openDescriptiveDataSetEditor(descriptiveDataSetUuid.getUuid(), modelService, partService, application);
|
103
|
}
|
104
|
}
|
105
|
}
|
106
|
});
|
107
|
|
108
|
//propagate selection
|
109
|
selectionChangedListener = (event -> selService.setSelection(event.getSelection()));
|
110
|
viewer.addSelectionChangedListener(selectionChangedListener);
|
111
|
|
112
|
//create context menu
|
113
|
menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.descriptiveDataSetNavigator"); //$NON-NLS-1$
|
114
|
|
115
|
init();
|
116
|
}
|
117
|
|
118
|
public void init(){
|
119
|
if (CdmStore.isActive()){
|
120
|
// if(conversation == null) {
|
121
|
// conversation = CdmStore.createConversation();
|
122
|
// }
|
123
|
if(cdmEntitySession == null){
|
124
|
cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
|
125
|
}
|
126
|
descriptiveDataSets = CdmStore.getService(IDescriptiveDataSetService.class).list(DescriptiveDataSet.class, null, null, null, null);
|
127
|
viewer.setInput(descriptiveDataSets);
|
128
|
}
|
129
|
}
|
130
|
|
131
|
public void addDescriptiveDataSet(DescriptiveDataSet descriptiveDataSetSet){
|
132
|
descriptiveDataSets.add(descriptiveDataSetSet);
|
133
|
refresh();
|
134
|
}
|
135
|
|
136
|
public void removeDescriptiveDataSet(DescriptiveDataSet descriptiveDataSetSet){
|
137
|
descriptiveDataSets.remove(descriptiveDataSetSet);
|
138
|
refresh();
|
139
|
}
|
140
|
|
141
|
public void refresh(){
|
142
|
refresh(false);
|
143
|
}
|
144
|
|
145
|
public void refresh(boolean reloadDescriptiveDataSets){
|
146
|
if(reloadDescriptiveDataSets){
|
147
|
cdmEntitySession.dispose();
|
148
|
cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
|
149
|
IDescriptiveDataSetService service = CdmStore.getService(IDescriptiveDataSetService.class);
|
150
|
descriptiveDataSets = service.list(DescriptiveDataSet.class, null, null, null, null);
|
151
|
}
|
152
|
viewer.setInput(descriptiveDataSets);
|
153
|
viewer.refresh();
|
154
|
}
|
155
|
|
156
|
@Inject
|
157
|
@Optional
|
158
|
private void updateView(@UIEventTopic(WorkbenchEventConstants.REFRESH_DATASET_NAVIGATOR) DescriptiveDataSet dataSet) {
|
159
|
DescriptiveDataSet load = cdmEntitySession.load(dataSet, true);
|
160
|
viewer.update(load, null);
|
161
|
refresh();
|
162
|
}
|
163
|
|
164
|
|
165
|
|
166
|
@Override
|
167
|
public ICdmEntitySession getCdmEntitySession() {
|
168
|
return cdmEntitySession;
|
169
|
}
|
170
|
|
171
|
@Override
|
172
|
public Collection<DescriptiveDataSet> getRootEntities() {
|
173
|
return null;
|
174
|
}
|
175
|
|
176
|
@Override
|
177
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
178
|
return null;
|
179
|
}
|
180
|
|
181
|
public ESelectionService getSelService() {
|
182
|
return selService;
|
183
|
}
|
184
|
|
185
|
@PreDestroy
|
186
|
public void dispose() {
|
187
|
|
188
|
if(cdmEntitySession != null) {
|
189
|
cdmEntitySession.dispose();
|
190
|
cdmEntitySession = null;
|
191
|
}
|
192
|
}
|
193
|
|
194
|
@Focus
|
195
|
public void setFocus() {
|
196
|
|
197
|
if(cdmEntitySession != null) {
|
198
|
cdmEntitySession.bind();
|
199
|
}
|
200
|
}
|
201
|
|
202
|
@Override
|
203
|
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
|
204
|
// TODO Auto-generated method stub
|
205
|
|
206
|
}
|
207
|
|
208
|
@Override
|
209
|
public void contextStop(IMemento memento, IProgressMonitor monitor) {
|
210
|
}
|
211
|
|
212
|
@Override
|
213
|
public void contextStart(IMemento memento, IProgressMonitor monitor) {
|
214
|
if(viewer!=null && viewer.getControl()!=null && !viewer.getControl().isDisposed()){
|
215
|
init();
|
216
|
}
|
217
|
}
|
218
|
|
219
|
@Override
|
220
|
public void contextRefresh(IProgressMonitor monitor) {
|
221
|
}
|
222
|
|
223
|
@Override
|
224
|
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
|
225
|
}
|
226
|
}
|