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
.store
.CdmStore
;
45 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
48 * <p>MoveTaxonHandler class.</p>
54 public class MoveTaxonHandler
extends AbstractHandler
implements IPostOperationEnabled
{
56 private TaxonNode parentTaxonNode
;
57 protected IWorkbenchPage activePage
;
59 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
62 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
63 activePage
= HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage();
64 TaxonNavigator taxonNavigator
= (TaxonNavigator
)NavigationUtil
.showView(TaxonNavigator
.ID
);
66 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
68 Iterator selectionIterator
= selection
.iterator();
69 TaxonNode taxonNode
= null;
70 UUID taxonNodeUUID
= null;
71 // do not show the current selection
72 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
74 if (selection
.size() == 1){
75 Object object
= selectionIterator
.next();
76 if(object
instanceof TaxonNode
){
77 taxonNode
= HibernateProxyHelper
.deproxy(object
,TaxonNode
.class);
78 taxonNodeUUID
= taxonNode
.getUuid();
79 excludeTaxa
.add(taxonNode
.getTaxon().getUuid());
82 if( MessageDialog
.openConfirm(HandlerUtil
.getActiveShell(event
), "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){
88 // TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
89 if (taxonNode
!= 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
); //$NON-NLS-1$
102 NavigationUtil
.executeOperation(operation
);
103 taxonNavigator
.refresh();
111 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
114 public boolean postOperation(CdmBase objectAffectedByOperation
) {
123 public boolean onComplete() {