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)
51 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
52 TaxonNavigator taxonNavigator
= NavigationUtil
.showNavigator();
54 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
56 Iterator selectionIterator
= selection
.iterator();
57 Set
<TaxonNode
> taxonNodes
= new HashSet
<TaxonNode
>();
58 // do not show the current selection
59 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
62 while (selectionIterator
.hasNext()){
63 Object object
= selectionIterator
.next();
64 if(object
instanceof TaxonNode
){
65 TaxonNode taxonNode
= (TaxonNode
) object
;
66 taxonNodes
.add(taxonNode
);
67 excludeTaxa
.add(taxonNode
.getTaxon().getUuid());
71 // TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
73 parentTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
), taxonNavigator
.getConversationHolder(), "Choose new parent", excludeTaxa
, null, null);
75 if(parentTaxonNode
!= null){
76 if(NavigationUtil
.isDirty(parentTaxonNode
)){
77 MessageDialog
.openWarning(HandlerUtil
.getActiveShell(event
), "Unsaved Parent Taxon", "There are unsaved " +
78 "changes in the parent taxon. Please save first.");
82 AbstractPostOperation operation
= new MoveTaxonOperation("Move taxon to new parent",
83 NavigationUtil
.getUndoContext(),
88 taxonNavigator
); //$NON-NLS-1$
89 NavigationUtil
.executeOperation(operation
);
97 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
101 public boolean postOperation(CdmBase objectAffectedByOperation
) {
111 public boolean onComplete() {