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