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
.Iterator
;
14 import java
.util
.List
;
15 import java
.util
.UUID
;
17 import org
.eclipse
.core
.commands
.AbstractHandler
;
18 import org
.eclipse
.core
.commands
.ExecutionEvent
;
19 import org
.eclipse
.core
.commands
.ExecutionException
;
20 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
21 import org
.eclipse
.jface
.viewers
.TreeSelection
;
22 import org
.eclipse
.ui
.IWorkbenchPage
;
23 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
25 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
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
.preference
.PreferencesUtil
;
34 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
37 * <p>MoveTaxonHandler class.</p>
43 public class MoveTaxonHandler
extends AbstractHandler
implements IPostOperationEnabled
{
45 private TaxonNode parentTaxonNode
;
46 protected IWorkbenchPage activePage
;
48 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
53 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
54 activePage
= HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage();
55 TaxonNavigator taxonNavigator
= (TaxonNavigator
)NavigationUtil
.showView(TaxonNavigator
.ID
);
57 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
59 Iterator selectionIterator
= selection
.iterator();
60 TaxonNode taxonNode
= null;
61 UUID taxonNodeUUID
= null;
62 // do not show the current selection
63 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
66 if (selection
.size() == 1){
67 Object object
= selectionIterator
.next();
68 if(object
instanceof TaxonNode
){
69 taxonNode
= HibernateProxyHelper
.deproxy(object
,TaxonNode
.class);
70 taxonNodeUUID
= taxonNode
.getUuid();
71 excludeTaxa
.add(taxonNode
.getTaxon().getUuid());
74 if( MessageDialog
.openConfirm(HandlerUtil
.getActiveShell(event
), "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){
81 // TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
82 if (taxonNode
!= null){
83 boolean moveToNewParent
= true;
84 if (PreferencesUtil
.getSortNodesNaturally()){
85 if(!MessageDialog
.openQuestion(null, "Target node", "The choosen target node should be the parent?")){
86 moveToNewParent
= false;
88 parentTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
), taxonNavigator
.getConversationHolder(), "Choose the taxon above the moved taxon.", excludeTaxa
, null, null);
90 parentTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
), taxonNavigator
.getConversationHolder(), "Choose new parent", excludeTaxa
, null, null);
92 if(parentTaxonNode
!= null){
93 if(NavigationUtil
.isDirty(parentTaxonNode
)){
94 MessageDialog
.openWarning(HandlerUtil
.getActiveShell(event
), "Unsaved Parent Taxon", "There are unsaved " +
95 "changes in the parent taxon. Please save first.");
99 AbstractPostOperation operation
= new MoveTaxonOperation
100 ("Move taxon to new parent", NavigationUtil
.getUndoContext(),
101 taxonNode
, parentTaxonNode
, taxonNavigator
, taxonNavigator
, moveToNewParent
); //$NON-NLS-1$
102 NavigationUtil
.executeOperation(operation
);
103 taxonNavigator
.refresh();
112 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
116 public boolean postOperation(CdmBase objectAffectedByOperation
) {
126 public boolean onComplete() {