2b58358a42334e89f19e3ecc4bc15a48fd1261aa
[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.jface.action.Action;
14 import org.eclipse.jface.resource.ImageDescriptor;
15 import org.eclipse.swt.widgets.Shell;
16 import org.eclipse.ui.IEditorInput;
17 import org.eclipse.ui.IEditorPart;
18 import org.eclipse.ui.PartInitException;
19
20 import eu.etaxonomy.cdm.model.taxon.Taxon;
21 import eu.etaxonomy.taxeditor.ITaxEditorConstants;
22 import eu.etaxonomy.taxeditor.TaxEditorPlugin;
23 import eu.etaxonomy.taxeditor.UiUtil;
24 import eu.etaxonomy.taxeditor.actions.cdm.MoveTaxonAction;
25 import eu.etaxonomy.taxeditor.editor.SelectTaxonDialog;
26 import eu.etaxonomy.taxeditor.model.NameEditorInput;
27
28 /**
29 * @author p.ciardelli
30 * @created 26.05.2008
31 * @version 1.0
32 */
33 public class MoveTaxonDialogAction extends Action {
34 private static final Logger logger = Logger
35 .getLogger(MoveTaxonDialogAction.class);
36
37 private static String text = "Move this taxon to a new parent";
38 private ImageDescriptor image = TaxEditorPlugin.getDefault()
39 .getImageRegistry().getDescriptor(ITaxEditorConstants.MOVE_ICON);
40
41 private Taxon taxon;
42
43 private MoveTaxonDialogAction() {
44 super(text);
45 setImageDescriptor(image);
46 }
47
48 public MoveTaxonDialogAction(Taxon taxon) {
49 this();
50 this.taxon = taxon;
51 }
52
53 public void run() {
54
55 IEditorPart editor = null;
56
57 try {
58 // Prompt user "Would you like to save?" before showing dialog
59 // "Cancel" cancels action - "No" does not
60 IEditorInput editorInput = new NameEditorInput(taxon);
61 editor = UiUtil.getEditorByInput(editorInput);
62 if (UiUtil.getActivePage().saveEditor(editor, true) == false) {
63 return;
64 }
65 } catch (PartInitException e1) {
66 e1.printStackTrace();
67 }
68
69 // Get destination taxon from dialog
70 Shell shell = UiUtil.getShell();
71 SelectTaxonDialog dialog = new SelectTaxonDialog(shell, SelectTaxonDialog.TAXON_TO_NEW_PARENT);
72 Taxon destinationTaxon = dialog.open(taxon);
73
74 // Abort action if user cancelled dialog without choosing a taxon
75 if (destinationTaxon == null) {
76 return;
77 }
78
79 // Move taxon in CDM
80 // Taxon oldParent = taxon.getTaxonomicParent();
81 new MoveTaxonAction(taxon, destinationTaxon).run();
82
83 // For some reason, old parent is not getting the hint that one of its children is gone
84 // new SaveTaxonAction(oldParent).run();
85 // new SaveTaxonAction(destinationTaxon).run();
86
87 editor.doSave(null);
88 }
89 }