Delete unused method
[taxeditor.git] / eu.etaxonomy.taxeditor.navigation / src / main / java / eu / etaxonomy / taxeditor / navigation / navigator / handler / MoveTaxonHandler.java
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.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 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;
26
27 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
28 import eu.etaxonomy.cdm.model.common.CdmBase;
29 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
30 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
31 import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigator;
32 import eu.etaxonomy.taxeditor.navigation.navigator.operation.MoveTaxonOperation;
33 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
34 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
35 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
36 import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
37
38 /**
39 * <p>MoveTaxonHandler class.</p>
40 *
41 * @author n.hoffmann
42 * @created 01.04.2009
43 * @version 1.0
44 */
45 public class MoveTaxonHandler extends AbstractHandler implements IPostOperationEnabled {
46
47 private TaxonNode parentTaxonNode;
48 protected IWorkbenchPage activePage;
49 /* (non-Javadoc)
50 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
51 */
52 /** {@inheritDoc} */
53 @Override
54 public Object execute(ExecutionEvent event) throws ExecutionException {
55 activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
56 TaxonNavigator taxonNavigator = (TaxonNavigator)NavigationUtil.showView(TaxonNavigator.ID);
57
58 TreeSelection selection = (TreeSelection) HandlerUtil.getCurrentSelection(event);
59
60 Iterator selectionIterator = selection.iterator();
61 Set<TaxonNode> taxonNodes = new HashSet<TaxonNode>();
62 TaxonNode taxonNode= null;
63 Set<UUID> taxonNodeUUIDs = new HashSet<UUID>();
64 // do not show the current selection
65 List<UUID> excludeTaxa = new ArrayList<UUID>();
66
67 //if (selection.size() == 1){
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 /*} else{
79 if( MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Moving taxon", "The operation move accepted taxon to other parent is available only for a single taxon.")){
80 return null;
81 }
82 }*/
83
84
85 // TaxonNode taxonNode = (TaxonNode) selection.getFirstElement();
86 if (taxonNodes.size() >= 1){
87 boolean moveToNewParent = true;
88 if (PreferencesUtil.getSortNodesNaturally()){
89 if(!MessageDialog.openQuestion(null, "Target node", "The choosen target node should be the parent?")){
90 moveToNewParent = false;
91 }
92 parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), taxonNavigator.getConversationHolder(), "Choose the taxon above the moved taxon.", excludeTaxa, null, null);
93 }else{
94 parentTaxonNode = TaxonNodeSelectionDialog.select(HandlerUtil.getActiveShell(event), taxonNavigator.getConversationHolder(), "Choose new parent", excludeTaxa, null, null);
95 }
96 if(parentTaxonNode != null){
97 if(NavigationUtil.isDirty(parentTaxonNode)){
98 MessageDialog.openWarning(HandlerUtil.getActiveShell(event), "Unsaved Parent Taxon", "There are unsaved " +
99 "changes in the parent taxon. Please save first.");
100 return null;
101 }
102
103 AbstractPostOperation operation = new MoveTaxonOperation
104 ("Move taxon to new parent", NavigationUtil.getUndoContext(),
105 taxonNodeUUIDs, parentTaxonNode, taxonNavigator, taxonNavigator, moveToNewParent); //$NON-NLS-1$
106 NavigationUtil.executeOperation(operation);
107 taxonNavigator.refresh();
108
109 }
110 }
111 return null;
112 }
113
114 /* (non-Javadoc)
115 * @see eu.etaxonomy.taxeditor.operations.IPostOperationEnabled#postOperation(eu.etaxonomy.cdm.model.common.CdmBase)
116 */
117 /** {@inheritDoc} */
118 @Override
119 public boolean postOperation(CdmBase objectAffectedByOperation) {
120 return true;
121 }
122
123 /**
124 * <p>onComplete</p>
125 *
126 * @return a boolean.
127 */
128 @Override
129 public boolean onComplete() {
130 return false;
131 }
132
133
134
135 }