Project

General

Profile

Revision 0e4f55de

ID0e4f55de2f1f5d33b17223b8ca679770c3ddf0d6
Parent a5b67ac3
Child 34dad812, 3f2943e8

Added by Patrick Plitzner about 3 years ago

ref #6921 Initial import of e4 classes

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/e4/DataImportViewE4.java
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
import javax.inject.Inject;
17
import javax.inject.Named;
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.e4.ui.services.IServiceConstants;
23
import org.eclipse.jface.viewers.CheckboxTableViewer;
24
import org.eclipse.jface.wizard.IWizard;
25
import org.eclipse.jface.wizard.WizardDialog;
26
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.events.SelectionAdapter;
28
import org.eclipse.swt.events.SelectionEvent;
29
import org.eclipse.swt.layout.GridData;
30
import org.eclipse.swt.layout.GridLayout;
31
import org.eclipse.swt.widgets.Button;
32
import org.eclipse.swt.widgets.Composite;
33
import org.eclipse.swt.widgets.Display;
34
import org.eclipse.swt.widgets.Event;
35
import org.eclipse.swt.widgets.Label;
36
import org.eclipse.swt.widgets.Listener;
37
import org.eclipse.swt.widgets.Shell;
38
import org.eclipse.swt.widgets.Table;
39
import org.eclipse.swt.widgets.TableItem;
40
import org.eclipse.swt.widgets.Text;
41
import org.eclipse.ui.IMemento;
42
import org.eclipse.ui.PlatformUI;
43
import org.eclipse.ui.forms.widgets.FormToolkit;
44
import org.eclipse.wb.swt.ResourceManager;
45

  
46
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
47
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
48
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
49
import eu.etaxonomy.cdm.model.taxon.Classification;
50
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
51
import eu.etaxonomy.taxeditor.databaseAdmin.wizard.ImportPreferencesWizard;
52
import eu.etaxonomy.taxeditor.model.IContextListener;
53
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
54
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
55
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
56
import eu.etaxonomy.taxeditor.store.CdmStore;
57
import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
58
import eu.etaxonomy.taxeditor.view.dataimport.SaveImportedSpecimenAction;
59

  
60
/**
61
 * View which shows a list of "data" that can be imported into the CDM
62
 * @author pplitzner
63
 * @date 22.08.2017
64
 *
65
 * @param <T> the CDM type that will be handled by this view
66
 */
67
public abstract class DataImportViewE4<T> implements IPartContentHasFactualData,
68
IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IContextListener, Listener{
69

  
70
    protected final Logger logger = Logger.getLogger(DataImportViewE4.class);
71

  
72
    @Inject
73
    private Shell shell;
74

  
75
    protected Collection<T> results = new ArrayList<T>();
76

  
77
    protected boolean updated = false;
78

  
79
    protected OccurenceQuery query;
80

  
81
    private static ConversationHolder conversationHolder;
82

  
83
    private SaveImportedSpecimenAction saveImportedSpecimenAction;
84

  
85
    private Text textClassification;
86

  
87
    private Classification classification;
88

  
89
    private Text textReferenceString;
90

  
91
    private Button toggleButton;
92

  
93
    private boolean state;
94

  
95
    private Button openConfigurator;
96

  
97
    public Classification getClassification() {
98
		return classification;
99
	}
100

  
101
	public void setClassification(Classification classification) {
102
		this.classification = classification;
103
	}
104

  
105
	private Button btnBrowseClassification;
106

  
107
	private Button btnClear;
108

  
109
    private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
110

  
111
    private Table table;
112

  
113
    /**
114
     * Constructs a new DataImportEditor and registers it to listen to context changes
115
     */
116
    public DataImportViewE4() {
117
        CdmStore.getContextManager().addContextListener(this);
118
        if(CdmStore.isActive()){
119
            initConversation();
120
        }
121
    }
122

  
123
    /**
124
     * Create contents of the view part.
125
     * @param parent
126
     */
127
    @PostConstruct
128
    public void createPartControl(Composite parent, @Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
129
        this.shell = shell;
130
        Composite composite = new Composite(parent, SWT.NONE);
131
        composite.setLayout(new GridLayout(2, false));
132

  
133
        Composite composite_1 = new Composite(composite, SWT.NONE);
134
        GridData gd_composite_1 = new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1);
135
        gd_composite_1.widthHint = 280;
136
        composite_1.setLayoutData(gd_composite_1);
137
        composite_1.setLayout(new GridLayout(3, false));
138

  
139
    	Label label = new Label(composite_1, SWT.TOP);
140
		label.setText("Classification");
141
		label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
142
		textClassification = new Text(composite_1, SWT.BORDER);
143
		textClassification.setEnabled(false);
144
		GridData gd_textClassification = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
145
		gd_textClassification.widthHint = 118;
146
		textClassification.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
147
		btnBrowseClassification = new Button(composite_1, SWT.NONE);
148
		btnBrowseClassification.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/open.gif"));
149
		btnBrowseClassification.addListener(SWT.Selection, this);
150
		btnClear = new Button(composite_1, SWT.NONE);
151
		btnClear.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
152
		btnClear.addListener(SWT.Selection, this);
153
		//source reference
154

  
155
        Label labelRef = new Label(composite_1, SWT.NONE);
156
        labelRef.setText("Default import souce reference");
157
        labelRef.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
158
        textReferenceString = new Text(composite_1, SWT.NONE);
159
        textReferenceString.setEnabled(true);
160
        GridData gd_textReferenceString = new GridData(SWT.LEFT, SWT.CENTER, true, true, 3, 1);
161
        gd_textReferenceString.widthHint = 229;
162
        textReferenceString.setLayoutData(gd_textReferenceString);
163

  
164
        //open configuration
165
        openConfigurator = new Button(composite_1, SWT.PUSH);
166
        openConfigurator.setText("Configuration");
167
        new Label(composite_1, SWT.NONE);
168
        new Label(composite_1, SWT.NONE);
169
        openConfigurator.addSelectionListener(new SelectionAdapter(){
170
            @Override
171
            public void widgetSelected(SelectionEvent e) {
172

  
173
                IWizard wizard = new ImportPreferencesWizard();
174
                WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
175
                dialog.open();
176
            }
177
        });
178

  
179
      //checkbox table for result
180
        Composite composite_2 = new Composite(composite, SWT.NONE);
181
        GridData gd_composite_2 = new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1);
182
        gd_composite_2.heightHint = 454;
183
        gd_composite_2.widthHint = 403;
184
        composite_2.setLayoutData(gd_composite_2);
185
       composite_2.setLayout(new GridLayout(2, false));
186

  
187

  
188
       CheckboxTableViewer checkboxTableViewer = CheckboxTableViewer.newCheckList(composite_2, SWT.BORDER | SWT.FULL_SELECTION);
189

  
190

  
191
       table = checkboxTableViewer.getTable();
192
       GridData gd_table = new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1);
193
       gd_table.heightHint = 444;
194
       gd_table.widthHint = 312;
195
       table.setLayoutData(gd_table);
196
       toolkit.paintBordersFor(table);
197
       //toggle button
198
       toggleButton = new Button(composite_2, SWT.PUSH);
199
       GridData gd_toggleButton = new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1);
200
       gd_toggleButton.widthHint = 56;
201
       toggleButton.setLayoutData(gd_toggleButton);
202
       toggleButton.setText("Toggle");
203
       toggleButton.addSelectionListener(new SelectionAdapter(){
204
           @Override
205
           public void widgetSelected(SelectionEvent e) {
206
               state = state ? false : true;
207
               for (TableItem item: getTable().getItems()){
208
                       item.setChecked(state);
209
               }
210

  
211
           }
212
       });
213
        createActions();
214
        initializeToolBar();
215
    }
216

  
217
    /**
218
     * Create the actions.
219
     */
220
    private void createActions() {
221
        saveImportedSpecimenAction = new SaveImportedSpecimenAction();
222
    }
223

  
224
    /**
225
     * Initialize the toolbar.
226
     */
227
    private void initializeToolBar() {
228
        //FIXME E4 migrate
229
//        IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
230
//        tbm.add(saveImportedSpecimenAction);
231
    }
232

  
233
    public Table getTable() {
234
        return table;
235
    }
236

  
237
    public void setQuery(OccurenceQuery query) {
238
        this.query = query;
239
    }
240

  
241
    public void setResults(Collection<T> results) {
242
        this.results = results;
243
        updated=false;
244
    }
245

  
246
    @PreDestroy
247
    public void dispose() {
248
        CdmStore.getContextManager().removeContextListener(this);
249
    }
250

  
251
    @Override
252
    public void contextRefresh(IProgressMonitor monitor) {
253
        refresh();
254
    }
255

  
256
    protected void refresh(){
257
        if (!updated){
258
            if (getTable() != null){
259
                getTable().removeAll();
260
            }
261
            for(T item:results){
262
                TableItem tableItem = new TableItem(getTable(), SWT.NONE);
263
                tableItem.setText(getTextForTableItem(item));
264
                tableItem.setData(item);
265
            }
266
            updated = true;
267
        }
268
    }
269

  
270
    public abstract void query();
271

  
272
    @Override
273
    public void update(CdmDataChangeMap changeEvents) {
274
        //nothing
275
    }
276

  
277
    /**
278
     * Returns the text label of the given item.
279
     * @param item the item for which the label should be returns
280
     * @return the label of the item
281
     */
282
    protected abstract String getTextForTableItem(T item);
283

  
284
    @Focus
285
    public void setFocus() {
286
        getTable().setFocus();
287
        //make sure to bind again if maybe in another view the conversation was unbound
288
        if(getConversationHolder()!=null && !getConversationHolder().isBound()){
289
            getConversationHolder().bind();
290
        }
291
    }
292

  
293
    @Override
294
    public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
295
    }
296

  
297
    @Override
298
    public void contextStop(IMemento memento, IProgressMonitor monitor) {
299
    }
300

  
301
    @Override
302
    public void contextStart(IMemento memento, IProgressMonitor monitor) {
303
        initConversation();
304
    }
305

  
306
    private void initConversation(){
307
        if(conversationHolder==null){
308
            conversationHolder = CdmStore.createConversation();
309
        }
310
    }
311

  
312
    @Override
313
    public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
314
        if(getConversationHolder()!=null && getConversationHolder().isBound() && !getConversationHolder().isClosed()) {
315
            getConversationHolder().close();
316
        }
317
    }
318

  
319
    /**
320
     * @return the conversationHolder
321
     */
322
    @Override
323
    public ConversationHolder getConversationHolder() {
324
        if(CdmStore.isActive() && conversationHolder==null){
325
            initConversation();
326
        }
327
        return conversationHolder;
328
    }
329

  
330
    @Override
331
	public void handleEvent(Event event) {
332
	    if(event.widget==btnBrowseClassification){
333
	        classification = SelectionDialogFactory.getSelectionFromDialog(Classification.class, shell, null, null);
334
	        if(classification!=null){
335
	            textClassification.setText(classification.getTitleCache());
336
	        }
337
	    }
338
	    else if(event.widget==btnClear){
339
	        classification = null;
340
	        textClassification.setText("");
341
	    }
342
	}
343

  
344
    public String getReferenceString() {
345
        return textReferenceString.getText();
346
    }
347
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/e4/GbifResponseImportViewE4.java
1
/**
2
* Copyright (C) 2014 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.io.IOException;
12
import java.net.URISyntaxException;
13
import java.util.Collection;
14

  
15
import org.apache.http.client.ClientProtocolException;
16

  
17
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper;
18
import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
19

  
20
/**
21
 * @author pplitzner
22
 * @date Sep 5, 2014
23
 *
24
 */
25
public class GbifResponseImportViewE4 extends DataImportViewE4<GbifResponse> {
26

  
27

  
28
    public static final String ID = "eu.etaxonomy.taxeditor.view.dataimport.GbifResponseImportView";
29

  
30
    /* (non-Javadoc)
31
     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#getTextForTableItem(java.lang.Object)
32
     */
33
    @Override
34
    protected String getTextForTableItem(GbifResponse item) {
35
        String text = "";
36
        if(item.getDataSetProtocol()!=null){
37
            text += "["+item.getDataSetProtocol()+"] ";
38
        }
39
        text += item.getDerivedUnitFacade().innerDerivedUnit().generateTitle();
40
        return text;
41
    }
42

  
43
    /* (non-Javadoc)
44
     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#query()
45
     */
46
    @Override
47
    public void query() {
48
        String errorMessage = "Could not execute query " + query;
49
        try{
50
            //Collection<GbifResponse> results = new GbifQueryServiceWrapper().query(query);
51
            //setResults(results);
52

  
53
           // String errorMessage = "Could not execute query " + query;
54

  
55
       //     Collection<SpecimenOrObservationBase<?>> results = new ArrayList<SpecimenOrObservationBase<?>>();
56
                Collection<GbifResponse> results = new GbifQueryServiceWrapper().query(query);
57

  
58
                setResults(results);
59

  
60

  
61
//
62
               // results = repo.getUnits();
63

  
64
            } catch (ClientProtocolException e) {
65
                logger.error(errorMessage, e);
66
            } catch (IOException e) {
67
                logger.error(errorMessage, e);
68
            } catch (URISyntaxException e) {
69
				// TODO Auto-generated catch block
70
				e.printStackTrace();
71
			}
72
        }
73

  
74
//            setResults(results);
75
//
76
//        }
77
//        } catch (ClientProtocolException e) {
78
//            logger.error(errorMessage, e);
79
//        } catch (IOException e) {
80
//            logger.error(errorMessage, e);
81
//        } catch (URISyntaxException e) {
82
//            logger.error(errorMessage, e);
83
//        }
84

  
85
  //  }
86

  
87

  
88

  
89

  
90

  
91

  
92
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/e4/SpecimenImportViewE4.java
1
/**
2
* Copyright (C) 2014 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.io.IOException;
12
import java.io.InputStream;
13
import java.net.URI;
14
import java.util.ArrayList;
15
import java.util.Collection;
16

  
17
import org.apache.http.client.ClientProtocolException;
18
import org.w3c.dom.Element;
19
import org.w3c.dom.NodeList;
20

  
21
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
22
import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseResponse;
23
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206DataHolder;
24
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
25
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportParser;
26
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportState;
27
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206XMLFieldGetter;
28
import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdParseUtility;
29
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Identification;
30
import eu.etaxonomy.cdm.io.specimen.abcd206.in.UnitAssociationWrapper;
31

  
32
/**
33
 * @author pplitzner
34
 * @date Sep 3, 2014
35
 *
36
 */
37
public class SpecimenImportViewE4 extends DataImportViewE4<BioCaseResponse> {
38

  
39
    public static final String ID = "eu.etaxonomy.taxeditor.view.dataimport.SpecimenImportView"; //$NON-NLS-1$
40

  
41
    private URI endPoint;
42

  
43
    public SpecimenImportViewE4() {
44
    }
45

  
46
    /**
47
     * @param endPoint
48
     */
49
    public void setEndpoint(URI endPoint) {
50
        this.endPoint = endPoint;
51
    }
52

  
53
    /* (non-Javadoc)
54
     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#getTextForTableItem(java.lang.Object)
55
     */
56
    @Override
57
    protected String getTextForTableItem(BioCaseResponse item) {
58
        //TODO: could be defined in user preferences...
59
        String name = null;
60
        if(!(((Abcd206DataHolder)item.getAbcdDataHolder()).getIdentificationList() == null) && !((Abcd206DataHolder)item.getAbcdDataHolder()).getIdentificationList().isEmpty()){
61
           Identification identification =  ((Abcd206DataHolder)item.getAbcdDataHolder()).getIdentificationList().iterator().next();
62
           name = identification.getScientificName();
63
        }
64
        if (name != null){
65
            return name +" - "+((Abcd206DataHolder)item.getAbcdDataHolder()).getCollectionCode() + " - "+ ((Abcd206DataHolder)item.getAbcdDataHolder()).getUnitID() + " - "+ ((Abcd206DataHolder)item.getAbcdDataHolder()).getKindOfUnit();
66
        }else {
67
            return ((Abcd206DataHolder)item.getAbcdDataHolder()).getCollectionCode() + " - "+ ((Abcd206DataHolder)item.getAbcdDataHolder()).getUnitID() + " - "+ ((Abcd206DataHolder)item.getAbcdDataHolder()).getKindOfUnit();
68
        }
69
    }
70

  
71
    /* (non-Javadoc)
72
     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#query()
73
     */
74
    @Override
75
    public void query() {
76
        String errorMessage = "Could not execute query " + query;
77

  
78
        Collection<BioCaseResponse> results = new ArrayList<BioCaseResponse>();
79
        try {
80
            //FIXME move ABCD import to cdmlib -> this will also get rid of the transient services
81
            InputStream resultStream;
82
            resultStream = new BioCaseQueryServiceWrapper().query(query, endPoint);
83
            Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(null, null);
84
            configurator.setSourceUri(endPoint);
85

  
86
            //            TransientCdmRepository repo =
87
//                    new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
88
            //configurator.setCdmAppController(repo);
89

  
90
            //TODO: do not query all data but with the selected triple IDs -> see GbifResponseImportView
91
            configurator.setAddMediaAsMediaSpecimen(true);
92
            configurator.setAllowReuseOtherClassifications(true);
93
            configurator.setMoveNewTaxaToDefaultClassification(false);
94
            UnitAssociationWrapper unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(resultStream, null);
95
            NodeList unitsList = unitAssociationWrapper.getAssociatedUnits();
96
            Abcd206DataHolder dataHolder = new Abcd206DataHolder();
97
            Abcd206XMLFieldGetter abcdFieldGetter = new Abcd206XMLFieldGetter(dataHolder, unitAssociationWrapper.getPrefix());
98
            Abcd206ImportState state = new Abcd206ImportState(configurator);
99
            state.setDataHolder(dataHolder);
100
            BioCaseResponse response = null;
101
            if (unitsList != null){
102
                for (int i = 0; i <unitsList.getLength(); i++){
103
                    Element item = (Element) unitsList.item(i);
104
                    dataHolder = new Abcd206DataHolder();
105
                    abcdFieldGetter = new Abcd206XMLFieldGetter(dataHolder, unitAssociationWrapper.getPrefix());
106
                    state.setPrefix(unitAssociationWrapper.getPrefix());
107
                    Abcd206ImportParser.setUnitPropertiesXML(item, abcdFieldGetter, state);
108
                    String[] tripleIdBioCase = new String[3];
109
                    tripleIdBioCase[0] =dataHolder.getUnitID();
110
                    tripleIdBioCase[1] = dataHolder.getInstitutionCode();
111
                    tripleIdBioCase[2] = dataHolder.getCollectionCode();
112

  
113
                    response = new BioCaseResponse(dataHolder, endPoint, tripleIdBioCase );
114
                    results.add(response);
115
                }
116
            }
117

  
118
//            Job job = CdmStore.getImportManager().createIOServiceJob(configurator, resultStream, SOURCE_TYPE.INPUTSTREAM);
119
//            CdmStore.getImportManager().run(job);
120

  
121
            setResults(results);
122
        } catch (ClientProtocolException e) {
123
            logger.error(errorMessage, e);
124
        } catch (IOException e) {
125
            logger.error(errorMessage, e);
126
        }
127

  
128
       // setResults(results);
129

  
130
    }
131

  
132

  
133

  
134
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)