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
.core
.expressions
.EvaluationContext
;
23 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
24 import org
.eclipse
.jface
.viewers
.TreeSelection
;
25 import org
.eclipse
.ui
.IEditorInput
;
26 import org
.eclipse
.ui
.IEditorReference
;
27 import org
.eclipse
.ui
.IWorkbenchPage
;
28 import org
.eclipse
.ui
.PartInitException
;
29 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
31 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
32 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
33 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
34 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
35 import eu
.etaxonomy
.cdm
.model
.common
.ITreeNode
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
38 import eu
.etaxonomy
.taxeditor
.editor
.TaxonEditorInput
;
39 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
40 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigator
;
41 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.MoveTaxonOperation
;
42 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
43 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
44 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
45 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
46 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
47 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionNaturalOrderDialog
;
50 * <p>MoveTaxonHandler class.</p>
56 public class MoveTaxonHandler
extends AbstractHandler
implements IPostOperationEnabled
{
58 private TaxonNode parentTaxonNode
;
59 protected IWorkbenchPage activePage
;
61 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
64 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
65 activePage
= HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage();
66 TaxonNavigator taxonNavigator
= (TaxonNavigator
)NavigationUtil
.showView(TaxonNavigator
.ID
);
68 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
70 Iterator selectionIterator
= selection
.iterator();
71 TaxonNode taxonNode
= null;
72 UUID taxonNodeUUID
= null;
73 // do not show the current selection
74 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
76 if (selection
.size() == 1){
77 Object object
= selectionIterator
.next();
78 if(object
instanceof TaxonNode
){
79 taxonNode
= HibernateProxyHelper
.deproxy(object
,TaxonNode
.class);
80 taxonNodeUUID
= taxonNode
.getUuid();
81 excludeTaxa
.add(taxonNode
.getTaxon().getUuid());
84 if( MessageDialog
.openConfirm(HandlerUtil
.getActiveShell(event
), "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){
90 // TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
91 if (taxonNode
!= null){
92 boolean moveToNewParent
= true;
93 if (PreferencesUtil
.getSortNodesNaturally()){
94 if(!MessageDialog
.openQuestion(null, "Target node", "The choosen target node should be the parent?")){
95 moveToNewParent
= false;
97 parentTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
), taxonNavigator
.getConversationHolder(), "Choose the taxon above the moved taxon.", excludeTaxa
, null, null);
99 parentTaxonNode
= TaxonNodeSelectionDialog
.select(HandlerUtil
.getActiveShell(event
), taxonNavigator
.getConversationHolder(), "Choose new parent", excludeTaxa
, null, null);
101 if(parentTaxonNode
!= null){
102 if(NavigationUtil
.isDirty(parentTaxonNode
)){
103 MessageDialog
.openWarning(HandlerUtil
.getActiveShell(event
), "Unsaved Parent Taxon", "There are unsaved " +
104 "changes in the parent taxon. Please save first.");
108 AbstractPostOperation operation
= new MoveTaxonOperation
109 ("Move taxon to new parent", NavigationUtil
.getUndoContext(),
110 taxonNode
, parentTaxonNode
, taxonNavigator
, taxonNavigator
, moveToNewParent
); //$NON-NLS-1$
111 NavigationUtil
.executeOperation(operation
);
112 taxonNavigator
.refresh();
120 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
123 public boolean postOperation(CdmBase objectAffectedByOperation
) {
132 public boolean onComplete() {