From 025f3eb9f8936553e442641114182184722eeb8a Mon Sep 17 00:00:00 2001 From: Cherian Mathew Date: Thu, 3 Sep 2015 18:31:02 +0200 Subject: [PATCH] Update operation for move taxon nodes --- eu.etaxonomy.taxeditor.application/.classpath | 1 - .../editor/MultiPageTaxonEditor.java | 8 + .../TransientOccurenceService.java | 9 + .../TreeNodeDropAdapterAssistant.java | 422 +++++++++--------- .../navigator/handler/MoveTaxonHandler.java | 29 +- .../operation/MoveTaxonOperation.java | 51 +-- .../operation/RemotingMoveTaxonOperation.java | 26 +- 7 files changed, 279 insertions(+), 267 deletions(-) diff --git a/eu.etaxonomy.taxeditor.application/.classpath b/eu.etaxonomy.taxeditor.application/.classpath index 0f0d04b90..4c0364cad 100644 --- a/eu.etaxonomy.taxeditor.application/.classpath +++ b/eu.etaxonomy.taxeditor.application/.classpath @@ -4,6 +4,5 @@ - diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java index 4cb7f9708..e58a897b2 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/MultiPageTaxonEditor.java @@ -557,4 +557,12 @@ IDirtyMarkable, IPartContentHasDetails, ISecuredEditor, IPartContentHasMedia { return true; } + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.model.IPartContentHasMedia#canAttachMedia() + */ + @Override + public boolean canAttachMedia() { + return true; + } + } diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientOccurenceService.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientOccurenceService.java index 001a7ab7b..ec9c41dcd 100644 --- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientOccurenceService.java +++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientOccurenceService.java @@ -29,6 +29,7 @@ import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade; import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException; import eu.etaxonomy.cdm.api.service.DeleteResult; import eu.etaxonomy.cdm.api.service.IOccurrenceService; +import eu.etaxonomy.cdm.api.service.UpdateResult; import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase; import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator; import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator; @@ -1031,4 +1032,12 @@ public class TransientOccurenceService implements IOccurrenceService { public DeleteResult deleteSingleRead(UUID arg0, UUID arg1) { return defaultService.deleteSingleRead(arg0, arg1); } + + /* (non-Javadoc) + * @see eu.etaxonomy.cdm.api.service.IOccurrenceService#moveDerivate(java.util.UUID, java.util.UUID, java.util.UUID) + */ + @Override + public UpdateResult moveDerivate(UUID specimenFromUuid, UUID specimenToUuid, UUID derivateUuid) { + return defaultService.moveDerivate(specimenFromUuid, specimenToUuid, derivateUuid); + } } diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapterAssistant.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapterAssistant.java index f29a03d64..842f9a8c6 100644 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapterAssistant.java +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TreeNodeDropAdapterAssistant.java @@ -1,12 +1,12 @@ // $Id$ /** - * Copyright (C) 2007 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. - */ +* Copyright (C) 2007 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.navigation.navigator; @@ -14,6 +14,7 @@ import java.util.EnumSet; import java.util.HashSet; import java.util.Iterator; import java.util.Set; +import java.util.UUID; import org.apache.log4j.Logger; import org.eclipse.core.commands.operations.AbstractOperation; @@ -52,221 +53,228 @@ import eu.etaxonomy.taxeditor.store.CdmStore; */ public class TreeNodeDropAdapterAssistant extends CommonDropAdapterAssistant implements IPostOperationEnabled { - private static final Logger logger = Logger.getLogger(TreeNodeDropAdapterAssistant.class); - - /** Constant ID="eu.etaxonomy.taxeditor.navigation.navig"{trunked} */ - public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator.dropassistant"; //$NON-NLS-1$ - - private static final EnumSet UPDATE = EnumSet.of(CRUD.UPDATE); - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.ui.navigator.CommonDropAdapter, org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object) - */ - /** {@inheritDoc} */ - @Override - public IStatus handleDrop(CommonDropAdapter dropAdapter, - DropTargetEvent dropTargetEvent, Object target) { - - - if (target instanceof ITaxonTreeNode) { - Set taxonNodes = getSelectedTaxa(); - ITaxonTreeNode targetTreeNode = (ITaxonTreeNode) target; - if (targetTreeNode instanceof Classification){ - targetTreeNode = ((Classification)targetTreeNode).getRootNode(); - targetTreeNode = HibernateProxyHelper.deproxy(targetTreeNode, TaxonNode.class); + private static final Logger logger = Logger.getLogger(TreeNodeDropAdapterAssistant.class); + + /** Constant ID="eu.etaxonomy.taxeditor.navigation.navig"{trunked} */ + public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator.dropassistant"; //$NON-NLS-1$ + + private static final EnumSet UPDATE = EnumSet.of(CRUD.UPDATE); + + /* (non-Javadoc) + * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#handleDrop(org.eclipse.ui.navigator.CommonDropAdapter, org.eclipse.swt.dnd.DropTargetEvent, java.lang.Object) + */ + /** {@inheritDoc} */ + @Override + public IStatus handleDrop(CommonDropAdapter dropAdapter, + DropTargetEvent dropTargetEvent, Object target) { + + + if (target instanceof ITaxonTreeNode) { + Set taxonNodes = getSelectedTaxa(); + ITaxonTreeNode targetTreeNode = (ITaxonTreeNode) target; + if (targetTreeNode instanceof Classification){ + targetTreeNode = ((Classification)targetTreeNode).getRootNode(); + targetTreeNode = HibernateProxyHelper.deproxy(targetTreeNode, TaxonNode.class); + } + //if(taxonNodes != null) { + if (taxonNodes.size() >= 1){ + return moveTaxon(taxonNodes, targetTreeNode); + /*} else{ + if( MessageDialog.openConfirm(null, "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){ + return null; + } + }*/ } - if(taxonNodes != null) { - if (taxonNodes.size() == 1){ - return moveTaxon(taxonNodes.iterator().next(), targetTreeNode); - } else{ - if( MessageDialog.openConfirm(null, "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){ - return null; - } - } - } - } - - return Status.CANCEL_STATUS; - } - - private Set getSelectedTaxa(){ - HashSet taxonNodes = new HashSet(); - - ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); - if (selection instanceof TreeSelection) { - - Iterator selectionIterator = ((TreeSelection) selection).iterator(); - - while (selectionIterator.hasNext()){ - Object object = selectionIterator.next(); - if(object instanceof TaxonNode){ - TaxonNode taxonNode = (TaxonNode) object; - taxonNodes.add(taxonNode); - } - } - } - return taxonNodes.size() > 0 ? taxonNodes : null; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData) - */ - /** {@inheritDoc} */ - @Override - public IStatus validateDrop(Object target, int operation, - TransferData transferType) { - if (target instanceof ITaxonTreeNode) { - - // check users permissions with target taxonnode and taxon - if (target instanceof TaxonNode) { - TaxonNode targetNode = (TaxonNode)target; - Boolean hasTargetNodePermission = CdmStore.currentAuthentiationHasPermission(targetNode, UPDATE); + } + + return Status.CANCEL_STATUS; + } + + private Set getSelectedTaxa(){ + HashSet taxonNodes = new HashSet(); + + ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); + if (selection instanceof TreeSelection) { + + Iterator selectionIterator = ((TreeSelection) selection).iterator(); + + while (selectionIterator.hasNext()){ + Object object = selectionIterator.next(); + if(object instanceof TaxonNode){ + TaxonNode taxonNode = (TaxonNode) object; + taxonNodes.add(taxonNode); + } + } + } + return taxonNodes.size() > 0 ? taxonNodes : null; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.navigator.CommonDropAdapterAssistant#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData) + */ + /** {@inheritDoc} */ + @Override + public IStatus validateDrop(Object target, int operation, + TransferData transferType) { + if (target instanceof ITaxonTreeNode) { + + // check users permissions with target taxonnode and taxon + if (target instanceof TaxonNode) { + TaxonNode targetNode = (TaxonNode)target; + Boolean hasTargetNodePermission = CdmStore.currentAuthentiationHasPermission(targetNode, UPDATE); Boolean hasTargetTaxonPermission = CdmStore.currentAuthentiationHasPermission(targetNode.getTaxon(), UPDATE); if(logger.isDebugEnabled()){ logger.debug("target: " + targetNode.getTaxon().getTitleCache()); } - if(!hasTargetNodePermission || ! hasTargetNodePermission){ - if(logger.isDebugEnabled()){ - logger.debug("CANCEL_STATUS for target node: " + hasTargetNodePermission.toString() + " " + hasTargetTaxonPermission.toString() + " "); - } - return Status.CANCEL_STATUS; - } - } - - // do not allow to drop onto itself and - // check users permissions with all selected taxon nodes and taxa - for(TaxonNode taxonNode : getSelectedTaxa()){ - logger.debug("selectedTaxa: " + taxonNode.getTaxon().getTitleCache()); - Boolean isSameTaxonNode = taxonNode.equals(target); - Boolean hasTaxonNodePermission = CdmStore.currentAuthentiationHasPermission(taxonNode, UPDATE); - Boolean hasTaxonPermission = CdmStore.currentAuthentiationHasPermission(taxonNode.getTaxon(), UPDATE); + if(!hasTargetNodePermission || ! hasTargetNodePermission){ + if(logger.isDebugEnabled()){ + logger.debug("CANCEL_STATUS for target node: " + hasTargetNodePermission.toString() + " " + hasTargetTaxonPermission.toString() + " "); + } + return Status.CANCEL_STATUS; + } + } + + // do not allow to drop onto itself and + // check users permissions with all selected taxon nodes and taxa + for(TaxonNode taxonNode : getSelectedTaxa()){ + logger.debug("selectedTaxa: " + taxonNode.getTaxon().getTitleCache()); + Boolean isSameTaxonNode = taxonNode.equals(target); + Boolean hasTaxonNodePermission = CdmStore.currentAuthentiationHasPermission(taxonNode, UPDATE); + Boolean hasTaxonPermission = CdmStore.currentAuthentiationHasPermission(taxonNode.getTaxon(), UPDATE); if ( - isSameTaxonNode - || !hasTaxonNodePermission - || !hasTaxonPermission - ) { + isSameTaxonNode + || !hasTaxonNodePermission + || !hasTaxonPermission + ) { if(logger.isDebugEnabled()){ logger.debug("CANCEL_STATUS for selected " + isSameTaxonNode.toString() + " " + hasTaxonNodePermission.toString() + " " + hasTaxonPermission.toString() + " "); } - return Status.CANCEL_STATUS; - } - } - logger.debug("OK_STATUS"); - return Status.OK_STATUS; - } - logger.debug("CANCEL_STATUS"); - return Status.CANCEL_STATUS; - } - - - /** - * @param childTaxonNode - * @param parentTaxon - * @return - */ - private IStatus moveTaxon(TaxonNode taxonNode, ITaxonTreeNode targetITaxonTreeNode) { - - TaxonNavigator taxonNavigator; - taxonNavigator = (TaxonNavigator) NavigationUtil.showView(TaxonNavigator.ID); - - if(targetITaxonTreeNode instanceof TaxonNode){ - - TaxonNode targetTaxonNode = (TaxonNode) targetITaxonTreeNode; - // Make sure parent taxon does not have unsaved changes - if (NavigationUtil.isDirty(targetTaxonNode)){ - MessageDialog.openWarning(NavigationUtil.getShell(), "Unsaved Parent Taxon", "There are unsaved " + - "changes in the parent taxon. Pleas save first."); - return Status.CANCEL_STATUS; - } - + return Status.CANCEL_STATUS; + } + } + logger.debug("OK_STATUS"); + return Status.OK_STATUS; + } + logger.debug("CANCEL_STATUS"); + return Status.CANCEL_STATUS; + } + + + /** + * @param childTaxonNode + * @param parentTaxon + * @return + */ + private IStatus moveTaxon(Set taxonNodes, ITaxonTreeNode targetITaxonTreeNode) { + + TaxonNavigator taxonNavigator; + taxonNavigator = (TaxonNavigator) NavigationUtil.showView(TaxonNavigator.ID); + + if(targetITaxonTreeNode instanceof TaxonNode){ + + TaxonNode targetTaxonNode = (TaxonNode) targetITaxonTreeNode; + // Make sure parent taxon does not have unsaved changes + if (NavigationUtil.isDirty(targetTaxonNode)){ + MessageDialog.openWarning(NavigationUtil.getShell(), "Unsaved Parent Taxon", "There are unsaved " + + "changes in the parent taxon. Pleas save first."); + return Status.CANCEL_STATUS; + } + + } + Iterator taxIterator = taxonNodes.iterator(); + Set uuids = new HashSet(); + TaxonNode node = null; + while(taxIterator.hasNext()){ + node = taxIterator.next(); + uuids.add(node.getUuid()); } - if (!PreferencesUtil.getSortNodesNaturally()){ - IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext(); - if (workspaceUndoContext == null) { - logger.error("Workspace undo context is null. DND operation cancelled"); - return Status.CANCEL_STATUS; - } - - if(CdmStore.getCurrentSessionManager().isRemoting()) { - AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, taxonNode, (TaxonNode)targetITaxonTreeNode, true); - NavigationUtil.executeOperation(operation, null); - } else { - AbstractPostOperation operation = new MoveTaxonOperation - ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true); - NavigationUtil.executeOperation(operation); - } - logger.info("Moved taxa to new parent " + targetITaxonTreeNode); - return Status.OK_STATUS; - }else{ - String[] buttonLables = {"Parent", "Predecessor", "Cancel"}; - MessageDialog dialog = new MessageDialog(null, "Target node", null, "Do you want to use the target node as parent or do you want to move the taxon below the target.", MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0); - dialog.open(); - int returnCode = dialog.getReturnCode(); - if (returnCode == 0){ - IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext(); - if (workspaceUndoContext == null) { - logger.error("Workspace undo context is null. DND operation cancelled"); - return Status.CANCEL_STATUS; - } - - - if(CdmStore.getCurrentSessionManager().isRemoting()) { - AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, taxonNode, (TaxonNode)targetITaxonTreeNode, true); - NavigationUtil.executeOperation(operation, null); - } else { - AbstractPostOperation operation = new MoveTaxonOperation - ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true); - NavigationUtil.executeOperation(operation); - } - - logger.info("Moved taxa to new parent " + targetITaxonTreeNode); - return Status.OK_STATUS; - }else if (returnCode == 1){ - IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext(); - if (workspaceUndoContext == null) { - logger.error("Workspace undo context is null. DND operation cancelled"); - return Status.CANCEL_STATUS; - } - - if(CdmStore.getCurrentSessionManager().isRemoting()) { - AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, taxonNode, (TaxonNode)targetITaxonTreeNode, true); - NavigationUtil.executeOperation(operation, null); - } else { - AbstractPostOperation operation = new MoveTaxonOperation - ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, false); - NavigationUtil.executeOperation(operation); - } - logger.info("Moved taxa to new parent " + targetITaxonTreeNode); - return Status.OK_STATUS; - } else{ - return Status.CANCEL_STATUS; + if (!PreferencesUtil.getSortNodesNaturally()){ + IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext(); + if (workspaceUndoContext == null) { + logger.error("Workspace undo context is null. DND operation cancelled"); + return Status.CANCEL_STATUS; + } + + if(CdmStore.getCurrentSessionManager().isRemoting()) { + AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, (TaxonNode)targetITaxonTreeNode, true); + NavigationUtil.executeOperation(operation, null); + } else { + AbstractPostOperation operation = new MoveTaxonOperation + ("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, true); + NavigationUtil.executeOperation(operation); } - - } - - } - - /* (non-Javadoc) - * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase) - */ - /** {@inheritDoc} */ - @Override + logger.info("Moved taxa to new parent " + targetITaxonTreeNode); + return Status.OK_STATUS; + }else{ + String[] buttonLables = {"Parent", "Predecessor", "Cancel"}; + MessageDialog dialog = new MessageDialog(null, "Target node", null, "Do you want to use the target node as parent or do you want to move the taxon below the target.", MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0); + dialog.open(); + int returnCode = dialog.getReturnCode(); + if (returnCode == 0){ + IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext(); + if (workspaceUndoContext == null) { + logger.error("Workspace undo context is null. DND operation cancelled"); + return Status.CANCEL_STATUS; + } + + if(CdmStore.getCurrentSessionManager().isRemoting()) { + AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, (TaxonNode)targetITaxonTreeNode, true); + NavigationUtil.executeOperation(operation, null); + } else { + AbstractPostOperation operation = new MoveTaxonOperation + ("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, true); + NavigationUtil.executeOperation(operation); + } + + logger.info("Moved taxa to new parent " + targetITaxonTreeNode); + return Status.OK_STATUS; + }else if (returnCode == 1){ + IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext(); + if (workspaceUndoContext == null) { + logger.error("Workspace undo context is null. DND operation cancelled"); + return Status.CANCEL_STATUS; + } + TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode; + + if(CdmStore.getCurrentSessionManager().isRemoting()) { + AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, targetNode.getParent(), true); + NavigationUtil.executeOperation(operation, null); + } else { + AbstractPostOperation operation = new MoveTaxonOperation + ("Move Taxon", workspaceUndoContext, uuids, targetNode.getParent(), this, taxonNavigator, false); + NavigationUtil.executeOperation(operation); + } + logger.info("Moved taxa to new parent " + targetITaxonTreeNode); + return Status.OK_STATUS; + } else{ + return Status.CANCEL_STATUS; + } + + + } + } + + /* (non-Javadoc) + * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase) + */ + /** {@inheritDoc} */ + @Override public boolean postOperation(CdmBase objectAffectedByOperation) { - return true; - } - - /** - *

onComplete

- * - * @return a boolean. - */ - @Override + return true; + } + + /** + *

onComplete

+ * + * @return a boolean. + */ + @Override public boolean onComplete() { - // TODO Auto-generated method stub - return false; - } + // TODO Auto-generated method stub + return false; + } } diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/MoveTaxonHandler.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/MoveTaxonHandler.java index d275e3c90..a761433ad 100644 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/MoveTaxonHandler.java +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/handler/MoveTaxonHandler.java @@ -10,8 +10,10 @@ package eu.etaxonomy.taxeditor.navigation.navigator.handler; import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import java.util.UUID; import org.eclipse.core.commands.AbstractHandler; @@ -48,7 +50,6 @@ public class MoveTaxonHandler extends AbstractHandler implements IPostOperationE * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent) */ /** {@inheritDoc} */ - @Override public Object execute(ExecutionEvent event) throws ExecutionException { activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage(); @@ -57,29 +58,32 @@ public class MoveTaxonHandler extends AbstractHandler implements IPostOperationE TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event); Iterator selectionIterator = selection.iterator(); - TaxonNode taxonNode = null; - UUID taxonNodeUUID = null; + Set taxonNodes = new HashSet(); + TaxonNode taxonNode= null; + Set taxonNodeUUIDs = new HashSet(); // do not show the current selection List excludeTaxa = new ArrayList(); + //if (selection.size() == 1){ - if (selection.size() == 1){ + while (selectionIterator.hasNext()){ Object object = selectionIterator.next(); if(object instanceof TaxonNode){ - taxonNode = HibernateProxyHelper.deproxy(object,TaxonNode.class); - taxonNodeUUID = taxonNode.getUuid(); + taxonNode = HibernateProxyHelper.deproxy(object,TaxonNode.class); + taxonNodes.add(taxonNode); + taxonNodeUUIDs.add(taxonNode.getUuid()); excludeTaxa.add(taxonNode.getTaxon().getUuid()); } - } else{ + } + /*} else{ if( MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){ return null; } - } - + }*/ // TaxonNode taxonNode = (TaxonNode) selection.getFirstElement(); - if (taxonNode != null){ + if (taxonNodes.size() >= 1){ boolean moveToNewParent = true; if (PreferencesUtil.getSortNodesNaturally()){ if(!MessageDialog.openQuestion(null, "Target node", "The choosen target node should be the parent?")){ @@ -98,13 +102,12 @@ public class MoveTaxonHandler extends AbstractHandler implements IPostOperationE AbstractPostOperation operation = new MoveTaxonOperation ("Move taxon to new parent", NavigationUtil.getUndoContext(), - taxonNode, parentTaxonNode, taxonNavigator, taxonNavigator, moveToNewParent); //$NON-NLS-1$ + taxonNodeUUIDs, parentTaxonNode, taxonNavigator, taxonNavigator, moveToNewParent); //$NON-NLS-1$ NavigationUtil.executeOperation(operation); taxonNavigator.refresh(); } } - return null; } @@ -127,4 +130,6 @@ public class MoveTaxonHandler extends AbstractHandler implements IPostOperationE return false; } + + } diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/MoveTaxonOperation.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/MoveTaxonOperation.java index 2eff48f93..830d572a4 100644 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/MoveTaxonOperation.java +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/MoveTaxonOperation.java @@ -9,6 +9,9 @@ package eu.etaxonomy.taxeditor.navigation.navigator.operation; +import java.util.Set; +import java.util.UUID; + import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.operations.IUndoContext; import org.eclipse.core.runtime.IAdaptable; @@ -20,11 +23,9 @@ import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; import eu.etaxonomy.cdm.api.service.ITaxonNodeService; import eu.etaxonomy.cdm.api.service.UpdateResult; import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode; -import eu.etaxonomy.cdm.model.taxon.TaxonNode; import eu.etaxonomy.taxeditor.model.MessagingUtils; import eu.etaxonomy.taxeditor.operation.AbstractPersistentPostOperation; import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled; -import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; import eu.etaxonomy.taxeditor.store.CdmStore; /** @@ -43,33 +44,10 @@ public class MoveTaxonOperation extends AbstractPersistentPostOperation { /** * A reference to the former taxonomical parents */ + //private Map oldParentTreeNodes; - - - private final TaxonNode taxonNode; + private final Set taxonNodesUuid; private final boolean moveToParentNode; - - /** - *

Constructor for MoveTaxonOperation.

- * - * @param label a {@link java.lang.String} object. - * @param undoContext a {@link org.eclipse.core.commands.operations.IUndoContext} object. - * @param taxonNodes a {@link java.util.Set} object. - * @param newParentTreeNode a {@link eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode} object. - * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object. - * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object. - */ - - public MoveTaxonOperation(String label, - IUndoContext undoContext, - TaxonNode taxonNodeToMove, - ITaxonTreeNode newParentTreeNode, - IPostOperationEnabled postOperationEnabled, - IConversationEnabled conversationEnabled, - boolean moveToParentNode) { - this(label, undoContext, taxonNodeToMove, newParentTreeNode, postOperationEnabled, conversationEnabled, null, moveToParentNode); - } - /** *

Constructor for MoveTaxonOperation.

* @@ -80,29 +58,20 @@ public class MoveTaxonOperation extends AbstractPersistentPostOperation { * @param postOperationEnabled a {@link eu.etaxonomy.taxeditor.operation.IPostOperationEnabled} object. * @param conversationEnabled a {@link eu.etaxonomy.cdm.api.conversation.IConversationEnabled} object. */ + public MoveTaxonOperation(String label, IUndoContext undoContext, + Set taxonNodesUUIDToMove, ITaxonTreeNode newParentTreeNode, IPostOperationEnabled postOperationEnabled, IConversationEnabled conversationEnabled, boolean moveToParentNode) { + super(label, undoContext, postOperationEnabled, conversationEnabled); - public MoveTaxonOperation(String label, - IUndoContext undoContext, - TaxonNode taxonNodeToMove, - ITaxonTreeNode newParentTreeNode, - IPostOperationEnabled postOperationEnabled, - IConversationEnabled conversationEnabled, - ICdmEntitySessionEnabled cdmEntitySessionEnabled, - boolean moveToParentNode) { - super(label, undoContext, postOperationEnabled, conversationEnabled, cdmEntitySessionEnabled); - - this.taxonNode = taxonNodeToMove; + this.taxonNodesUuid = taxonNodesUUIDToMove; /*for (TaxonNode node:taxonNodes){ this.taxonNodes.add(service.load(node.getUuid())); }*/ - this.newParentTreeNode = newParentTreeNode; this.moveToParentNode = moveToParentNode; // Save old parent ITaxonTreeNodes for undo //this.parentNode = taxonNode.getParent(); - } /* (non-Javadoc) @@ -115,7 +84,7 @@ public class MoveTaxonOperation extends AbstractPersistentPostOperation { bind(); monitor.worked(20); - UpdateResult result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNode(this.taxonNode.getUuid(),newParentTreeNode.getUuid(), moveToParentNode); + UpdateResult result = CdmStore.getService(ITaxonNodeService.class).moveTaxonNodes(this.taxonNodesUuid,newParentTreeNode.getUuid()); // try { // for (TaxonNode taxonNode : taxonNodes){ // TaxonNode newTaxonNode = newParentTreeNode.addChildNode(taxonNode, diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingMoveTaxonOperation.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingMoveTaxonOperation.java index 057d5d30c..65e514478 100644 --- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingMoveTaxonOperation.java +++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/operation/RemotingMoveTaxonOperation.java @@ -9,6 +9,8 @@ */ package eu.etaxonomy.taxeditor.navigation.navigator.operation; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; import org.eclipse.core.runtime.IAdaptable; @@ -30,7 +32,7 @@ public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation { private final static String LABEL = "Move Taxon operation"; - private final UUID taxonNodeToMoveUuid; + private Set taxonNodesToMoveUuid; private final UUID newParentTreeNodeUuid; private final boolean moveToParentNode; @@ -40,7 +42,8 @@ public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation { UUID newParentTreeNodeUuid, boolean moveToParentNode) { super(LABEL, Action.Update, source,async); - this.taxonNodeToMoveUuid = taxonNodeToMoveUuid; + taxonNodesToMoveUuid = new HashSet(); + taxonNodesToMoveUuid.add(taxonNodeToMoveUuid); this.newParentTreeNodeUuid = newParentTreeNodeUuid; this.moveToParentNode = moveToParentNode; } @@ -51,7 +54,19 @@ public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation { TaxonNode newParentTreeNode, boolean moveToParentNode) { super(LABEL, Action.Update, source,async); - this.taxonNodeToMoveUuid = taxonNodeToMove.getUuid(); + taxonNodesToMoveUuid = new HashSet(); + taxonNodesToMoveUuid.add(taxonNodeToMove.getUuid()); + this.newParentTreeNodeUuid = newParentTreeNode.getUuid(); + this.moveToParentNode = moveToParentNode; + } + + public RemotingMoveTaxonOperation(Object source, + boolean async, + Set taxonNodesToMoveUuid, + TaxonNode newParentTreeNode, + boolean moveToParentNode) { + super(LABEL, Action.Update, source,async); + this.taxonNodesToMoveUuid = taxonNodesToMoveUuid; this.newParentTreeNodeUuid = newParentTreeNode.getUuid(); this.moveToParentNode = moveToParentNode; } @@ -61,9 +76,8 @@ public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation { */ @Override protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception { - return CdmApplicationState.getService(ITaxonNodeService.class).moveTaxonNode(taxonNodeToMoveUuid, - newParentTreeNodeUuid, - moveToParentNode); + return CdmApplicationState.getService(ITaxonNodeService.class).moveTaxonNodes(taxonNodesToMoveUuid, + newParentTreeNodeUuid); } } -- 2.34.1