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
.actions
.ui
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.commands
.ExecutionException
;
14 import org
.eclipse
.core
.commands
.operations
.IUndoableOperation
;
15 import org
.eclipse
.jface
.action
.Action
;
16 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
17 import org
.eclipse
.swt
.widgets
.Shell
;
18 import org
.eclipse
.ui
.IEditorInput
;
19 import org
.eclipse
.ui
.IEditorPart
;
20 import org
.eclipse
.ui
.PartInitException
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.taxeditor
.ITaxEditorConstants
;
24 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
25 import eu
.etaxonomy
.taxeditor
.actions
.cdm
.MoveTaxonAction
;
26 import eu
.etaxonomy
.taxeditor
.controller
.EditorController
;
27 import eu
.etaxonomy
.taxeditor
.controller
.GlobalController
;
28 import eu
.etaxonomy
.taxeditor
.editor
.SelectTaxonDialog
;
29 import eu
.etaxonomy
.taxeditor
.model
.NameEditorInput
;
30 import eu
.etaxonomy
.taxeditor
.operations
.MoveTaxonOperation
;
37 public class MoveTaxonDialogAction
extends Action
{
38 private static final Logger logger
= Logger
39 .getLogger(MoveTaxonDialogAction
.class);
41 private static String text
= "Move this taxon to a new parent";
42 private static ImageDescriptor image
= TaxEditorPlugin
.getDefault()
43 .getImageRegistry().getDescriptor(ITaxEditorConstants
.MOVE_ICON
);
45 public MoveTaxonDialogAction() {
51 Taxon taxon
= EditorController
.getActiveEditor().getTaxon();
52 IEditorPart editor
= null;
55 // TODO? Prompt user "Would you like to save?" before showing dialog
56 // "Cancel" cancels action - "No" does not
57 if (EditorController
.save(taxon
, true) == false) {
61 // Get destination taxon from dialog
62 SelectTaxonDialog dialog
= new SelectTaxonDialog(GlobalController
.getShell(),
63 SelectTaxonDialog
.TAXON_TO_NEW_PARENT
);
64 Taxon destinationTaxon
= dialog
.open(taxon
);
66 // Abort action if user cancelled dialog without choosing a taxon
67 if (destinationTaxon
== null) {
72 IUndoableOperation operation
= new MoveTaxonOperation(this.getText(),
73 GlobalController
.getWorkbenchUndoContext(), taxon
, destinationTaxon
);
75 GlobalController
.executeOperation(operation
);
77 // For some reason, old parent is not getting the hint that one of its children is gone
78 // new SaveTaxonAction(oldParent).run();
79 // new SaveTaxonAction(destinationTaxon).run();