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
.Classification
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
31 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
32 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigator
;
33 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TreeNodeDropAdapter
.MovingType
;
34 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.MoveTaxonOperation
;
35 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
36 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
37 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
38 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
41 * <p>MoveTaxonHandler class.</p>
47 public class MoveTaxonHandler
extends AbstractHandler
implements IPostOperationEnabled
{
49 private TaxonNode parentTaxonNode
;
50 protected IWorkbenchPage activePage
;
52 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
56 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
57 activePage
= HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage();
58 TaxonNavigator taxonNavigator
= (TaxonNavigator
)NavigationUtil
.showView(TaxonNavigator
.ID
);
60 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
62 Iterator selectionIterator
= selection
.iterator();
63 Set
<TaxonNode
> taxonNodes
= new HashSet
<TaxonNode
>();
64 TaxonNode taxonNode
= null;
65 Set
<UUID
> taxonNodeUUIDs
= new HashSet
<UUID
>();
66 // do not show the current selection
67 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
69 //if (selection.size() == 1){
71 while (selectionIterator
.hasNext()){
72 Object object
= selectionIterator
.next();
73 if(object
instanceof TaxonNode
){
74 taxonNode
= HibernateProxyHelper
.deproxy(object
,TaxonNode
.class);
75 taxonNodes
.add(taxonNode
);
76 taxonNodeUUIDs
.add(taxonNode
.getUuid());
77 excludeTaxa
.add(taxonNode
.getTaxon().getUuid());
81 if( MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){
87 // TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
88 if (taxonNodes
.size() >= 1){
89 Classification classification
= taxonNodes
.iterator().next().getClassification();
90 MovingType moveToNewParent
= MovingType
.CHILD
;
91 if (PreferencesUtil
.getSortNodesNaturally()){
92 if(!MessageDialog
.openQuestion(null, "Target node", "The choosen target node should be the parent?")){
93 moveToNewParent
= MovingType
.BEHIND
;
95 parentTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
), taxonNavigator
.getConversationHolder(), "Choose the taxon above the moved taxon.", excludeTaxa
, null, classification
);
97 parentTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
), taxonNavigator
.getConversationHolder(), "Choose new parent", excludeTaxa
, null, classification
);
99 if(parentTaxonNode
!= null){
100 if(NavigationUtil
.isDirty(parentTaxonNode
)){
101 MessageDialog
.openWarning(HandlerUtil
.getActiveShell(event
), "Unsaved Parent Taxon", "There are unsaved " +
102 "changes in the parent taxon. Please save first.");
107 AbstractPostOperation operation
= new MoveTaxonOperation
108 ("Move taxon to new parent", NavigationUtil
.getUndoContext(),
109 taxonNodeUUIDs
, parentTaxonNode
, taxonNavigator
, taxonNavigator
, moveToNewParent
); //$NON-NLS-1$
110 NavigationUtil
.executeOperation(operation
);
111 taxonNavigator
.refresh();
119 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
123 public boolean postOperation(CdmBase objectAffectedByOperation
) {
133 public boolean onComplete() {