Merge branch 'develop' of wp5.e-taxonomy.eu:/var/git/taxeditor into remoting-4.0
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / dataimport / DataImportEditor.java
index 0343fe9bcf468c46ed52f8799ba336be34e3dcdb..6a7ce39f37802dc424b490ba56a85b59270a9092 100644 (file)
@@ -11,6 +11,7 @@ package eu.etaxonomy.taxeditor.editor.view.dataimport;
 
 import java.util.Collection;
 
+import org.apache.log4j.Logger;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.viewers.TableViewer;
@@ -28,10 +29,9 @@ import org.eclipse.ui.part.EditorPart;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
-import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.model.IContextListener;
-import eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider;
+import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
 import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
 import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
 import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
@@ -43,18 +43,19 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @date 20.09.2013
  *
  */
-public abstract class DataImportEditor<T extends IIdentifiableEntity> extends EditorPart implements IPartContentHasFactualData, IDirtyMarkableSelectionProvider,
+public abstract class DataImportEditor<T> extends EditorPart implements IPartContentHasFactualData, IDirtyMarkable,
 IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IContextListener{
 
+    protected Logger logger = Logger.getLogger(DataImportEditor.class);
+
     private ConversationHolder conversation;
 
     private TableViewer tableViewer;
 
     /**
-     * Constructs a new DataImportEditor with a new {@link ConversationHolder}
+     * Constructs a new DataImportEditor and registers it to listen to context changes
      */
     public DataImportEditor() {
-        CdmStore.getContextManager().addContextListener(this);
     }
 
     /* (non-Javadoc)
@@ -64,7 +65,7 @@ IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, I
     public void createPartControl(Composite parent) {
 
         Table table = new Table(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
-        table.setHeaderVisible(true);//TODO: set header title as BioCase query
+        table.setHeaderVisible(true);//TODO: set header title as query
         table.setLinesVisible(true);
         tableViewer = new TableViewer(table);
 
@@ -84,6 +85,7 @@ IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, I
      */
     @Override
     public void setFocus() {
+        tableViewer.getControl().setFocus();
         //make sure to bind again if maybe in another view the conversation was unbound
         if(!conversation.isBound()){
             conversation.bind();
@@ -96,11 +98,12 @@ IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, I
      */
     @Override
     public void init(IEditorSite site, IEditorInput input) throws PartInitException {
+        CdmStore.getContextManager().addContextListener(this);
         setSite(site);
         setInput(input);
         setPartName(input.getName());
         setTitleToolTip(input.getName());
-        conversation = ((DataImportEditorInput)input).getConversationHolder();
+        conversation = ((DataImportEditorInput<T>)input).getConversationHolder();
     }
 
     /* (non-Javadoc)
@@ -144,24 +147,31 @@ IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, I
         IEditorInput editorInput = getEditorInput();
         setInput(editorInput);
         if(editorInput instanceof DataImportEditorInput){
-            tableViewer.getTable().clearAll();
+            tableViewer.getTable().removeAll();
             Collection<T> results = ((DataImportEditorInput<T>) editorInput).getResults();
             if(results!=null){
-                for(T specimen:results){
+                for(T item:results){
                     TableItem tableItem = new TableItem(tableViewer.getTable(), SWT.NONE);
-                    tableItem.setText(specimen.generateTitle());
-                    tableItem.setData(specimen);
+                    tableItem.setText(getTextForTableItem(item));
+                    tableItem.setData(item);
                 }
             }
         }
     }
 
+    /**
+     * Returns the text label of the given item.
+     * @param item the item for which the label should be returnes
+     * @return the label of the item
+     */
+    protected abstract String getTextForTableItem(T item);
+
     /* (non-Javadoc)
      * @see eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
      */
     @Override
     public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
-        if(conversation!=null &&!conversation.isClosed()) {
+        if(conversation!=null && conversation.isBound() && !conversation.isClosed()) {
             conversation.close();
         }
     }
@@ -190,6 +200,14 @@ IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, I
         // cannot be changed
     }
 
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
+     */
+    @Override
+    public void forceDirty() {
+        // cannot be dirty
+    }
+
     /* (non-Javadoc)
      * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
      */