started to refactor action delegation
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / actions / ui / MoveTaxonDialogAction.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9
10 package eu.etaxonomy.taxeditor.actions.ui;
11
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;
21
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;
31
32 /**
33 * @author p.ciardelli
34 * @created 26.05.2008
35 * @version 1.0
36 */
37 public class MoveTaxonDialogAction extends Action {
38 private static final Logger logger = Logger
39 .getLogger(MoveTaxonDialogAction.class);
40
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);
44
45 public MoveTaxonDialogAction() {
46 super(text, image);
47 }
48
49 public void run() {
50
51 Taxon taxon = EditorController.getActiveEditor().getTaxon();
52 IEditorPart editor = null;
53
54
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) {
58 return;
59 }
60
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);
65
66 // Abort action if user cancelled dialog without choosing a taxon
67 if (destinationTaxon == null) {
68 return;
69 }
70
71 // Move taxon in CDM
72 IUndoableOperation operation = new MoveTaxonOperation(this.getText(),
73 GlobalController.getWorkbenchUndoContext(), taxon, destinationTaxon);
74
75 GlobalController.executeOperation(operation);
76
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();
80
81 editor.doSave(null);
82 }
83 }