2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.handler
;
12 import java
.util
.ArrayList
;
13 import java
.util
.HashSet
;
14 import java
.util
.Iterator
;
15 import java
.util
.List
;
17 import java
.util
.UUID
;
19 import org
.eclipse
.core
.commands
.AbstractHandler
;
20 import org
.eclipse
.core
.commands
.ExecutionEvent
;
21 import org
.eclipse
.core
.commands
.ExecutionException
;
22 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
23 import org
.eclipse
.jface
.viewers
.TreeSelection
;
24 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
26 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
28 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
29 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigator
;
30 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.MoveTaxonOperation
;
31 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
32 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
33 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
36 * <p>MoveTaxonHandler class.</p>
42 public class MoveTaxonHandler
extends AbstractHandler
implements IPostOperationEnabled
{
44 private TaxonNode parentTaxonNode
;
47 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
50 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
51 TaxonNavigator taxonNavigator
= NavigationUtil
.showNavigator();
53 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
55 Iterator selectionIterator
= selection
.iterator();
56 Set
<TaxonNode
> taxonNodes
= new HashSet
<TaxonNode
>();
57 // do not show the current selection
58 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
61 while (selectionIterator
.hasNext()){
62 Object object
= selectionIterator
.next();
63 if(object
instanceof TaxonNode
){
64 TaxonNode taxonNode
= (TaxonNode
) object
;
65 taxonNodes
.add(taxonNode
);
66 excludeTaxa
.add(taxonNode
.getTaxon().getUuid());
70 // TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
72 parentTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
), taxonNavigator
.getConversationHolder(), "Choose new parent", excludeTaxa
, null, null);
74 if(parentTaxonNode
!= null){
75 if(NavigationUtil
.isDirty(parentTaxonNode
)){
76 MessageDialog
.openWarning(HandlerUtil
.getActiveShell(event
), "Unsaved Parent Taxon", "There are unsaved " +
77 "changes in the parent taxon. Please save first.");
81 AbstractPostOperation operation
= new MoveTaxonOperation
82 ("Move taxon to new parent", NavigationUtil
.getUndoContext(),
83 taxonNodes
, parentTaxonNode
, this, taxonNavigator
); //$NON-NLS-1$
84 NavigationUtil
.executeOperation(operation
);
92 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
95 public boolean postOperation(CdmBase objectAffectedByOperation
) {
104 public boolean onComplete() {