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 org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.commands
.AbstractHandler
;
14 import org
.eclipse
.core
.commands
.ExecutionEvent
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.commands
.operations
.IUndoableOperation
;
17 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
18 import org
.eclipse
.swt
.widgets
.Dialog
;
19 import org
.eclipse
.swt
.widgets
.Shell
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
22 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonSearchDialog
;
23 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
24 import eu
.etaxonomy
.taxeditor
.store
.operations
.MoveTaxonOperation
;
31 public class MoveTaxonHandler
extends AbstractHandler
{
32 private static final Logger logger
= Logger
33 .getLogger(MoveTaxonHandler
.class);
36 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
38 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
39 Shell shell
= NavigationUtil
.getShell();
40 Taxon taxon
= (Taxon
) NavigationUtil
.getCurrentSelection(event
);
42 Dialog dialog
= new TaxonSearchDialog(shell
);
43 Object value
= ((TaxonSearchDialog
) dialog
).open();
45 logger
.warn("child " +taxon
.toString());
46 logger
.warn("parent " + ((Taxon
) value
).toString());
48 if (value
instanceof Taxon
) {
49 Taxon parentTaxon
= (Taxon
) value
;
51 if(NavigationUtil
.isDirty(parentTaxon
)){
52 MessageDialog
.openWarning(shell
, "Unsaved Parent Taxon", "There are unsaved " +
53 "changes in the parent taxon. Pleas save first.");
57 IUndoableOperation operation
= new MoveTaxonOperation
58 ("Move taxon to new parent", NavigationUtil
.getUndoContext(),
59 taxon
, parentTaxon
); //$NON-NLS-1$
60 NavigationUtil
.executeOperation(operation
);
62 logger
.warn("TaxonSearchDialog did not return a Taxon object.");