1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.navigation.navigator.e4.handler;
|
11
|
|
12
|
import java.util.ArrayList;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.Iterator;
|
15
|
import java.util.List;
|
16
|
import java.util.Set;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import javax.inject.Named;
|
20
|
|
21
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
22
|
import org.eclipse.e4.core.di.annotations.Execute;
|
23
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
24
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
25
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
26
|
import org.eclipse.jface.dialogs.MessageDialog;
|
27
|
import org.eclipse.jface.viewers.TreeSelection;
|
28
|
import org.eclipse.swt.widgets.Shell;
|
29
|
|
30
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
31
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
32
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
33
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
34
|
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
35
|
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
|
36
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
37
|
import eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapter.MovingType;
|
38
|
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TaxonNavigatorE4;
|
39
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
|
40
|
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
|
41
|
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
|
42
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
43
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
|
44
|
|
45
|
/**
|
46
|
*
|
47
|
* @author pplitzner
|
48
|
* @date 05.09.2017
|
49
|
*
|
50
|
*/
|
51
|
public class MoveTaxonHandlerE4 implements IPostOperationEnabled {
|
52
|
|
53
|
private TaxonNode parentTaxonNode;
|
54
|
|
55
|
@Execute
|
56
|
public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection,
|
57
|
@Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
|
58
|
@Named(IServiceConstants.ACTIVE_PART)MPart activePart) {
|
59
|
|
60
|
TaxonNavigatorE4 taxonNavigator = (TaxonNavigatorE4) activePart.getObject();
|
61
|
|
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>();
|
68
|
|
69
|
while (selectionIterator.hasNext()){
|
70
|
Object object = selectionIterator.next();
|
71
|
if(object instanceof TaxonNode){
|
72
|
taxonNode = HibernateProxyHelper.deproxy(object,TaxonNode.class);
|
73
|
taxonNodes.add(taxonNode);
|
74
|
taxonNodeUUIDs.add(taxonNode.getUuid());
|
75
|
excludeTaxa.add(taxonNode.getTaxon().getUuid());
|
76
|
}
|
77
|
}
|
78
|
|
79
|
|
80
|
if (taxonNodes.size() >= 1){
|
81
|
Classification classification = taxonNodes.iterator().next().getClassification();
|
82
|
MovingType moveToNewParent = MovingType.CHILD;
|
83
|
if (PreferencesUtil.getSortNodesNaturally()){
|
84
|
if(!MessageDialog.openQuestion(null, Messages.MoveTaxonHandler_TARGET_NODE, Messages.MoveTaxonHandler_TARGET_NODE_MESSAGE)){
|
85
|
moveToNewParent = MovingType.BEHIND;
|
86
|
}
|
87
|
parentTaxonNode = TaxonNodeSelectionDialog.select(shell, taxonNavigator.getConversationHolder(), Messages.MoveTaxonHandler_CHOOSE_ABOVE, excludeTaxa, null, classification);
|
88
|
}else{
|
89
|
parentTaxonNode = TaxonNodeSelectionDialog.select(shell, taxonNavigator.getConversationHolder(), Messages.MoveTaxonHandler_CHOOSE_PARENT, excludeTaxa, null, classification);
|
90
|
}
|
91
|
if(parentTaxonNode != null){
|
92
|
if(NavigationUtil.isDirty(parentTaxonNode)){
|
93
|
MessageDialog.openWarning(shell, Messages.MoveTaxonHandler_UNSAVED_PARENT, Messages.MoveTaxonHandler_UNSAVED_PARENT_MESSAGE);
|
94
|
return;
|
95
|
}
|
96
|
|
97
|
AbstractPostOperation<?> operation = new MoveTaxonOperation
|
98
|
(Messages.MoveTaxonHandler_MOVE_TO_PARENT, NavigationUtil.getUndoContext(), taxonNodeUUIDs, parentTaxonNode, taxonNavigator, taxonNavigator, moveToNewParent); //$NON-NLS-1$
|
99
|
AbstractUtility.executeOperation(operation);
|
100
|
taxonNavigator.refresh();
|
101
|
|
102
|
}
|
103
|
}
|
104
|
}
|
105
|
|
106
|
@CanExecute
|
107
|
private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
|
108
|
boolean canExecute = false;
|
109
|
menuItem.setVisible(canExecute);
|
110
|
canExecute = selection.getFirstElement() instanceof TaxonNode;
|
111
|
return canExecute;
|
112
|
}
|
113
|
|
114
|
/** {@inheritDoc} */
|
115
|
@Override
|
116
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
117
|
return true;
|
118
|
}
|
119
|
|
120
|
@Override
|
121
|
public boolean onComplete() {
|
122
|
return false;
|
123
|
}
|
124
|
|
125
|
}
|