// $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;
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;
*/
public class TreeNodeDropAdapterAssistant extends CommonDropAdapterAssistant implements IPostOperationEnabled {
- private static final Logger logger = Logger.getLogger(TreeNodeDropAdapterAssistant.class);
-
- /** Constant <code>ID="eu.etaxonomy.taxeditor.navigation.navig"{trunked}</code> */
- public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator.dropassistant"; //$NON-NLS-1$
-
- private static final EnumSet<CRUD> 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<TaxonNode> 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 <code>ID="eu.etaxonomy.taxeditor.navigation.navig"{trunked}</code> */
+ public static final String ID = "eu.etaxonomy.taxeditor.navigation.navigator.dropassistant"; //$NON-NLS-1$
+
+ private static final EnumSet<CRUD> 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<TaxonNode> 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<TaxonNode> getSelectedTaxa(){
- HashSet<TaxonNode> taxonNodes = new HashSet<TaxonNode>();
-
- 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<TaxonNode> getSelectedTaxa(){
+ HashSet<TaxonNode> taxonNodes = new HashSet<TaxonNode>();
+
+ 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<TaxonNode> 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<TaxonNode> taxIterator = taxonNodes.iterator();
+ Set<UUID> uuids = new HashSet<UUID>();
+ 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;
- }
-
- /**
- * <p>onComplete</p>
- *
- * @return a boolean.
- */
- @Override
+ return true;
+ }
+
+ /**
+ * <p>onComplete</p>
+ *
+ * @return a boolean.
+ */
+ @Override
public boolean onComplete() {
- // TODO Auto-generated method stub
- return false;
- }
+ // TODO Auto-generated method stub
+ return false;
+ }
}
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;
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;
/**
/**
* A reference to the former taxonomical parents
*/
+ //private Map<TaxonNode, ITaxonTreeNode> oldParentTreeNodes;
-
-
- private final TaxonNode taxonNode;
+ private final Set<UUID> taxonNodesUuid;
private final boolean moveToParentNode;
-
- /**
- * <p>Constructor for MoveTaxonOperation.</p>
- *
- * @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);
- }
-
/**
* <p>Constructor for MoveTaxonOperation.</p>
*
* @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<UUID> 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)
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,