smaller changes for specimen import and others
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / dataimport / DataImportView.java
index e7746b639730904a2ff1520552018a01acda352f..5c7a5d71b131a16b9180c94556aa6655ec51f0ae 100644 (file)
@@ -18,23 +18,33 @@ import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.action.IToolBarManager;
 import org.eclipse.jface.viewers.CheckboxTableViewer;
 import org.eclipse.swt.SWT;
+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.Table;
 import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.IMemento;
 import org.eclipse.ui.forms.widgets.FormToolkit;
 import org.eclipse.ui.part.ViewPart;
+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.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;
 
 /**
  * View which shows a list of "data" that can be imported into the CDM
@@ -45,7 +55,7 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  */
 
 public abstract class DataImportView<T> extends ViewPart implements IPartContentHasFactualData,
-IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IContextListener{
+IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IContextListener, Listener{
 
     protected final Logger logger = Logger.getLogger(DataImportView.class);
 
@@ -56,6 +66,24 @@ IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, I
     private static ConversationHolder conversationHolder;
 
     private SaveImportedSpecimenAction saveImportedSpecimenAction;
+    
+    private Text textClassification;
+    private Classification classification;
+    /**
+        * @return the classification
+        */
+       public Classification getClassification() {
+               return classification;
+       }
+
+       /**
+        * @param classification the classification to set
+        */
+       public void setClassification(Classification classification) {
+               this.classification = classification;
+       }
+       private Button btnBrowseClassification;
+    private Button btnClear;
 
     private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
 
@@ -77,11 +105,29 @@ IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, I
      */
     @Override
     public void createPartControl(Composite parent) {
+       final Composite composite = new Composite(parent, SWT.NULL);
+
+               GridLayout gridLayout = new GridLayout();
+               gridLayout.numColumns = 4;
+               composite.setLayout(gridLayout);
+       Label label = new Label(composite, SWT.NONE);
+               label.setText("Classification");
+               textClassification = new Text(composite, SWT.NONE);
+               textClassification.setEnabled(false);
+               textClassification.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+               btnBrowseClassification = new Button(composite, SWT.NONE);
+               btnBrowseClassification.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/open.gif"));
+               btnBrowseClassification.addListener(SWT.Selection, this);
+               btnClear = new Button(composite, SWT.NONE);
+               btnClear.setImage(ResourceManager.getPluginImage("eu.etaxonomy.taxeditor.store", "icons/trash.gif"));
+               btnClear.addListener(SWT.Selection, this);
 
         CheckboxTableViewer checkboxTableViewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER | SWT.FULL_SELECTION);
         table = checkboxTableViewer.getTable();
         toolkit.paintBordersFor(table);
 
+        
+        
         createActions();
         initializeToolBar();
         initializeMenu();
@@ -145,7 +191,7 @@ IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, I
     }
 
     protected void refresh(){
-        getTable().removeAll();
+       // getTable().removeAll();
         for(T item:results){
             TableItem tableItem = new TableItem(getTable(), SWT.NONE);
             tableItem.setText(getTextForTableItem(item));
@@ -234,5 +280,17 @@ IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, I
         }
         return conversationHolder;
     }
-
+    @Override
+       public void handleEvent(Event event) {
+           if(event.widget==btnBrowseClassification){
+               classification = SelectionDialogFactory.getSelectionFromDialog(Classification.class, getSite().getShell(), null, null);
+               if(classification!=null){
+                   textClassification.setText(classification.getTitleCache());
+               }
+           }
+           else if(event.widget==btnClear){
+               classification = null;
+               textClassification.setText("");
+           }
+       }
 }