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.navigator.handler;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.Iterator;
|
15
|
import java.util.List;
|
16
|
import java.util.Set;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import org.eclipse.core.commands.AbstractHandler;
|
20
|
import org.eclipse.core.commands.ExecutionEvent;
|
21
|
import org.eclipse.core.commands.ExecutionException;
|
22
|
import org.eclipse.jface.dialogs.MessageDialog;
|
23
|
import org.eclipse.jface.viewers.TreeSelection;
|
24
|
import org.eclipse.ui.handlers.HandlerUtil;
|
25
|
|
26
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
27
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
28
|
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
|
29
|
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
|
30
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
|
31
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
32
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
33
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
|
34
|
|
35
|
/**
|
36
|
* <p>MoveTaxonHandler class.</p>
|
37
|
*
|
38
|
* @author n.hoffmann
|
39
|
* @created 01.04.2009
|
40
|
* @version 1.0
|
41
|
*/
|
42
|
public class MoveTaxonHandler extends AbstractHandler implements IPostOperationEnabled {
|
43
|
|
44
|
private TaxonNode parentTaxonNode;
|
45
|
|
46
|
/* (non-Javadoc)
|
47
|
* @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
|
48
|
*/
|
49
|
/** {@inheritDoc} */
|
50
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
51
|
TaxonNavigator taxonNavigator = NavigationUtil.showNavigator();
|
52
|
|
53
|
TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
|
54
|
|
55
|
Iterator selectionIterator = selection.iterator();
|
56
|
Set<TaxonNode> taxonNodes = new HashSet<TaxonNode>();
|
57
|
// do not show the current selection
|
58
|
List<UUID> excludeTaxa = new ArrayList<UUID>();
|
59
|
|
60
|
|
61
|
while (selectionIterator.hasNext()){
|
62
|
Object object = selectionIterator.next();
|
63
|
if(object instanceof TaxonNode){
|
64
|
TaxonNode taxonNode = (TaxonNode) object;
|
65
|
taxonNodes.add(taxonNode);
|
66
|
excludeTaxa.add(taxonNode.getTaxon().getUuid());
|
67
|
}
|
68
|
}
|
69
|
|
70
|
// TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
|
71
|
|
72
|
parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), taxonNavigator.getConversationHolder(), "Choose new parent", excludeTaxa, null, null);
|
73
|
|
74
|
if(parentTaxonNode != null){
|
75
|
if(NavigationUtil.isDirty(parentTaxonNode)){
|
76
|
MessageDialog.openWarning(HandlerUtil.getActiveShell(event), "Unsaved Parent Taxon", "There are unsaved " +
|
77
|
"changes in the parent taxon. Please save first.");
|
78
|
return null;
|
79
|
}
|
80
|
|
81
|
AbstractPostOperation operation = new MoveTaxonOperation
|
82
|
("Move taxon to new parent", NavigationUtil.getUndoContext(),
|
83
|
taxonNodes, parentTaxonNode, this, taxonNavigator); //$NON-NLS-1$
|
84
|
NavigationUtil.executeOperation(operation);
|
85
|
|
86
|
}
|
87
|
|
88
|
return null;
|
89
|
}
|
90
|
|
91
|
/* (non-Javadoc)
|
92
|
* @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
|
93
|
*/
|
94
|
/** {@inheritDoc} */
|
95
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
96
|
return true;
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* <p>onComplete</p>
|
101
|
*
|
102
|
* @return a boolean.
|
103
|
*/
|
104
|
public boolean onComplete() {
|
105
|
return false;
|
106
|
}
|
107
|
|
108
|
}
|