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
.navigation
.navigator
.handler
;
12 import java
.util
.ArrayList
;
13 import java
.util
.HashSet
;
14 import java
.util
.Iterator
;
15 import java
.util
.List
;
17 import java
.util
.UUID
;
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
.IWorkbenchPage
;
25 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
27 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
28 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
30 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
31 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigator
;
32 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.MoveTaxonOperation
;
33 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
34 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
35 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
36 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
39 * <p>MoveTaxonHandler class.</p>
45 public class MoveTaxonHandler
extends AbstractHandler
implements IPostOperationEnabled
{
47 private TaxonNode parentTaxonNode
;
48 protected IWorkbenchPage activePage
;
50 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
54 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
55 activePage
= HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage();
56 TaxonNavigator taxonNavigator
= (TaxonNavigator
)NavigationUtil
.showView(TaxonNavigator
.ID
);
58 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
60 Iterator selectionIterator
= selection
.iterator();
61 Set
<TaxonNode
> taxonNodes
= new HashSet
<TaxonNode
>();
62 TaxonNode taxonNode
= null;
63 Set
<UUID
> taxonNodeUUIDs
= new HashSet
<UUID
>();
64 // do not show the current selection
65 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
67 //if (selection.size() == 1){
69 while (selectionIterator
.hasNext()){
70 Object object
= selectionIterator
.next();
71 if(object
instanceof TaxonNode
){
72 taxonNode
= HibernateProxyHelper
.deproxy(object
,TaxonNode
.class);
73 taxonNodes
.add(taxonNode
);
74 taxonNodeUUIDs
.add(taxonNode
.getUuid());
75 excludeTaxa
.add(taxonNode
.getTaxon().getUuid());
79 if( MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){
85 // TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
86 if (taxonNodes
.size() >= 1){
87 boolean moveToNewParent
= true;
88 if (PreferencesUtil
.getSortNodesNaturally()){
89 if(!MessageDialog
.openQuestion(null, "Target node", "The choosen target node should be the parent?")){
90 moveToNewParent
= false;
92 parentTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
), taxonNavigator
.getConversationHolder(), "Choose the taxon above the moved taxon.", excludeTaxa
, null, null);
94 parentTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
), taxonNavigator
.getConversationHolder(), "Choose new parent", excludeTaxa
, null, null);
96 if(parentTaxonNode
!= null){
97 if(NavigationUtil
.isDirty(parentTaxonNode
)){
98 MessageDialog
.openWarning(HandlerUtil
.getActiveShell(event
), "Unsaved Parent Taxon", "There are unsaved " +
99 "changes in the parent taxon. Please save first.");
103 AbstractPostOperation operation
= new MoveTaxonOperation
104 ("Move taxon to new parent", NavigationUtil
.getUndoContext(),
105 taxonNodeUUIDs
, parentTaxonNode
, taxonNavigator
, taxonNavigator
, moveToNewParent
); //$NON-NLS-1$
106 NavigationUtil
.executeOperation(operation
);
107 taxonNavigator
.refresh();
115 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
119 public boolean postOperation(CdmBase objectAffectedByOperation
) {
129 public boolean onComplete() {