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
.e4
.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 javax
.inject
.Named
;
21 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
22 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
23 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
24 import org
.eclipse
.jface
.viewers
.TreeSelection
;
25 import org
.eclipse
.swt
.widgets
.Shell
;
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
.model
.AbstractUtility
;
32 import eu
.etaxonomy
.taxeditor
.navigation
.NavigationUtil
;
33 import eu
.etaxonomy
.taxeditor
.navigation
.l10n
.Messages
;
34 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TreeNodeDropAdapter
.MovingType
;
35 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.e4
.TaxonNavigatorE4
;
36 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.MoveTaxonOperation
;
37 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
38 import eu
.etaxonomy
.taxeditor
.operation
.IPostOperationEnabled
;
39 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
40 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.TaxonNodeSelectionDialog
;
48 public class MoveTaxonHandlerE4
implements IPostOperationEnabled
{
50 private TaxonNode parentTaxonNode
;
52 public void execute(@Named(IServiceConstants
.ACTIVE_SELECTION
)TreeSelection selection
,
53 @Named(IServiceConstants
.ACTIVE_SHELL
)Shell shell
,
54 @Named(IServiceConstants
.ACTIVE_PART
)MPart activePart
) {
56 TaxonNavigatorE4 taxonNavigator
= (TaxonNavigatorE4
) activePart
.getObject();
58 Iterator
<?
> selectionIterator
= selection
.iterator();
59 Set
<TaxonNode
> taxonNodes
= new HashSet
<TaxonNode
>();
60 TaxonNode taxonNode
= null;
61 Set
<UUID
> taxonNodeUUIDs
= new HashSet
<UUID
>();
62 // do not show the current selection
63 List
<UUID
> excludeTaxa
= new ArrayList
<UUID
>();
65 while (selectionIterator
.hasNext()){
66 Object object
= selectionIterator
.next();
67 if(object
instanceof TaxonNode
){
68 taxonNode
= HibernateProxyHelper
.deproxy(object
,TaxonNode
.class);
69 taxonNodes
.add(taxonNode
);
70 taxonNodeUUIDs
.add(taxonNode
.getUuid());
71 excludeTaxa
.add(taxonNode
.getTaxon().getUuid());
76 if (taxonNodes
.size() >= 1){
77 Classification classification
= taxonNodes
.iterator().next().getClassification();
78 MovingType moveToNewParent
= MovingType
.CHILD
;
79 if (PreferencesUtil
.getSortNodesNaturally()){
80 if(!MessageDialog
.openQuestion(null, Messages
.MoveTaxonHandler_TARGET_NODE
, Messages
.MoveTaxonHandler_TARGET_NODE_MESSAGE
)){
81 moveToNewParent
= MovingType
.BEHIND
;
83 parentTaxonNode
= TaxonNodeSelectionDialog
.select(shell
, taxonNavigator
.getConversationHolder(), Messages
.MoveTaxonHandler_CHOOSE_ABOVE
, excludeTaxa
, null, classification
);
85 parentTaxonNode
= TaxonNodeSelectionDialog
.select(shell
, taxonNavigator
.getConversationHolder(), Messages
.MoveTaxonHandler_CHOOSE_PARENT
, excludeTaxa
, null, classification
);
87 if(parentTaxonNode
!= null){
88 if(NavigationUtil
.isDirty(parentTaxonNode
)){
89 MessageDialog
.openWarning(shell
, Messages
.MoveTaxonHandler_UNSAVED_PARENT
, Messages
.MoveTaxonHandler_UNSAVED_PARENT_MESSAGE
);
93 AbstractPostOperation
<?
> operation
= new MoveTaxonOperation
94 (Messages
.MoveTaxonHandler_MOVE_TO_PARENT
, NavigationUtil
.getUndoContext(), taxonNodeUUIDs
, parentTaxonNode
, taxonNavigator
, taxonNavigator
, moveToNewParent
); //$NON-NLS-1$
95 AbstractUtility
.executeOperation(operation
);
96 taxonNavigator
.refresh();
104 public boolean postOperation(CdmBase objectAffectedByOperation
) {
109 public boolean onComplete() {