1
|
/**
|
2
|
* Copyright (C) 2013 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
|
package eu.etaxonomy.taxeditor.view.dataimport.e4;
|
10
|
|
11
|
import java.time.LocalDate;
|
12
|
import java.time.format.DateTimeFormatter;
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.Collection;
|
15
|
|
16
|
import javax.annotation.PostConstruct;
|
17
|
import javax.annotation.PreDestroy;
|
18
|
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.eclipse.core.runtime.IProgressMonitor;
|
21
|
import org.eclipse.e4.ui.di.Focus;
|
22
|
import org.eclipse.jface.viewers.CheckboxTableViewer;
|
23
|
import org.eclipse.jface.wizard.IWizard;
|
24
|
import org.eclipse.jface.wizard.WizardDialog;
|
25
|
import org.eclipse.swt.SWT;
|
26
|
import org.eclipse.swt.events.SelectionAdapter;
|
27
|
import org.eclipse.swt.events.SelectionEvent;
|
28
|
import org.eclipse.swt.layout.GridData;
|
29
|
import org.eclipse.swt.layout.GridLayout;
|
30
|
import org.eclipse.swt.widgets.Button;
|
31
|
import org.eclipse.swt.widgets.Composite;
|
32
|
import org.eclipse.swt.widgets.Display;
|
33
|
import org.eclipse.swt.widgets.Event;
|
34
|
import org.eclipse.swt.widgets.Label;
|
35
|
import org.eclipse.swt.widgets.Listener;
|
36
|
import org.eclipse.swt.widgets.Table;
|
37
|
import org.eclipse.swt.widgets.TableItem;
|
38
|
import org.eclipse.swt.widgets.Text;
|
39
|
import org.eclipse.ui.IMemento;
|
40
|
import org.eclipse.ui.forms.widgets.FormToolkit;
|
41
|
import org.eclipse.wb.swt.ResourceManager;
|
42
|
|
43
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
44
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
45
|
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
|
46
|
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
|
47
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
48
|
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
|
49
|
import eu.etaxonomy.taxeditor.databaseAdmin.wizard.ImportPreferencesWizard;
|
50
|
import eu.etaxonomy.taxeditor.model.IContextListener;
|
51
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
52
|
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
|
53
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
54
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
55
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
56
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
|
57
|
import eu.etaxonomy.taxeditor.workbench.part.IEditorAreaPart;
|
58
|
|
59
|
/**
|
60
|
* View which shows a list of "data" that can be imported into the CDM
|
61
|
* @author pplitzner
|
62
|
* @date 22.08.2017
|
63
|
*
|
64
|
* @param <T> the CDM type that will be handled by this view
|
65
|
*/
|
66
|
public abstract class DataImportViewE4<T> implements IPartContentHasFactualData,
|
67
|
IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IContextListener, Listener, IEditorAreaPart{
|
68
|
|
69
|
protected final Logger logger = Logger.getLogger(DataImportViewE4.class);
|
70
|
|
71
|
protected Collection<T> results = new ArrayList<>();
|
72
|
|
73
|
protected boolean updated = false;
|
74
|
|
75
|
protected OccurenceQuery query;
|
76
|
|
77
|
private static ConversationHolder conversationHolder;
|
78
|
|
79
|
private SaveImportedSpecimenActionE4 saveImportedSpecimenAction;
|
80
|
|
81
|
private Text textClassification;
|
82
|
|
83
|
private Classification classification;
|
84
|
|
85
|
protected Text textReferenceString;
|
86
|
|
87
|
private Button selectAllButton;
|
88
|
//private Button selectNoneButton;
|
89
|
|
90
|
private Button importButton;
|
91
|
|
92
|
private boolean state;
|
93
|
|
94
|
private Button openConfigurator;
|
95
|
|
96
|
private Abcd206ImportConfigurator config;
|
97
|
|
98
|
public Classification getClassification() {
|
99
|
return classification;
|
100
|
}
|
101
|
|
102
|
public void setClassification(Classification classification) {
|
103
|
this.classification = classification;
|
104
|
}
|
105
|
|
106
|
private Button btnBrowseClassification;
|
107
|
|
108
|
private Button btnClear;
|
109
|
|
110
|
private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
|
111
|
|
112
|
private Table table;
|
113
|
private Composite composite_3;
|
114
|
|
115
|
/**
|
116
|
* Constructs a new DataImportEditor and registers it to listen to context changes
|
117
|
*/
|
118
|
public DataImportViewE4() {
|
119
|
CdmStore.getContextManager().addContextListener(this);
|
120
|
}
|
121
|
|
122
|
/**
|
123
|
* Create contents of the view part.
|
124
|
* @param parent
|
125
|
*/
|
126
|
@PostConstruct
|
127
|
public void createPartControl(Composite parent) {
|
128
|
if(CdmStore.isActive()){
|
129
|
initConversation();
|
130
|
}
|
131
|
else{
|
132
|
return;
|
133
|
}
|
134
|
parent.setLayout(new GridLayout(1, false));
|
135
|
Composite composite = new Composite(parent, SWT.NONE);
|
136
|
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
137
|
// composite.setBounds(0, 0, 0, 298);
|
138
|
composite.setLayout(new GridLayout(2, false));
|
139
|
|
140
|
Composite composite_1 = new Composite(composite, SWT.NONE);
|
141
|
// gd_composite_1.widthHint = 280;
|
142
|
composite_1.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
|
143
|
composite_1.setLayout(new GridLayout(3, false));
|
144
|
|
145
|
Label label = new Label(composite_1, SWT.TOP);
|
146
|
label.setText("Classification");
|
147
|
label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
|
148
|
textClassification = new Text(composite_1, SWT.BORDER);
|
149
|
textClassification.setEnabled(false);
|
150
|
GridData gd_textClassification = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
|
151
|
// gd_textClassification.widthHint = 118;
|
152
|
textClassification.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
|
153
|
btnBrowseClassification = new Button(composite_1, SWT.NONE);
|
154
|
btnBrowseClassification.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/open.gif"));
|
155
|
btnBrowseClassification.addListener(SWT.Selection, this);
|
156
|
btnClear = new Button(composite_1, SWT.NONE);
|
157
|
btnClear.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
|
158
|
btnClear.addListener(SWT.Selection, this);
|
159
|
//source reference
|
160
|
|
161
|
Label labelRef = new Label(composite_1, SWT.NONE);
|
162
|
labelRef.setText("Import souce reference");
|
163
|
labelRef.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
|
164
|
textReferenceString = new Text(composite_1, SWT.NONE);
|
165
|
textReferenceString.setEnabled(true);
|
166
|
GridData gd_textReferenceString = new GridData(SWT.LEFT, SWT.CENTER, true, true, 3, 1);
|
167
|
gd_textReferenceString.widthHint = 229;
|
168
|
textReferenceString.setLayoutData(gd_textReferenceString);
|
169
|
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
|
170
|
LocalDate localDate = LocalDate.now();
|
171
|
|
172
|
textReferenceString.setText("Specimen Import " + localDate.toString());
|
173
|
//open configuration
|
174
|
|
175
|
PreferencesUtil.getLocalAbcdImportConfigurator(false);
|
176
|
|
177
|
openConfigurator = new Button(composite_1, SWT.PUSH);
|
178
|
openConfigurator.setText("Configuration");
|
179
|
new Label(composite_1, SWT.NONE);
|
180
|
new Label(composite_1, SWT.NONE);
|
181
|
|
182
|
openConfigurator.addSelectionListener(new SelectionAdapter(){
|
183
|
@Override
|
184
|
public void widgetSelected(SelectionEvent e) {
|
185
|
|
186
|
IWizard wizard = new ImportPreferencesWizard();
|
187
|
WizardDialog dialog = new WizardDialog(e.display.getActiveShell(), wizard);
|
188
|
dialog.open();
|
189
|
|
190
|
}
|
191
|
});
|
192
|
|
193
|
//checkbox table for result
|
194
|
Composite composite_2 = new Composite(composite, SWT.NONE);
|
195
|
composite_2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
196
|
composite_2.setLayout(new GridLayout(2, false));
|
197
|
|
198
|
|
199
|
CheckboxTableViewer checkboxTableViewer = CheckboxTableViewer.newCheckList(composite_2, SWT.BORDER | SWT.FULL_SELECTION);
|
200
|
|
201
|
|
202
|
table = checkboxTableViewer.getTable();
|
203
|
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
204
|
table.addListener(SWT.Selection, this);
|
205
|
toolkit.paintBordersFor(table);
|
206
|
|
207
|
composite_3 = new Composite(composite_2, SWT.NONE);
|
208
|
// gd_composite_3.heightHint = 48;
|
209
|
composite_3.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
|
210
|
toolkit.paintBordersFor(composite_3);
|
211
|
composite_3.setLayout(new GridLayout(1, false));
|
212
|
//toggle button
|
213
|
selectAllButton = new Button(composite_3, SWT.PUSH);
|
214
|
selectAllButton.setText("Select all/none");
|
215
|
new Label(composite_2, SWT.NONE);
|
216
|
|
217
|
// Composite composite_4 = new Composite(composite_2, SWT.NONE);
|
218
|
// composite_4.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
|
219
|
// composite_4.setBackground(composite.getBackground());
|
220
|
// toolkit.adapt(composite_4);
|
221
|
// toolkit.paintBordersFor(composite_4);
|
222
|
|
223
|
importButton = new Button(composite_2, SWT.PUSH);
|
224
|
importButton.setSize(48, 25);
|
225
|
importButton.setText("Import");
|
226
|
importButton.addSelectionListener(new SelectionAdapter(){
|
227
|
@Override
|
228
|
public void widgetSelected(SelectionEvent e) {
|
229
|
saveImportedSpecimenAction.run();
|
230
|
}
|
231
|
});
|
232
|
// new Label(composite_2, SWT.NONE);
|
233
|
// new Label(composite_2, SWT.NONE);
|
234
|
// new Label(composite_2, SWT.NONE);
|
235
|
// new Label(composite_2, SWT.NONE);
|
236
|
// new Label(composite_2, SWT.NONE);
|
237
|
// new Label(composite_2, SWT.NONE);
|
238
|
selectAllButton.addSelectionListener(new SelectionAdapter(){
|
239
|
@Override
|
240
|
public void widgetSelected(SelectionEvent e) {
|
241
|
state = state ? false : true;
|
242
|
for (TableItem item: getTable().getItems()){
|
243
|
item.setChecked(state);
|
244
|
}
|
245
|
|
246
|
}
|
247
|
});
|
248
|
//import button
|
249
|
|
250
|
saveImportedSpecimenAction = new SaveImportedSpecimenActionE4(this);
|
251
|
initializeToolBar();
|
252
|
}
|
253
|
|
254
|
/**
|
255
|
* Initialize the toolbar.
|
256
|
*/
|
257
|
private void initializeToolBar() {
|
258
|
//FIXME E4 migrate
|
259
|
// IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
|
260
|
// tbm.add(saveImportedSpecimenAction);
|
261
|
}
|
262
|
|
263
|
public Table getTable() {
|
264
|
return table;
|
265
|
}
|
266
|
|
267
|
public void setQuery(OccurenceQuery query) {
|
268
|
this.query = query;
|
269
|
}
|
270
|
|
271
|
public void setResults(Collection<T> results) {
|
272
|
this.results = results;
|
273
|
updated=false;
|
274
|
|
275
|
}
|
276
|
|
277
|
@PreDestroy
|
278
|
public void dispose() {
|
279
|
CdmStore.getContextManager().removeContextListener(this);
|
280
|
}
|
281
|
|
282
|
@Override
|
283
|
public void contextRefresh(IProgressMonitor monitor) {
|
284
|
refresh();
|
285
|
}
|
286
|
|
287
|
protected void refresh(){
|
288
|
if (!updated){
|
289
|
if (getTable() != null){
|
290
|
getTable().removeAll();
|
291
|
}
|
292
|
if(results!=null){
|
293
|
for(T item:results){
|
294
|
TableItem tableItem = new TableItem(getTable(), SWT.NONE);
|
295
|
tableItem.setText(getTextForTableItem(item));
|
296
|
tableItem.setData(item);
|
297
|
}
|
298
|
}
|
299
|
updated = true;
|
300
|
}
|
301
|
}
|
302
|
|
303
|
public abstract void query();
|
304
|
|
305
|
@Override
|
306
|
public void update(CdmDataChangeMap changeEvents) {
|
307
|
//nothing
|
308
|
}
|
309
|
|
310
|
/**
|
311
|
* Returns the text label of the given item.
|
312
|
* @param item the item for which the label should be returns
|
313
|
* @return the label of the item
|
314
|
*/
|
315
|
protected abstract String getTextForTableItem(T item);
|
316
|
|
317
|
@Focus
|
318
|
public void setFocus() {
|
319
|
if(getTable()!=null){
|
320
|
getTable().setFocus();
|
321
|
}
|
322
|
//make sure to bind again if maybe in another view the conversation was unbound
|
323
|
if(getConversationHolder()!=null && !getConversationHolder().isBound()){
|
324
|
getConversationHolder().bind();
|
325
|
}
|
326
|
}
|
327
|
|
328
|
@Override
|
329
|
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
|
330
|
}
|
331
|
|
332
|
@Override
|
333
|
public void contextStop(IMemento memento, IProgressMonitor monitor) {
|
334
|
}
|
335
|
|
336
|
@Override
|
337
|
public void contextStart(IMemento memento, IProgressMonitor monitor) {
|
338
|
initConversation();
|
339
|
}
|
340
|
|
341
|
private void initConversation(){
|
342
|
if(conversationHolder==null){
|
343
|
conversationHolder = CdmStore.createConversation();
|
344
|
}
|
345
|
}
|
346
|
|
347
|
@Override
|
348
|
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
|
349
|
if(getConversationHolder()!=null && getConversationHolder().isBound() && !getConversationHolder().isClosed()) {
|
350
|
getConversationHolder().close();
|
351
|
}
|
352
|
}
|
353
|
|
354
|
/**
|
355
|
* @return the conversationHolder
|
356
|
*/
|
357
|
@Override
|
358
|
public ConversationHolder getConversationHolder() {
|
359
|
if(CdmStore.isActive() && conversationHolder==null){
|
360
|
initConversation();
|
361
|
}
|
362
|
return conversationHolder;
|
363
|
}
|
364
|
|
365
|
@Override
|
366
|
public void handleEvent(Event event) {
|
367
|
if(event.widget==btnBrowseClassification){
|
368
|
classification = SelectionDialogFactory.getSelectionFromDialog(Classification.class, event.widget.getDisplay().getActiveShell(), null, null);
|
369
|
if(classification!=null){
|
370
|
textClassification.setText(classification.getTitleCache());
|
371
|
}
|
372
|
}
|
373
|
else if(event.widget==btnClear){
|
374
|
classification = null;
|
375
|
textClassification.setText("");
|
376
|
}
|
377
|
|
378
|
else {
|
379
|
if(event.widget == table){
|
380
|
TableItem[] item = table.getSelection();
|
381
|
if (item.length == 1){
|
382
|
Object o = item[0].getData();
|
383
|
}
|
384
|
}
|
385
|
}
|
386
|
}
|
387
|
|
388
|
public String getReferenceString() {
|
389
|
return textReferenceString.getText();
|
390
|
}
|
391
|
}
|