-// $Id$
/**
* Copyright (C) 2007 EDIT
* European Distributed Institute of Taxonomy
import java.util.Set;
import org.apache.log4j.Logger;
-import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.jface.dialogs.IconAndMessageDialog;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.TransferData;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.navigator.CommonDropAdapter;
import org.eclipse.ui.navigator.CommonDropAdapterAssistant;
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
-import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
-import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
-import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
-import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
/**
*
* @author p.ciardelli
* @created 03.06.2009
- * @version 1.0
*/
public class TreeNodeDropAdapterAssistant extends CommonDropAdapterAssistant implements IPostOperationEnabled {
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;
targetTreeNode = ((Classification)targetTreeNode).getRootNode();
targetTreeNode = HibernateProxyHelper.deproxy(targetTreeNode, TaxonNode.class);
}
- if(taxonNodes != null) {
- if (taxonNodes.size() == 1){
- return moveTaxon(taxonNodes.iterator().next(), targetTreeNode);
- } else{
+ //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;
}
- }
+ }*/
}
}
-
+
return Status.CANCEL_STATUS;
}
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection instanceof TreeSelection) {
- Iterator selectionIterator = ((TreeSelection) selection).iterator();
+ Iterator<?> selectionIterator = ((TreeSelection) selection).iterator();
while (selectionIterator.hasNext()){
Object object = selectionIterator.next();
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,
// 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);
+ boolean hasTargetNodePermission = CdmStore.currentAuthentiationHasPermission(targetNode, UPDATE);
+ boolean hasTargetTaxonPermission = targetNode.getTaxon() == null ?
+ true :
+ CdmStore.currentAuthentiationHasPermission(targetNode.getTaxon(), UPDATE);
if(logger.isDebugEnabled()){
- logger.debug("target: " + targetNode.getTaxon().getTitleCache());
+ logger.debug("target: " + targetNode.getTaxon() == null? "-" : targetNode.getTaxon().getTitleCache()); //$NON-NLS-1$
}
if(!hasTargetNodePermission || ! hasTargetNodePermission){
if(logger.isDebugEnabled()){
- logger.debug("CANCEL_STATUS for target node: " + hasTargetNodePermission.toString() + " " + hasTargetTaxonPermission.toString() + " ");
+ logger.debug("CANCEL_STATUS for target node: " + hasTargetNodePermission + " " + hasTargetTaxonPermission + " "); //$NON-NLS-1$
}
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 (logger.isDebugEnabled()){
+ logger.debug("selectedTaxa: " + taxonNode.getTaxon() == null? "-" : taxonNode.getTaxon().getTitleCache());
+ }
+ boolean isSameTaxonNode = taxonNode.equals(target);
+ boolean hasTaxonNodePermission = CdmStore.currentAuthentiationHasPermission(taxonNode, UPDATE);
+ boolean hasTaxonPermission = taxonNode.getTaxon() == null ?
+ true :
+ CdmStore.currentAuthentiationHasPermission(taxonNode.getTaxon(), UPDATE);
if (
isSameTaxonNode
|| !hasTaxonNodePermission
|| !hasTaxonPermission
) {
if(logger.isDebugEnabled()){
- logger.debug("CANCEL_STATUS for selected " + isSameTaxonNode.toString() + " " + hasTaxonNodePermission.toString() + " " + hasTaxonPermission.toString() + " ");
+ logger.debug("CANCEL_STATUS for selected " + isSameTaxonNode + " " + hasTaxonNodePermission + " " + hasTaxonPermission + " "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
return Status.CANCEL_STATUS;
}
}
- logger.debug("OK_STATUS");
+ if (logger.isDebugEnabled()){logger.debug("OK_STATUS");} //$NON-NLS-1$
return Status.OK_STATUS;
}
- logger.debug("CANCEL_STATUS");
+ if (logger.isDebugEnabled()){logger.debug("CANCEL_STATUS");} //$NON-NLS-1$
return Status.CANCEL_STATUS;
}
* @param parentTaxon
* @return
*/
- private IStatus moveTaxon(TaxonNode taxonNode, ITaxonTreeNode targetITaxonTreeNode) {
-
- TaxonNavigator taxonNavigator;
- taxonNavigator = (TaxonNavigator) NavigationUtil.showView(TaxonNavigator.ID);
+ private IStatus moveTaxon(Set<TaxonNode> taxonNodes, ITaxonTreeNode targetITaxonTreeNode) {
- 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;
- }
-
- }
- if (!PreferencesUtil.getSortNodesNaturally()){
- IUndoContext workspaceUndoContext = NavigationUtil.getWorkbenchUndoContext();
- if (workspaceUndoContext == null) {
- logger.error("Workspace undo context is null. DND operation cancelled");
+// TaxonNavigator taxonNavigator;
+// taxonNavigator = (TaxonNavigator) AbstractUtility.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(), TreeNodeDropAdapter.TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT, TreeNodeDropAdapter.TREE_NODE_DROP_ADAPTER_UNSAVED_PARENT_MESSAGE);
+//// return Status.CANCEL_STATUS;
+//// }
+//
+// }
+// Iterator<TaxonNode> taxIterator = taxonNodes.iterator();
+// Set<UUID> 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"); //$NON-NLS-1$
+// return Status.CANCEL_STATUS;
+// }
+//
+// AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, (TaxonNode)targetITaxonTreeNode, MovingType.CHILD);
+// AbstractUtility.executeOperation(operation, (RemotingCdmHandlerE4)null);
+//
+//
+// logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
+// return Status.OK_STATUS;
+// }else{
+// String[] buttonLables = {TreeNodeDropAdapter.TREE_NODE_DROP_ADAPTER_CHILD, TreeNodeDropAdapter.TREE_NODE_DROP_ADAPTER_BEHIND, TreeNodeDropAdapter.TREE_NODE_DROP_ADAPTER_CANCEL};
+// MessageDialog dialog = new MessageDialog(null, TreeNodeDropAdapter.TARGET_NODE, null, TreeNodeDropAdapter.DO_YOU_WANT_TO_MOVE_THE_TAXONNODE_AS_CHILD_OR_BEHIND_THE_TARGET_NODE, 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"); //$NON-NLS-1$
+// return Status.CANCEL_STATUS;
+// }
+//
+// AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, (TaxonNode)targetITaxonTreeNode, MovingType.CHILD);
+// AbstractUtility.executeOperation(operation, (RemotingCdmHandlerE4)null);
+//
+//
+// logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
+// 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"); //$NON-NLS-1$
+// return Status.CANCEL_STATUS;
+// }
+// TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
+//
+// AbstractOperation operation = new RemotingMoveTaxonOperation(taxonNavigator, false, uuids, targetNode, MovingType.BEHIND);
+// AbstractUtility.executeOperation(operation, (RemotingCdmHandlerE4)null);
+//
+// logger.info("Moved taxa to new parent " + targetITaxonTreeNode); //$NON-NLS-1$
+// return Status.OK_STATUS;
+//// }else if (returnCode == 2){
+//// 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, MovingType.PREVIOUS);
+//// NavigationUtil.executeOperation(operation, null);
+//// } else {
+//// AbstractPostOperation operation = new MoveTaxonOperation
+//// ("Move Taxon", workspaceUndoContext, uuids, targetNode, this, taxonNavigator, MovingType.PREVIOUS);
+//// NavigationUtil.executeOperation(operation);
+//// }
+//// logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
+//// return Status.OK_STATUS;
+// } else{
return Status.CANCEL_STATUS;
- }
-
- 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;
- }
-
- 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;
- }
-
- 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;
- }
-
-
- }
+// }
+// }
}
- /* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
- */
/** {@inheritDoc} */
@Override
public boolean postOperation(CdmBase objectAffectedByOperation) {