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
.handler
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.eclipse
.core
.commands
.AbstractHandler
;
18 import org
.eclipse
.core
.commands
.ExecutionEvent
;
19 import org
.eclipse
.core
.commands
.ExecutionException
;
20 import org
.eclipse
.core
.commands
.operations
.IUndoableOperation
;
21 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
22 import org
.eclipse
.swt
.widgets
.Shell
;
24 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
26 import eu
.etaxonomy
.taxeditor
.dialogs
.filteredSelection
.FilteredTaxonNodeSelectionDialog
;
27 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
28 import eu
.etaxonomy
.taxeditor
.operations
.IPostOperationEnabled
;
29 import eu
.etaxonomy
.taxeditor
.operations
.MoveTaxonOperation
;
36 public class MoveTaxonHandler
extends AbstractHandler
implements IPostOperationEnabled
{
37 private static final Logger logger
= Logger
38 .getLogger(MoveTaxonHandler
.class);
39 private TaxonNode parentTaxonNode
;
42 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
44 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
45 Shell shell
= NavigationUtil
.getShell();
46 TaxonNode taxonNode
= (TaxonNode
) NavigationUtil
.getCurrentSelection(event
);
48 // do not show the current selection
49 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
50 excludeTaxa
.add(taxonNode
.getTaxon().getUuid());
51 parentTaxonNode
= FilteredTaxonNodeSelectionDialog
.selectTaxonNode(shell
, "Choose new parent", excludeTaxa
, null);
53 if(parentTaxonNode
!= null){
55 logger
.warn("child " +taxonNode
.getTaxon().toString());
56 logger
.warn("parent " + parentTaxonNode
.toString());
58 if(NavigationUtil
.isDirty(parentTaxonNode
)){
59 MessageDialog
.openWarning(shell
, "Unsaved Parent Taxon", "There are unsaved " +
60 "changes in the parent taxon. Please save first.");
64 IUndoableOperation operation
= new MoveTaxonOperation
65 ("Move taxon to new parent", NavigationUtil
.getUndoContext(),
66 taxonNode
, parentTaxonNode
, this); //$NON-NLS-1$
67 NavigationUtil
.executeOperation(operation
);
75 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
77 public boolean postOperation(CdmBase objectAffectedByOperation
) {
78 NavigationUtil
.selectInNavigator(objectAffectedByOperation
, parentTaxonNode
);