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