3 * Copyright (C) 2015 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * 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
.HashSet
;
13 import java
.util
.Iterator
;
16 import org
.eclipse
.core
.commands
.ExecutionEvent
;
17 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
18 import org
.eclipse
.core
.runtime
.IStatus
;
19 import org
.eclipse
.core
.runtime
.Status
;
20 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
21 import org
.eclipse
.jface
.viewers
.TreeSelection
;
22 import org
.eclipse
.ui
.IWorkbenchPage
;
23 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
25 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
26 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonNodeDeletionConfigurator
;
27 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonNodeDeletionConfigurator
.ChildHandling
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
31 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
32 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
33 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingDeleteTaxonNodeOperation
;
34 import eu
.etaxonomy
.taxeditor
.operation
.RemotingCdmHandler
;
35 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.deleteConfigurator
.DeleteConfiguratorDialog
;
42 public class RemotingDeleteTaxonNodeHandler
extends RemotingCdmHandler
{
44 private TaxonDeletionConfigurator config
;
45 private Set
<ITaxonTreeNode
> treeNodes
;
50 public RemotingDeleteTaxonNodeHandler() {
51 super(TaxonNavigatorLabels
.DELETE_TAXON_NODE_LABEL
);
55 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
58 public IStatus
allowOperations(ExecutionEvent event
) {
59 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
61 Iterator selectionIterator
= selection
.iterator();
62 treeNodes
= new HashSet
<ITaxonTreeNode
>();
64 while (selectionIterator
.hasNext()){
65 Object object
= selectionIterator
.next();
66 if(object
instanceof ITaxonTreeNode
) {
67 treeNodes
.add((ITaxonTreeNode
) object
);
70 boolean allEditorsClosed
= true;
71 IWorkbenchPage activePage
= HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage();
72 for (ITaxonTreeNode treeNode
: treeNodes
) {
73 if(treeNode
instanceof TaxonNode
) {
74 allEditorsClosed
&= EditorUtil
.closeObsoleteEditor((TaxonNode
) treeNode
, activePage
);
77 if(!allEditorsClosed
) {
78 return new Status(IStatus
.WARNING
,
80 TaxonNavigatorLabels
.RELATED_EDITOR_NOT_CLOSED_MESSAGE
);
83 config
= new TaxonDeletionConfigurator();
85 if (treeNodes
.size() == 1 ){
87 ITaxonTreeNode treeNode
= treeNodes
.iterator().next();
88 ITaxonTreeNode taxonNode
= treeNode
;
89 TaxonNodeDeletionConfigurator configNodes
= new TaxonNodeDeletionConfigurator();
90 if (taxonNode
instanceof Classification
&& taxonNode
.hasChildNodes()){
91 if(!DeleteConfiguratorDialog
.openConfirmWithConfigurator(config
, HandlerUtil
.getActiveShell(event
), "Confirm Deletion", "Do you really want to delete the classification? The tree has children, they will be deleted, too.")){
92 return Status
.CANCEL_STATUS
;
94 } else if (taxonNode
instanceof Classification
&& !taxonNode
.hasChildNodes()){
95 if(!DeleteConfiguratorDialog
.openConfirmWithConfigurator(config
, HandlerUtil
.getActiveShell(event
), "Confirm Deletion", "Do you really want to delete the classification?")){
96 return Status
.CANCEL_STATUS
;
100 if (taxonNode
.hasChildNodes()){
101 DeleteConfiguratorDialog dialog
= new DeleteConfiguratorDialog(
103 HandlerUtil
.getActiveShell(event
),
106 "Do you really want to delete the selected node? It has childnodes, they will be deleted, too.",
107 MessageDialog
.WARNING
, new String
[] { "Delete all children",
108 "Move children to parent node", "Skip" }, 0);
109 int result
= dialog
.open();
112 //delete all children
113 configNodes
.setChildHandling(ChildHandling
.DELETE
);
114 config
.setTaxonNodeConfig(configNodes
);
115 } else if (result
== 1){
117 configNodes
.setChildHandling(ChildHandling
.MOVE_TO_PARENT
);
118 config
.setTaxonNodeConfig(configNodes
);
119 } else if (result
== 2){
120 return Status
.CANCEL_STATUS
;
123 if(!DeleteConfiguratorDialog
.openConfirmWithConfigurator(config
, HandlerUtil
.getActiveShell(event
), "Confirm Deletion", "Do you really want to delete the selected node?")){
124 return Status
.CANCEL_STATUS
;
129 return Status
.OK_STATUS
;
133 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
136 public AbstractOperation
prepareOperation(ExecutionEvent event
) {
137 return new RemotingDeleteTaxonNodeOperation(event
.getTrigger(),
144 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
147 public void onComplete() {
148 // TODO Auto-generated method stub