2 * Copyright (C) 2015 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.
9 package eu
.etaxonomy
.taxeditor
.navigation
.navigator
.handler
;
11 import java
.util
.HashSet
;
12 import java
.util
.Iterator
;
15 import org
.eclipse
.core
.commands
.ExecutionEvent
;
16 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
17 import org
.eclipse
.core
.runtime
.IStatus
;
18 import org
.eclipse
.core
.runtime
.Status
;
19 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
20 import org
.eclipse
.jface
.viewers
.TreeSelection
;
21 import org
.eclipse
.ui
.IWorkbenchPage
;
22 import org
.eclipse
.ui
.handlers
.HandlerUtil
;
24 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationState
;
25 import eu
.etaxonomy
.cdm
.api
.service
.config
.NodeDeletionConfigurator
.ChildHandling
;
26 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonDeletionConfigurator
;
27 import eu
.etaxonomy
.cdm
.api
.service
.config
.TaxonNodeDeletionConfigurator
;
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
.model
.MessagingUtils
;
33 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.TaxonNavigatorLabels
;
34 import eu
.etaxonomy
.taxeditor
.navigation
.navigator
.operation
.RemotingDeleteTaxonNodeOperation
;
35 import eu
.etaxonomy
.taxeditor
.operation
.RemotingCdmHandler
;
36 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.deleteConfigurator
.DeleteConfiguratorDialog
;
43 public class RemotingDeleteTaxonNodeHandler
extends RemotingCdmHandler
{
45 private TaxonDeletionConfigurator config
;
46 private Set
<ITaxonTreeNode
> treeNodes
;
48 public RemotingDeleteTaxonNodeHandler() {
49 super(TaxonNavigatorLabels
.DELETE_TAXON_NODE_LABEL
);
53 public IStatus
allowOperations(ExecutionEvent event
) {
54 TreeSelection selection
= (TreeSelection
) HandlerUtil
.getCurrentSelection(event
);
56 Iterator
<?
> selectionIterator
= selection
.iterator();
57 treeNodes
= new HashSet
<ITaxonTreeNode
>();
59 while (selectionIterator
.hasNext()){
60 Object object
= selectionIterator
.next();
61 if(object
instanceof ITaxonTreeNode
) {
62 treeNodes
.add((ITaxonTreeNode
) object
);
65 boolean allEditorsClosed
= true;
66 IWorkbenchPage activePage
= HandlerUtil
.getActiveWorkbenchWindow(event
).getActivePage();
67 for (ITaxonTreeNode treeNode
: treeNodes
) {
68 if(treeNode
instanceof TaxonNode
) {
69 allEditorsClosed
&= EditorUtil
.closeObsoleteEditor((TaxonNode
) treeNode
, activePage
);
72 if(!allEditorsClosed
) {
73 return new Status(IStatus
.WARNING
,
75 TaxonNavigatorLabels
.RELATED_EDITOR_NOT_CLOSED_MESSAGE
);
78 config
= new TaxonDeletionConfigurator();
80 if (treeNodes
.size() == 1 ){
81 ITaxonTreeNode treeNode
= treeNodes
.iterator().next();
82 ITaxonTreeNode taxonNode
= treeNode
;
83 if (taxonNode
instanceof Classification
){
84 taxonNode
= CdmApplicationState
.getCurrentAppConfig().getClassificationService().load(taxonNode
.getUuid());
86 taxonNode
= CdmApplicationState
.getCurrentAppConfig().getTaxonNodeService().load(taxonNode
.getUuid());
88 if (taxonNode
== null){
89 MessagingUtils
.informationDialog("Node already deleted", "The taxon node was already deleted. Please reopen the taxon navigator to refresh the view.");
90 return Status
.CANCEL_STATUS
;
93 TaxonNodeDeletionConfigurator configNodes
= new TaxonNodeDeletionConfigurator();
94 if (taxonNode
instanceof Classification
) {
96 if (taxonNode
.hasChildNodes()) {
97 message
= "Do you really want to delete the classification? The tree has children, they will be deleted, too.";
99 message
= "Do you really want to delete the classification?";
101 if (!DeleteConfiguratorDialog
.openConfirm(
102 HandlerUtil
.getActiveShell(event
), "Confirm Deletion",
104 return Status
.CANCEL_STATUS
;
109 if (taxonNode
.hasChildNodes()){
110 DeleteConfiguratorDialog dialog
= new DeleteConfiguratorDialog(
112 HandlerUtil
.getActiveShell(event
),
115 "Do you really want to delete the selected node? It has childnodes, they will be deleted, too.",
116 MessageDialog
.WARNING
, new String
[] { "Delete all children",
117 "Move children to parent node", "Skip" }, 0);
118 int result
= dialog
.open();
121 //delete all children
122 configNodes
.setChildHandling(ChildHandling
.DELETE
);
123 config
.setTaxonNodeConfig(configNodes
);
124 } else if (result
== 1){
126 configNodes
.setChildHandling(ChildHandling
.MOVE_TO_PARENT
);
127 config
.setTaxonNodeConfig(configNodes
);
128 } else if (result
== 2){
129 return Status
.CANCEL_STATUS
;
132 if(!DeleteConfiguratorDialog
.openConfirmWithConfigurator(configNodes
, HandlerUtil
.getActiveShell(event
), "Confirm Deletion", "Do you really want to delete the selected node?")){
133 return Status
.CANCEL_STATUS
;
135 config
.setTaxonNodeConfig(configNodes
);
139 return Status
.OK_STATUS
;
143 public AbstractOperation
prepareOperation(ExecutionEvent event
) {
144 return new RemotingDeleteTaxonNodeOperation(event
.getTrigger(),
151 public void onComplete() {