commit 0e4f55de2f1f5d33b17223b8ca679770c3ddf0d6
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Tue Aug 22 15:40:18 2017 +0200

    ref #6921 Initial import of e4 classes

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/e4/DataImportViewE4.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/e4/DataImportViewE4.java
new file mode 100644
index 000000000..06eb321ae
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/e4/DataImportViewE4.java
@@ -0,0 +1,347 @@
+/**
+* Copyright (C) 2013 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.view.dataimport.e4;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.e4.ui.di.Focus;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.wb.swt.ResourceManager;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.databaseAdmin.wizard.ImportPreferencesWizard;
+import eu.etaxonomy.taxeditor.model.IContextListener;
+import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
+import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
+import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.SelectionDialogFactory;
+import eu.etaxonomy.taxeditor.view.dataimport.SaveImportedSpecimenAction;
+
+/**
+ * View which shows a list of "data" that can be imported into the CDM
+ * @author pplitzner
+ * @date 22.08.2017
+ *
+ * @param <T> the CDM type that will be handled by this view
+ */
+public abstract class DataImportViewE4<T> implements IPartContentHasFactualData,
+IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IContextListener, Listener{
+
+    protected final Logger logger = Logger.getLogger(DataImportViewE4.class);
+
+    @Inject
+    private Shell shell;
+
+    protected Collection<T> results = new ArrayList<T>();
+
+    protected boolean updated = false;
+
+    protected OccurenceQuery query;
+
+    private static ConversationHolder conversationHolder;
+
+    private SaveImportedSpecimenAction saveImportedSpecimenAction;
+
+    private Text textClassification;
+
+    private Classification classification;
+
+    private Text textReferenceString;
+
+    private Button toggleButton;
+
+    private boolean state;
+
+    private Button openConfigurator;
+
+    public Classification getClassification() {
+		return classification;
+	}
+
+	public void setClassification(Classification classification) {
+		this.classification = classification;
+	}
+
+	private Button btnBrowseClassification;
+
+	private Button btnClear;
+
+    private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
+
+    private Table table;
+
+    /**
+     * Constructs a new DataImportEditor and registers it to listen to context changes
+     */
+    public DataImportViewE4() {
+        CdmStore.getContextManager().addContextListener(this);
+        if(CdmStore.isActive()){
+            initConversation();
+        }
+    }
+
+    /**
+     * Create contents of the view part.
+     * @param parent
+     */
+    @PostConstruct
+    public void createPartControl(Composite parent, @Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
+        this.shell = shell;
+        Composite composite = new Composite(parent, SWT.NONE);
+        composite.setLayout(new GridLayout(2, false));
+
+        Composite composite_1 = new Composite(composite, SWT.NONE);
+        GridData gd_composite_1 = new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1);
+        gd_composite_1.widthHint = 280;
+        composite_1.setLayoutData(gd_composite_1);
+        composite_1.setLayout(new GridLayout(3, false));
+
+    	Label label = new Label(composite_1, SWT.TOP);
+		label.setText("Classification");
+		label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
+		textClassification = new Text(composite_1, SWT.BORDER);
+		textClassification.setEnabled(false);
+		GridData gd_textClassification = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+		gd_textClassification.widthHint = 118;
+		textClassification.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
+		btnBrowseClassification = new Button(composite_1, SWT.NONE);
+		btnBrowseClassification.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/open.gif"));
+		btnBrowseClassification.addListener(SWT.Selection, this);
+		btnClear = new Button(composite_1, SWT.NONE);
+		btnClear.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
+		btnClear.addListener(SWT.Selection, this);
+		//source reference
+
+        Label labelRef = new Label(composite_1, SWT.NONE);
+        labelRef.setText("Default import souce reference");
+        labelRef.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
+        textReferenceString = new Text(composite_1, SWT.NONE);
+        textReferenceString.setEnabled(true);
+        GridData gd_textReferenceString = new GridData(SWT.LEFT, SWT.CENTER, true, true, 3, 1);
+        gd_textReferenceString.widthHint = 229;
+        textReferenceString.setLayoutData(gd_textReferenceString);
+
+        //open configuration
+        openConfigurator = new Button(composite_1, SWT.PUSH);
+        openConfigurator.setText("Configuration");
+        new Label(composite_1, SWT.NONE);
+        new Label(composite_1, SWT.NONE);
+        openConfigurator.addSelectionListener(new SelectionAdapter(){
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+
+                IWizard wizard = new ImportPreferencesWizard();
+                WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
+                dialog.open();
+            }
+        });
+
+      //checkbox table for result
+        Composite composite_2 = new Composite(composite, SWT.NONE);
+        GridData gd_composite_2 = new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1);
+        gd_composite_2.heightHint = 454;
+        gd_composite_2.widthHint = 403;
+        composite_2.setLayoutData(gd_composite_2);
+       composite_2.setLayout(new GridLayout(2, false));
+
+
+       CheckboxTableViewer checkboxTableViewer = CheckboxTableViewer.newCheckList(composite_2, SWT.BORDER | SWT.FULL_SELECTION);
+
+
+       table = checkboxTableViewer.getTable();
+       GridData gd_table = new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1);
+       gd_table.heightHint = 444;
+       gd_table.widthHint = 312;
+       table.setLayoutData(gd_table);
+       toolkit.paintBordersFor(table);
+       //toggle button
+       toggleButton = new Button(composite_2, SWT.PUSH);
+       GridData gd_toggleButton = new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1);
+       gd_toggleButton.widthHint = 56;
+       toggleButton.setLayoutData(gd_toggleButton);
+       toggleButton.setText("Toggle");
+       toggleButton.addSelectionListener(new SelectionAdapter(){
+           @Override
+           public void widgetSelected(SelectionEvent e) {
+               state = state ? false : true;
+               for (TableItem item: getTable().getItems()){
+                       item.setChecked(state);
+               }
+
+           }
+       });
+        createActions();
+        initializeToolBar();
+    }
+
+    /**
+     * Create the actions.
+     */
+    private void createActions() {
+        saveImportedSpecimenAction = new SaveImportedSpecimenAction();
+    }
+
+    /**
+     * Initialize the toolbar.
+     */
+    private void initializeToolBar() {
+        //FIXME E4 migrate
+//        IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
+//        tbm.add(saveImportedSpecimenAction);
+    }
+
+    public Table getTable() {
+        return table;
+    }
+
+    public void setQuery(OccurenceQuery query) {
+        this.query = query;
+    }
+
+    public void setResults(Collection<T> results) {
+        this.results = results;
+        updated=false;
+    }
+
+    @PreDestroy
+    public void dispose() {
+        CdmStore.getContextManager().removeContextListener(this);
+    }
+
+    @Override
+    public void contextRefresh(IProgressMonitor monitor) {
+        refresh();
+    }
+
+    protected void refresh(){
+        if (!updated){
+            if (getTable() != null){
+                getTable().removeAll();
+            }
+            for(T item:results){
+                TableItem tableItem = new TableItem(getTable(), SWT.NONE);
+                tableItem.setText(getTextForTableItem(item));
+                tableItem.setData(item);
+            }
+            updated = true;
+        }
+    }
+
+    public abstract void query();
+
+    @Override
+    public void update(CdmDataChangeMap changeEvents) {
+        //nothing
+    }
+
+    /**
+     * Returns the text label of the given item.
+     * @param item the item for which the label should be returns
+     * @return the label of the item
+     */
+    protected abstract String getTextForTableItem(T item);
+
+    @Focus
+    public void setFocus() {
+        getTable().setFocus();
+        //make sure to bind again if maybe in another view the conversation was unbound
+        if(getConversationHolder()!=null && !getConversationHolder().isBound()){
+            getConversationHolder().bind();
+        }
+    }
+
+    @Override
+    public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
+    }
+
+    @Override
+    public void contextStop(IMemento memento, IProgressMonitor monitor) {
+    }
+
+    @Override
+    public void contextStart(IMemento memento, IProgressMonitor monitor) {
+        initConversation();
+    }
+
+    private void initConversation(){
+        if(conversationHolder==null){
+            conversationHolder = CdmStore.createConversation();
+        }
+    }
+
+    @Override
+    public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
+        if(getConversationHolder()!=null && getConversationHolder().isBound() && !getConversationHolder().isClosed()) {
+            getConversationHolder().close();
+        }
+    }
+
+    /**
+     * @return the conversationHolder
+     */
+    @Override
+    public ConversationHolder getConversationHolder() {
+        if(CdmStore.isActive() && conversationHolder==null){
+            initConversation();
+        }
+        return conversationHolder;
+    }
+
+    @Override
+	public void handleEvent(Event event) {
+	    if(event.widget==btnBrowseClassification){
+	        classification = SelectionDialogFactory.getSelectionFromDialog(Classification.class, shell, null, null);
+	        if(classification!=null){
+	            textClassification.setText(classification.getTitleCache());
+	        }
+	    }
+	    else if(event.widget==btnClear){
+	        classification = null;
+	        textClassification.setText("");
+	    }
+	}
+
+    public String getReferenceString() {
+        return textReferenceString.getText();
+    }
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/e4/GbifResponseImportViewE4.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/e4/GbifResponseImportViewE4.java
new file mode 100644
index 000000000..3c59b5059
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/e4/GbifResponseImportViewE4.java
@@ -0,0 +1,92 @@
+/**
+* Copyright (C) 2014 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.view.dataimport.e4;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Collection;
+
+import org.apache.http.client.ClientProtocolException;
+
+import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper;
+import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
+
+/**
+ * @author pplitzner
+ * @date Sep 5, 2014
+ *
+ */
+public class GbifResponseImportViewE4 extends DataImportViewE4<GbifResponse> {
+
+
+    public static final String ID = "eu.etaxonomy.taxeditor.view.dataimport.GbifResponseImportView";
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#getTextForTableItem(java.lang.Object)
+     */
+    @Override
+    protected String getTextForTableItem(GbifResponse item) {
+        String text = "";
+        if(item.getDataSetProtocol()!=null){
+            text += "["+item.getDataSetProtocol()+"] ";
+        }
+        text += item.getDerivedUnitFacade().innerDerivedUnit().generateTitle();
+        return text;
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#query()
+     */
+    @Override
+    public void query() {
+        String errorMessage = "Could not execute query " + query;
+        try{
+            //Collection<GbifResponse> results = new GbifQueryServiceWrapper().query(query);
+            //setResults(results);
+
+           // String errorMessage = "Could not execute query " + query;
+
+       //     Collection<SpecimenOrObservationBase<?>> results = new ArrayList<SpecimenOrObservationBase<?>>();
+                Collection<GbifResponse> results = new GbifQueryServiceWrapper().query(query);
+
+                setResults(results);
+
+
+//
+               // results = repo.getUnits();
+
+            } catch (ClientProtocolException e) {
+                logger.error(errorMessage, e);
+            } catch (IOException e) {
+                logger.error(errorMessage, e);
+            } catch (URISyntaxException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+        }
+
+//            setResults(results);
+//
+//        }
+//        } catch (ClientProtocolException e) {
+//            logger.error(errorMessage, e);
+//        } catch (IOException e) {
+//            logger.error(errorMessage, e);
+//        } catch (URISyntaxException e) {
+//            logger.error(errorMessage, e);
+//        }
+
+  //  }
+
+
+
+
+
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/e4/SpecimenImportViewE4.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/e4/SpecimenImportViewE4.java
new file mode 100755
index 000000000..88bae2149
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/dataimport/e4/SpecimenImportViewE4.java
@@ -0,0 +1,134 @@
+/**
+* Copyright (C) 2014 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.view.dataimport.e4;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.http.client.ClientProtocolException;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
+import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseResponse;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206DataHolder;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportParser;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportState;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206XMLFieldGetter;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdParseUtility;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.Identification;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.UnitAssociationWrapper;
+
+/**
+ * @author pplitzner
+ * @date Sep 3, 2014
+ *
+ */
+public class SpecimenImportViewE4 extends DataImportViewE4<BioCaseResponse> {
+
+    public static final String ID = "eu.etaxonomy.taxeditor.view.dataimport.SpecimenImportView"; //$NON-NLS-1$
+
+    private URI endPoint;
+
+    public SpecimenImportViewE4() {
+    }
+
+    /**
+     * @param endPoint
+     */
+    public void setEndpoint(URI endPoint) {
+        this.endPoint = endPoint;
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#getTextForTableItem(java.lang.Object)
+     */
+    @Override
+    protected String getTextForTableItem(BioCaseResponse item) {
+        //TODO: could be defined in user preferences...
+        String name = null;
+        if(!(((Abcd206DataHolder)item.getAbcdDataHolder()).getIdentificationList() == null) && !((Abcd206DataHolder)item.getAbcdDataHolder()).getIdentificationList().isEmpty()){
+           Identification identification =  ((Abcd206DataHolder)item.getAbcdDataHolder()).getIdentificationList().iterator().next();
+           name = identification.getScientificName();
+        }
+        if (name != null){
+            return name +" - "+((Abcd206DataHolder)item.getAbcdDataHolder()).getCollectionCode() + " - "+ ((Abcd206DataHolder)item.getAbcdDataHolder()).getUnitID() + " - "+ ((Abcd206DataHolder)item.getAbcdDataHolder()).getKindOfUnit();
+        }else {
+            return ((Abcd206DataHolder)item.getAbcdDataHolder()).getCollectionCode() + " - "+ ((Abcd206DataHolder)item.getAbcdDataHolder()).getUnitID() + " - "+ ((Abcd206DataHolder)item.getAbcdDataHolder()).getKindOfUnit();
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.view.dataimport.DataImportView#query()
+     */
+    @Override
+    public void query() {
+        String errorMessage = "Could not execute query " + query;
+
+        Collection<BioCaseResponse> results = new ArrayList<BioCaseResponse>();
+        try {
+            //FIXME move ABCD import to cdmlib -> this will also get rid of the transient services
+            InputStream resultStream;
+            resultStream = new BioCaseQueryServiceWrapper().query(query, endPoint);
+            Abcd206ImportConfigurator configurator = Abcd206ImportConfigurator.NewInstance(null, null);
+            configurator.setSourceUri(endPoint);
+
+            //            TransientCdmRepository repo =
+//                    new TransientCdmRepository(CdmStore.getCurrentApplicationConfiguration());
+            //configurator.setCdmAppController(repo);
+
+            //TODO: do not query all data but with the selected triple IDs -> see GbifResponseImportView
+            configurator.setAddMediaAsMediaSpecimen(true);
+            configurator.setAllowReuseOtherClassifications(true);
+            configurator.setMoveNewTaxaToDefaultClassification(false);
+            UnitAssociationWrapper unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(resultStream, null);
+            NodeList unitsList = unitAssociationWrapper.getAssociatedUnits();
+            Abcd206DataHolder dataHolder = new Abcd206DataHolder();
+            Abcd206XMLFieldGetter abcdFieldGetter = new Abcd206XMLFieldGetter(dataHolder, unitAssociationWrapper.getPrefix());
+            Abcd206ImportState state = new Abcd206ImportState(configurator);
+            state.setDataHolder(dataHolder);
+            BioCaseResponse response = null;
+            if (unitsList != null){
+                for (int i = 0; i <unitsList.getLength(); i++){
+                    Element item = (Element) unitsList.item(i);
+                    dataHolder = new Abcd206DataHolder();
+                    abcdFieldGetter = new Abcd206XMLFieldGetter(dataHolder, unitAssociationWrapper.getPrefix());
+                    state.setPrefix(unitAssociationWrapper.getPrefix());
+                    Abcd206ImportParser.setUnitPropertiesXML(item, abcdFieldGetter, state);
+                    String[] tripleIdBioCase = new String[3];
+                    tripleIdBioCase[0] =dataHolder.getUnitID();
+                    tripleIdBioCase[1] = dataHolder.getInstitutionCode();
+                    tripleIdBioCase[2] = dataHolder.getCollectionCode();
+
+                    response = new BioCaseResponse(dataHolder, endPoint, tripleIdBioCase );
+                    results.add(response);
+                }
+            }
+
+//            Job job = CdmStore.getImportManager().createIOServiceJob(configurator, resultStream, SOURCE_TYPE.INPUTSTREAM);
+//            CdmStore.getImportManager().run(job);
+
+            setResults(results);
+        } catch (ClientProtocolException e) {
+            logger.error(errorMessage, e);
+        } catch (IOException e) {
+            logger.error(errorMessage, e);
+        }
+
+       // setResults(results);
+
+    }
+
+
+
+}
