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.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.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerDropAdapter;
import org.eclipse.swt.dnd.DND;
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 org.eclipse.ui.navigator.CommonViewer;
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.cdm.model.common.OrderedTermBase;
-import eu.etaxonomy.cdm.model.common.TermBase;
import eu.etaxonomy.cdm.model.taxon.Classification;
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.editor.definedterm.DefinedTermEditor;
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
protected TreeNodeDropAdapter(TaxonNavigatorViewer navigatorViewer) {
super(navigatorViewer);
this.navigatorViewer = navigatorViewer;
-
+
}
-
+
private final TaxonNavigatorViewer navigatorViewer;
private static final Logger logger = Logger.getLogger(TreeNodeDropAdapter.class);
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)
*/
@Override
public boolean performDrop(Object target) {
-
+
if (target instanceof ITaxonTreeNode) {
Set<TaxonNode> taxonNodes = getSelectedTaxa();
ITaxonTreeNode targetTreeNode = (ITaxonTreeNode) target;
}
if(taxonNodes != null) {
if (taxonNodes.size() == 1){
- return moveTaxon(taxonNodes.iterator().next(), targetTreeNode);
+ 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 true;
}
}
}
-
+
return false;
}
@Override
public boolean 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;
* @param parentTaxon
* @return
*/
- private boolean moveTaxon(TaxonNode taxonNode, ITaxonTreeNode targetITaxonTreeNode) {
+ private boolean moveTaxon(Set<TaxonNode> taxonNodes, ITaxonTreeNode targetITaxonTreeNode) {
TaxonNavigator taxonNavigator;
taxonNavigator = (TaxonNavigator) NavigationUtil.showView(TaxonNavigator.ID);
}
}
+ 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 false;
}
-
+
AbstractPostOperation operation = new MoveTaxonOperation
- ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true);
+ ("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, true);
NavigationUtil.executeOperation(operation);
-
+
logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
return true;
}else{
logger.error("Workspace undo context is null. DND operation cancelled");
return false;
}
-
+
AbstractPostOperation operation = new MoveTaxonOperation
- ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, true);
+ ("Move Taxon", workspaceUndoContext, uuids, targetITaxonTreeNode, this, taxonNavigator, true);
NavigationUtil.executeOperation(operation);
-
+
logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
return true;
}else if (returnCode == 1){
logger.error("Workspace undo context is null. DND operation cancelled");
return false;
}
-
+ TaxonNode targetNode = (TaxonNode) targetITaxonTreeNode;
+
AbstractPostOperation operation = new MoveTaxonOperation
- ("Move Taxon", workspaceUndoContext, taxonNode, targetITaxonTreeNode, this, taxonNavigator, false);
+ ("Move Taxon", workspaceUndoContext, uuids, targetNode.getParent(), this, taxonNavigator, false);
NavigationUtil.executeOperation(operation);
-
+
logger.info("Moved taxa to new parent " + targetITaxonTreeNode);
return true;
} else{
return false;
}
-
-
+
+
}
}
public void dragOver(DropTargetEvent event) {
super.dragOver(event);
event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_INSERT_AFTER;
-
+
}
-
+
}