Project

General

Profile

Download (2.22 KB) Statistics
| Branch: | Tag: | Revision:
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.navigation.handler;
11

    
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;
20

    
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;
25

    
26
/**
27
 * @author n.hoffmann
28
 * @created 01.04.2009
29
 * @version 1.0
30
 */
31
public class MoveTaxonHandler extends AbstractHandler {
32
	private static final Logger logger = Logger
33
			.getLogger(MoveTaxonHandler.class);
34

    
35
	/* (non-Javadoc)
36
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
37
	 */
38
	public Object execute(ExecutionEvent event) throws ExecutionException {
39
		Shell shell = NavigationUtil.getShell();
40
		Taxon taxon = (Taxon) NavigationUtil.getCurrentSelection(event);
41
		
42
		Dialog dialog = new TaxonSearchDialog(shell);
43
        Object value = ((TaxonSearchDialog) dialog).open();
44
        
45
        logger.warn("child " +taxon.toString());
46
        logger.warn("parent " + ((Taxon) value).toString());
47
        
48
		if (value instanceof Taxon) {
49
			Taxon parentTaxon = (Taxon) value;
50
			
51
			if(NavigationUtil.isDirty(parentTaxon)){
52
				MessageDialog.openWarning(shell, "Unsaved Parent Taxon", "There are unsaved " +
53
						"changes in the parent taxon. Pleas save first.");
54
				return null;
55
			}
56
			
57
			IUndoableOperation operation = new MoveTaxonOperation
58
					("Move taxon to new parent", NavigationUtil.getUndoContext(), 
59
								taxon, parentTaxon); //$NON-NLS-1$
60
			NavigationUtil.executeOperation(operation);
61
		} else {
62
			logger.warn("TaxonSearchDialog did not return a Taxon object.");
63
		}
64
		
65
		return null;
66
	}
67
}
(4-4/6)