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
.application
.CdmApplicationState
;
26 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
27 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonNodeDeletionConfigurator
;
28 import eu
.etaxonomy
.cdm
.api
.service
.config
.NodeDeletionConfigurator
.ChildHandling
;
29 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
31 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
32 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
33 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
34 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
35 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
36 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingDeleteTaxonNodeOperation
;
37 import eu
.etaxonomy
.taxeditor
.operation
.RemotingCdmHandler
;
38 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.deleteConfigurator
.DeleteConfiguratorDialog
;
45 public class RemotingDeleteTaxonNodeHandler
extends RemotingCdmHandler
{
47 private TaxonDeletionConfigurator config
;
48 private Set
<ITaxonTreeNode
> treeNodes
;
53 public RemotingDeleteTaxonNodeHandler() {
54 super(TaxonNavigatorLabels
.DELETE_TAXON_NODE_LABEL
);
58 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#allowOperations(org.eclipse.core.commands.ExecutionEvent)
61 public IStatus
allowOperations(ExecutionEvent event
) {
62 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
64 Iterator selectionIterator
= selection
.iterator();
65 treeNodes
= new HashSet
<ITaxonTreeNode
>();
67 while (selectionIterator
.hasNext()){
68 Object object
= selectionIterator
.next();
69 if(object
instanceof ITaxonTreeNode
) {
70 treeNodes
.add((ITaxonTreeNode
) object
);
73 boolean allEditorsClosed
= true;
74 IWorkbenchPage activePage
= HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage();
75 for (ITaxonTreeNode treeNode
: treeNodes
) {
76 if(treeNode
instanceof TaxonNode
) {
77 allEditorsClosed
&= EditorUtil
.closeObsoleteEditor((TaxonNode
) treeNode
, activePage
);
80 if(!allEditorsClosed
) {
81 return new Status(IStatus
.WARNING
,
83 TaxonNavigatorLabels
.RELATED_EDITOR_NOT_CLOSED_MESSAGE
);
86 config
= new TaxonDeletionConfigurator();
88 if (treeNodes
.size() == 1 ){
89 ITaxonTreeNode treeNode
= treeNodes
.iterator().next();
90 ITaxonTreeNode taxonNode
= treeNode
;
91 if (taxonNode
instanceof Classification
){
92 taxonNode
= CdmApplicationState
.getCurrentAppConfig().getClassificationService().load(taxonNode
.getUuid());
94 taxonNode
= CdmApplicationState
.getCurrentAppConfig().getTaxonNodeService().load(taxonNode
.getUuid());
96 if (taxonNode
== null){
97 MessagingUtils
.informationDialog("Node already deleted", "The taxon node was already deleted. Please reopen the taxon navigator to refresh the view.");
98 return Status
.CANCEL_STATUS
;
101 TaxonNodeDeletionConfigurator configNodes
= new TaxonNodeDeletionConfigurator();
102 if (taxonNode
instanceof Classification
&& taxonNode
.hasChildNodes()){
103 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.")){
104 return Status
.CANCEL_STATUS
;
106 } else if (taxonNode
instanceof Classification
&& !taxonNode
.hasChildNodes()){
107 if(!DeleteConfiguratorDialog
.openConfirmWithConfigurator(config
, HandlerUtil
.getActiveShell(event
), "Confirm Deletion", "Do you really want to delete the classification?")){
108 return Status
.CANCEL_STATUS
;
112 if (taxonNode
.hasChildNodes()){
113 DeleteConfiguratorDialog dialog
= new DeleteConfiguratorDialog(
115 HandlerUtil
.getActiveShell(event
),
118 "Do you really want to delete the selected node? It has childnodes, they will be deleted, too.",
119 MessageDialog
.WARNING
, new String
[] { "Delete all children",
120 "Move children to parent node", "Skip" }, 0);
121 int result
= dialog
.open();
124 //delete all children
125 configNodes
.setChildHandling(ChildHandling
.DELETE
);
126 config
.setTaxonNodeConfig(configNodes
);
127 } else if (result
== 1){
129 configNodes
.setChildHandling(ChildHandling
.MOVE_TO_PARENT
);
130 config
.setTaxonNodeConfig(configNodes
);
131 } else if (result
== 2){
132 return Status
.CANCEL_STATUS
;
135 if(!DeleteConfiguratorDialog
.openConfirmWithConfigurator(configNodes
, HandlerUtil
.getActiveShell(event
), "Confirm Deletion", "Do you really want to delete the selected node?")){
136 return Status
.CANCEL_STATUS
;
138 config
.setTaxonNodeConfig(configNodes
);
142 return Status
.OK_STATUS
;
146 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#prepareOperation(org.eclipse.core.commands.ExecutionEvent)
149 public AbstractOperation
prepareOperation(ExecutionEvent event
) {
150 return new RemotingDeleteTaxonNodeOperation(event
.getTrigger(),
157 * @see eu.etaxonomy.taxeditor.operation.RemotingCdmHandler#onComplete()
160 public void onComplete() {
161 // TODO Auto-generated method stub