/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* 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.
*/
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.handlers.HandlerUtil;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.taxon.Classification;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
+import eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapter.MovingType;
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.ui.dialog.selection.TaxonNodeSelectionDialog;
/**
public class MoveTaxonHandler extends AbstractHandler implements IPostOperationEnabled {
private TaxonNode parentTaxonNode;
-
+ protected IWorkbenchPage activePage;
/* (non-Javadoc)
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
*/
/** {@inheritDoc} */
- public Object execute(ExecutionEvent event) throws ExecutionException {
- TaxonNavigator taxonNavigator = NavigationUtil.showNavigator();
-
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
+ TaxonNavigator taxonNavigator = (TaxonNavigator)NavigationUtil.showView(TaxonNavigator.ID);
+
TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
-
+
Iterator selectionIterator = selection.iterator();
Set<TaxonNode> taxonNodes = new HashSet<TaxonNode>();
+ TaxonNode taxonNode= null;
+ Set<UUID> taxonNodeUUIDs = new HashSet<UUID>();
// do not show the current selection
List<UUID> excludeTaxa = new ArrayList<UUID>();
-
-
+
+ //if (selection.size() == 1){
+
while (selectionIterator.hasNext()){
Object object = selectionIterator.next();
if(object instanceof TaxonNode){
- TaxonNode taxonNode = (TaxonNode) object;
+ taxonNode = HibernateProxyHelper.deproxy(object,TaxonNode.class);
taxonNodes.add(taxonNode);
+ taxonNodeUUIDs.add(taxonNode.getUuid());
excludeTaxa.add(taxonNode.getTaxon().getUuid());
}
}
-
-// TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
-
- parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), taxonNavigator.getConversationHolder(), "Choose new parent", excludeTaxa, null, null);
-
- if(parentTaxonNode != null){
- if(NavigationUtil.isDirty(parentTaxonNode)){
- MessageDialog.openWarning(HandlerUtil.getActiveShell(event), "Unsaved Parent Taxon", "There are unsaved " +
- "changes in the parent taxon. Please save first.");
+ /*} 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;
}
-
- AbstractPostOperation operation = new MoveTaxonOperation
- ("Move taxon to new parent", NavigationUtil.getUndoContext(),
- taxonNodes, parentTaxonNode, this, taxonNavigator); //$NON-NLS-1$
- NavigationUtil.executeOperation(operation);
-
+ }*/
+
+
+// TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
+ if (taxonNodes.size() >= 1){
+ Classification classification = taxonNodes.iterator().next().getClassification();
+ MovingType moveToNewParent = MovingType.CHILD;
+ if (PreferencesUtil.getSortNodesNaturally()){
+ if(!MessageDialog.openQuestion(null, "Target node", "The choosen target node should be the parent?")){
+ moveToNewParent = MovingType.BEHIND;
+ }
+ parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), taxonNavigator.getConversationHolder(), "Choose the taxon above the moved taxon.", excludeTaxa, null, classification);
+ }else{
+ parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), taxonNavigator.getConversationHolder(), "Choose new parent", excludeTaxa, null, classification);
+ }
+ if(parentTaxonNode != null){
+ if(NavigationUtil.isDirty(parentTaxonNode)){
+ MessageDialog.openWarning(HandlerUtil.getActiveShell(event), "Unsaved Parent Taxon", "There are unsaved " +
+ "changes in the parent taxon. Please save first.");
+ return null;
+ }
+
+
+ AbstractPostOperation operation = new MoveTaxonOperation
+ ("Move taxon to new parent", NavigationUtil.getUndoContext(),
+ taxonNodeUUIDs, parentTaxonNode, taxonNavigator, taxonNavigator, moveToNewParent); //$NON-NLS-1$
+ NavigationUtil.executeOperation(operation);
+ taxonNavigator.refresh();
+
+ }
}
-
return null;
}
* @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
*/
/** {@inheritDoc} */
- public boolean postOperation(CdmBase objectAffectedByOperation) {
+ @Override
+ public boolean postOperation(CdmBase objectAffectedByOperation) {
return true;
}
*
* @return a boolean.
*/
- public boolean onComplete() {
+ @Override
+ public boolean onComplete() {
return false;
}
+
+
+
}