2 * Copyright (C) 2013 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.view
.dataimport
.e4
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Collection
;
14 import javax
.annotation
.PostConstruct
;
15 import javax
.annotation
.PreDestroy
;
17 import org
.apache
.logging
.log4j
.LogManager
;
18 import org
.apache
.logging
.log4j
.Logger
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.e4
.ui
.di
.Focus
;
21 import org
.eclipse
.jface
.viewers
.CheckboxTableViewer
;
22 import org
.eclipse
.jface
.wizard
.IWizard
;
23 import org
.eclipse
.jface
.wizard
.WizardDialog
;
24 import org
.eclipse
.swt
.SWT
;
25 import org
.eclipse
.swt
.events
.SelectionAdapter
;
26 import org
.eclipse
.swt
.events
.SelectionEvent
;
27 import org
.eclipse
.swt
.layout
.GridData
;
28 import org
.eclipse
.swt
.layout
.GridLayout
;
29 import org
.eclipse
.swt
.widgets
.Button
;
30 import org
.eclipse
.swt
.widgets
.Composite
;
31 import org
.eclipse
.swt
.widgets
.Display
;
32 import org
.eclipse
.swt
.widgets
.Event
;
33 import org
.eclipse
.swt
.widgets
.Label
;
34 import org
.eclipse
.swt
.widgets
.Listener
;
35 import org
.eclipse
.swt
.widgets
.Table
;
36 import org
.eclipse
.swt
.widgets
.TableItem
;
37 import org
.eclipse
.swt
.widgets
.Text
;
38 import org
.eclipse
.ui
.IMemento
;
39 import org
.eclipse
.ui
.forms
.widgets
.FormToolkit
;
41 import eu
.etaxonomy
.cdm
.ext
.occurrence
.OccurenceQuery
;
42 import eu
.etaxonomy
.taxeditor
.databaseAdmin
.wizard
.ImportPreferencesWizard
;
43 import eu
.etaxonomy
.taxeditor
.model
.IContextListener
;
44 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
45 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasFactualData
;
46 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
47 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
48 import eu
.etaxonomy
.taxeditor
.workbench
.part
.IEditorAreaPart
;
51 * View which shows a list of "data" that can be imported into the CDM
56 * @param <T> the CDM type that will be handled by this view
58 public abstract class DataImportView
<T
> implements IPartContentHasFactualData
, IPartContentHasDetails
, IPartContentHasSupplementalData
, IContextListener
, Listener
, IEditorAreaPart
{
60 protected final Logger logger
= LogManager
.getLogger();
62 protected Collection
<T
> results
= new ArrayList
<>();
64 protected boolean updated
= false;
66 protected OccurenceQuery query
;
68 private SaveImportedSpecimenAction saveImportedSpecimenAction
;
70 protected Text textReferenceString
;
72 private Button selectAllButton
;
74 private Button importButton
;
76 private boolean state
;
78 private final FormToolkit toolkit
= new FormToolkit(Display
.getCurrent());
81 private Composite composite_3
;
84 * Constructs a new DataImportEditor and registers it to listen to context changes
86 public DataImportView() {
87 CdmStore
.getContextManager().addContextListener(this);
91 * Create contents of the view part.
95 public void createPartControl(Composite parent
) {
97 parent
.setLayout(new GridLayout(1, false));
98 Composite composite
= new Composite(parent
, SWT
.NONE
);
99 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1));
100 // composite.setBounds(0, 0, 0, 298);
101 composite
.setLayout(new GridLayout(2, false));
103 Composite composite_1
= new Composite(composite
, SWT
.NONE
);
104 // gd_composite_1.widthHint = 280;
105 composite_1
.setLayoutData(new GridData(SWT
.FILL
, SWT
.TOP
, false, false, 1, 1));
106 composite_1
.setLayout(new GridLayout(3, false));
108 // Label label = new Label(composite_1, SWT.TOP);
109 // label.setText("Classification");
110 // label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
111 // textClassification = new Text(composite_1, SWT.BORDER);
112 // textClassification.setEnabled(false);
113 // GridData gd_textClassification = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
114 //// gd_textClassification.widthHint = 118;
115 // textClassification.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
116 // btnBrowseClassification = new Button(composite_1, SWT.NONE);
117 // btnBrowseClassification.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/open.gif"));
118 // btnBrowseClassification.addListener(SWT.Selection, this);
119 // btnClear = new Button(composite_1, SWT.NONE);
120 // btnClear.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
121 // btnClear.addListener(SWT.Selection, this);
124 // Label labelRef = new Label(composite_1, SWT.NONE);
125 // labelRef.setText("Import souce reference");
126 // labelRef.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
127 // textReferenceString = new Text(composite_1, SWT.NONE);
128 // textReferenceString.setEnabled(true);
129 // GridData gd_textReferenceString = new GridData(SWT.LEFT, SWT.CENTER, true, true, 3, 1);
130 // gd_textReferenceString.widthHint = 229;
131 // textReferenceString.setLayoutData(gd_textReferenceString);
132 // DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
133 // LocalDate localDate = LocalDate.now();
135 // textReferenceString.setText("Specimen Import " + localDate.toString());
138 // PreferencesUtil.getLocalAbcdImportConfigurator(false);
140 // openConfigurator = new Button(composite_1, SWT.PUSH);
141 // openConfigurator.setText("Configuration");
142 // new Label(composite_1, SWT.NONE);
143 // new Label(composite_1, SWT.NONE);
145 // openConfigurator.addSelectionListener(new SelectionAdapter(){
147 // public void widgetSelected(SelectionEvent e) {
149 // IWizard wizard = new ImportPreferencesWizard();
150 // WizardDialog dialog = new WizardDialog(e.display.getActiveShell(), wizard);
156 //checkbox table for result
157 Composite composite_2
= new Composite(composite
, SWT
.NONE
);
158 composite_2
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1));
159 composite_2
.setLayout(new GridLayout(2, false));
162 CheckboxTableViewer checkboxTableViewer
= CheckboxTableViewer
.newCheckList(composite_2
, SWT
.BORDER
| SWT
.FULL_SELECTION
);
164 table
= checkboxTableViewer
.getTable();
165 table
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 1, 1));
166 table
.addListener(SWT
.Selection
, this);
167 toolkit
.paintBordersFor(table
);
169 composite_3
= new Composite(composite_2
, SWT
.NONE
);
170 // gd_composite_3.heightHint = 48;
171 composite_3
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, false, false, 1, 1));
172 toolkit
.paintBordersFor(composite_3
);
173 composite_3
.setLayout(new GridLayout(1, false));
175 selectAllButton
= new Button(composite_3
, SWT
.PUSH
);
176 selectAllButton
.setText("Select all/none");
177 new Label(composite_2
, SWT
.NONE
);
179 // Composite composite_4 = new Composite(composite_2, SWT.NONE);
180 // composite_4.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
181 // composite_4.setBackground(composite.getBackground());
182 // toolkit.adapt(composite_4);
183 // toolkit.paintBordersFor(composite_4);
185 importButton
= new Button(composite_2
, SWT
.PUSH
);
186 importButton
.setSize(48, 25);
187 importButton
.setText("Import");
188 importButton
.addSelectionListener(new SelectionAdapter(){
190 public void widgetSelected(SelectionEvent e
) {
191 IWizard wizard
= new ImportPreferencesWizard();
192 WizardDialog dialog
= new WizardDialog(e
.display
.getActiveShell(), wizard
);
193 int status
= dialog
.open();
195 saveImportedSpecimenAction
.run();
199 // new Label(composite_2, SWT.NONE);
200 // new Label(composite_2, SWT.NONE);
201 // new Label(composite_2, SWT.NONE);
202 // new Label(composite_2, SWT.NONE);
203 // new Label(composite_2, SWT.NONE);
204 // new Label(composite_2, SWT.NONE);
205 selectAllButton
.addSelectionListener(new SelectionAdapter(){
207 public void widgetSelected(SelectionEvent e
) {
208 state
= state ?
false : true;
209 for (TableItem item
: getTable().getItems()){
210 item
.setChecked(state
);
217 saveImportedSpecimenAction
= new SaveImportedSpecimenAction(this);
222 * Initialize the toolbar.
224 private void initializeToolBar() {
226 // IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
227 // tbm.add(saveImportedSpecimenAction);
230 public Table
getTable() {
234 public void setQuery(OccurenceQuery query
) {
238 public void setResults(Collection
<T
> results
) {
239 this.results
= results
;
245 public void dispose() {
246 CdmStore
.getContextManager().removeContextListener(this);
250 public void contextRefresh(IProgressMonitor monitor
) {
254 protected void refresh(){
256 if (getTable() != null){
257 getTable().removeAll();
261 TableItem tableItem
= new TableItem(getTable(), SWT
.NONE
);
262 tableItem
.setText(getTextForTableItem(item
));
263 tableItem
.setData(item
);
270 public abstract void query();
273 * Returns the text label of the given item.
274 * @param item the item for which the label should be returns
275 * @return the label of the item
277 protected abstract String
getTextForTableItem(T item
);
280 public void setFocus() {
281 if(getTable()!=null){
282 getTable().setFocus();
287 public void contextAboutToStop(IMemento memento
, IProgressMonitor monitor
) {
291 public void contextStop(IMemento memento
, IProgressMonitor monitor
) {
295 public void contextStart(IMemento memento
, IProgressMonitor monitor
) {
300 public void workbenchShutdown(IMemento memento
, IProgressMonitor monitor
) {
304 public void handleEvent(Event event
) {
305 // if(event.widget==btnBrowseClassification){
306 // classification = SelectionDialogFactory.getSelectionFromDialog(Classification.class, event.widget.getDisplay().getActiveShell(), null, null);
307 // if(classification!=null){
308 // textClassification.setText(classification.getTitleCache());
311 // else if(event.widget==btnClear){
312 // classification = null;
313 // textClassification.setText("");
317 if(event
.widget
== table
){
318 TableItem
[] item
= table
.getSelection();
319 if (item
.length
== 1){
320 Object o
= item
[0].getData();
326 public String
getReferenceString() {
327 return textReferenceString
.getText();