From c1c463d760a7c0ea8a99f8ba243ce45913cb3c82 Mon Sep 17 00:00:00 2001 From: Katja Luther Date: Mon, 16 Nov 2015 12:36:11 +0100 Subject: [PATCH] fix move whole description to another description and adding delete configurator to bulk editor --- .../bulkeditor/handler/DeleteHandler.java | 22 ++++++- .../DescriptionElementDragListener.java | 13 +++- .../DescriptionElementDropAdapter.java | 1 + .../MoveDescriptionElementsOperation.java | 7 ++- .../DeleteConfiguratorDialog.java | 5 +- .../DeleteTaxonConfiguratorComposite.java | 59 ++++++++++++++++++- .../DescriptionElementSourceSection.java | 4 +- 7 files changed, 96 insertions(+), 15 deletions(-) diff --git a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/DeleteHandler.java b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/DeleteHandler.java index 3f15c4f7d..3c7e7e9e2 100644 --- a/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/DeleteHandler.java +++ b/eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/handler/DeleteHandler.java @@ -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 "; } } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptionElementDragListener.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptionElementDragListener.java index de3e46f0d..e5e58d0f6 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptionElementDragListener.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptionElementDragListener.java @@ -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()]); + } + } /** diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptionElementDropAdapter.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptionElementDropAdapter.java index 488cc775b..9af171323 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptionElementDropAdapter.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/DescriptionElementDropAdapter.java @@ -74,6 +74,7 @@ public class DescriptionElementDropAdapter extends ViewerDropAdapter { EditorUtil.executeOperation(operation); + return true; } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/MoveDescriptionElementsOperation.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/MoveDescriptionElementsOperation.java index 564b12262..d2f26b6df 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/MoveDescriptionElementsOperation.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/operation/MoveDescriptionElementsOperation.java @@ -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); } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/deleteConfigurator/DeleteConfiguratorDialog.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/deleteConfigurator/DeleteConfiguratorDialog.java index 647addd10..c2d947ab5 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/deleteConfigurator/DeleteConfiguratorDialog.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/deleteConfigurator/DeleteConfiguratorDialog.java @@ -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)); diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/deleteConfigurator/DeleteTaxonConfiguratorComposite.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/deleteConfigurator/DeleteTaxonConfiguratorComposite.java index cd481441d..aaa06118c 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/deleteConfigurator/DeleteTaxonConfiguratorComposite.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/deleteConfigurator/DeleteTaxonConfiguratorComposite.java @@ -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 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; + }*/ } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/DescriptionElementSourceSection.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/DescriptionElementSourceSection.java index 5cfb24654..bbd8752f3 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/DescriptionElementSourceSection.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/DescriptionElementSourceSection.java @@ -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); } -- 2.34.1