fix move whole description to another description and adding delete configurator...
authorKatja Luther <k.luther@bgbm.org>
Mon, 16 Nov 2015 11:36:11 +0000 (12:36 +0100)
committerKatja Luther <k.luther@bgbm.org>
Mon, 16 Nov 2015 11:36:11 +0000 (12:36 +0100)
eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/DeleteHandler.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptionElementDragListener.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptionElementDropAdapter.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/MoveDescriptionElementsOperation.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/deleteConfigurator/DeleteConfiguratorDialog.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/deleteConfigurator/DeleteTaxonConfiguratorComposite.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/DescriptionElementSourceSection.java

index 3f15c4f..3c7e7e9 100644 (file)
@@ -16,6 +16,7 @@ import java.util.List;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.ui.IEditorInput;
@@ -33,6 +34,8 @@ import eu.etaxonomy.cdm.api.service.IReferenceService;
 import eu.etaxonomy.cdm.api.service.ITaxonService;
 import eu.etaxonomy.cdm.api.service.IUserService;
 import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
+import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator;
+import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
 import eu.etaxonomy.cdm.model.common.Group;
 import eu.etaxonomy.cdm.model.common.User;
@@ -50,6 +53,8 @@ import eu.etaxonomy.taxeditor.bulkeditor.internal.TaxeditorBulkeditorPlugin;
 import eu.etaxonomy.taxeditor.model.DeleteResultMessagingUtils;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator.DeleteConfiguratorDialog;
+import eu.etaxonomy.taxeditor.ui.dialog.deleteConfigurator.DeleteTaxonConfiguratorComposite;
 
 
 /**
@@ -130,10 +135,23 @@ public class DeleteHandler extends AbstractHandler {
                                                ITaxonService service = controller.getTaxonService();
                                                if (object != null){
                                                        if (object instanceof Taxon){
-                                                               result = service.deleteTaxon(((TaxonBase) object).getUuid(), null, null);
+                                                               TaxonDeletionConfigurator config = new TaxonDeletionConfigurator();
+                                                               config.setDeleteInAllClassifications(true);
+                                                               DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), "Confirm Deletion",  null,  "Do you really want to delete the taxon", MessageDialog.WARNING, new String[] { "Delete", "Skip" }, 0); 
+                                                               int result_dialog= dialog.open();
+                                                               if (result_dialog == 1){
+                                                                       return null;
+                                                               }
+                                                               result = service.deleteTaxon(((TaxonBase) object).getUuid(), config, null);
                                                                errorMessage = "The taxon ";
                                                        }else{
-                                                               result = service.deleteSynonym(((Synonym)object).getUuid(), null);
+                                                               SynonymDeletionConfigurator config = new SynonymDeletionConfigurator();
+                                                               DeleteConfiguratorDialog dialog = new DeleteConfiguratorDialog(config, HandlerUtil.getActiveShell(event), "Confirm Deletion",  null,  "Do you really want to delete the synonym", MessageDialog.WARNING, new String[] { "Delete", "Skip" }, 0); 
+                                                               int result_dialog= dialog.open();
+                                                               if (result_dialog == 1){
+                                                                       return null;
+                                                               }
+                                                               result = service.deleteSynonym(((Synonym)object).getUuid(), config);
                                                                errorMessage = "The synonym ";
                                                        }
                                                }
index de3e46f..e5e58d0 100644 (file)
@@ -18,6 +18,7 @@ import org.eclipse.swt.dnd.DND;
 import org.eclipse.swt.dnd.DragSourceAdapter;
 import org.eclipse.swt.dnd.DragSourceEvent;
 
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
@@ -30,6 +31,7 @@ import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 public class DescriptionElementDragListener extends DragSourceAdapter {
 
        private DescriptiveViewPart part;
+       private DescriptionBase description;
        
        public DescriptionElementDragListener(DescriptiveViewPart part){
                this.part = part;
@@ -43,9 +45,10 @@ public class DescriptionElementDragListener extends DragSourceAdapter {
                        return;
                // FIXME what to do here?
                if (event.detail != DND.DROP_NONE) {
-                       IStructuredSelection selection = (IStructuredSelection) part.getViewer()
-                                       .getSelection();
-                       part.changed(null);
+                       //IStructuredSelection selection = (IStructuredSelection) part.getViewer().getSelection();
+                       part.getViewer().refresh();
+                       
+               part.changed(null);
                }
        }
        
@@ -59,6 +62,8 @@ public class DescriptionElementDragListener extends DragSourceAdapter {
                for (Object object : selection.toList()){
                        if(object instanceof DescriptionBase){
                                descriptionElements.addAll(((DescriptionBase) object).getElements());
+                               description = HibernateProxyHelper.deproxy(object, DescriptionBase.class);
+                               
                        }else if(object instanceof FeatureNodeContainer){
                                descriptionElements.addAll(((FeatureNodeContainer) object).getDescriptionElements());
                        }else if(object instanceof DescriptionElementBase){
@@ -69,7 +74,9 @@ public class DescriptionElementDragListener extends DragSourceAdapter {
                if (DescriptionElementTransfer.getInstance().isSupportedType(
                                event.dataType)) {
                        event.data = descriptionElements.toArray(new DescriptionElementBase[descriptionElements.size()]);
+                       
                }
+               
        }
        
        /**
index 488cc77..9af1713 100644 (file)
@@ -74,6 +74,7 @@ public class DescriptionElementDropAdapter extends ViewerDropAdapter {
                
                EditorUtil.executeOperation(operation);
                
+               
                return true;
        }
 
index 564b122..d2f26b6 100644 (file)
@@ -88,13 +88,14 @@ public class MoveDescriptionElementsOperation extends AbstractPostTaxonOperation
                for(DescriptionElementBase deBase : descriptionElements) {
                    descriptionElementsUuid.add(deBase.getUuid());
                }
-
+               UpdateResult result; 
                if(targetDescription == null){
-                   UpdateResult result = service.moveDescriptionElementsToDescription(descriptionElementsUuid, targetTaxonUuid, moveMessage, isCopy);
+                       result = service.moveDescriptionElementsToDescription(descriptionElementsUuid, targetTaxonUuid, moveMessage, isCopy);
 
                } else {
                    UUID targetDescriptionUuid = targetDescription.getUuid();
-                   service.moveDescriptionElementsToDescription(descriptionElementsUuid, targetDescriptionUuid, isCopy);
+                   result = service.moveDescriptionElementsToDescription(descriptionElementsUuid, targetDescriptionUuid, isCopy);
+                   
                }
                return postExecute(targetDescription);
        }
index 647addd..c2d947a 100644 (file)
@@ -20,6 +20,7 @@ import org.eclipse.swt.widgets.Shell;
 import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
 import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator;
 import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator;
+import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
 import eu.etaxonomy.cdm.api.service.config.TaxonNodeDeletionConfigurator;
 
 /**
@@ -45,8 +46,8 @@ public class DeleteConfiguratorDialog extends MessageDialog{
     @Override
     protected Control createCustomArea(Composite parent) {
         DeleteConfiguratorComposite composite = new DeleteConfiguratorComposite(parent, NONE);
-        if(configurator instanceof TaxonBaseDeletionConfigurator){
-            composite.addConfiguratorComposite(new DeleteTaxonConfiguratorComposite((TaxonBaseDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
+        if(configurator instanceof TaxonDeletionConfigurator){
+            composite.addConfiguratorComposite(new DeleteTaxonConfiguratorComposite((TaxonDeletionConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
         }
         else if(configurator instanceof SpecimenDeleteConfigurator){
             composite.addConfiguratorComposite(new DeleteSpecimenConfiguratorComposite((SpecimenDeleteConfigurator) configurator, composite.getSectionConfigure(), SWT.NONE));
index cd48144..aaa0611 100644 (file)
@@ -16,13 +16,21 @@ import org.eclipse.jface.databinding.swt.WidgetProperties;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.DisposeEvent;
 import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.layout.RowLayout;
 import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
 import org.eclipse.ui.forms.widgets.FormToolkit;
 
-import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator;
+import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
+import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+
 
 /**
  * @author pplitzner
@@ -33,15 +41,19 @@ public class DeleteTaxonConfiguratorComposite extends Composite {
     private final DataBindingContext m_bindingContext;
 
     private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
-    private final TaxonBaseDeletionConfigurator configurator;
+    private final TaxonDeletionConfigurator configurator;
     private final Button btnDeleteTaxonName;
+    private final Button btnDeleteInAllClassifications;
+    private Combo classificationSelectionCombo;
+  
+    
 
     /**
      * Create the composite.
      * @param parent
      * @param style
      */
-    public DeleteTaxonConfiguratorComposite(TaxonBaseDeletionConfigurator configurator, Composite parent, int style) {
+    public DeleteTaxonConfiguratorComposite(TaxonDeletionConfigurator configurator, Composite parent, int style) {
         super(parent, style);
         this.configurator = configurator;
         addDisposeListener(new DisposeListener() {
@@ -56,6 +68,12 @@ public class DeleteTaxonConfiguratorComposite extends Composite {
 
         btnDeleteTaxonName = new Button(this, SWT.CHECK);
         btnDeleteTaxonName.setText("Delete taxon name if possible");
+        btnDeleteTaxonName.setSelection(true);
+        
+        btnDeleteInAllClassifications = new Button(this, SWT.CHECK);
+        btnDeleteInAllClassifications.setText("Delete taxon in all classifications");
+        btnDeleteInAllClassifications.setSelection(true);
+        
         m_bindingContext = initDataBindings();
 
     }
@@ -65,8 +83,43 @@ public class DeleteTaxonConfiguratorComposite extends Composite {
         //
         IObservableValue observeSelectionBtnDeleteTaxonNameObserveWidget = WidgetProperties.selection().observe(btnDeleteTaxonName);
         IObservableValue deleteNameIfPossibleConfiguratorObserveValue = PojoProperties.value("deleteNameIfPossible").observe(configurator);
+        
+        IObservableValue observeSelectionBtnDeleteInAllClassificationObserveWidget = WidgetProperties.selection().observe(btnDeleteInAllClassifications);
+        IObservableValue deleteInAllClassificationsConfiguratorObserveValue = PojoProperties.value("deleteInAllClassifications").observe(configurator);
         bindingContext.bindValue(observeSelectionBtnDeleteTaxonNameObserveWidget, deleteNameIfPossibleConfiguratorObserveValue, null, null);
+        bindingContext.bindValue(observeSelectionBtnDeleteInAllClassificationObserveWidget, deleteInAllClassificationsConfiguratorObserveValue, null, null);
         //
         return bindingContext;
     }
+    
+   /* private Control createClassificationSelectionCombo(Composite parent){
+//             classifications = CdmStore.getTaxonTreeService().list(null, null, null, null, null);
+
+               Composite classificationSelection = new Composite(parent, SWT.NULL);
+               classificationSelection.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
+
+               GridLayout layout = new GridLayout();
+               classificationSelection.setLayout(layout);
+
+               Label label = new Label(classificationSelection, SWT.NULL);
+               // TODO not working is not really true but leave it here to remind everyone that this is under construction
+               label.setText("Select Classification");
+               classificationSelectionCombo = new Combo(classificationSelection, SWT.BORDER | SWT.READ_ONLY);
+               classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
+               List<Classification> classifications = 
+
+               for(Classification tree : classifications){
+                       classificationSelectionCombo.add(tree.getName().getText(), classifications.indexOf(tree));
+
+               }
+
+               classificationSelectionCombo.select(classifications.indexOf(selectedClassification));
+
+               // TODO remember last selection
+               classificationSelectionCombo.addSelectionListener(this);
+
+
+
+               return classificationSelection;
+       }*/
 }
index 5cfb246..bbd8752 100644 (file)
@@ -38,10 +38,10 @@ public class DescriptionElementSourceSection extends AbstractEntityCollectionSec
        /** {@inheritDoc} */
        @Override
        public DescriptionElementSource createNewElement() {
-           if(getEntity().getId() == 0) {
+          /* if(getEntity().getId() == 0) {
                MessagingUtils.warningDialog("Description not saved", this, "Please save the newly created description before adding source");
                return null;
-           }
+           }*/
                return DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
        }